Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Start Win32 dialog from Qt Application

    General and Desktop
    2
    5
    1104
    Loading More Posts
    • 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.
    • OlexandrLynda
      OlexandrLynda last edited by

      I need some help with Win32. I`m working in VS2015.
      my win32 dialog class:

      class AddProcedureType
      {
      public:
          AddProcedureType();
          ~AddProcedureType();
          static BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
      
      private:
          HWND hDialog;
          static AddProcedureType *ptr;
          void Cls_OnClose(HWND hwnd);
          BOOL Cls_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam);
          void Cls_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify);
      };
      

      And I want to call that window from Qt Application:

      void getAddProcedureTypeDialog(WId id)
      {
          AddProcedureType dlg;
          HINSTANCE h = GetModuleHandle(NULL);
          std::cout << "Error code : ";
          std::cout << DialogBox(h, MAKEINTRESOURCE(IDD_MAIN), (HWND)id, dlg.DlgProc);
          std::cout << "\nGetLastError() : " << GetLastError() << std::endl;
          std::cout << "CommDlgExtendedError() : " << CommDlgExtendedError() << std::endl;
      }
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent)
      {
          getAddProcedureTypeDialog(this->winId());
      }
      

      But when I ran program it shows only Qt App without win32 dialog.
      And out is :

      Error code : -1
      GetLastError() : 0
      CommDlgExtendedError() : 0
      

      P.S. I know about Qt Dialogs, but in this case I need Win32 dialog.

      1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by Chris Kawa

        Hi, welcome to devnet.

        I tried out a stripped down version of your code and it works fine. Could you try it on your side too?

        INT_PTR CALLBACK DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
        {
            if(uMsg == WM_CLOSE)
            {
                EndDialog(hwndDlg, 0);
                return TRUE;
            }
            return FALSE;
        }
        
        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent)
        {
            HINSTANCE h = GetModuleHandle(NULL);
            DialogBox(h, MAKEINTRESOURCE(IDD_MAIN), (HWND)winId(), DialogProc);
        }
        
        OlexandrLynda 1 Reply Last reply Reply Quote 1
        • OlexandrLynda
          OlexandrLynda @Chris Kawa last edited by

          @Chris-Kawa Are you using VS 2015?

          and my dlgProc is :

          BOOL CALLBACK AddProcedureType::DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
          {
          	switch (message)
          	{
          		HANDLE_MSG(hWnd, WM_CLOSE, ptr->Cls_OnClose);
          		HANDLE_MSG(hWnd, WM_INITDIALOG, ptr->Cls_OnInitDialog);
          		HANDLE_MSG(hWnd, WM_COMMAND, ptr->Cls_OnCommand);
          	}
          	return FALSE;
          }
          
          1 Reply Last reply Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators last edited by

            Are you using VS 2015?

            Yes.

            I wanted you to try the simpler example without extra classes and indirections to see if it's a problem in your code or more general.

            OlexandrLynda 1 Reply Last reply Reply Quote 0
            • OlexandrLynda
              OlexandrLynda @Chris Kawa last edited by

              @Chris-Kawa My mentor helped me, the problem was that I need to include resource.rc file to project.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post