|
|
Create a region using CreatePolygonRgn and then use PtInRegion to determine whether the point is in the region. Win32 API or MFC CRgn... your choice.
onwards and upwards...
|
|
|
|
|
I'm working on a hobby war simulation game in Visual C++ .NET and am having a problem with multithreading. I don't know much about it, and am wondering if there may even be a better solution than multithreading for this problem:
The game is running in an MDI parent with multiple forms. A user wants to move units from one city to another; The Main Menu child tells the Map child that it needs the user to select a target city. I want the Main Menu to pause its code processing at that point until the user selects a city, which then is passed back to the Main Menu so it may continue processing.
The problem I am running into is this: The player selects an invalid city to move to -- I want to generate another MDI child that acts as a popup to inform them they can't move there and what their options are. When I do this (as shown in the code below) the new Popup child flashes on the screen for just a moment then disappears. I am guessing that this is because the Military_MoveThread is ending, so it closes anything initialized in the thread, but I am not really sure why it does this. I want the thread to end but the new MDI child popup to remain on the screen. I've tried running the popup as a new thread but it does exactly the same thing.
Here is basically what I have:
<br />
void InitiateMove()<br />
{<br />
ThreadStart *myThreadDelegate = new ThreadStart(this, Military_MoveThread);<br />
trd = new Thread(myThreadDelegate);<br />
trd->IsBackground = true;<br />
trd->Start();<br />
}<br />
void Military_MoveThread()<br />
{<br />
theClient->EnableMap();<br />
<br />
theMap->iTargetMode = 1;<br />
<br />
while( theMap->iTargetMode == 1 )<br />
{<br />
Thread::Sleep( 100 );<br />
}<br />
<br />
if( theClient->iTargetCity == -1 )<br />
{<br />
theClient->EnableAllForms();<br />
theMap->EnableAllCities();<br />
return;<br />
}<br />
<br />
if( theClient->PlayerOwnsCity( theClient->iTargetCity ) == false &&<br />
theClient->clientCityButtons[ theClient->iTargetCity ]->iOwner != -1 )<br />
{<br />
Popup( String::Concat( S"Master ", theClient->Name, S", that city does not belong to us!" ) );<br />
theMap->EnableAllCities();<br />
theClient->iTargetCity = -1;<br />
return;<br />
}<br />
<br />
}<br />
void Popup( String *advise )<br />
{<br />
<br />
confirmPopup->RequestConfirm( advise );<br />
}
My question is: Is there an easier way for the main menu child to wait on the map for data? If not, what do I need to do to keep the confirmPopup child from disappearing right after it appears?
Thanks,
Cyric
|
|
|
|
|
Hi guys,
This is my problem. I created a win32 dll file with a dialog box on it(created using Insert>Resource>Dialog Box) and called it using the DialogBox(..) command inside the dll.
Now I tried loading the dll file from a new application but then the dialog box doesnt pop up. lemme know as to what i'm doing wrong in here. Should I copy the .res, .rc file that was used in the dll to the directory where i am loading the dll ?
Also I tried returning a number inside the function that pops up the Dialogbox. I found that when i load the dll the number is returned but no dialog box pops up
Thanks in advance
|
|
|
|
|
Can you post the code here? This might help us
|
|
|
|
|
Hi.... i had created a dialog box using insert > Resource > Dialog and this is the code
#include "stdafx.h"
#include "windows.h"
#include "resource.h"
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(wParam)
{
case IDA:
// TO DO
EndDialog(hWndDlg, 0);
return TRUE;
case IDB:
// TO DO
EndDialog(hWndDlg, 0);
return TRUE;
}
case WM_CLOSE:
EndDialog(hWndDlg, 0);
return TRUE;
break;
}
return FALSE;
}
int __declspec(dllexport) brow()
{
DialogBox((HINSTANCE)GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DLGFIRST), NULL, (DLGPROC)DlgProc);
return 432; // to test whether the function is called
}
BOOL APIENTRY DllMain( HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved )
{
return TRUE;
}
|
|
|
|
|
I am experiencing the same problem!!
I've searched over the net but found nothing other than the same question asked on several other sites.(no answers).
|
|
|
|
|
i need to convert a file path like this
C:\Program Files\Somedir\somefile.exe
into
somefile.exe
in other words get the short file name of it,
im making my own process viewer, i tried putting the path into a CString
and doing
pName.Right( pName.ReverseFind( '\\' ) )
and also tried
pName.Right( pName.Find( '\\' ) )
but neither way worked,
i would like to get this thing done today.
also what is the best function and most effective function to a kill a process?
|
|
|
|
|
Try this
pName.Right(pName.GetLength() - (pName.ReverseFind( '\\' )+1) );
|
|
|
|
|
There is always the CRT function _splitpath.
onwards and upwards...
|
|
|
|
|
thanks guys, but i still need to know the best way to kill the process
|
|
|
|
|
Hello all gurus..
I have a program that takes file name and send it to printer.
The program uses powerpoint, ms word, ms excel automation to print all powerpoint files, doc files, and excel files.
The program runs perfectly right before I change the setting of the project.
I changed the project setting as followed,
<br />
c++ -> preprocessor -> WIN32;_WINDOWS;_DEBUG,_UNICODE, UNICODE, _WIN32_WINNT=0X0400;<br />
c++ -> Struct Member Alignment -> 1 Byte (/Zp1)<br />
link -> Advance -> Entry Point -> wWinMainCRTStartup<br />
Before I print any file, I opened all three powerpoint, ms word and ms excel application. And then close all three application after all files get printed.
here the code how I open and close three applications.
<br />
void myApp::OpenApps(bool &open)<br />
{<br />
CoInitialize(NULL);<br />
if(!app.CreateDispatch(L"Excel.Application"))<br />
{<br />
AfxMessageBox(L"Could not create Excel Application Object.");<br />
open = false;<br />
}<br />
else<br />
{<br />
app.put_Visible(TRUE);
app.put_WindowState(2);
app.put_UserControl(TRUE);
<br />
lpDisp = app.get_Workbooks();
ASSERT (lpDisp);<br />
books.AttachDispatch(lpDisp);
}<br />
if(!mswApp.CreateDispatch(L"Word.Application"))<br />
{<br />
open = false; <br />
}<br />
else <br />
{ <br />
mswApp.put_Visible(TRUE);<br />
mswApp.put_WindowState(2);
mswDocs = mswApp.get_Documents();<br />
<br />
}<br />
if(!pptApp.CreateDispatch (L"Powerpoint.Application"))<br />
{<br />
open = false;<br />
}<br />
else<br />
{ <br />
pptApp.put_Visible(1);<br />
pptApp.put_WindowState(2); <br />
}<br />
}<br />
void myApp::CloseApps(void)<br />
{ <br />
app.Quit();<br />
app.ReleaseDispatch();<br />
app=NULL;<br />
<br />
mswApp.Quit(covFalse,covOptional,covOptional); <br />
mswDocs.ReleaseDispatch();<br />
mswApp.ReleaseDispatch(); <br />
mswApp = NULL;<br />
<br />
pptApp.Quit(); <br />
pptApp.ReleaseDispatch ();<br />
<br />
pptApp = NULL;<br />
<br />
CoUninitialize();
}<br />
<br />
Let's only talk about printing MS Word file.
After the project setting got changed, only the first document file get printed and but it has error when opening the next document. here the code to print the word document files.
<br />
void CClientJob::PrintWithMsWord(CString fname)<br />
{<br />
VARIANT tv;<br />
tv.vt = VT_BSTR;<br />
tv.bstrVal = fname.AllocSysString();
CDocument0 doc;<br />
<br />
doc = mswDocs.Open(&tv,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional);<br />
SetMSWordPageSetup(doc);<br />
doc.PrintOut(covFalse,covOptional,covOptional,covOptional,covOptional,covOptional,<br />
covOptional, covOptional,covOptional,covOptional,covOptional,covOptional,<br />
covOptional,covOptional,covOptional,covOptional,covOptional,covOptional);<br />
doc.Close(covFalse,covOptional,covOptional);<br />
<br />
mswDocs = NULL;<br />
}
I know this is something to do with my project setting coz it has no problem before.
I need to have that setting also. I can't change the setting and need to print office files too.
Am I missing any other setting?
thank you
|
|
|
|
|
I don't think it is due to your setting that causes your problem.
Try to place in the exception catch in your codes and see if it helps. It always better to have these try .. catch around.
try
{
..
}
catch(_com_error e)
{
TRACE(_T("Error: %08x %s\n"), e.Error(), e.ErrorMessage());
_bstr_t bstrDesc = e.Description();
if(bstrDesc.length() > 0)
{
TRACE(_T("Description: %s\n"), static_cast<LPTSTR>(desc));
}
}
hope this helps
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
I'm writing a 3D modeling app using MFC MDI framework. I'm trying to get a dockable dialog bar with a Treeview control to display a list of objects within the project's workspace, but I can't seem to access the treeview for initialization or manipulation. I've created a dialog template in the resource editor with a treeview control in the dialog. I then created a class for the dialog box/bar, and assigned a variable to the treecontrol (m_tree). I then declared the entire dialogbar in CMainFrame. The dialog bar loads, and is dockable, but I can't seem to initialize it anywhere. I've tried initilizing it in the Dialog class OnCreate, and OnInitDialog, but it has no effect. I also tried to apply afx_msg overrides to the CMainFrame class, but I get an error saying I can't call a static function (something along those lines). Does anyone know how I can get this thing running, or know of any good articles/tutorials that deal with a dockable treeview in an MDI application?
|
|
|
|
|
|
I am using VisualC++ to write a multimedia program using COM. I get link errors when I compile my program stating that CLSID_FilterGraph and IID_IGraphBuilder are unresolved externals. Here is the code they appear in:
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder,
(void**)&pBuilder);
The code is straighforward and the CLSID_FilterGraph can even be found using search in the file uuids.h. When I include it the link errors remain. I made sure to include DirectX headers and libraries in the link paths for VisualC++. Here is a list of all of the headers and defines I have included:
#define _WIN32_DCOM
#include <dshow.h>
#include<uuids.h>
#include <commdlg.h>
#include <commctrl.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#ifndef GetWindowLongPtr
#define GetWindowLongPtrA GetWindowLongA
#define GetWindowLongPtrW GetWindowLongW
#ifdef UNICODE
#define GetWindowLongPtr GetWindowLongPtrW
#else
#define GetWindowLongPtr GetWindowLongPtrA
#endif // !UNICODE
#endif // !GetWindowLongPtr
#ifndef SetWindowLongPtr
#define SetWindowLongPtrA SetWindowLongA
#define SetWindowLongPtrW SetWindowLongW
#ifdef UNICODE
#define SetWindowLongPtr SetWindowLongPtrW
#else
#define SetWindowLongPtr SetWindowLongPtrA
#endif // !UNICODE
#endif // !SetWindowLongPtr
#ifndef GWLP_USERDATA
#define GWLP_USERDATA (-21)
#endif
I realize that some of these defines and included are irrelavent. I copied everything from the example files (which worked) in the way of headers and I thought I should show you what I had tried. I've been staring at this problem for a day now and any help would be greatly appreciated.
Thanks
Jeff
|
|
|
|
|
Hello!.. this code:
<br />
#include <list><br />
<br />
struct ElementLista {<br />
string jid;<br />
string nombre;<br />
string subscripcion;<br />
} elem;<br />
<br />
typedef std::list<ElementLista> Lista;<br />
gives me the following errors:
c:\program files\microsoft visual studio\vc98\include\memory(16) : error C2061: syntax error : identifier 'THIS_FILE'
c:\program files\microsoft visual studio\vc98\include\memory(17) : error C2091: function returns function
c:\program files\microsoft visual studio\vc98\include\memory(17) : error C2809: 'operator new' has no formal parameters
c:\program files\microsoft visual studio\vc98\include\memory(20) : error C2954: template definitions cannot nest
any ideas? thanks!
|
|
|
|
|
#include <list>
#include <string>
struct ElementLista {
std::string jid;
std::string nombre;
std::string subscripcion;
} ;
typedef std::list< ElementLista> Lista;
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
sorry, i get the same errors.
i' using vc++6.0
|
|
|
|
|
That makes sense. I compiled in VC6 before posting that code so it will compile.
I tried many variations on the code you posted and could not reproduce the compiler errors you posted. It is likely your error is in another place in your code.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
damn
it's the only place i use stl.
if i comment that out, everything else works
|
|
|
|
|
Ok, went back and looked at your original post more closely. THIS_FILE provides a clue so I put my code in a .cpp file and produced the errors you reported.
Then put the declarations back into a header file and instantiate a Lista variable in the .cpp file. No compile errors.
Give it a try.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
i need the 'Lista' as an atribute of a class.
#include <list>
#include <string>
struct ElementLista {
std::string jid;
std::string nombre;
std::string subscripcion;
} elem;
typedef std::list< ElementLista> Lista;
class CProtocolo
{
public:
Lista ListaContactos;
..
.
.
};
|
|
|
|
|
struct ElementLista {
std::string jid;
std::string nombre;
std::string subscripcion;
} elem;
That declares a variable named "elem" of type ElementLista at file scope which i don't think you want. Plus it can cause compile errors due to redefinition of the variable.
Using the type for a class member variable is fine.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
#include < list > before the MFC macros(*) kick in.
(*)
<small>#ifdef _DEBUG<br />
#define new DEBUG_NEW<br />
#undef THIS_FILE<br />
static char THIS_FILE[] = __FILE__;<br />
#endif</small>
---
"Man will never be free until the last king is strangled with the entrails of the last priest". -- Denis Diderot
|
|
|
|
|