我想通过点击并将光标从一个点移动到另一个点来画一条线,我刚刚复制了下面的代码,我的WindowProcedure看起来是这样的:
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//PAINTSTRUCT ps;
HDC hdc;
bool draw = false;
int x = 0, y=0;
//InvalidateRect(hwnd, NULL, true);
switch (uMsg)
{
case WM_LBUTTONDOWN:
draw = true;
x = LOWORD(lParam);
y = HIWORD(lParam);
return 0;
case WM_LBUTTONUP:
if (draw)
{
hdc = GetDC(hwnd);
MoveToEx(hdc, x, y, NULL);
LineTo(hdc, LOWORD(lParam), HIWORD(lParam));
ReleaseDC(hwnd, hdc);
}
draw = FALSE;
return 0;
case WM_MOUSEMOVE:
if (draw)
{
hdc = GetDC(hwnd);
MoveToEx(hdc, x, y, NULL);
LineTo(hdc, x = LOWORD(lParam), y = HIWORD(lParam));
ReleaseDC(hwnd, hdc);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}但是当我点击的时候,什么都没有发生,就像一次只能处理一个案例,对吗?当我注释前两个案例时,它会画线,所以它会进入switch,但这不是我想要做的。有什么建议吗?
发布于 2017-04-09 01:45:22
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//PAINTSTRUCT ps;
HDC hdc;
static bool draw = false; // ←static
static int x = 0, y=0; // ←这个怎么样?
https://stackoverflow.com/questions/43297329
复制相似问题