Modeless Dialog not moving
-
Hey all Ive created a API modeless dialog inside of a DLL, and is created whenever the calling program calls the appropriate exported function. In a past thread that i posted, this dialog would cause the application to lock up with the not responding dialog. Thanks to someones tip to use DefWindowProc() I can now get the dialog to work (pops up, and close button properly closes when clicked), only it appears to not be responding to move messages (the message called when i would like to drag the dialog around on the screen). From DLLMain:
hDLL = hinstDLL;
The exported function that starts the dialog://mWnd is handle to main window of calling program //aWnd is handle to active window (programm calling is MDI) int __stdcall WINAPI x(HWND mWnd, HWND aWnd, char *data, char *params, BOOL show, BOOL nopause){ MSG msg; hDlg = CreateDialog(hDLL, MAKEINTRESOURCE(IDD_DIALOG1), mWnd, (DLGPROC)DlgCallBack); ShowWindow(hDlg,SW_SHOW); while (GetMessage(&msg, NULL, 0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } }
The DLGPROC:LRESULT CALLBACK x(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){ switch (uMsg) { case WM_COMMAND: switch(wParam){ case IDOK: DestroyWindow(hDlg); return TRUE; } break; case WM_DESTROY: DestroyWindow(hDlg); PostQuitMessage(0); return TRUE; } return DefWindowProc(hwnd, uMsg, wParam, lParam); }
-
Hey all Ive created a API modeless dialog inside of a DLL, and is created whenever the calling program calls the appropriate exported function. In a past thread that i posted, this dialog would cause the application to lock up with the not responding dialog. Thanks to someones tip to use DefWindowProc() I can now get the dialog to work (pops up, and close button properly closes when clicked), only it appears to not be responding to move messages (the message called when i would like to drag the dialog around on the screen). From DLLMain:
hDLL = hinstDLL;
The exported function that starts the dialog://mWnd is handle to main window of calling program //aWnd is handle to active window (programm calling is MDI) int __stdcall WINAPI x(HWND mWnd, HWND aWnd, char *data, char *params, BOOL show, BOOL nopause){ MSG msg; hDlg = CreateDialog(hDLL, MAKEINTRESOURCE(IDD_DIALOG1), mWnd, (DLGPROC)DlgCallBack); ShowWindow(hDlg,SW_SHOW); while (GetMessage(&msg, NULL, 0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } }
The DLGPROC:LRESULT CALLBACK x(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){ switch (uMsg) { case WM_COMMAND: switch(wParam){ case IDOK: DestroyWindow(hDlg); return TRUE; } break; case WM_DESTROY: DestroyWindow(hDlg); PostQuitMessage(0); return TRUE; } return DefWindowProc(hwnd, uMsg, wParam, lParam); }
KnaveR wrote: while (GetMessage(&msg, NULL, 0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } Shouldn't this be:
while (GetMessage(&msg, NULL, 0,0))
{
if (! IsWindow(hDlg) || ! IsDialogMessage(hDlg, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
KnaveR wrote: while (GetMessage(&msg, NULL, 0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } Shouldn't this be:
while (GetMessage(&msg, NULL, 0,0))
{
if (! IsWindow(hDlg) || ! IsDialogMessage(hDlg, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Hey all Ive created a API modeless dialog inside of a DLL, and is created whenever the calling program calls the appropriate exported function. In a past thread that i posted, this dialog would cause the application to lock up with the not responding dialog. Thanks to someones tip to use DefWindowProc() I can now get the dialog to work (pops up, and close button properly closes when clicked), only it appears to not be responding to move messages (the message called when i would like to drag the dialog around on the screen). From DLLMain:
hDLL = hinstDLL;
The exported function that starts the dialog://mWnd is handle to main window of calling program //aWnd is handle to active window (programm calling is MDI) int __stdcall WINAPI x(HWND mWnd, HWND aWnd, char *data, char *params, BOOL show, BOOL nopause){ MSG msg; hDlg = CreateDialog(hDLL, MAKEINTRESOURCE(IDD_DIALOG1), mWnd, (DLGPROC)DlgCallBack); ShowWindow(hDlg,SW_SHOW); while (GetMessage(&msg, NULL, 0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } }
The DLGPROC:LRESULT CALLBACK x(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){ switch (uMsg) { case WM_COMMAND: switch(wParam){ case IDOK: DestroyWindow(hDlg); return TRUE; } break; case WM_DESTROY: DestroyWindow(hDlg); PostQuitMessage(0); return TRUE; } return DefWindowProc(hwnd, uMsg, wParam, lParam); }
Maybe you should try patching up your switch for WM_COMMAND, considering this note in MSDN: The WM_COMMAND message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated. wParam The high-order word specifies the notification code if the message is from a control. If the message is from an accelerator, this value is 1. If the message is from a menu, this value is zero. The low-order word specifies the identifier of the menu item, control, or accelerator. You completely switched on wParam instead of breaking out the hiword and loword :doh:
**switch( LOWORD(wParam) ){** case IDOK: DestroyWindow(hDlg); return TRUE; }
-
Maybe you should try patching up your switch for WM_COMMAND, considering this note in MSDN: The WM_COMMAND message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated. wParam The high-order word specifies the notification code if the message is from a control. If the message is from an accelerator, this value is 1. If the message is from a menu, this value is zero. The low-order word specifies the identifier of the menu item, control, or accelerator. You completely switched on wParam instead of breaking out the hiword and loword :doh:
**switch( LOWORD(wParam) ){** case IDOK: DestroyWindow(hDlg); return TRUE; }
Thnx for pointing that out, but it seems something else might be amiss. I just tried putting my "return DefWindowProc(hwnd, uMsg, wParam, lParam);" statement at the top so that all messages would be handled by the default window proc, thinking that this would allow my dialog to perform basic dragable behavior, but it is still not budging. One other thing i noticed is that if i use my hDlg, which i get from CreateDialog(), inside the DefWindowProc an exception is thrown. Am I wrong in thinking that this should work, as hDlg works with calls to DestroyWindow? I also would like to thank you all for your help, I have spent many days trying to track down what I am doing wrong.
-
Hey all Ive created a API modeless dialog inside of a DLL, and is created whenever the calling program calls the appropriate exported function. In a past thread that i posted, this dialog would cause the application to lock up with the not responding dialog. Thanks to someones tip to use DefWindowProc() I can now get the dialog to work (pops up, and close button properly closes when clicked), only it appears to not be responding to move messages (the message called when i would like to drag the dialog around on the screen). From DLLMain:
hDLL = hinstDLL;
The exported function that starts the dialog://mWnd is handle to main window of calling program //aWnd is handle to active window (programm calling is MDI) int __stdcall WINAPI x(HWND mWnd, HWND aWnd, char *data, char *params, BOOL show, BOOL nopause){ MSG msg; hDlg = CreateDialog(hDLL, MAKEINTRESOURCE(IDD_DIALOG1), mWnd, (DLGPROC)DlgCallBack); ShowWindow(hDlg,SW_SHOW); while (GetMessage(&msg, NULL, 0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } }
The DLGPROC:LRESULT CALLBACK x(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){ switch (uMsg) { case WM_COMMAND: switch(wParam){ case IDOK: DestroyWindow(hDlg); return TRUE; } break; case WM_DESTROY: DestroyWindow(hDlg); PostQuitMessage(0); return TRUE; } return DefWindowProc(hwnd, uMsg, wParam, lParam); }
KnaveR wrote: return DefWindowProc(hwnd, uMsg, wParam, lParam); Shouldn't this be
return Def**Dlg**Proc(hwnd, uMsg, wParam, lParam);
instead? -- jlr http://jlamas.blogspot.com/[^] -
KnaveR wrote: return DefWindowProc(hwnd, uMsg, wParam, lParam); Shouldn't this be
return Def**Dlg**Proc(hwnd, uMsg, wParam, lParam);
instead? -- jlr http://jlamas.blogspot.com/[^] -
Given this note in MSDN in relation to possessing a DialogProc: You should use the dialog box procedure only if you use the dialog box class for the dialog box. This is the default class and is used when no explicit class is specified in the dialog box template. Although the dialog box procedure is similar to a window procedure, it must not call the DefWindowProc function to process unwanted messages. Unwanted messages are processed internally by the dialog box window procedure. Have you just tried returning FALSE instead of other processing, as per this note: Typically, the dialog box procedure should return TRUE if it processed the message, and FALSE if it did not. If the dialog box procedure returns FALSE, the dialog manager performs the default dialog operation in response to the message. Maybe with the improved handler (using the IsDialogMessage) you don't need to call DefWindowProc. Also, there is this note: If the dialog box procedure processes a message that requires a specific return value, the dialog box procedure should set the desired return value by calling SetWindowLong(hwndDlg, DWL_MSGRESULT, lResult) immediately before returning TRUE. Note that you must call SetWindowLong immediately before returning TRUE; doing so earlier may result in the DWL_MSGRESULT value being overwritten by a nested dialog box message.
-
Given this note in MSDN in relation to possessing a DialogProc: You should use the dialog box procedure only if you use the dialog box class for the dialog box. This is the default class and is used when no explicit class is specified in the dialog box template. Although the dialog box procedure is similar to a window procedure, it must not call the DefWindowProc function to process unwanted messages. Unwanted messages are processed internally by the dialog box window procedure. Have you just tried returning FALSE instead of other processing, as per this note: Typically, the dialog box procedure should return TRUE if it processed the message, and FALSE if it did not. If the dialog box procedure returns FALSE, the dialog manager performs the default dialog operation in response to the message. Maybe with the improved handler (using the IsDialogMessage) you don't need to call DefWindowProc. Also, there is this note: If the dialog box procedure processes a message that requires a specific return value, the dialog box procedure should set the desired return value by calling SetWindowLong(hwndDlg, DWL_MSGRESULT, lResult) immediately before returning TRUE. Note that you must call SetWindowLong immediately before returning TRUE; doing so earlier may result in the DWL_MSGRESULT value being overwritten by a nested dialog box message.
You are Da Man!!! A million thnx!!! Have you just tried returning FALSE instead of other processing, as per this note... Maybe with the improved handler (using the IsDialogMessage) you don't need to call DefWindowProc. Originally I was returning FALSE, but was not using IsDialogMessage. Hope that this helps someone in the future.