因为在 EasyX 中窗口默认无法被拖动改变窗口大小,于是我重写了 WNDPROC 函数如下
LRESULT MyWindowProcess(HWND handle, UINT message, WPARAM wparam, LPARAM lparam) {
switch (message) {
case WM_SIZING: {
RECT* rect = (RECT*)lparam;
change_size = true;
change_size_width = width;
change_size_height = height;
return 0;
}
}
return EasyXProcess(handle, message, wparam, lparam);
}
然后我在主线程有一个 while 循环每 30 秒轮询一次当前的 resize 状况
while (true) {
if (timer.on_clock() == true) {
timer.reset();
Resize(NULL, change_size_width, change_size_height);
}
Sleep(1);
}
然后,当用户拖动的时候,窗口有明显的卡顿感,会出现如下图的情况:
然而对于大多数软件而言都不会出现这种卡顿的情况,请问该如何解决?
或者说,我该怎么样才能操纵默认绘图设备的 buffer 大小而不是是使用 Resize 重复缩放窗口
**PS:EasyX 窗口也是个绘图设备,并且似乎不会随着 Win32 设置大小的变化而变化,所以直接使用 win32 api 设置会导致 EasyX 裁剪掉“多余”的部分,导致黑边
**
完整示范
#include <windows.h>
#include <graphics.h>
#include <conio.h>
bool change_size = false;
int change_size_width;
int change_size_height;
WNDPROC EasyXProcess;
LRESULT MyWindowProcess(HWND handle, UINT message, WPARAM wparam, LPARAM lparam) {
switch (message) {
case WM_SIZING: {
RECT* rect = (RECT*)lparam;
change_size = true;
change_size_width = rect->right - rect->left;
change_size_height = rect->bottom - rect->top;
return 0;
}
}
return EasyXProcess(handle, message, wparam, lparam);
}
int main() {
initgraph(900, 900);
// 取消拖动改变大小限制
SetWindowLong(GetHWnd(), GWL_STYLE, GetWindowLong(GetHWnd(), GWL_STYLE) | (WS_MAXIMIZEBOX));
SetWindowLong(GetHWnd(), GWL_STYLE, (GetWindowLong(GetHWnd(), GWL_STYLE) | WS_THICKFRAME));
EasyXProcess = reinterpret_cast<WNDPROC>(GetWindowLongPtr(GetHWnd(), GWLP_WNDPROC));
SetWindowLongPtr(GetHWnd(), GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(MyWindowProcess));
// 计时器
time_t timer = clock();
setbkcolor(RGB(41, 42, 43));
BeginBatchDraw();
cleardevice();
FlushBatchDraw();
while (true) {
if (clock() - timer >= 38) {
if (change_size == true) {
change_size = false;
Resize(NULL, change_size_width, change_size_height);
cleardevice();
FlushBatchDraw();
}
}
}
EndBatchDraw();
_getch();
return 0;
}