📄 dummydesktopdlg.cpp
字号:
// DummyDeskTopDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DummyDeskTop.h"
#include "DummyDeskTopDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
#pragma data_seg("mydata")
d_list now_desk;
d_list pre_desk;
d_list desktop[4];
#pragma data_seg()
/////////////////////////////////////////////////////////////////////////////
// CDummyDeskTopDlg dialog
CDummyDeskTopDlg::CDummyDeskTopDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDummyDeskTopDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDummyDeskTopDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_nEdgeSnapGap=50;
}
void CDummyDeskTopDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDummyDeskTopDlg)
DDX_Control(pDX, IDC_BUTTON4, m_w4);
DDX_Control(pDX, IDC_BUTTON3, m_w3);
DDX_Control(pDX, IDC_BUTTON2, m_w2);
DDX_Control(pDX, IDC_BUTTON1, m_w1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDummyDeskTopDlg, CDialog)
//{{AFX_MSG_MAP(CDummyDeskTopDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_WM_CLOSE()
ON_WM_MOUSEMOVE()
ON_WM_WINDOWPOSCHANGING()
ON_WM_KILLFOCUS()
//}}AFX_MSG_MAP
ON_MESSAGE( WM_SYSTEMTRAY, OnSystemTray )
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDummyDeskTopDlg message handlers
BOOL CDummyDeskTopDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
// TODO: Add extra initialization here
nid.cbSize = sizeof( NOTIFYICONDATA );
nid.hWnd = m_hWnd;
nid.uID = ID_SYSTEMTRAY;
nid.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
nid.uCallbackMessage = WM_SYSTEMTRAY;
nid.hIcon = AfxGetApp()->LoadIcon(ID_SYSTEMTRAY);
strcpy( nid.szTip, "虚拟桌面" );
::Shell_NotifyIcon( NIM_ADD,&nid );
//.............................
this->SetWindowText("虚拟桌面");
pre_desk_num=0;
now_desk_num=0;
m_SmallSize=0;
DWORD Style = ::GetWindowLong(AfxGetMainWnd()->m_hWnd,GWL_EXSTYLE);
Style=WS_EX_TOPMOST | WS_EX_TOOLWINDOW ;
AfxGetMainWnd()->ShowWindow(FALSE);
::SetWindowLong(AfxGetMainWnd()->m_hWnd,GWL_EXSTYLE,Style);
AfxGetMainWnd()->ShowWindow(TRUE);
//::SetWindowPos(GetSafeHwnd(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
//SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOSIZE | WS_EX_TOPMOST);
screen_x=GetSystemMetrics(SM_CXSCREEN);
// CRect rect;
// GetWindowRect(&rect);
GetWindowRect( &m_rectFull );
SetWindowPos( &wndTopMost,screen_x-m_rectFull.Width(),0,0,0,SWP_NOSIZE);
m_rectSmall = m_rectFull;
m_rectSmall.bottom = m_rectFull.bottom-90;
// rect=m_rectSmall;
// calculate our half size based on bottom of "More" button
// GetWindowRect( &rect );
return TRUE; // return TRUE unless you set the focus to a control
}
void CDummyDeskTopDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
CDialog::OnSysCommand(nID, lParam);
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDummyDeskTopDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDummyDeskTopDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CDummyDeskTopDlg::EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
char buff[256];
if(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE)
{
::GetWindowText(hwnd,buff,255);
if(lstrcmp(buff,"Program Manager")==0) //桌面不隐藏
return 1;
if(!lstrcmp(buff,"虚拟桌面")) //自己不隐藏
{
::GetClassName(hwnd,buff,255); //因为文件夹有可能和
if(lstrcmp(buff,"CabinetWClass")!=0)
return 1;
}
::GetClassName(hwnd,buff,255); //任务栏不隐藏
if(lstrcmp(buff,"Shell_TrayWnd")==0)
return 1;
now_desk.d_insert(hwnd,0);
::ShowWindow(hwnd,SW_HIDE);
}
return 1;
}
void CDummyDeskTopDlg::OnButton4()
{
// TODO: Add your control notification handler code here
pre_desk_num=now_desk_num;
pre_desk=now_desk;
now_desk_num=3;
::EnumWindows(CDummyDeskTopDlg::EnumWindowsProc,NULL);
pre_desk.d_comp(now_desk);
pre_desk.d_read_add(desktop[pre_desk_num],0);
now_desk.d_read_add(desktop[pre_desk_num],1);
desktop[now_desk_num].d_comp(now_desk);
desktop[now_desk_num].d_read_add(desktop[now_desk_num],0);
i=1;
while(i<=desktop[now_desk_num].d_getnCount())
::ShowWindow(desktop[now_desk_num].d_read(i++),SW_SHOW);
m_w1.SetWindowText("1");
m_w2.SetWindowText("2");
m_w3.SetWindowText("3");
m_w4.SetWindowText("S4");
}
void CDummyDeskTopDlg::OnButton2()
{
// TODO: Add your control notification handler code here
pre_desk_num=now_desk_num;
pre_desk=now_desk;
now_desk_num=1;
::EnumWindows(CDummyDeskTopDlg::EnumWindowsProc,NULL);
pre_desk.d_comp(now_desk);
pre_desk.d_read_add(desktop[pre_desk_num],0);
now_desk.d_read_add(desktop[pre_desk_num],1);
desktop[now_desk_num].d_comp(now_desk);
desktop[now_desk_num].d_read_add(desktop[now_desk_num],0);
i=1;
while(i<=desktop[now_desk_num].d_getnCount())
::ShowWindow(desktop[now_desk_num].d_read(i++),SW_SHOW);
m_w1.SetWindowText("1");
m_w2.SetWindowText("S2");
m_w3.SetWindowText("3");
m_w4.SetWindowText("4");
}
void CDummyDeskTopDlg::OnButton1()
{
// TODO: Add your control notification handler code here
pre_desk_num=now_desk_num;
pre_desk=now_desk;
now_desk_num=0;
::EnumWindows(CDummyDeskTopDlg::EnumWindowsProc,NULL);
pre_desk.d_comp(now_desk);
pre_desk.d_read_add(desktop[pre_desk_num],0);
now_desk.d_read_add(desktop[pre_desk_num],1);
desktop[now_desk_num].d_comp(now_desk);
desktop[now_desk_num].d_read_add(desktop[now_desk_num],0);
desktop[now_desk_num].d_comp(now_desk);
desktop[now_desk_num].d_read_add(desktop[now_desk_num],0);
i=1;
while(i<=desktop[now_desk_num].d_getnCount())
::ShowWindow(desktop[now_desk_num].d_read(i++),SW_SHOW);
m_w1.SetWindowText("S1");
m_w2.SetWindowText("2");
m_w3.SetWindowText("3");
m_w4.SetWindowText("4");
}
void CDummyDeskTopDlg::OnButton3()
{
// TODO: Add your control notification handler code here
pre_desk_num=now_desk_num;
pre_desk=now_desk;
now_desk_num=2;
::EnumWindows(CDummyDeskTopDlg::EnumWindowsProc,NULL);
pre_desk.d_comp(now_desk);
pre_desk.d_read_add(desktop[pre_desk_num],0);
now_desk.d_read_add(desktop[pre_desk_num],1);
desktop[now_desk_num].d_comp(now_desk);
desktop[now_desk_num].d_read_add(desktop[now_desk_num],0);
i=1;
while(i<=desktop[now_desk_num].d_getnCount())
::ShowWindow(desktop[now_desk_num].d_read(i++),SW_SHOW);
m_w1.SetWindowText("1");
m_w2.SetWindowText("2");
m_w3.SetWindowText("S3");
m_w4.SetWindowText("4");
}
LRESULT CDummyDeskTopDlg::OnSystemTray( WPARAM wParam,LPARAM lParam)
{
if ( wParam = ID_SYSTEMTRAY )
{
switch( lParam )
{
case WM_LBUTTONDOWN :
{
{this->ShowWindow(SW_SHOW);
}
this->SetForegroundWindow();
this->SetActiveWindow();
break ;
}
case WM_RBUTTONDOWN :
{
break ;}
case WM_LBUTTONDBLCLK:
break ;
}
}
return 0;
}
void CDummyDeskTopDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
NOTIFYICONDATA nid;
nid.cbSize = sizeof( NOTIFYICONDATA );
nid.hWnd = m_hWnd;
nid.uID =ID_SYSTEMTRAY;
nid.uFlags = 0;
::Shell_NotifyIcon( NIM_DELETE,&nid );
::EnumWindows(CDummyDeskTopDlg::EnumWindowsProc,NULL);
i=1;
while(i<=now_desk.d_getnCount())
::ShowWindow(now_desk.d_read(i++),SW_SHOW);
CDialog::OnClose();
}
BOOL CDummyDeskTopDlg::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::Create(IDD, pParentWnd);
}
void CDummyDeskTopDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/* CRect rect;
if ( m_SmallSize )
{
rect = m_rectFull;
}
else
{
rect = m_rectSmall;
}
// SetWindowPos( NULL,500,500,rect.Width( ) , rect.Height( ) ,
// SWP_NOZORDER );
SetWindowPos( NULL,screen_x-m_rectFull.Width(),0,rect.Width( ) ,rect.Height( ), SWP_NOZORDER);
m_SmallSize = !m_SmallSize ;*/
CDialog::OnMouseMove(nFlags, point);
}
void CDummyDeskTopDlg::OnWindowPosChanging( WINDOWPOS* lpwndpos )
{
RECT rcScrn;
SystemParametersInfo (SPI_GETWORKAREA, 0, &rcScrn, 0);
// Snap X axis
if (abs(lpwndpos->x - rcScrn.left) <= m_nEdgeSnapGap)
lpwndpos->x = rcScrn.left;
else if (abs(lpwndpos->x + lpwndpos->cx - rcScrn.right) <= m_nEdgeSnapGap)
lpwndpos->x = rcScrn.right - lpwndpos->cx;
// Snap Y axis
if (abs(lpwndpos->y - rcScrn.top) <= m_nEdgeSnapGap)
lpwndpos->y = rcScrn.top;
else if (abs(lpwndpos->y + lpwndpos->cy - rcScrn.bottom) <= m_nEdgeSnapGap)
lpwndpos->y = rcScrn.bottom - lpwndpos->cy;
}
void CDummyDeskTopDlg::OnKillFocus(CWnd* pNewWnd)
{
CDialog::OnKillFocus(pNewWnd);
// CRect rect;
// if ( m_SmallSize )
// {
// rect = m_rectFull;
// }
// else
// {
// rect = m_rectSmall;
// }
// TODO: Add your message handler code here
// SetWindowPos( NULL,screen_x-m_rectFull.Width(),0,rect.Width( ) ,rect.Height( ), SWP_NOZORDER);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -