📄 tmainfrm1.cpp
字号:
HWND hWnd = (HWND)lParam;
if(nNotify == 0 && nCtrlID == 1 && hWnd == NULL && IsIdle())
{
hWnd = ::GetDlgItem(m_wndDlgBar.m_hWnd, IDC_MPQSEARCHMASK);
::GetWindowText(hWnd, szMask, sizeof(szMask)-1);
m_strMask = szMask;
OpenMpqArchive(m_strMpqName, m_strFileList);
return TRUE;
}
return CFrameWnd::OnCommand(wParam, lParam);
}
BOOL TMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
{
// create splitter window
if (!m_wndSplitter.CreateStatic(this, 1, 2))
return FALSE;
if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(TTreeView), CSize(250, 0), pContext) ||
!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(TListView), CSize(100, 0), pContext))
{
m_wndSplitter.DestroyWindow();
return FALSE;
}
// Remember pointers to both views
m_pTreeView = DYNAMIC_DOWNCAST(TTreeView, m_wndSplitter.GetPane(0, 0));
m_pListView = DYNAMIC_DOWNCAST(TListView, m_wndSplitter.GetPane(0, 1));
m_pTreeView->SetLinkPointers(this, m_pListView);
m_pListView->SetLinkPointers(this, m_pTreeView);
return TRUE;
}
void TMainFrame::OnUpdateViewStyles(CCmdUI* pCmdUI)
{
TListView* pView = GetListViewPane();
if (pView == NULL)
pCmdUI->Enable(FALSE);
else
{
DWORD dwStyle = pView->GetStyle() & LVS_TYPEMASK;
if (pCmdUI->m_nID == ID_VIEW_LINEUP)
{
if (dwStyle == LVS_ICON || dwStyle == LVS_SMALLICON)
pCmdUI->Enable();
else
pCmdUI->Enable(FALSE);
}
else
{
pCmdUI->Enable();
BOOL bChecked = FALSE;
switch (pCmdUI->m_nID)
{
case ID_VIEW_DETAILS:
bChecked = (dwStyle == LVS_REPORT);
break;
case ID_VIEW_SMALLICON:
bChecked = (dwStyle == LVS_SMALLICON);
break;
case ID_VIEW_LARGEICON:
bChecked = (dwStyle == LVS_ICON);
break;
case ID_VIEW_LIST:
bChecked = (dwStyle == LVS_LIST);
break;
default:
bChecked = FALSE;
break;
}
pCmdUI->SetRadio(bChecked ? 1 : 0);
}
}
}
void TMainFrame::OnViewStyle(UINT nCommandID)
{
TListView* pView = GetListViewPane();
if (pView != NULL)
{
DWORD dwStyle = (UINT)-1;
switch (nCommandID)
{
case ID_VIEW_LINEUP:
{
CListCtrl& refListCtrl = pView->GetListCtrl();
refListCtrl.Arrange(LVA_SNAPTOGRID);
}
break;
case ID_VIEW_DETAILS:
dwStyle = LVS_REPORT;
break;
case ID_VIEW_SMALLICON:
dwStyle = LVS_SMALLICON;
break;
case ID_VIEW_LARGEICON:
dwStyle = LVS_ICON;
break;
case ID_VIEW_LIST:
dwStyle = LVS_LIST;
break;
}
if (dwStyle != -1)
pView->ModifyStyle(LVS_TYPEMASK, dwStyle);
}
}
void TMainFrame::OnSize(UINT nType, int cx, int cy)
{
NOTIFYICONDATA nim;
RECT rect;
CFrameWnd::OnSize(nType, cx, cy);
// If there is a console window, resize it too
if(m_hConsole != NULL)
{
m_pListView->GetWindowRect(&rect);
::MoveWindow(m_hConsole, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE);
}
// If we are going to minimize, minimize the parent too
if(nType == SIZE_MINIMIZED && cfg.bMinToSystray)
{
ZeroMemory(&nim, sizeof(NOTIFYICONDATA));
nim.cbSize = sizeof(NOTIFYICONDATA);
nim.hWnd = m_hWnd;
nim.uID = SYSTRAY_ICON_ID;
nim.uFlags = NIF_TIP | NIF_MESSAGE | NIF_ICON;
nim.uCallbackMessage = WM_SYSTRAYEVENT;
nim.hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME));
LoadString(AfxGetResourceHandle(), AFX_IDS_APP_TITLE, nim.szTip, sizeof(nim.szTip)-1);
Shell_NotifyIcon(NIM_ADD, &nim);
ShowWindow(SW_HIDE);
return;
}
}
void TMainFrame::OnSystrayEvent(WPARAM, LPARAM lParam)
{
NOTIFYICONDATA nim;
CWnd * pForeground = NULL;
if(lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
{
ZeroMemory(&nim, sizeof(NOTIFYICONDATA));
nim.cbSize = sizeof(NOTIFYICONDATA);
nim.hWnd = m_hWnd;
nim.uID = SYSTRAY_ICON_ID;
Shell_NotifyIcon(NIM_DELETE, &nim);
ShowWindow(SW_RESTORE);
pForeground = (m_pNameBreaker != NULL) ? m_pNameBreaker : (CWnd *)this;
pForeground->BringWindowToTop();
pForeground->SetForegroundWindow();
}
}
void TMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if(m_pNameBreaker != NULL)
m_pNameBreaker->SendMessage(WM_SYSCOMMAND, nID, lParam);
CFrameWnd::OnSysCommand(nID, lParam);
}
// Do not call the ancestor's OnEraseBkgnd because of window flicking
BOOL TMainFrame::OnEraseBkgnd(CDC * /* pDC */)
{
// return CFrameWnd::OnEraseBkgnd(pDC);
return 0;
}
void TMainFrame::OnClose()
{
// If the console is open, destroy it and wait a while.
if(m_hConsole != NULL && IsWindow(m_hConsole))
::SendMessage(m_hConsole, WM_CLOSECONSOLE, 0, 0);
// If a background operation runs, ask the user
if(m_hWorkThread != NULL)
{
if(AfxMessageBox(IDS_WANTEXITIFBGWORK, MB_YESNO | MB_ICONQUESTION) != IDYES)
return;
}
CFrameWnd::OnClose();
}
void TMainFrame::OnDestroy()
{
WINDOWPLACEMENT wpl;
CFrameWnd::OnDestroy();
// Kill the worker thread, if any
if(m_hWorkThread != NULL)
{
SetEvent(m_hStopEvent);
WaitForSingleObject(m_hWorkThread, 1000);
CloseHandle(m_hWorkThread);
m_hWorkThread = NULL;
}
if(m_hStopEvent != NULL)
{
CloseHandle(m_hStopEvent);
m_hStopEvent = NULL;
}
// Free the archive handle
CloseMpqArchive();
// Unload Storm.dll, if loaded.
if(m_hStorm != NULL)
{
FreeDLL(m_hStorm);
m_hStorm = NULL;
}
// Save the position of the window
wpl.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(&wpl);
cfg.rectMainWnd = wpl.rcNormalPosition;
cfg.nShowCommand = wpl.showCmd;
}
void TMainFrame::OnSetStatusText(WPARAM, LPARAM lParam)
{
char * szText = (char *)lParam;
if(szText != NULL)
m_wndStatusBar.SetPaneText(0, szText, TRUE);
}
// Handles requests of script interpreter for getting color
HBRUSH TMainFrame::OnCtlColorEdit(WPARAM wParam, LPARAM)
{
HDC hDC = (HDC)wParam;
SetTextColor(hDC, RGB(255, 255, 255));
SetBkColor(hDC, RGB(0, 0, 0));
return m_hBrush;
}
// Notify message that the console has been destroyed
void TMainFrame::OnConsoleDestroyed(WPARAM, LPARAM)
{
m_hConsole = NULL;
}
//-----------------------------------------------------------------------------
// Command handlers
// For actions that can run when no background thread runs
void TMainFrame::MustBeIdle(CCmdUI* pCmdUI)
{
pCmdUI->Enable(IsIdle());
}
void TMainFrame::MustHaveDocAndIdle(CCmdUI* pCmdUI)
{
pCmdUI->Enable(HasDocAndIsIdle());
}
void TMainFrame::MustHaveItemAndIdle(CCmdUI* pCmdUI)
{
pCmdUI->Enable(IsItemSelAndIdle());
}
void TMainFrame::OnFileNew()
{
if(IsIdle())
NewMpqArchive();
}
void TMainFrame::OnFileOpen()
{
if(IsIdle())
OpenMpqArchive(NULL, NULL);
}
void TMainFrame::OnFileClose()
{
if(HasDocAndIsIdle())
CloseMpqArchive();
}
void TMainFrame::OnOpsOpen()
{
if(IsItemSelAndIdle())
OpenSelectedFile(FALSE);
}
void TMainFrame::OnOpsOpenWith()
{
if(IsItemSelAndIdle())
OpenSelectedFile(TRUE);
}
void TMainFrame::OnOpsExtract()
{
if(IsItemSelAndIdle())
ExtractSelectedFiles();
}
void TMainFrame::OnOpsRename()
{
if(IsItemSelAndIdle())
RenameFile();
}
void TMainFrame::OnOpsRemove()
{
if(IsItemSelAndIdle())
RemoveFiles();
}
void TMainFrame::OnOpsNewFolder()
{
if(HasDocAndIsIdle())
NewFolder();
}
void TMainFrame::OnOpsAddFiles()
{
if(HasDocAndIsIdle())
AddFiles(NULL);
}
void TMainFrame::OnOpsProperties()
{
if(IsItemSelAndIdle())
ShowProperties();
}
void TMainFrame::OnOpsGetListFile()
{
if(HasDocAndIsIdle())
ExtractListFile();
}
void TMainFrame::OnOpsGetAttributes()
{
if(HasDocAndIsIdle())
ExtractAttributes();
}
void TMainFrame::OnOpsExtractArchive()
{
if(HasDocAndIsIdle())
ExtractArchive();
}
void TMainFrame::OnOpsBuildArchive()
{
if(IsIdle())
BuildArchive();
}
void TMainFrame::OnOpsCompactArchive()
{
if(HasDocAndIsIdle())
CompactArchive();
}
void TMainFrame::OnToolsNameBreaker()
{
if(HasDocAndIsIdle())
NameBreaker(m_strMpqName, m_strFileList);
}
void TMainFrame::OnToolsMergeListfiles()
{
MergeListfiles();
}
void TMainFrame::OnToolsScriptConsole()
{
if(IsIdle())
RunMpq2000Script("");
}
void TMainFrame::OnToolsMpq2000Script()
{
if(IsIdle())
RunMpq2000Script(NULL);
}
void TMainFrame::OnToolsOptions()
{
if(IsIdle())
Options();
}
void TMainFrame::OnToolsAddFileOptions()
{
if(IsIdle())
AddFileOptions();
}
// This code must NOT cal the default handler, because
// the CFrameWnd has no document.
void TMainFrame::OnDropFiles(HDROP)
{}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -