General controls do not display properly when resizing a window

Introduction:

I am creating a tab with child dialogs as pages.

I have Visual Styles enabled through the #pragma comment. I also called InitCommonControlsEx and #pragma comment( lib, "comctl32.lib" ) .

Initially, when windows load, the dialog and common controls have a corresponding background, see image below:

enter image description here

When resizing things are not so coordinated → the background starts incompatibly noticeably. I will provide a screenshot below:

enter image description here

You can clearly see that checkbox and static control have the wrong background, while it seems to me that the dialog box (created to control the child) has the correct background.

Edited November 24, 2014:

After including controls in group boxes , apparently, there are no problems with painting. My monitor is an old CRT (Samsung SyncMaster 753s), and I have poor eyesight, but again it seems that everything is drawing correctly. The window still flickers from resizing, but I tried everything in my power to fix it.

Question:

How can i fix this?

MY EFFORTS TO SOLVE THIS:

I haven't found anything yet, but I'm still Gogling, typing this question ...

RELATED INFORMATION:

Here are instructions for creating a demo that illustrates the problem:

1.) Create an empty C++ project in Visual Studio ;

2.) add a header file, name it pomocne_funkcije.h and copy / paste the following:

 #include <windows.h> #include <windowsx.h> #include <comutil.h> #include <commctrl.h> #include <stdio.h> #include <vector> #include <ole2.h> #include <string> #include <stdlib.h> #include <locale.h> #include <Uxtheme.h> #pragma comment( linker, "/manifestdependency:\"type='win32' \ name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' \ language='*'\"") #pragma comment( lib, "comctl32.lib") #pragma comment( lib,"Msimg32.lib") #pragma comment( lib, "comsuppw.lib") #pragma comment( lib, "UxTheme.lib") 

3.) Create a dialog box in the resource editor, add checkbox static control.

Set the following for the dialog box:

  • Border: none
  • Management: true
  • Control parent: true
  • Style: child
  • System menu: false

