15,979
社区成员
发帖
与我相关
我的任务
分享
UINT_PTR CALLBACK OFNHookProc(HWND hdlg,UINT uiMsg,WPARAM wParam,LPARAM lParam)
{
hdlg=GetParent(hdlg);
if (uiMsg==WM_INITDIALOG)
{
RECT rect;
GetWindowRect(hdlg, &rect);
HMONITOR hMonitor=MonitorFromWindow(hdlg, MONITOR_DEFAULTTONEAREST);
MONITORINFOEX info;
info.cbSize=sizeof(info);
if (!GetMonitorInfo(hMonitor, &info))
{
return 0;
}
int x = info.rcWork.left + ((info.rcWork.right-info.rcWork.left)-(rect.right-rect.left)) / 2;
int y = info.rcWork.top + ((info.rcWork.bottom-info.rcWork.top)-(rect.bottom-rect.top)) / 3;
int flag=SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE;
return SetWindowPos(hdlg, NULL, x, y, 0, 0, flag);
}
return 0;
}
void selectIcon(HWND dlg)
{
OPENFILENAME ofn;
ofn.hInstance=hInst;
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = dlg;
ofn.lpstrFile = szIcoFile;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = _T("Ico文件\0*.ico\0所有文件\0*.*\0\0");
ofn.nFilterIndex = 0;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle=NULL;
ofn.lpstrCustomFilter=NULL;
ofn.lpstrDefExt=NULL;
ofn.lpTemplateName=NULL;
ofn.pvReserved=NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_ENABLEHOOK;
ofn.lpfnHook=OFNHookProc;
if (!GetOpenFileName(&ofn))
{
return;
}
}