又见win32。画图出现的诡异现象
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// 分析菜单选择:
switch (wmId)
{
case DROP_DOWN_LIST:
{
.......省略
if (idx >= 0)
{
ZeroMemory(g_szMessage, sizeof(g_szMessage));
SendMessage(drop_down_list, CB_GETLBTEXT, idx, (WPARAM)g_szMessage); //获取第点击项的数据
//宽字符转换
wcs2mbs(g_szMessage, g_chResult);
if (strcmp(g_chResult, "圆") == 0)
{
g_Temp = 0;
}
SendMessage(hWnd, WM_PAINT, 0, 0);
}
break;
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
HPEN pen1 = CreatePen(PS_SOLID, 1, RGB(0, 0, 255));
HPEN pen2 = CreatePen(PS_SOLID, 1, RGB(0, 0, 255));
SelectObject(hdc, pen1);
SelectObject(hdc, pen2);
//如果我用if条件。 但我用combobox点击“圆”这个选项。画不出来圆,但是如果我移动屏幕。使窗口不断重绘,圆会慢慢画出来。
if (g_Temp == 0)
{
circle(hdc, LPPOINT(pen1), LPPOINT(pen2));//画圆
}
//但是如果我把这个函数不用if。会画出一个圆。并不需要像上述那样。
circle(hdc, LPPOINT(pen1), LPPOINT(pen2));//画圆
DeleteObject(pen1);
DeleteObject(pen2);
EndPaint(hWnd, &ps);
break;
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
好吧,我啥也不会。只是求解。这不好百度,所以发论坛。求知道的人提点下。感激不尽