Я задаю цвет основного окна основного фона, регистрируя класс окна с помощью свойства hbrBackground, например:
wcex.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
, а затем:
RegisterClassExW(&wcex);
Окно результатов имеет белый цвет. У меня темно-серый цвет, когда я минимизирую / увеличиваю окно. Как я могу получить темно-серый фон сразу?
Спасибо!
РЕДАКТИРОВАТЬ: функция обратного вызова:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hgGroupBox1;
static HWND hsFileSize;
static HWND hsFileName;
static HWND hsStatic1;
static HWND hsStatic2;
static HWND hsStatic3;
static HWND hsStatic4;
static HWND hsFileID;
static HWND hlbTagV2Frames;
static HWND hStatus;
static HBRUSH hbrBkgnd;
int hauteur, largeur;
std::wstringstream lbFrames;
switch (message)
{
case WM_CREATE:
hsStatic1 = CreateWindowEx(0, L"STATIC", L"Fichier :", WS_CHILD | WS_VISIBLE, 5, 5, 60, 20, hWnd, (HMENU)ID_STATIC1, (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), nullptr);
hsFileName = CreateWindowEx(0, L"STATIC", L"", WS_CHILD | WS_VISIBLE, 65, 5, 800, 20, hWnd, (HMENU)ID_STATICFILENAME, (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), nullptr);
hgGroupBox1 = CreateWindowEx(0, L"BUTTON", L"TagV2", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 5, 30, 420, hauteur - 100, hWnd, (HMENU)ID_GROUPEBOX1, (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), nullptr);
hsStatic2 = CreateWindowEx(0, L"STATIC", L"Taille :", WS_CHILD | WS_VISIBLE, 15, 50, 100, 20, hWnd, (HMENU)ID_STATIC2, (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), nullptr);
hsFileSize = CreateWindowEx(0, L"STATIC", nullptr, WS_CHILD | WS_VISIBLE | WS_BORDER, 15, 75, 100, 20, hWnd, (HMENU) ID_STATICFILESIZE, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE), nullptr);
hsStatic3 = CreateWindowEx(0, L"STATIC", L"Entête :", WS_CHILD | WS_VISIBLE, 15, 100, 100, 20, hWnd, (HMENU)ID_STATIC3, (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), nullptr);
hsFileID = CreateWindowEx(0, L"STATIC", nullptr, WS_CHILD | WS_VISIBLE | WS_BORDER, 15, 125, 200, 20, hWnd, (HMENU)ID_STATICENTETEID, (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), nullptr);
hsStatic4 = CreateWindowEx(0, L"STATIC", L"Attributs du tagV2 :", WS_CHILD | WS_VISIBLE, 15, 150, 150, 20, hWnd, (HMENU)ID_GROUPEBOX1, (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), nullptr);
hlbTagV2Frames = CreateWindow(L"LISTBOX", L"", WS_VISIBLE | WS_CHILD | WS_BORDER | LBS_NOTIFY, 15, 175, 400, 200, hWnd, (HMENU)ID_LISTBOXFRAMES, (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), nullptr);
ShowWindow(hsStatic1, SW_SHOW);
ShowWindow(hgGroupBox1, SW_SHOW);
ShowWindow(hsStatic2, SW_SHOW);
ShowWindow(hsFileSize, SW_SHOW);
ShowWindow(hsStatic3, SW_SHOW);
ShowWindow(hsFileID, SW_SHOW);
ShowWindow(hStatus, SW_SHOW);
ShowWindow(hsStatic4, SW_SHOW);
ShowWindow(hlbTagV2Frames, SW_SHOW);
break;
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
// Analyse les sélections de menu :
switch (wmId)
{
case IDM_FICHIER_OUVRIR:
//Here comes the file treatement code.
}
break;
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// TODO: Ajoutez ici le code de dessin qui utilise hdc...
EndPaint(hWnd, &ps);
}
break;
case WM_CTLCOLORSTATIC:
{
HDC hdcStatic = (HDC)wParam;
SetTextColor(hdcStatic, RGB(0, 0, 0));
SetBkColor(hdcStatic, DKGRAY_BRUSH);
hbrBkgnd = CreateSolidBrush(DKGRAY_BRUSH);
return (INT_PTR)hbrBkgnd;
}
}
case WM_CTLCOLORBTN:
{
HDC hdcButton = (HDC)wParam;
SetTextColor(hdcButton, RGB(255, 255, 255));
SetBkColor(hdcButton, DKGRAY_BRUSH);
}
hbrBkgnd = CreateSolidBrush(DKGRAY_BRUSH);
return (INT_PTR)hbrBkgnd;
case WM_ERASEBKGND:
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;