UnfitElf
December 11th, 2006, 03:54 AM
Hi people,
I have a global HWND variable (gHwnd) which is assigned from a call to CreateWindowEx. I have a timer variable stored in a file which i am reading it. I then create the timer (in the WM_CREATE event) and pass it the gHwnd as the paramater.
The problem is the timer message (im not using a timer proc, but the WM_TIMER message) never gets send to my window.
However, if i pass the timer function the hwnd varibale passed into the windows proc on the WM_CREATE message the timer message is sent to my window.
In short, the gHwnd is not correct or invalid or somthing, why?
Some code will help explane :)
int WINAPI WinMain (... etc
{
INITCOMMONCONTROLSEX init = { sizeof(INITCOMMONCONTROLSEX), ICC_STANDARD_CLASSES };
//ICC_STANDARD_CLASSES | ICC_LISTVIEW_CLASSES };
InitCommonControlsEx(&init);
MSG messages; // Here messages to the application are saved
WNDCLASSEX wincl; // Data structure for the windowclass
// The Window structure
// windows class setup etc..
// Register the window class, and if it fails quit the program
if (!RegisterClassEx (&wincl))
return 0;
// gHwnd Assigned here!
// The class is registered, let's create the program
gHwnd = CreateWindowEx (
0, // Extended possibilites for variation
szClassName, // Classname
"CheckIt v2.0", // Title Text
WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, //WS_OVERLAPPEDWINDOW, // default window
CW_USEDEFAULT, // Windows decides the position
CW_USEDEFAULT, // where the window ends up on the screen
650, // The programs width
270, // and height in pixels
HWND_DESKTOP, // The window is a child-window to desktop
NULL, // No menu
hThisInstance, // Program Instance handler
NULL // No Window Creation data
);
// Run the message loop. It will run until GetMessage() returns 0
while (GetMessage (&messages, NULL, 0, 0))
{
// Translate virtual-key messages into character messages
TranslateMessage(&messages);
// Send message to WindowProcedure
DispatchMessage(&messages);
}
// The program return-value is 0 - The value that PostQuitMessage() gave
return (int)messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) // handle the messages
{
case WM_CREATE:
{
// SetTimer(gHwnd, someValue); // My main window doesn't recieve messages
SetTimer(hwnd, someValue); // Works!!
// Shouldnt gHwnd and hwnd be the same :S ???
}
break;
// etc etc..
The problem is when do i create the timer if i need a valid handle to my main window? Normally my timer creation (along with other stuff is in a function) I dont really want to pass the hwnd to the function as it doesnt make 'natural sence' for the function name etc. (fussy i know lol).
I want my global !! :(
Any help?
I have a global HWND variable (gHwnd) which is assigned from a call to CreateWindowEx. I have a timer variable stored in a file which i am reading it. I then create the timer (in the WM_CREATE event) and pass it the gHwnd as the paramater.
The problem is the timer message (im not using a timer proc, but the WM_TIMER message) never gets send to my window.
However, if i pass the timer function the hwnd varibale passed into the windows proc on the WM_CREATE message the timer message is sent to my window.
In short, the gHwnd is not correct or invalid or somthing, why?
Some code will help explane :)
int WINAPI WinMain (... etc
{
INITCOMMONCONTROLSEX init = { sizeof(INITCOMMONCONTROLSEX), ICC_STANDARD_CLASSES };
//ICC_STANDARD_CLASSES | ICC_LISTVIEW_CLASSES };
InitCommonControlsEx(&init);
MSG messages; // Here messages to the application are saved
WNDCLASSEX wincl; // Data structure for the windowclass
// The Window structure
// windows class setup etc..
// Register the window class, and if it fails quit the program
if (!RegisterClassEx (&wincl))
return 0;
// gHwnd Assigned here!
// The class is registered, let's create the program
gHwnd = CreateWindowEx (
0, // Extended possibilites for variation
szClassName, // Classname
"CheckIt v2.0", // Title Text
WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, //WS_OVERLAPPEDWINDOW, // default window
CW_USEDEFAULT, // Windows decides the position
CW_USEDEFAULT, // where the window ends up on the screen
650, // The programs width
270, // and height in pixels
HWND_DESKTOP, // The window is a child-window to desktop
NULL, // No menu
hThisInstance, // Program Instance handler
NULL // No Window Creation data
);
// Run the message loop. It will run until GetMessage() returns 0
while (GetMessage (&messages, NULL, 0, 0))
{
// Translate virtual-key messages into character messages
TranslateMessage(&messages);
// Send message to WindowProcedure
DispatchMessage(&messages);
}
// The program return-value is 0 - The value that PostQuitMessage() gave
return (int)messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) // handle the messages
{
case WM_CREATE:
{
// SetTimer(gHwnd, someValue); // My main window doesn't recieve messages
SetTimer(hwnd, someValue); // Works!!
// Shouldnt gHwnd and hwnd be the same :S ???
}
break;
// etc etc..
The problem is when do i create the timer if i need a valid handle to my main window? Normally my timer creation (along with other stuff is in a function) I dont really want to pass the hwnd to the function as it doesnt make 'natural sence' for the function name etc. (fussy i know lol).
I want my global !! :(
Any help?