建立对应结构后用memset将结构体清零后再注册相关成员变量,随后调用创建ComDlg函数,范例如下:
//颜色通用对话框
COLORREF RGB_CLR,CustColors[16];
CHOOSECOLOR CD_CLR;
memset(&CD_CLR,0,sizeof(CD_CLR));
CD_CLR.lStructSize = sizeof(CHOOSECOLOR);
CD_CLR.hwndOwner = hWnd;
CD_CLR.Flags = CC_FULLOPEN;
CD_CLR.lpCustColors = (LPDWORD)CustColors;//此处不可缺
//选择文件通用对话框
OPENFILENAME FILE;
memset(&FILE,0,sizeof(FILE));
FILE.lStructSize = sizeof(OPENFILENAME);
FILE.hwndOwner = hWnd;
FILE.hInstance = hInst;
FILE.Flags = OFN_FILEMUSTEXIST |OFN_EXPLORER;
FILE.lpstrFilter = "Formula Draw 2008 File(*.fd8)/0*.fd8/0";
FILE.nFilterIndex = 1;
FILE.nMaxFile = MAX_PATH;
FILE.lpstrFile = FILENAME;
FILE.lpstrDefExt = TEXT("*.fd8");//默认文件后缀
FILE.lpstrTitle = "保存图像";