在 OPENFILEW 对话框上使用钩子禁用调整大小控制

using hook on OPENFILEW dialog disables resize control

使用此代码绘制的结果对话框无法通过鼠标调整大小:

#include <windows.h>

static UINT_PTR CALLBACK OFNHookProc (HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam) {
  return 0;
}

int main() {
  OPENFILENAMEW ofn;
  ZeroMemory(&ofn, sizeof(ofn));
  ofn.lStructSize = sizeof(OPENFILENAMEW);
  ofn.nMaxFile = MAX_PATH;
  ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_ENABLEHOOK;
  ofn.lpfnHook = OFNHookProc;
  GetOpenFileNameW(&ofn);
  return 0;
}

删除 OFN_ENABLEHOOK 会显示正确的对话框 window,右下角带有调整大小指示器。如何制作用户可调整大小并带有挂钩程序的对话框?

(当然这里hook是mock的,只是为了说明错误,不管我在里面放什么,当然如果其他方面都正确,结果是一样的)

使用 OFN_ENABLEHOOK 时需要包含 OFN_ENABLESIZING 标志。这是记录在案的行为:

OPENFILENAME structure

OFN_ENABLESIZING
0x00800000
Enables the Explorer-style dialog box to be resized using either the mouse or the keyboard. By default, the Explorer-style Open and Save As dialog boxes allow the dialog box to be resized regardless of whether this flag is set. This flag is necessary only if you provide a hook procedure or custom template. The old-style dialog box does not permit resizing.