1. 文件夹选择框
1 TCHAR pszPath[MAX_PATH]; 2 BROWSEINFO bi; 3 bi.hwndOwner = this->GetSafeHwnd(); 4 bi.pidlRoot = NULL; 5 bi.pszDisplayName = NULL; 6 bi.lpszTitle = TEXT("请选择文件夹"); 7 bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; 8 bi.lpfn = NULL; 9 bi.lParam = 0; 10 bi.iImage = 0; 11 LPITEMIDLIST pidList = SHBrowseForFolder(&bi); 12 if ( pidList == NULL ) { 13 return; 14 } 15 if ( SHGetPathFromIDList(pidList, pszPath) ) { 16 m_strPcDir = pszPath; 17 SetDlgItemText( IDC_EDIT_PCDIR, m_strPcDir.GetBuffer(0) ); 18 }
2. 文件选择对话框
1 CFileDialog dlgFile(TRUE); 2 CString fileName; 3 const int c_cMaxFiles = 100; 4 const int c_cbBuffSize = (c_cMaxFiles * (MAX_PATH + 1)) + 1; 5 dlgFile.GetOFN().lpstrFile = fileName.GetBuffer(c_cbBuffSize); 6 dlgFile.GetOFN().nMaxFile = c_cMaxFiles; 7 8 dlgFile.DoModal(); 9 m_strSecondSrcFile = fileName; 10 fileName.ReleaseBuffer();
3. 对话框全屏(基本操作流程:获取桌面对话框属性 ----> 调用SetWindowPos()根据桌面对话框的属性设置对话框大小和位置)
BOOL CBaseDialog::OnInitDialog() { CDialog::OnInitDialog(); /* 全屏化对话框*/ HWND hDeskTopWnd=::GetDesktopWindow(); CRect rect; ::GetWindowRect(hDeskTopWnd, &rect); SetWindowPos(&wndTopMost, rect.left, rect.top,
rect.right-rect.left, rect.bottom-rect.top, 0);
return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE }
4. 设置对话框元素焦点
GetDlgItem(IDC_COWADDINFO_ENTERTIME_EDIT)->SetFocus();
5. ComoBox操作
((CComboBox*)GetDlgItem(IDC_COMBO_BOARD))->InsertString(0, L"0"); ((CComboBox*)GetDlgItem(IDC_COMBO_BOARD))->InsertString(1, L"1"); ((CComboBox*)GetDlgItem(IDC_COMBO_BOARD))->InsertString(2, L"2"); ((CComboBox*)GetDlgItem(IDC_COMBO_BOARD))->InsertString(3, L"3"); ((CComboBox*)GetDlgItem(IDC_COMBO_BOARD))->SetCurSel(0);
浙公网安备 33010602011771号