为什么当我画画的时候,鼠标在窗口里移动,却不是在同一时间到处画画?(WinAPI)
Why when I paint, and the mouse is moving in the window, the painting is not done at the same time everywhere? (WinAPI)
问了这个问题后,我更改了代码。它是有效的,但当WM_PAINT绘制窗口并且光标在其中移动时,绘制不会在任何地方同时进行。这里有一个视频可以更好地观看。这是我的WM_PAINT:
//TV is a struct with the dimensions of the window.
//BitmapBuffer is the bitmap containing the painting.
static int cont;
cont++;
HDC HDc;
PAINTSTRUCT ps;
HDc = BeginPaint(identifier, &ps);
Gdiplus::Graphics lienzo (HDc);
AlphaBlend(HDc, 0, 0, TV.width+4, TV.height+4, buffer, 0, 0, TV.width+4, TV.height+4, CopyInfo);
EndPaint(identifier, &ps);
由于问题出在移动鼠标时,可能WM_NCHITTEST消息与此有关:
case WM_NCHITTEST:
POINTS point1 = MAKEPOINTS(lParam);
POINT point2;
point2.x = point1.x;
point2.y = point1.y;
ScreenToClient(hwnd, &point2);
if (PtInRegion(region, point2.x, point2.y))
{
if (inWindow == false) //inWindow is true when the cursor is in the window
{
inWindow = true;
TrackMouseEvent(&structure);
Repaint(); //this function repaint the buffer and after call invalidrect
}
return HTCLIENT;
}
else
{
if (inWindow == true)
{
inWindow = false;
Repaint();
}
return HTTRANSPARENT;
}
break;
有人知道为什么会发生这种事吗?
很难看出问题,因为您的代码没有定义Repaint。但是,您应该使用InvalidateRect来告诉Windows哪个区域正在更新
说。。。Windows很难使用双缓冲技术对out更新图像进行编程。这是指绘制到内存(位图(,然后将位图位图位图到屏幕上。
你发现这个答案很有用用GDI+和C++减少闪烁
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- 运行同一解决方案的另一个项目的项目
- 从持续时间构造std::chrono::system_clock::time_point
- 为什么具有静态存储持续时间的同一内联变量在包含在 VS2017 编译的两个翻译单元中时会构造和销毁两次
- 图问题:找出两个节点是否在每个节点的O(1)时间和O(2)存储中共享同一分支
- 同一程序的运行时间差异很大,有时达到1000+us
- 对于同一任务,线程的等待时间在 0 到 30000 微秒之间系统地切换
- 我如何仅使用一个Arduino uno才能在同一时间和同一方向上旋转两个步进电动机
- C Winapi:如何将当前时间转换为字符串
- 使用 winAPI 获取计算机工作时间
- 为什么同一次执行的时间不同
- 在同一列表的while循环中迭代for循环所需的Big-O时间
- 如何使用 WinAPI 可靠地将本地时间转换为 UTC C++ 在 Windows 计算机上
- WinAPI Sleep()函数调用的睡眠时间比预期的要长
- 同一类型的多个声明是否会影响编译时间
- 我可以读取两个值的选项在同一时间使用popt库
- OpenGL的平移和旋转在同一时间
- 如何在同一时间弹出2堆栈
- 使用WinAPI将夏令时和UTC转换为本地时间
- c++游戏-循环和按键在同一时间