Getting Window Handle?
Does anyone know of a way to get the window handle of the program (something like GetHandleModule to get the instance)
???
Thanks..
If you haven''t saved off your window handle during application startup you can call FindWindow(Ex) to enumerate windows until you find the one you are looking for (or even EnumWindows).
HTH,
-mordell
__________________________________________
Yeah, sure... we are laughing WITH you ...
Yeah, sure... we are laughing WITH you ...
Thanks..
but those functions require some knowledge of the window (class name, etc)
What I''m trying to write is to display a messagebox but without knowledge of the main window so it can be used in any program.
Passing NULL is fine but I would like it to be tied to the program when multithreading comes into issue.
but those functions require some knowledge of the window (class name, etc)
What I''m trying to write is to display a messagebox but without knowledge of the main window so it can be used in any program.
Passing NULL is fine but I would like it to be tied to the program when multithreading comes into issue.
No problemo..
Your thread proc has a LPVOID * param that can be used to pass in the window handle from the parent thread (or other params).
If I have multiple params I''m passing into the thread proc, I usually have some sort of structure like:
struct thread_proc_params {
HWND hwnd;
int param1;
float param2;
object *param3;
};
anyways...the thread function has all it needs to do its job.

HTH,
-mordell
__________________________________________
Yeah, sure... we are laughing WITH you ...
Yeah, sure... we are laughing WITH you ...
??? Mordell, could you please explain furthur?
I''m trying to do this
MessageBox(THIS_HANDLE, "Blah", "Blah", MB_OK);
How do I get THIS_HANDLE that is the main window handle?
Thanks..
I''m trying to do this
MessageBox(THIS_HANDLE, "Blah", "Blah", MB_OK);
How do I get THIS_HANDLE that is the main window handle?
Thanks..
Gads! I don''t know where I was coming from!! I totally missed the entire point of your post...for some reason I thought it had something to do with you having a thread running off somewhere and needing multiple parameters (including window handle)!!
Unless you have saved your application window handle somewhere, and pass it to whatever modules might need it, I don''t know how you would get your main window handle without knowing something about it in advance...my apologies!
Here''s the post where I went off on a tangent regarding the multiple thread issue:
If I understand correctly, you have a worker thread that is off doing something right? Some sort of background processing?
Somewhere in your application code, you spawn this thread...maybe its in response to interaction with a UI element, maybe its buried down in some logic code somehere...whatever the case may be.
But, somewhere, you have code similar to this:
thread = CreateThread(0L, 0, (LPTHREAD_START_ROUTINE)threadProc, (LPVOID)hwnd, 0, &thread_id);
The LPVOID param in this instance happens to be my application window handle (from within my WNDPROC). The casting may be necessary to avoid compiler objections.
Now, somewhere you have threadProc defined:
void threadProc(LPVOID pVoid) {
//:
//: our client window
//:
HWND hwnd = (HWND)pVoid;
xfile_generator xcc;
xcc.compile( hwnd );
}
Notice, I had to cast the pVoid param back into an HWND so that I could use it for whatever....maybe I report messages back via MessageBox, maybe I post custom messages back to the application to update status bars or progress windows, etc..
Now, I decide that I need to be able to pass multiple paramters to my threadProc..maybe add a filename to my xfile compiler, so I do something like this:
typedef struct XFILE_PARAMS {
HWND hwnd; //: client window
char filename[255]; //: input filename
} XFILE_PARAMS;
My call to CreateThread becomes something like this:
static XFILE_PARAMS xParams;
memset(&xParams, 0L, sizeof( XFILE_PARAMS ));
//: setup params
//:
xParams.hwnd = hwnd;
strcpy(xParams.filename, "somenamefilename");
thread = CreateThread(0L, 0, (LPTHREAD_START_ROUTINE)threadProc, (LPVOID)&xParams, 0, &thread_id);
My threadProc routine now looks something like this:
void threadProc(LPVOID pVoid) {
XFILE_PARAMS *xParams = (XFILE_PARAMS *)pVoid ;
xfile_generator xcc;
xcc.compile( xParams->hwnd, xParams->filename );
}
Just build your structures to include whatever parameter information you might need!

HTH,
-mordell
__________________________________________
Yeah, sure... we are laughing WITH you ...
Yeah, sure... we are laughing WITH you ...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement