?? taskswitcherdlg.cpp
字號:
// TaskSwitcherDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TaskSwitcher.h"
#include "TaskSwitcherDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTaskSwitcherDlg dialog
/**************************************************************
*說明:
* 這四個全局變量作用分別是
* g_iWndCount: 當前系統運行的任務數
* g_hWndArray[]:保存當前運行任務的窗口句柄
* g_strWndTextArray[]:保存運行任務的窗口標題
* g_hWndIconArray[]:保存運行任務的窗口圖標句柄
**************************************************************/
#define MAX_TASK_NUMBER (int)24
extern int g_iWndCount;
extern HWND g_hWndArray[MAX_TASK_NUMBER];
extern CString g_strWndTextArray[MAX_TASK_NUMBER];
extern HICON g_hWndIconArray[MAX_TASK_NUMBER];
/**************************************************************
*函數名稱:EnumWindowProc(...),回調函數
*函數功能:枚舉當前運行的任務,并獲取它們的窗口句柄、窗口標題、
圖標句柄
**************************************************************/
BOOL CALLBACK EnumWindowProc(HWND hWnd, LPARAM lparam)
{
CWnd *pWnd = CWnd::FromHandle(hWnd);
if(pWnd != NULL && pWnd->IsWindowVisible())
{
pWnd->GetWindowText(g_strWndTextArray[g_iWndCount]);
if(!g_strWndTextArray[g_iWndCount].IsEmpty())
{
g_strWndTextArray[g_iWndCount].TrimLeft();
g_strWndTextArray[g_iWndCount].TrimRight();
if(g_strWndTextArray[g_iWndCount] == "顯示桌面")
{
g_hWndArray[MAX_TASK_NUMBER] = hWnd;
g_hWndIconArray[MAX_TASK_NUMBER] = pWnd->GetIcon(FALSE);
}
else
{
g_hWndArray[g_iWndCount] = hWnd;
g_hWndIconArray[g_iWndCount] = pWnd->GetIcon(FALSE);
g_iWndCount ++;
}
}
}
return TRUE;
}
CTaskSwitcherDlg::CTaskSwitcherDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTaskSwitcherDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTaskSwitcherDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTaskSwitcherDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTaskSwitcherDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTaskSwitcherDlg, CDialog)
//{{AFX_MSG_MAP(CTaskSwitcherDlg)
ON_BN_CLICKED(IDC_BTN_MENU, OnBtnMenu)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTaskSwitcherDlg message handlers
BOOL CTaskSwitcherDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
ShowWindow(SW_SHOWMAXIMIZED);
// ShowWindow(SW_SHOWMINIMIZED);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTaskSwitcherDlg::OnOK()
{
// TODO: Add extra validation here
if(pListMenu)
{
pListMenu = NULL;
delete pListMenu;
}
CDialog::OnOK();
}
/*********************************************************************************
*函數名稱:OnBtnMenu()
*函數功能:按鈕響應函數,點擊后彈出當前運行任務菜單
*輸入參數:無
*輸出參數:無
*創建者:孫軍杰
*創建日期:2007-06-21
*********************************************************************************/
//Initialize task list menu and implement task switch
void CTaskSwitcherDlg::OnBtnMenu()
{
// TODO: Add your control notification handler code here
if(pListMenu)
{
pListMenu = NULL;
delete pListMenu;
}
pListMenu = new CMenu;
if(!pListMenu->CreatePopupMenu())
{
return;
}
int count = pListMenu->GetMenuItemCount();
g_iWndCount = 0;
::EnumWindows((WNDENUMPROC)EnumWindowProc, 0);
for(int i = 0; i < g_iWndCount; i ++)
{
pListMenu->InsertMenu(i, MF_BYPOSITION, IDM_TASK0 + i, g_strWndTextArray[i]);
}
pListMenu->InsertMenu(g_iWndCount, MF_BYPOSITION, IDM_SHOWDESKTOP, TEXT("顯示桌面"));
pListMenu->TrackPopupMenu(TPM_RIGHTALIGN, 240, 26, AfxGetMainWnd());
}
/*********************************************************************************
*函數名稱:OnCmdMsg(...)
*函數功能:在此處用來相應點擊菜單后的動作:執行任務切換
*輸入參數:見MSDN
*輸出參數:見MSDN
*創建者:孫軍杰
*創建日期:2007-06-21
*********************************************************************************/
BOOL CTaskSwitcherDlg::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// TODO: Add your specialized code here and/or call the base class
if (pHandlerInfo == NULL)
{
// Filter the commands sent to a text color menu option
if(nID == IDM_SHOWDESKTOP)
{
::SetForegroundWindow(g_hWndArray[MAX_TASK_NUMBER]);
return TRUE;
}
else
{
for (int i = 0; i <= g_iWndCount; i++)
{
if (nID - IDM_TASK0 == (unsigned)i)
{
if (nCode == CN_COMMAND)
{
// Handle WM_COMMAND message
::SetForegroundWindow(g_hWndArray[i]);
}
return TRUE;
}
}
}
}
return CDialog::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -