gpt4 book ai didi

c++ - 当样式为 WS_CHILD 时,通过 ps.rcPaint 查找脏区域不起作用

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

我用C++写过用WinApi画的程序。我的回调函数:

/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage(0); /* send a WM_QUIT to the message queue */
break;
case WM_ERASEBKGND:
{
elWidget *widget = (elWidget *)GetWindowLong(hwnd, GWL_USERDATA);
if (widget)
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HBRUSH hBrush = CreateSolidBrush(widget->color.ColorRef());
FillRect((HDC)wParam, &ps.rcPaint, hBrush);
DeleteObject(hBrush);
EndPaint(hwnd, &ps);
}
}
break;
default: /* for messages that we don't deal with */
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}

它适用于独立窗口(样式为 WS_OVERLAPPED),但当样式为 WS_CHILDWS_CHILD | WS_VISIBLE 那么 ps.rcPaint 总是 (0,0,0,0)。我不知道如何修复它。

elButton::elButton(elWidget *owner)
: elWidget(owner)
{
WNDCLASSEX winclChild; /* Data structure for the windowclass */
/* The Window structure */
winclChild.hInstance = gThisInstance; //global variable instance
winclChild.lpszClassName = L"Child";
winclChild.lpfnWndProc = WindowProcedure; /* This function is called by windows */
winclChild.style = CS_DBLCLKS; /* Catch double-clicks */
winclChild.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
winclChild.hIcon = LoadIcon (NULL, IDI_APPLICATION);
winclChild.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
winclChild.hCursor = LoadCursor (NULL, IDC_ARROW);
winclChild.lpszMenuName = NULL; /* No menu */
winclChild.cbClsExtra = 0; /* No extra bytes after the window class */
winclChild.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
winclChild.hbrBackground = 0;// CreateSolidBrush(RGB(255, 200, 200));//(HBRUSH)COLOR_WINDOW;//COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx(&winclChild))
return;
hwnd = CreateWindowEx(
0, /* Extended possibilites for variation */
L"Child", /* Classname */
L"Title", /* Title Text */
WS_CHILD | WS_VISIBLE,
100,
100,
40,
40,
owner->getHwnd(), /* The window is a child-window to desktop */
NULL, /* No menu */
gThisInstance, /* Program Instance handler */
this /* to lParam */
);
SetWindowLong(hwnd, GWL_USERDATA, (long)this);
}

我可以在 Google 磁盘上添加整个项目的链接,但我不能保证它会永久存在多年。

最佳答案

BeginPaint 应该只在 WM_PAINT 上调用,

要获取 WM_ERASEBKGND 上的剪辑框,请调用 GetClipBox((HDC)wParam,&rect); 而不是

关于c++ - 当样式为 WS_CHILD 时,通过 ps.rcPaint 查找脏区域不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33976115/

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