通用对话框有以下六个
DWORD CommDlgExtendedError();
This function returns a common dialog box error value. This value indicates the most recent error to occur during the execution of one of the following common dialog box functions:
ChooseColor
ChooseFont
GetOpenFileName
GetSaveFileName
PageSetupDlg
PrintDlg
举例 :
ChooseColor
HINSTANCE hCommLib;//Common dlg instance
typedef BOOL (*LPFNCHOOSECOLOR) (LPCHOOSECOLOR lpcc);
LPFNCHOOSECOLOR lpfnChooseColor;
//Load common dlg
hCommLib = LoadLibrary(TEXT("Commdlg.dll"));
if(hCommLib){
lpfnChooseColor =(LPFNCHOOSECOLOR) GetProcAddress(hCommLib,TEXT("ChooseColor"));
}
CHOOSECOLOR cc;
static COLORREF cr[16];
// TCHAR szOut[128];
INT rc;
// Initialize color structure.
memset (&cc, 0, sizeof (cc));
memset (&cr, 0, sizeof (cr));
cc.lStructSize = sizeof (cc);
cc.hwndOwner = NULL;
cc.hInstance = NULL;
cc.rgbResult = g_Option.rgbColor;
cc.lpCustColors = cr;
cc.Flags = CC_ANYCOLOR;
rc = (lpfnChooseColor) (&cc);
在动态库中,可以用以上代码打开设置颜色对话框,然而在Exe 中就不可以了。
改为以下形式就可以了
cc.hwndOwner = hwnDlg;
cc.hInstance = hCommLib;
因该是句柄的问题。
Best Regards To All!