我正在使用WinAPI和GDI创建自定义gui。重绘时出现一些问题。如果我要拖动窗口,它会重绘,但是如果我将窗口拖动到屏幕之外,它不会重绘。看下面的截图:
ToxicInjector.cpp:
#include "ToxicInjector.h"
...
// Method register native window object
bool ToxicInject::Application::RegisterNativeWindow()
{
WNDCLASSEX wc{ sizeof(WNDCLASSEX) };
...
wc.style = CS_VREDRAW | CS_HREDRAW;
...
}
// Window message procedure
LRESULT ToxicInject::Application::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
// Executes when window creates
case WM_CREATE:
{
this->CreateNativeControls();
...
}
break;
...
// Need for draw custom controls
case WM_DRAWITEM:
{
static LPDRAWITEMSTRUCT pdis = reinterpret_cast<LPDRAWITEMSTRUCT>(lParam);
switch (pdis->CtlID)
{
case UPDATE_BUTTON:
{
if (pdis->itemState & ODS_SELECTED)
this->isMouseOnUpdateBtn = true;
else
this->isMouseOnUpdateBtn = false;
this->DrawUpdateButton(pdis->hDC);
}
break;
case INJECT_BUTTON:
{
if (pdis->itemState & ODS_SELECTED)
this->isMouseOnInjectBtn = true;
else
this->isMouseOnInjectBtn = false;
this->DrawInjectButton(pdis->hDC);
}
break;
case BROWSE_BUTTON:
{
if (pdis->itemState & ODS_SELECTED)
this->isMouseOnBrowseBtn = true;
else
this->isMouseOnBrowseBtn = false;
this->DrawBrowseButton(pdis->hDC);
}
break;
}
}
break;
...
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
...
// Method creates all native-window controls
void ToxicInject::Application::CreateNativeControls()
{
...
this->hUpdate_Button = CreateWindow(L"BUTTON", L"", WS_VISIBLE| WS_CHILD | BS_OWNERDRAW, 224, 50, 212, 26, this->hwnd, reinterpret_cast<HMENU>(this->UPDATE_BUTTON), 0, 0);
this->hInject_Button = CreateWindow(L"BUTTON", L"", WS_VISIBLE| WS_CHILD | BS_OWNERDRAW, 224, 76 + 15, 212, 26, this->hwnd, reinterpret_cast<HMENU>(this->INJECT_BUTTON), 0, 0);
this->hBrowse_Button = CreateWindow(L"BUTTON", L"", WS_VISIBLE| WS_CHILD | BS_OWNERDRAW, 224, 91 + 26 + 15, 212, 26, this->hwnd, reinterpret_cast<HMENU>(this->BROWSE_BUTTON), 0, 0);
}
...
// Method draw update button
void ToxicInject::Application::DrawUpdateButton(HDC hDC)
{
...
if (this->isMouseOnUpdateBtn)
{
bg = CreateSolidBrush(RGB(44, 97, 46));
/*DRAW BACKGROUND*/
FillRect(hDC, &rc, bg);
/*DRAW BOTTOM LINE*/
SelectObject(hDC, hPen);
MoveToEx(hDC, 0, 26, 0);
LineTo(hDC, 212, 26);
/*DRAW TEXT*/
SetBkColor(hDC, RGB(44, 97, 46));
SetTextColor(hDC, RGB(255, 255, 255));
SelectObject(hDC, hTahoma_Regular);
TextOut(hDC, 83, 3, L"Update", 7);
/*FREE GDI MEMORY*/
DeleteObject(bg);
DeleteObject(hTahoma_Regular);
DeleteObject(hPen);
}
else
{
bg = CreateSolidBrush(RGB(67, 156, 70));
/*DRAW BACKGROUND*/
FillRect(hDC, &rc, bg);
/*DRAW BOTTOM LINE*/
SelectObject(hDC, hPen);
MoveToEx(hDC, 0, 26, 0);
LineTo(hDC, 212, 26);
/*DRAW TEXT*/
SetBkColor(hDC, RGB(67, 156, 70));
SetTextColor(hDC, RGB(255, 255, 255));
SelectObject(hDC, hTahoma_Regular);
TextOut(hDC, 83, 2, L"Update", 7);
/*FREE GDI MEMORY*/
DeleteObject(bg);
DeleteObject(hTahoma_Regular);
DeleteObject(hPen);
}
}
...
对不起,我的英语=)。如何解决该问题?
答案 0 :(得分:0)
所以我修好了!。
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT pdis = reinterpret_cast<LPDRAWITEMSTRUCT>(lParam);
switch (pdis->CtlID)
...
}
指向DRAWITEMSTRUCT
的指针应该是非静态的!这是逻辑错误,我的错误。
完美工作=)。
答案 1 :(得分:-2)
您可以强制对WM_MOVE进行重新粉刷
case WM_MOVE:
this->OnWindow_Paint();
break;