4.) Here is the code for main.cpp :

 #include "pomocne_funkcije.h" static HINSTANCE hInst; // dialog procedure for firts tab INT_PTR CALLBACK Ugovori(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG: { EnableThemeDialogTexture( hDlg, ETDT_ENABLETAB ); } return (INT_PTR)TRUE; } return (INT_PTR)FALSE; } // main window procedure LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { static HWND hDlgFirstTab; // handle to the first page dialog box switch(msg) { case WM_CREATE: { RECT rcClient = {0}; ::GetClientRect( hwnd, &rcClient ); HWND hwndTab = CreateWindowEx( 0, WC_TABCONTROL, L"Ugovori", WS_CHILD | WS_VISIBLE, 10, 10, rcClient.right - rcClient.left - 20, rcClient.bottom - rcClient.top - 63, hwnd, (HMENU)3000, ((LPCREATESTRUCT)lParam)->hInstance, 0 ); TCITEM tci = {0}; tci.mask = TCIF_TEXT; tci.pszText = L" "; TabCtrl_InsertItem( hwndTab, 0, &tci ); // set font so cyrilic symbols can be properly displayed instead of ??? SendMessage( hwnd, WM_SETFONT, (WPARAM)(HFONT)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE ); SendMessage( hwndTab, WM_SETFONT, (WPARAM)(HFONT)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE ); // create page ( dialog box ) hDlgFirstTab = CreateDialog( ((LPCREATESTRUCT)lParam)->hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, (DLGPROC)Ugovori ); // dialog procedure ShowWindow( hDlgFirstTab, SW_SHOW ); } return 0L; case WM_MOVE: case WM_MOVING: case WM_SIZING: case WM_SIZE: { RECT rcClient = {0}; GetClientRect( hwnd, &rcClient ); SetWindowPos( GetDlgItem( hwnd, 3000 ), NULL, rcClient.left + 10, // move it away from window edge by 10 pixels rcClient.top + 10, // move it away from window edge by 10 pixels rcClient.right - rcClient.left - 20, // - 63 was the size of the button, // but I have deleted that button here to preserve space rcClient.bottom - rcClient.top - 63, SWP_NOZORDER | SWP_NOCOPYBITS ); // get tab control client rectangle GetClientRect( GetDlgItem( hwnd, 3000 ), &rcTab ); //============= place dialog box into tab client area MapWindowPoints( GetDlgItem( hwnd, 3000 ), hwnd, (LPPOINT)(&rcTab), 2 ); // get tab display area TabCtrl_AdjustRect( GetDlgItem( hwnd, 3000 ), FALSE, &rcTab ); // move dialog box SetWindowPos(hDlgFirstTab, NULL, rcTab.left, rcTab.top, rcTab.right - rcTab.left, rcTab.bottom - rcTab.top, SWP_NOZORDER); //========================= done // repaint window InvalidateRect( hwnd, NULL, FALSE ); } return 0L; case WM_ERASEBKGND: return 1L; case WM_PAINT: { PAINTSTRUCT ps = {0}; HDC hdc = BeginPaint( hwnd, &ps ); SendMessage( hwnd, WM_PRINTCLIENT, (WPARAM)hdc, 0 ); EndPaint( hwnd, &ps ); } return 0L; case WM_PRINTCLIENT: { RECT rcClient = {0}; GetClientRect( hwnd, &rcClient ); FillRect( (HDC)wParam, &rcClient, (HBRUSH)GetStockObject(WHITE_BRUSH) ); } return 0L; case WM_CLOSE: ::DestroyWindow(hwnd); return 0L; case WM_DESTROY: ::PostQuitMessage(0); return 0L; default: return ::DefWindowProc( hwnd, msg, wParam, lParam ); } return 0; } // WinMain int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // store hInstance in global variable for later use hInst = hInstance; WNDCLASSEX wc; HWND hwnd; MSG Msg; // initialize common controls INITCOMMONCONTROLSEX iccex; iccex.dwSize = sizeof(INITCOMMONCONTROLSEX); iccex.dwICC = ICC_LISTVIEW_CLASSES | ICC_UPDOWN_CLASS | ICC_STANDARD_CLASSES | ICC_TAB_CLASSES; InitCommonControlsEx(&iccex); // register main window class wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInst; wc.hIcon = LoadIcon( hInstance, IDI_APPLICATION ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH ); wc.lpszMenuName = NULL; wc.lpszClassName = L"Main_Window"; wc.hIconSm = LoadIcon( hInstance, IDI_APPLICATION ); if(!RegisterClassEx(&wc)) { MessageBox(NULL, L"Window Registration Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } // create main window hwnd = CreateWindowEx( 0, L"Main_Window", L"Contract manager", WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, 0 ); if(hwnd == NULL) { MessageBox(NULL, L"Nemogu da napravim prozor!", L"Greska!", MB_ICONEXCLAMATION | MB_OK); return 0; } ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; } 

I work in Visual Studio 2008 on Windows XP using C++ and WinAPI .

+6
source share
1 answer

This is WS_CLIPCHILDREN in your main window. This violates EnableThemeDialogTexture() on the first resize.

This was the problem; It took me days to figure this out. I created a simple application in Visual Studio:

  1. explicit link to ComCtrl v 6
  2. InitCommonControlsEx()
  3. tab dialog box
  4. sub dialog for tab contents (brother on tab)
  5. in sub-dialog, switch and static
  6. not fancy processing WM_PRINTCLIENT or anything like that
  7. just EnableThemeDialogTexture() in the WM_INITDIALOG subdialog

I went to test it on XP and ... it worked just fine and looked beautiful (that is, there was no this problem ).

I set up my little test program so that it looked more like my application, one small step at a time. Adding WS_CLIPCHILDREN to the main dialog was where everything fell apart, and this exact problem started to arise. According to the code you provided, you are also using WS_CLIPCHILDREN in the main window.

Now, of course, flickering has become a problem. But at least one riddle has been solved.

+1
source

Source: https://habr.com/ru/post/1207502/


All Articles