diskdisk
June 7th, 2009, 08:09 PM
Help people.
How can I kill a timer that is in dialog window from a main window ?
Code sample:
BOOL CALLBACK
PreferencesDlgProc (HWND hdlg, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
{
}
break;
case WM_COMMAND:
{
if (wParam == SET_TIMER)
{
SetTimer(hdlg,1,10000,NULL);
}
}
break;
case WM_TIMER:
{
if (wParam == 1)
{
KillTimer(hdlg,1);
MessageBox(hdlg, "Test", "Message", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
}
break;
default:
return FALSE;
}
return TRUE;
}
LRESULT CALLBACK
WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_USER:
{
switch(lParam)
{
case WM_RBUTTONDOWN:
GetCursorPos(&p);
SetForegroundWindow(hwnd);
retCmd=TrackPopupMenu(hPopupMenu, TPM_RETURNCMD, p.x, p.y, 0, hwnd, NULL);
switch(retCmd)
{
case ID_OPEN_DIALOG:
{
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_PREFERENCES), hwnd, PreferencesDlgProc);
}
break;
case ID_CANCEL_TIMER:
{
KillTimer(hdlg,1);
}
break;
case ID_CONTEXT_EXIT:
PostMessage(hwnd, WM_DESTROY, 0, 0);
break;
default:
break;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
This is not the code of the program. its just a sample. The point of the sample is when ID_CANCEL_TIMER function activated in the main window i want it to kill a timer in the dialog window. The problem is when i'm trying to compile this prog the compiler says that the 'hdlg' undeclared. I know that hdlg undeclared in the main window... it's declared in the dialog window.. but now, how to send a kill timer message to the dialog from within the main window ?
thanks..
How can I kill a timer that is in dialog window from a main window ?
Code sample:
BOOL CALLBACK
PreferencesDlgProc (HWND hdlg, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
{
}
break;
case WM_COMMAND:
{
if (wParam == SET_TIMER)
{
SetTimer(hdlg,1,10000,NULL);
}
}
break;
case WM_TIMER:
{
if (wParam == 1)
{
KillTimer(hdlg,1);
MessageBox(hdlg, "Test", "Message", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
}
break;
default:
return FALSE;
}
return TRUE;
}
LRESULT CALLBACK
WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_USER:
{
switch(lParam)
{
case WM_RBUTTONDOWN:
GetCursorPos(&p);
SetForegroundWindow(hwnd);
retCmd=TrackPopupMenu(hPopupMenu, TPM_RETURNCMD, p.x, p.y, 0, hwnd, NULL);
switch(retCmd)
{
case ID_OPEN_DIALOG:
{
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_PREFERENCES), hwnd, PreferencesDlgProc);
}
break;
case ID_CANCEL_TIMER:
{
KillTimer(hdlg,1);
}
break;
case ID_CONTEXT_EXIT:
PostMessage(hwnd, WM_DESTROY, 0, 0);
break;
default:
break;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
This is not the code of the program. its just a sample. The point of the sample is when ID_CANCEL_TIMER function activated in the main window i want it to kill a timer in the dialog window. The problem is when i'm trying to compile this prog the compiler says that the 'hdlg' undeclared. I know that hdlg undeclared in the main window... it's declared in the dialog window.. but now, how to send a kill timer message to the dialog from within the main window ?
thanks..