GetSaveFileName弹出文件选择框居中显示

来源:互联网 发布:知乎关键指标kpi 编辑:程序博客网 时间:2024/06/08 13:31

传入的结构体参数:

OPENFILENAME ofn;

ZeroMemory(&ofn, sizeof(ofn));

ofn.lpstrFile = 初始文件名;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = _T("Text Files(*.txt)|*.txt|All Files(*.*)|*.*||");
ofn.lpstrDefExt = _T("txt");
ofn.lpstrTitle = _T("保存为");
ofn.hInstance = GetModuleHandle(NULL);
ofn.Flags = OFN_HIDEREADONLY | OFN_ENABLEHOOK | OFN_EXPLORER;
ofn.hwndOwner = 父窗口句柄;
ofn.FlagsEx = OFN_EX_NOPLACESBAR;
ofn.lpfnHook = OFNHookProc;
ofn.lpstrInitialDir = prtMainFrame->InitPaht.c_str();

ofn.lStructSize = sizeof(OPENFILENAME); 

// 让窗口居中显示,主要是设置Hook函数,在Flags标志中必须设置OFN_ENABLEHOOK | OFN_EXPLORER,具体的作用请看msdn

下面看一下Hook函数的编写方法:

UINT_PTR CALLBACK OFNHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
if (uiMsg == WM_INITDIALOG)
{
RECT rcParent;
HWND hWndParent = GetParent(hdlg);
GetClientRect(hWndParent, &rcParent);
RECT rcHaotiMainFrame;
GetClientRect(按哪个窗口剧中的窗口句柄, &rcHaotiMainFrame);
POINT ptParentInScreen;
ptParentInScreen.x = rcParent.left;
ptParentInScreen.y = rcParent.top;
::ClientToScreen(hWndParent, (LPPOINT)&ptParentInScreen);
SetWindowPos(hWndParent, NULL,
ptParentInScreen.x + (rcHaotiMainFrame.right - rcHaotiMainFrame.left - (rcParent.right - rcParent.left)) / 2,
ptParentInScreen.y + (rcHaotiMainFrame.bottom - rcHaotiMainFrame.top - (rcParent.bottom - rcParent.top)) / 2,
0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
UNREFERENCED_PARAMETER(wParam);
return 1;
}

0 0
原创粉丝点击