Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Killing a timer in a dialog from main window?

DiskDiskDiskDisk Member Posts: 3
Help people.
How can I kill a timer that is in dialog window from a main window ?
Code sample:
[code]
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;
}
[/code]
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..

Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    [color=Blue]Main problem here is that DialogBox() API enters its own message loop (modal dialog), so your code in main window proc is not accessible until dialog is done. You can try to make a modeless dialog box with CreateDialog(), but then you need the IsDlgMessage() in the main loop.[/color]
  • DiskDiskDiskDisk Member Posts: 3
    ok thanks.. now all works fine..
    but what IsDlgMessage() doing ?
    is it neccessary ?

    "Call this member function to determine whether the given message is intended for a modeless dialog box; if it is, this function processes the message."

    It works great without calling this function.. do i need it anyway ?
Sign In or Register to comment.