📄 wndmain.cpp
字号:
if ( bEnding ) SendMessage( WM_CLOSE );
}
/////////////////////////////////////////////////////////////////////////////
// CMainWnd GUI modes
void CMainWnd::SetGUIMode(int nMode, BOOL bSaveState)
{
m_pWindows.ShowWindow( SW_HIDE );
if ( bSaveState )
{
if ( nMode < 0 ) nMode = Settings.General.GUIMode;
ShowControlBar( &m_wndMenuBar, FALSE, TRUE );
ShowControlBar( &m_wndNavBar, FALSE, TRUE );
ShowControlBar( &m_wndToolBar, FALSE, TRUE );
ShowControlBar( &m_wndTabBar, FALSE, TRUE );
ShowControlBar( &m_wndMonitorBar, FALSE, TRUE );
}
m_pWindows.SetGUIMode( nMode, bSaveState );
OnSkinChanged( 0, 0 );
if ( bSaveState )
{
DockControlBar( &m_wndMenuBar, AFX_IDW_DOCKBAR_TOP );
ShowControlBar( &m_wndMenuBar, TRUE, TRUE );
if ( nMode != GUI_WINDOWED && m_wndNavBar.HasLocalVersion() )
{
DockControlBar( &m_wndNavBar, AFX_IDW_DOCKBAR_TOP );
ShowControlBar( &m_wndNavBar, TRUE, TRUE );
}
else
{
DockControlBar( &m_wndToolBar, AFX_IDW_DOCKBAR_TOP );
ShowControlBar( &m_wndToolBar, TRUE, TRUE );
}
DockControlBar( &m_wndTabBar, nMode == GUI_WINDOWED ? AFX_IDW_DOCKBAR_BOTTOM : AFX_IDW_DOCKBAR_TOP );
ShowControlBar( &m_wndTabBar, TRUE, TRUE );
}
m_wndTabBar.SetMaximumWidth( nMode != GUI_WINDOWED ? 200 : 140 );
m_wndTabBar.SetMessage( (UINT)0 );
if ( bSaveState )
{
CRect rcWnd, rcBar;
GetWindowRect( &rcWnd );
if ( m_wndNavBar.IsVisible() )
m_wndNavBar.GetWindowRect( &rcBar );
else
m_wndToolBar.GetWindowRect( &rcBar );
rcBar.left = rcWnd.right - 128;
rcBar.right = rcWnd.right;
DockControlBar( &m_wndMonitorBar, AFX_IDW_DOCKBAR_TOP, &rcBar );
ShowControlBar( &m_wndMonitorBar, nMode == GUI_WINDOWED, TRUE );
}
m_pWindows.ShowWindow( SW_SHOW );
}
/////////////////////////////////////////////////////////////////////////////
// CMainWnd command architecture
BOOL CMainWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
if ( m_wndMonitorBar.m_hWnd != NULL )
{
if ( m_wndMonitorBar.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
}
if ( CMediaFrame::g_pMediaFrame != NULL )
{
if ( CMediaFrame::g_pMediaFrame->OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) )
return TRUE;
}
return CMDIFrameWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
}
BOOL CMainWnd::OnCommand(WPARAM wParam, LPARAM lParam)
{
if ( Plugins.OnCommand( m_pWindows.GetActive(), LOWORD( wParam ) ) ) return TRUE;
return CMDIFrameWnd::OnCommand( wParam, lParam );
}
void CMainWnd::OnUpdatePluginRange(CCmdUI* pCmdUI)
{
if ( ! Plugins.OnUpdate( m_pWindows.GetActive(), pCmdUI ) ) pCmdUI->Enable( FALSE );
}
/////////////////////////////////////////////////////////////////////////////
// CMainWnd menu GUI
void CMainWnd::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
CMDIFrameWnd::OnInitMenuPopup( pPopupMenu, nIndex, bSysMenu );
UINT nID = pPopupMenu->GetMenuItemID( 0 );
if ( nID != SC_RESTORE ) CoolMenu.AddMenu( pPopupMenu, TRUE );
}
void CMainWnd::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
CoolMenu.OnMeasureItem( lpMeasureItemStruct );
}
void CMainWnd::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CoolMenu.OnDrawItem( lpDrawItemStruct );
}
void CMainWnd::OnSysColorChange()
{
CMDIFrameWnd::OnSysColorChange();
CoolInterface.OnSysColourChange();
}
void CMainWnd::OnUpdateFrameTitle(BOOL bAddToTitle)
{
m_wndTabBar.OnUpdateCmdUI( this, FALSE );
m_wndNavBar.OnUpdateCmdUI( this, FALSE );
}
void CMainWnd::OnContextMenu(CWnd* pWnd, CPoint point)
{
if ( ( pWnd != this || OnNcHitTest( point ) != HTCAPTION ) )
{
CMenu* pMenu = Skin.GetMenu( _T("CMainWnd.View") );
if ( pMenu == NULL ) return;
pMenu->TrackPopupMenu( TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, point.x, point.y, this );
}
}
#define SNAP_PIXELS 6
void CMainWnd::OnWindowPosChanging(WINDOWPOS* lpwndpos)
{
CMDIFrameWnd::OnWindowPosChanging( lpwndpos );
CRect rcWork;
SystemParametersInfo( SPI_GETWORKAREA, 0, &rcWork, 0 );
if ( abs( lpwndpos->x ) <= ( rcWork.left + SNAP_PIXELS ) )
{
lpwndpos->x = rcWork.left;
}
else if ( ( lpwndpos->x + lpwndpos->cx ) >= ( rcWork.right - SNAP_PIXELS ) &&
( lpwndpos->x + lpwndpos->cx ) <= ( rcWork.right + SNAP_PIXELS ) )
{
lpwndpos->x = rcWork.right - lpwndpos->cx;
}
if ( abs( lpwndpos->y ) <= ( rcWork.top+SNAP_PIXELS ) )
{
lpwndpos->y = rcWork.top;
}
else if ( ( lpwndpos->y + lpwndpos->cy ) >= ( rcWork.bottom - SNAP_PIXELS ) &&
( lpwndpos->y + lpwndpos->cy ) <= ( rcWork.bottom + SNAP_PIXELS ) )
{
lpwndpos->y = rcWork.bottom-lpwndpos->cy;
}
}
/////////////////////////////////////////////////////////////////////////////
// CMainWnd common timer
void CMainWnd::OnTimer(UINT nIDEvent)
{
// Fix resource handle
if ( AfxGetResourceHandle() != m_hInstance )
AfxSetResourceHandle( m_hInstance );
// Propagate to children
if ( m_bTimer ) return;
m_bTimer = TRUE;
for ( POSITION pos = m_pWindows.GetIterator() ; pos ; )
{
CChildWnd* pChild = m_pWindows.GetNext( pos );
pChild->PostMessage( WM_TIMER, 1, 0 );
}
m_bTimer = FALSE;
Settings.Live.LoadWindowState = FALSE;
// Statistics
Statistics.Update();
// Hashing progress
// m_wndHashProgressBar.Run();
// Switch tray icon
BOOL bNeedTrayIcon = m_bTrayHide || Settings.General.TrayMinimise || Settings.General.CloseMode == 2;
if ( bNeedTrayIcon && ! m_bTrayIcon )
{
m_pTray.cbSize = sizeof(m_pTray);
m_pTray.hWnd = GetSafeHwnd();
m_pTray.uID = 0;
m_pTray.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
m_pTray.uCallbackMessage = WM_TRAY;
if ( CoolInterface.IsNewWindows() )
m_pTray.hIcon = AfxGetApp()->LoadIcon( IDI_SMALL );
else
m_pTray.hIcon = AfxGetApp()->LoadIcon( IDI_ICON );
_tcscpy( m_pTray.szTip, _T("Shareaza") );
m_bTrayIcon = ( Shell_NotifyIcon( NIM_ADD, &m_pTray ) != 0 );
}
else if ( m_bTrayIcon && ! bNeedTrayIcon )
{
Shell_NotifyIcon( NIM_DELETE, &m_pTray );
m_bTrayIcon = FALSE;
}
// Menu Bar
if ( m_wndMenuBar.IsWindowVisible() == FALSE ) ShowControlBar( &m_wndMenuBar, TRUE, FALSE );
// Update messages
UpdateMessages();
}
void CMainWnd::OnActivateApp(BOOL bActive, DWORD dwTask)
{
CMDIFrameWnd::OnActivateApp( bActive, dwTask );
if ( ! bActive )
{
CoFreeUnusedLibraries();
// SetProcessWorkingSetSize( GetCurrentProcess(), 0xFFFFFFFF, 0xFFFFFFFF );
}
}
void CMainWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CMDIFrameWnd::OnActivate( nState, pWndOther, bMinimized );
if ( nState != WA_INACTIVE )
{
if ( CChildWnd* pChildWnd = m_pWindows.GetActive() )
{
pChildWnd->SendMessage( WM_MDIACTIVATE, NULL, (LPARAM)pChildWnd->GetSafeHwnd() );
}
}
}
void CMainWnd::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
CMDIFrameWnd::OnGetMinMaxInfo( lpMMI );
lpMMI->ptMinTrackSize.x = 320;
lpMMI->ptMinTrackSize.y = 240;
if ( m_pSkin ) m_pSkin->OnGetMinMaxInfo( lpMMI );
}
LONG CMainWnd::OnLog(WPARAM wParam, LPARAM lParam)
{
LPTSTR pszLog = (LPTSTR)lParam;
if ( CSystemWnd* pWnd = (CSystemWnd*)m_pWindows.Find( RUNTIME_CLASS(CSystemWnd) ) )
{
pWnd->Add( (int)wParam, pszLog );
}
free( pszLog );
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// CMainWnd tray functionality
void CMainWnd::CloseToTray()
{
if ( m_bTrayHide ) return;
ShowWindow( SW_HIDE );
m_bTrayHide = TRUE;
}
void CMainWnd::OpenFromTray(int nShowCmd)
{
if ( m_bTrayHide ) ShowWindow( nShowCmd );
if ( IsIconic() ) SendMessage( WM_SYSCOMMAND, SC_RESTORE );
SetForegroundWindow();
m_bTrayHide = FALSE;
}
LONG CMainWnd::OnTray(UINT wParam, LONG lParam)
{
if ( LOWORD(lParam) == WM_LBUTTONDBLCLK )
{
OpenFromTray();
}
else if ( LOWORD(lParam) == WM_RBUTTONDOWN )
{
UINT nFlags = TPM_RIGHTBUTTON;
CPoint pt;
CRect rc;
GetCursorPos( &pt );
SystemParametersInfo( SPI_GETWORKAREA, 0, &rc, 0 );
nFlags |= TPM_CENTERALIGN;
if ( pt.y > GetSystemMetrics( SM_CYSCREEN ) / 2 )
{
pt.y = rc.bottom;
nFlags |= TPM_TOPALIGN;
}
else
{
pt.y = rc.top;
nFlags |= TPM_BOTTOMALIGN;
}
SetForegroundWindow();
CMenu* pMenu = Skin.GetMenu( _T("CMainWnd.Tray") );
if ( pMenu == NULL ) return 0;
MENUITEMINFO pInfo;
pInfo.cbSize = sizeof(pInfo);
pInfo.fMask = MIIM_STATE;
GetMenuItemInfo( pMenu->GetSafeHmenu(), ID_TRAY_OPEN, FALSE, &pInfo );
pInfo.fState |= MFS_DEFAULT;
SetMenuItemInfo( pMenu->GetSafeHmenu(), ID_TRAY_OPEN, FALSE, &pInfo );
pMenu->TrackPopupMenu( nFlags, pt.x, pt.y, this, NULL );
PostMessage( WM_NULL );
}
return 0;
}
void CMainWnd::OnTrayOpen()
{
OpenFromTray();
}
void CMainWnd::OnSysCommand(UINT nID, LPARAM lParam)
{
if ( ( nID & 0xFFF0 ) == SC_KEYMENU )
{
if ( lParam != ' ' && lParam != '-' )
{
if ( lParam )
m_wndMenuBar.OpenMenuChar( lParam );
else
m_wndMenuBar.OpenMenuBar();
return;
}
}
if ( m_bTrayHide )
{
switch ( nID & 0xFFF0 )
{
case SC_RESTORE:
OpenFromTray( SW_SHOWNORMAL );
return;
case SC_MAXIMIZE:
OpenFromTray( SW_SHOWMAXIMIZED );
return;
}
}
else
{
BOOL bShift = ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 );
switch ( nID & 0xFFF0 )
{
case SC_CLOSE:
if ( Settings.General.CloseMode == 0 )
{
CCloseModeDlg dlg;
if ( dlg.DoModal() != IDOK ) return;
}
if ( Settings.General.CloseMode == 3 && ! bShift )
{
if ( Settings.Live.AutoClose )
CloseToTray();
else
OnNetworkAutoClose();
return;
}
else if ( Settings.General.CloseMode == 2 && ! bShift )
{
CloseToTray();
return;
}
break;
case SC_MINIMIZE:
if ( ( Settings.General.TrayMinimise && ! bShift ) || ( ! Settings.General.TrayMinimise && bShift ) )
{
CloseToTray();
return;
}
break;
}
}
CMDIFrameWnd::OnSysCommand( nID, lParam );
}
/////////////////////////////////////////////////////////////////////////////
// CMainWnd custom message handlers
LONG CMainWnd::OnSkinChanged(UINT wParam, LONG lParam)
{
CWaitCursor pCursor;
m_pSkin = NULL;
m_pWindows.PostSkinRemove();
m_wndMenuBar.SetMenu( NULL );
m_wndToolBar.Clear();
CDownloadMonitorDlg::OnSkinChange( FALSE );
CSettingsManagerDlg::OnSkinChange( FALSE );
CFilePreviewDlg::OnSkinChange( FALSE );
Skin.Apply();
if ( CMenu* pMenu = Skin.GetMenu( _T("CMainWnd") ) )
{
m_wndMenuBar.SetMenu( pMenu->Detach() );
}
Skin.CreateToolBar( _T("CMainWnd"), &m_wndToolBar );
m_wndNavBar.OnSkinChange();
m_wndMenuBar.SetWatermark( Skin.GetWatermark( _T("CCoolMenuBar") ) );
m_wndTabBar.SetWatermark( Skin.GetWatermark( _T("CWndTabBar") ) );
if ( CWnd* pDockBar = GetDlgItem( AFX_IDW_DOCKBAR_TOP ) )
{
DWORD nBrush = GetClassLong( pDockBar->GetSafeHwnd(), GCL_HBRBACKGROUND );
if ( nBrush > 64 ) DeleteObject( (HBRUSH)nBrush );
nBrush = (DWORD)CreateSolidBrush( CoolInterface.m_crMidtone );
SetClassLong( pDockBar->GetSafeHwnd(), GCL_HBRBACKGROUND, (LONG)nBrush );
}
m_pSkin = Skin.GetWindowSkin( this );
if ( m_pSkin != NULL )
{
ModifyStyle( WS_CAPTION, 0 );
m_pWindows.ModifyStyleEx( WS_EX_CLIENTEDGE, 0 );
SetWindowRgn( NULL, TRUE );
m_pSkin->OnSize( this );
}
else
{
ModifyStyle( 0, WS_CAPTION, 0 );
m_pWindows.ModifyStyleEx( 0, WS_EX_CLIENTEDGE );
SetWindowRgn( NULL, TRUE );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -