gpt4 book ai didi

C++ Win32 窗口背景不重绘

转载 作者:太空宇宙 更新时间:2023-11-04 12:10:24 25 4
gpt4 key购买 nike

在尝试创建自己的 win32 包装器时,我遇到了这个问题。每当我调整窗口大小时,背景都不会重新绘制(http://i44.tinypic.com/23k855.png 白色应该是背景,但是当我缩小窗口时它会变黑)

我类的一部分:

void Register(  tstring _className,
tstring _menuName,
WNDPROC w32proc,
tstring hIcon,
HICON hIconSmall,
LPCTSTR hCursor,
HBRUSH hBrush=(HBRUSH)GetStockObject(WHITE_BRUSH),
UINT windowStyle = CS_HREDRAW | CS_VREDRAW,
int classExtraBytes=NULL,
int windowExtraBytes=NULL
)
{
className = _className;
menuName = _menuName;

wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = windowStyle;
wcex.lpfnWndProc = w32proc;
wcex.cbClsExtra = classExtraBytes;
wcex.cbWndExtra = windowExtraBytes;
wcex.hInstance = this->hInst;
wcex.hIcon = LoadIcon(this->hInst,hIcon.c_str());
wcex.hCursor = LoadCursor(NULL,hCursor);
wcex.hbrBackground = hBrush;
wcex.lpszMenuName = this->menuName.c_str();
wcex.lpszClassName = this->className.c_str();
wcex.hIconSm = hIconSmall;

RegisterClassEx(&wcex);
}

bool Create(tstring _windowTitle,
DWORD windowStyle,
int width=CW_USEDEFAULT,
int height=CW_USEDEFAULT,
int xPos=CW_USEDEFAULT,
int yPos=CW_USEDEFAULT,
HWND parent=NULL,
LPVOID lpParam=NULL,
HMENU menu=NULL
)
{
windowTitle = _windowTitle;

handle = CreateWindow(this->className.c_str(), this->windowTitle.c_str(), windowStyle,
xPos, yPos, width, height, parent, menu, this->hInst, lpParam);
if (!this->handle)
return false;

Show();
return true;
}

bool Show(int cmd=SW_SHOWNORMAL)
{
if( !ShowWindow(this->handle, cmd) || !UpdateWindow(this->handle) )
return false;
return true;
}

我的窗口过程:

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

以及我如何使用一切:

mainwin = new Window(hInstance);
mainwin->Register(TEXT("test"),TEXT("test"),WndProc,TEXT("small.ico"),NULL,IDC_ARROW,NULL,NULL,NULL);
mainwin->Create(TEXT("test window"),WS_OVERLAPPEDWINDOW );
mainwin->Show(nCmdShow);
while(mainwin->GetMsg() > 0)
mainwin->TranslateDispatchMsg();

一些帮助将不胜感激:)

ps: 我还尝试处理 WM_PAIN、WM_SIZE、WM_SIZING 消息来调用 UpdateWindow 和/或 ShowWindow 但没有成功

最佳答案

您正在将 NULL 传递给 RegisterhBrush 参数。这就是当您调整大小时背景不会重新绘制的原因。

我怀疑您打算使用可选参数并像这样调用它:

mainwin->Register(TEXT("test"), TEXT("test"), WndProc, TEXT("small.ico"),
NULL, IDC_ARROW);

关于C++ Win32 窗口背景不重绘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10103918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com