Start Win32 dialog from Qt Application



  • 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.


  • Moderators

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


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

  • Moderators

    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.



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.