// DeskTop.cpp : Defines the class behaviors for the application.
//#include "stdafx.h"
#include "DeskTop.h"
#include "DeskTopDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CDeskTopAppBEGIN_MESSAGE_MAP(CDeskTopApp, CWinApp)
//{{AFX_MSG_MAP(CDeskTopApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
//    DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CDeskTopApp constructionCDeskTopApp::CDeskTopApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}/////////////////////////////////////////////////////////////////////////////
// The one and only CDeskTopApp objectCDeskTopApp theApp;/////////////////////////////////////////////////////////////////////////////
// CDeskTopApp initializationBOOL CDeskTopApp::InitInstance()
{
AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
//  of your final executable, you should remove from the following
//  the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif CDeskTopDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with Cancel
} // Since the dialog has been closed, return FALSE so that we exit the
//  application, rather than start the application's message pump.
return FALSE;
}

解决方案 »

  1.   

    // DeskTop.h : main header file for the DESKTOP application
    //#if !defined(AFX_DESKTOP_H__AA893E62_F1C6_4201_946C_4B4E51C4290A__INCLUDED_)
    #define AFX_DESKTOP_H__AA893E62_F1C6_4201_946C_4B4E51C4290A__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000#ifndef __AFXWIN_H__
    #error include 'stdafx.h' before including this file for PCH
    #endif#include "resource.h" // main symbols/////////////////////////////////////////////////////////////////////////////
    // CDeskTopApp:
    // See DeskTop.cpp for the implementation of this class
    //class CDeskTopApp : public CWinApp
    {
    public:
    CDeskTopApp();// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CDeskTopApp)
    public:
    virtual BOOL InitInstance();
    //}}AFX_VIRTUAL// Implementation //{{AFX_MSG(CDeskTopApp)
    // NOTE - the ClassWizard will add and remove member functions here.
    //    DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };
    ///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DESKTOP_H__AA893E62_F1C6_4201_946C_4B4E51C4290A__INCLUDED_)
      

  2.   

    // DeskTopDlg.h : header file
    //#if !defined(AFX_DESKTOPDLG_H__4E388E00_2507_478D_8C6E_9196C035C1E1__INCLUDED_)
    #define AFX_DESKTOPDLG_H__4E388E00_2507_478D_8C6E_9196C035C1E1__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    #include <afxtempl.h>/////////////////////////////////////////////////////////////////////////////
    // CDeskTopDlg dialog
    //#######################################################################################
    // 使用的静态变量定义
    const int DESKTOP_CNT = 4; // 定义虚拟桌面数为4, 一般够用//#pragma data_seg("mydata") 
    // CArray<HWND,HWND> m_arrHwndDesktop[DESKTOP_CNT]; // 虚拟桌面列表
    //#pragma data_seg() class CDeskTopDlg : public CDialog
    {
    // Construction
    public:
    CDeskTopDlg(CWnd* pParent = NULL); // standard constructor
        static BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam);
    // afx_msg void OnWindowPosChanging( WINDOWPOS* lpwndpos );// Dialog Data
    //{{AFX_DATA(CDeskTopDlg)
    enum { IDD = IDD_DESKTOP_DIALOG };
    CListCtrl m_list;
    CTabCtrl m_tab;
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CDeskTopDlg)
    public:
    virtual BOOL DestroyWindow();
    virtual BOOL PreTranslateMessage(MSG* pMsg);
    protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    HICON m_hIcon; // Generated message map functions
    //{{AFX_MSG(CDeskTopDlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    virtual void OnOK();
    afx_msg void OnClose();
    afx_msg void OnBegindragList(NMHDR* pNMHDR, LRESULT* pResult);
    afx_msg void OnCheckAllDesk();
    afx_msg void OnItemchangedList(NMHDR* pNMHDR, LRESULT* pResult);
    afx_msg void OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult);
    afx_msg void OnButtonQuit();
    afx_msg void OnButtonExpand();
    //}}AFX_MSG
    afx_msg void OnSelectDesktop(int nID);
    afx_msg void OnHotKey(WPARAM wp,LPARAM lp);
    DECLARE_MESSAGE_MAP()
    private:
    // CArray<HWND,HWND> m_arrHwnd[DESKTOP_CNT];
    void TraceInfo();
    void InitTab(); // 初始化TAB控件
    void FillDeskList(int nDesk);

    // Initializes the virtual desktop manager
    void InitializeDesks(); // 初始化虚拟桌面管理

    // Un-initializes the virtual desktop manager
    void UninitializeDesks(); // 析构虚拟桌面管理

    // Loads the current active desk (based on m_nCurrDesk)
    void LoadDesk(BOOL bSetColors=TRUE); // 加载指定虚拟桌面的所有窗口(m_nCurrDesk)

    void SaveDesk(); // 保存当前桌面(m_nCurrDesk)
    void SwitchDesks(int nNewDesk); // 切换到新的桌面
    void SaveWnd(HWND hWnd); // 添加某个窗口到当前桌面(m_nCurrDesk)
    int  FindNormalWindow(int nDesk, HWND hWnd); // 在指定桌面查找指定的窗口句柄
    int  FindGluedWindow(HWND hWndGlue); // 查找指定的窗口句柄在全局窗口中的索引

    // Callback routine used by window enumeration
    static BOOL CALLBACK EnumCallback(HWND hWnd, LPARAM lParam);

    BOOL IsCandidate(HWND hWnd); // 是否是可以加入到某个虚拟桌面的候选窗口

    BOOL IsGlued(HWND hWndGlue) { return FindGluedWindow(hWndGlue) >= 0; } // 是否是在所有桌面都显示的窗口

    void AddToAllDesks(HWND hWnd); // 增加某个窗口到所有的虚拟桌面
    void RemoveFromAllDesks(HWND hWnd, int nTab); // 从所有的虚拟桌面中移除指定窗口

    // Moves the specified entry from one desk to another
    void MoveToDesk(int nOldDesk, int nOldEntry, int nNewDesk); // 把指定窗口从某个虚拟桌面移动到另外一个虚拟桌面

    // Glues or unglues the specified window
    void SetGlue(HWND hWndGlue, BOOL bGlue, int nTab); // 设置某个窗口是否是在所有桌面都显示的窗口

    // Returns the number of entries in the window collection
    int GetWindowCount(int nDesk); // 获取指定虚拟桌面上的窗口总数

    // Returns the number of entries in the glued window collection
    int GetGluedCount(); // 获取在所有桌面都显示窗口的窗口总数

    // Performs ShowWindow() for applications that aren't locked up
    BOOL SafeShowWindow(HWND hWnd, int nShowCmd); // 安全显示指定窗口,挂起者不显示

    BOOL IsRespondWindow(HWND hWnd); // 判断指定窗口是否是可以响应的窗口
    void ShowHideDesk(); // 

    private:
    // True if dragging is in progress
    BOOL m_bDragging; // 标记是否正在拖放窗口

    // Desk where draggin began
    int m_nDragDesk; // 

    // Number of selected listview entry
    int m_nSelectedEntry; // 窗口列表框中选中的窗口条目索引

    HCURSOR m_hcurDrop; // 拖放时可以放下的光标
    HCURSOR m_hcurNoDrop; // 禁止停放的光标

    CImageList m_imgList; // 窗口列表框使用的图标列表
    CStringArray m_arrStrDeskName; // 所有的虚拟桌面名称
    CArray<COLORREF,COLORREF> m_arrClrDesk; // 所有的虚拟桌面颜色
    CArray<HWND,HWND> m_arrHwndDesktop[DESKTOP_CNT]; // 每个桌面包含的窗口句柄
    CArray<HWND,HWND> m_arrHwndGlued; // 所有桌面都要显示的窗口句柄
    int m_nCurrDeskIndex; // 记录当前虚拟桌面的索引

    // TRUE if in the middle of switching desks
    // 是否正在切换桌面
    BOOL m_bSwitching;

    // TRUE if we encounter a locked up application that can't respond to messages
    // 是否是一个被挂起的无法相应我们消息的窗口
    BOOL m_bFrozen;

    // Window handles of the shell, desktop and any windows ZDDesk is displaying
    HWND m_hWndShell; // 任务栏窗口句柄
    HWND m_hWndDesktop; // 桌面窗口句柄
    HWND m_hWndPopup; // 本程序的弹出窗口句柄

    int m_nCurrDesk; // 当前激活的虚拟桌面索引

    // Registry interfaces
    // CZDRegistry *m_pRegistry; // 注册表操作接口指针
    // HKEY m_hKey; // 注册表键

    };//{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DESKTOPDLG_H__4E388E00_2507_478D_8C6E_9196C035C1E1__INCLUDED_)