📄 bxfiledialog.cpp
字号:
/************************************************************************/
void BXFileDialog::OnHistoryClicked()
{
SetSpecialDirectory(CSIDL_RECENT);
SetActiveButton(&m_btnHistory);
}
/************************************************************************/
/* OnPersonalClicked */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: Called when the specified side bar button is clicked */
/* Revisions: */
/************************************************************************/
void BXFileDialog::OnPersonalClicked()
{
SetSpecialDirectory(CSIDL_PERSONAL);
SetActiveButton(&m_btnPersonal);
}
/************************************************************************/
/* OnDesktopClicked */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: Called when the specified side bar button is clicked */
/* Revisions: */
/************************************************************************/
void BXFileDialog::OnDesktopClicked()
{
SetSpecialDirectory(CSIDL_DESKTOP);
SetActiveButton(&m_btnDeskTop);
}
/************************************************************************/
/* OnFavoritesClicked */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: Called when the specified side bar button is clicked */
/* Revisions: */
/************************************************************************/
void BXFileDialog::OnFavoritesClicked()
{
SetSpecialDirectory(CSIDL_FAVORITES);
SetActiveButton(&m_btnFavourites);
}
/************************************************************************/
/* OnWebFoldersClicked */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: Called when the specified side bar button is clicked */
/* Revisions: */
/************************************************************************/
void BXFileDialog::OnWebFoldersClicked()
{
SetSpecialDirectory(CSIDL_NETHOOD);
SetActiveButton(&m_btnWebFolders);
}
/************************************************************************/
/* SetSpecialDirectory */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: Navigates to a passed shell director based on the side */
/* .. bar button pressed. */
/* Revisions: */
/************************************************************************/
void BXFileDialog::SetSpecialDirectory(int nFolder)
{
LPITEMIDLIST lpIDList;
// get the "special folder" path for the passed folder
SHGetSpecialFolderLocation(0, nFolder, &lpIDList);
SHGetPathFromIDList(lpIDList, m_szFile);
CWnd* pWnd = GetParent()->GetDlgItem(edt1);
CListCtrl* pLCtrl = (CListCtrl*)GetParent()->GetDlgItem(lst1);
// Simulate a refresh to clear the current file name
// .. this can take a LONG time if the history folder is selected!
//
// If you find a better way of doing this, please let me know.
pLCtrl->PostMessage(WM_KEYDOWN,VK_F5,0x0020001);
pLCtrl->PostMessage(WM_KEYUP,VK_F5,0xC0020001);
// Add selection to edit box
pWnd->SetWindowText(m_szFile);
// Simulate a 'Return' key to make selection
m_bClear = TRUE;
pWnd->PostMessage(WM_KEYDOWN,VK_RETURN,0x0020001);
pWnd->PostMessage(WM_KEYUP,VK_RETURN,0xC0020001);
}
/************************************************************************/
/* SetActiveButton */
/* */
/* Created: 31:3:2001 */
/* Author: Norm Almond */
/* Description: Sets the currently active side bar button */
/* Revisions: */
/************************************************************************/
void BXFileDialog::SetActiveButton(BXSelBtn* btn)
{
m_btnHistory.SetState(FALSE);
m_btnPersonal.SetState(FALSE);
m_btnDeskTop.SetState(FALSE);
m_btnFavourites.SetState(FALSE);
m_btnWebFolders.SetState(FALSE);
// if we don't have a valid button, don't select any of them
if (btn != NULL)
btn->SetState(TRUE);
}
/************************************************************************/
/* OnSize */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff, Norm Almond, Tak^Shoran */
/* Description: WM_SIZE handler. */
/* Revisions: */
/************************************************************************/
void BXFileDialog::OnSize(UINT nType, int cx, int cy)
{
CRect rc;
CFileDialog::OnSize(nType, cx, cy);
GetWindowRect(&rc);
// The first time the dialog is sized needs special handling (we set
// .. up the new OK button here, for example.
if (m_bFirst)
{
InitialReSize(0, 0, cx, cy);
m_bFirst = false;
}
else if (m_bSizing)
ReSize(rc.left, rc.top, cx, cy);
}
/************************************************************************/
/* InitialReSize */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff, Norm Almond */
/* Description: Repositions and subclasses, etc, the dialog controls */
/* .. when the dialog is first intialised. */
/* Revisions: */
/************************************************************************/
void BXFileDialog::InitialReSize(int x, int y, int cx, int cy)
{
// position "Look In" label and combo, and the toolbar
CRect rcDlgCl;
GetClientRect(&rcDlgCl);
CWnd* pWndOutLookBar = GetDlgItem(IDC_OUTLOOK_BAR_PLACEHOLDER);
CRect rcOLBClient, rcOLBWindow, rcWnd;
pWndOutLookBar->GetClientRect(rcOLBClient);
pWndOutLookBar->GetWindowRect(rcOLBWindow);
int eRight = rcDlgCl.right - CONTROL_GAP;
int eLeft = rcDlgCl.left + CONTROL_GAP;
int eTop = rcDlgCl.top + CONTROL_GAP;
int eBot = rcDlgCl.bottom - CONTROL_GAP;
int iTmp;
CRect rcWin;
GetWindowRect(&rcWin);
iTmp = eLeft + m_SBWidth + CONTROL_GAP;
CWnd* pListCtrl = GetParent()->GetDlgItem(lst1);
CWnd* pComboCtrl = GetParent()->GetDlgItem(cmb2);
CWnd* pLabel = GetParent()->GetDlgItem(stc4);
pLabel = GetParent()->GetDlgItem(stc4);
pLabel->SetWindowPos(0, 40, eTop + 3, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
// TODO [DW]: Replace this toolbar with our own, as differnt OS versions
// .. have different command available. [4/8/2001]
HWND hWnd = FindWindowEx(GetParent()->m_hWnd, NULL,
"ToolbarWindow32", NULL);
CWnd wndToolbar;
wndToolbar.Attach(hWnd);
pComboCtrl->SetWindowPos(0, iTmp, eTop, 250, 180, SWP_NOZORDER);
wndToolbar.SetWindowPos(0, iTmp + CONTROL_GAP + 250, eTop, 0, 0,
SWP_NOSIZE | SWP_NOZORDER);
wndToolbar.Detach();
// Offset controls
CWnd* pWnd;
CWnd* pBar = GetDlgItem(IDC_OUTLOOK_BAR_PLACEHOLDER);
CRect rcBar;
pBar->GetWindowRect(rcBar);
if (m_bShowPreview)
pListCtrl->SetWindowPos(0, iTmp, eTop + 22 + CONTROL_GAP,
eLeft + 250 - CONTROL_GAP,
eBot - (CONTROL_GAP * 3) - (22 * 2) - eTop - 22, SWP_NOZORDER);
else
pListCtrl->SetWindowPos(0, iTmp, eTop + 22 + CONTROL_GAP,
eRight - iTmp, eBot - (CONTROL_GAP * 3) - (22 * 2) - eTop - 22,
SWP_NOZORDER);
pWnd = GetParent()->GetDlgItem(stc3); // File Name label
pWnd->SetWindowPos(0, iTmp, eBot - (CONTROL_GAP * 2) - (18 * 2), 60,
15, SWP_NOZORDER);
pWnd = GetParent()->GetDlgItem(stc2); // File type label
pWnd->SetWindowPos(0, iTmp, eBot - 18, 60, 15, SWP_NOZORDER);
iTmp += 70;
pWnd = GetParent()->GetDlgItem(edt1); // File Name
pWnd->SetWindowPos(0, iTmp, eBot - CONTROL_GAP - (22 * 2),
(eRight - 90 - 30 - iTmp), 22, SWP_NOZORDER);
pWnd = GetParent()->GetDlgItem(cmb1); // File Type
pWnd->SetWindowPos(0, iTmp, eBot - 22, (eRight - 90 - 30 - iTmp), 150,
SWP_NOZORDER);
// Add our bitmap menu button
HideControl(IDOK); // undocumented CFileDialog function
if (m_IsOpen)
{
m_btn.Create("&Open",WS_TABSTOP | WS_CHILD | BS_DEFPUSHBUTTON,
CRect(0, 0, 0, 0), this, ID_START);
m_btn.SetButtonImage(IDB_FILEOPEN, RGB(255,0,255));
}
else
{
m_btn.Create("&Save",WS_TABSTOP | WS_CHILD | BS_DEFPUSHBUTTON,
CRect(0, 0, 0, 0), this, ID_START);
m_btn.SetButtonImage(IDB_FILESAVE, RGB(255,0,255));
}
m_btn.SetWindowPos(0, eRight - 90, eBot - CONTROL_GAP - (22 * 2), 90,
22, SWP_NOZORDER);
m_btn.ShowWindow(SW_SHOW);
pWnd = GetParent()->GetDlgItem(IDCANCEL);
pWnd->SetWindowPos(0, eRight - 90, eBot - 22, 90, 22, SWP_NOZORDER);
// Add outlook style directory selection buttons
pWndOutLookBar->SetWindowPos(0, eLeft, eTop + 22 + CONTROL_GAP,
m_SBWidth, eBot - eTop - CONTROL_GAP - 22, SWP_NOZORDER);
iTmp = rcOLBClient.Width();
pWndOutLookBar->GetClientRect(rcOLBClient);
m_btnHeight = rcOLBClient.Height() / 5;
rcWnd.SetRect(0, 0, iTmp, m_btnHeight);
if (!m_btnHistory)
{
m_btnHistory.Create("History", WS_CHILD | WS_VISIBLE, rcWnd,
pWndOutLookBar, ID_BTN_HISTORY, &m_IL,0);
m_btnHistory.m_Enabled = TRUE;
}
rcWnd.OffsetRect(0, m_btnHeight);
if (!m_btnPersonal)
{
m_btnPersonal.Create("My Documents", WS_CHILD | WS_VISIBLE, rcWnd,
pWndOutLookBar, ID_BTN_PERSONAL, &m_IL,2);
m_btnPersonal.m_Enabled = TRUE;
}
rcWnd.OffsetRect(0, m_btnHeight);
if (!m_btnDeskTop)
{
m_btnDeskTop.Create("Desktop", WS_CHILD | WS_VISIBLE, rcWnd,
pWndOutLookBar, ID_BTN_DESKTOP, &m_IL,1);
m_btnDeskTop.m_Enabled = TRUE;
}
rcWnd.OffsetRect(0, m_btnHeight);
if (!m_btnFavourites)
{
m_btnFavourites.Create("Favourites", WS_CHILD | WS_VISIBLE, rcWnd,
pWndOutLookBar, ID_BTN_FAVORITES, &m_IL,3);
m_btnFavourites.m_Enabled = TRUE;
}
rcWnd.OffsetRect(0, m_btnHeight);
if (!m_btnWebFolders)
{
m_btnWebFolders.Create("Web Folders", WS_CHILD | WS_VISIBLE, rcWnd,
pWndOutLookBar, ID_BTN_WEBFOLDERS, &m_IL,4);
m_btnWebFolders.m_Enabled = TRUE;
}
// Added for preview
checkBox.Create("&Preview",
(m_bShowPreview ? WS_CHILD|WS_VISIBLE : WS_CHILD) | WS_TABSTOP |
BS_AUTOCHECKBOX, CRect(0,0,0,0), this, IDC_CHECK_PREVIEW);
checkBox.SetWindowPos(0,eRight - 90,
eBot - (CONTROL_GAP * 3) - (22 * 2) - 22, 90, 22, SWP_NOZORDER);
checkBox.SetFont(GetFont());
checkBox.SetCheck(m_bPreview);
PreviewRect = CRect(
(eLeft * 2) + m_SBWidth + 250 + CONTROL_GAP,
eTop + 22 + CONTROL_GAP,
eRight,
eBot - (CONTROL_GAP * 4) - (22 * 3)
);
m_nPreviewBoxWidth = PreviewRect.Width();
}
/************************************************************************/
/* OnHelpInfo */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: WM_HELPINFO handler. */
/* Revisions: */
/************************************************************************/
BOOL BXFileDialog::OnHelpInfo(HELPINFO* pHelpInfo)
{
#ifdef _USE_HTMLHELP
if (pHelpInfo->iCtrlId == IDC_CHECK_PREVIEW ||
pHelpInfo->iCtrlId == ID_BTN_HISTORY ||
pHelpInfo->iCtrlId == ID_BTN_PERSONAL ||
pHelpInfo->iCtrlId == ID_BTN_DESKTOP ||
pHelpInfo->iCtrlId == ID_BTN_FAVORITES ||
pHelpInfo->iCtrlId == ID_BTN_WEBFOLDERS)
DoPopupHelp(pHelpInfo->iCtrlId, pHelpInfo->MousePos);
else
CFileDialog::OnHelpInfo(pHelpInfo);
#else
CFileDialog::OnHelpInfo(pHelpInfo);
#endif
return TRUE;
}
/************************************************************************/
/* DoPopupHelp */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: If applicable, will show a popup help window for the */
/* .. non-standard controls this dialog adds. */
/* Revisions: */
/************************************************************************/
void BXFileDialog::DoPopupHelp(int nID, CPoint pt)
{
if (nID != IDC_STATIC) // Don't show help for un-named controls
{
CString strString;
strString.LoadString(nID);
DoPopupHelp(strString, pt);
}
}
/************************************************************************/
/* DoPopupHelp */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: If applicable, will show a popup help window for the */
/* .. non-standard controls this dialog adds. */
/* Revisions: */
/************************************************************************/
void BXFileDialog::DoPopupHelp(CString strString, CPoint pt)
{
#ifdef _USE_HTMLHELP
HH_POPUP hPop;
CString str;
hPop.cbStruct = sizeof(HH_POPUP);
hPop.hinst = 0;
hPop.idString = 0;
if (strString == _T(""))
hPop.pszText = "No help topic is associated with this item";
else
hPop.pszText = strString;
hPop.pt = pt;
hPop.clrForeground = GetSysColor(COLOR_INFOTEXT);
hPop.clrBackground = GetSysColor(COLOR_INFOBK);
hPop.rcMargins = CRect(-1, -1, -1, -1);
hPop.pszFont = "Arial, 8, , ";
HtmlHelp(NULL, NULL, HH_DISPLAY_TEXT_POPUP, (DWORD) (HH_POPUP*) &hPop);
#endif
}
void BXFileDialog::OnOk()
{
}
void BXFileDialog::OnMyOk(UINT nID)
{
// Simulate the user hiting the enter key
PostMessage(WM_KEYDOWN,VK_RETURN,0x0020001);
PostMessage(WM_KEYUP,VK_RETURN,0xC0020001);
EndDialog(nID);
}
void BXFileDialog::OnShowPreview()
{
m_bShowPreview = !m_bShowPreview;
CRect rcDlg;
GetWindowRect(rcDlg);
ReSize(rcDlg.left, rcDlg.top, rcDlg.Width(), rcDlg.Height());
}
/************************************************************************/
/* CenterWindowOnOwner */
/* */
/* Created: 31:3:2001 */
/* Author: Joel Bernard */
/* Description: A better center window function */
/* Revisions: */
/************************************************************************/
void BXFileDialog::CenterWindowOnOwner(CWnd *pWndToCenterOn)
{
// Get the client rectangle of the window on which we want to center
// Make sure the pointer is not NULL first
if (pWndToCenterOn == NULL)
return;
CRect rectToCenterOn;
pWndToCenterOn->GetWindowRect(&rectToCenterOn);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -