Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Modeless Dialog not moving

Modeless Dialog not moving

Scheduled Pinned Locked Moved C / C++ / MFC
json
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KnaveR777
    wrote on last edited by
    #1

    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); }

    D B J 3 Replies Last reply
    0
    • K KnaveR777

      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); }

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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

      K 1 Reply Last reply
      0
      • D David Crow

        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

        K Offline
        K Offline
        KnaveR777
        wrote on last edited by
        #3

        Thnx for this suggestion, I was wondering how GetMessage could could possibly be knowing that the msg was for my dialog... this answered that. However, I am still unable to move the dialog, any suggestions?

        1 Reply Last reply
        0
        • K KnaveR777

          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); }

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          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; }

          K 1 Reply Last reply
          0
          • B Blake Miller

            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; }

            K Offline
            K Offline
            KnaveR777
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • K KnaveR777

              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); }

              J Offline
              J Offline
              Jose Lamas Rios
              wrote on last edited by
              #6

              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/[^]

              K 1 Reply Last reply
              0
              • J Jose Lamas Rios

                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/[^]

                K Offline
                K Offline
                KnaveR777
                wrote on last edited by
                #7

                DefDlgProc will cause infinite recursion if i use it :(

                B 1 Reply Last reply
                0
                • K KnaveR777

                  DefDlgProc will cause infinite recursion if i use it :(

                  B Offline
                  B Offline
                  Blake V Miller
                  wrote on last edited by
                  #8

                  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.

                  K 1 Reply Last reply
                  0
                  • B Blake V Miller

                    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.

                    K Offline
                    K Offline
                    KnaveR777
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups