Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Start Win32 dialog from Qt Application
Forum Updated to NodeBB v4.3 + New Features

Start Win32 dialog from Qt Application

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.4k 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.
  • OlexandrLyndaO Offline
    OlexandrLyndaO Offline
    OlexandrLynda
    wrote on last edited by
    #1

    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
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      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);
      }
      
      OlexandrLyndaO 1 Reply Last reply
      1
      • Chris KawaC 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);
        }
        
        OlexandrLyndaO Offline
        OlexandrLyndaO Offline
        OlexandrLynda
        wrote on last edited by
        #3

        @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
        0
        • Chris KawaC Online
          Chris KawaC Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          OlexandrLyndaO 1 Reply Last reply
          0
          • Chris KawaC Chris Kawa

            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.

            OlexandrLyndaO Offline
            OlexandrLyndaO Offline
            OlexandrLynda
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved