Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-2027

Windows: Provide widget style hint to create dialog without system icon but close button in the titlebar

    XMLWordPrintable

Details

    • f4ffe2a2439928992c3f44085e81686d4f911417 (dev, 3.3.2014, 5.4)

    Description

      That's the default configuration for dialogs in most Windows application, but it is not possible to achive that with any combintation of Qt::WindowFlags. Ie. setting only Qt::Dialog on a toplevel dialog with parent results in system icon, "what's this" and close button. OR'ing with Qt::WindowTitleHint removes everything, and adding any other flag also enables the unwanted system menu.

      The following Win32 code creates a window with closing box and without system menu:

      • Set the icon in the class struct to 0
      • Use exStyle WS_EX_DLGMODALFRAME
      • Use Style WS_POPUPWINDOW ( WS_POPUP | WS_BORDER | WS_SYSMENU [! although it does not show])
        #include <windows.h>
        
        LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
        {
            switch (message) 
            {
            case WM_DESTROY:
         PostQuitMessage(0);
         break;
        
            default:
         return DefWindowProc(hWnd, message, wParam, lParam);
            }
            return 0;
        }
        
        int APIENTRY wWinMain(HINSTANCE hInstance,
                HINSTANCE /*hPrevInstance*/,
                LPTSTR    /*lpCmdLine*/,
                int       nCmdShow)
        {
            WNDCLASSEX wcex;
            
            wcex.cbSize = sizeof(WNDCLASSEX); 
            
            wcex.style  = CS_HREDRAW | CS_VREDRAW;
            wcex.lpfnWndProc = (WNDPROC)WndProc;
            wcex.cbClsExtra = 0;
            wcex.cbWndExtra = 0;
            wcex.hInstance = hInstance;
            wcex.hIcon  = NULL;
            wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
            wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
            wcex.lpszMenuName = NULL;
            wcex.lpszClassName = L"qtest";
            wcex.hIconSm = NULL;
            
            ATOM windowClass = RegisterClassEx(&wcex);
        
            HWND hWnd = CreateWindowEx(WS_EX_DLGMODALFRAME,
                (TCHAR*)windowClass, L"Example",
         WS_POPUPWINDOW | WS_CLIPSIBLINGS | WS_DLGFRAME | WS_OVERLAPPED | WS_SIZEBOX, 
                CW_USEDEFAULT, CW_USEDEFAULT, 200, 100, 0, 0, hInstance, 0);
            if (!hWnd)
         return FALSE;
            SendMessage(hWnd, WM_SETICON, 0, 0);
        
            ShowWindow(hWnd, nCmdShow);
            UpdateWindow(hWnd);
        
            MSG msg;
            while (GetMessage(&msg, 0, 0, 0)) {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
            return 0;
        }
        

      Attachments

        1. qtbug2027_demo.zip
          247 kB
        2. qtbug2027.zip
          2 kB

        Issue Links

          Activity

            People

              kleint Friedemann Kleint
              vhilshei Volker Hilsheimer
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: