首页 > 编程知识 正文

桌面小工具,简单桌面壁纸

时间:2023-05-05 15:34:17 阅读:155440 作者:1227

请注明转载引用于http://blog.csdn.net/chenyu Jing 1234

欢迎大家一起拍砖头!

参考英语文章: virtual desktop 3360 asimpledesktopmanagementtool

源代码请下载到原文链接。

一、引言几个月前,我有个大学同学用工具管理混合桌面。 我对有这样的道具感兴趣。 我认为只是为了隐藏显示不同桌面的APP应用程序。 作为好奇心,我开始研究混合桌面,得到了这篇文章。 我发现我以为这个工具只是显示隐藏用的想法是错误的。 让我们看看它是如何工作的。

二. Window Station and Window Desktop实际为Windows用Window Station and Desktop 结构来提供可增加的安全。

暂时来说,“桌面”是指包含用户界面对象(GDI对象)和用户对象的逻辑表示面。

窗口站是一个安全的内核对象,包含剪贴板、原子钟和一个或多个桌面对象。 它们存在默认的窗口工作站“WinSta0”。

这是一个交互式窗口站,“WinSta0”是唯一的交互式窗口站,可以显示用户界面和接收用户输入,而其他窗口站是非交互式的。

默认情况下,交互式容器工作站有三个桌面:默认、WinLogon和ScreenSaver。

)1)按ATL CTL DEL键时显示的窗口为WinLogon桌面。

)2)无论用户何时登录,都会创建并显示默认窗口。 此处的“默认”是指所有登录用户的默认活动桌面。 kfdhf按ATL CTL DEL键可切换回WinLogon桌面。

(3屏幕保护程序激活时,屏幕保护程序将显示并激活ScreenSave桌面。

由于这些桌面名称不敏感,因此它们只能是在容器工作站上指定名称的一个桌面,但一个桌面名称会在不同的窗口工作站上重复显示。

桌面还是一个安全的内核对象,创建新桌面后,它将与调用该进程的当前窗口工作站相关联。 那里总是只显示一个桌面,准备接受用户输入。

提供的桌面和交互式窗口工作站是联合的。 将调用活动窗口。

以下桌面和窗口工作站工程旨在提供不同流程的顶级解决方案。

三.虚拟桌面(简单APP应用程序)对于虚拟桌面,有助于创建和转换不同的桌面。 虽然它看起来像是从一个桌面移动到另一个桌面,但这不是真的,因为存在正在运行的APP应用程序

将桌面移动到另一个桌面。 就像我说的,这只是一个幻想,这个APP应用程序将在现在的桌面上关闭,在特别的桌面上打开。 这可能会导致未保存在APP应用程序中的数据丢失

由于可能重新启动,因此可能无法保存状态。

此APP应用程序使用hooks在APP应用程序的“控制面板”中显示“移动到”菜单选项。 有关hooks的详细信息将在文章中进行介绍,但将大致介绍工程中使用的APIs和类。

differentapisusedandclassesbuilt 1、初始化工作主要是获取当前桌面的名称,根据名称设置APP定位标题,生成右下角的图标,查询系统中桌面的数量和名称并写注册表

加载Evnent Hooker.dll,调用接口安装窗口HOOK和消息HOOK。

//checkswhetherthespecifieddesktopiscurrentactivedesktop (deskopofthecurrentthread ) )。 boolcdesktopmanager :3360 getcurrentdesktopname (tcharszdesktopname [ array _ size ] ); try{DWORD iOutCount=0; hdeskhcurrentdesktop=getthreaddesktop (getcurrentthreadid () ); if (! etuserobjectinformation (hcurrentdesktop,UOI_NAME,szDesktopName,ARRAY_SIZE - 1,iOutCount ) ) ) throw_t }catch(tchar*pszerrorstring )调试打印错误消息(pszerrorstring ); }catch(…) debugprinterrormessage(t ) (ncdesktopmanager 3360: iscurrentdesktop (texceptioncaughtincdesktopht b retopht b returesktop ) }return bReturn; }

//Windows procedur

e hook (filter) function.LRESULT CALLBACK WinProcHookProcedure(int nCode, WPARAM wParam, LPARAM lParam){if(0 > nCode)return CallNextHookEx(g_hPreviousWinProcHook ,nCode,wParam,lParam);CWPSTRUCT *pwsStruct = (CWPSTRUCT *) lParam;switch(pwsStruct->message){//Handle the init menu message.case WM_INITMENU:{HMENU hMenu = (HMENU) pwsStruct->wParam;OutputDebugString(_T("nWinProcHookProcedure:tMenu WM_INITMENUPOPUP Event Fired."));TCHAR szWindowText[ARRAY_SIZE] = {0};GetWindowText(pwsStruct->hwnd, szWindowText, ARRAY_SIZE);//Hook "Move To" Menu Into System Menu.if(0 != _tcscmp(szWindowText, _T("Virtual Desktop !")))InsertMenu(pwsStruct->hwnd);}}return CallNextHookEx(g_hPreviousWinProcHook ,nCode,wParam,lParam);}//Set the Windows procedure filter.bool InstallWinProcHook(void){bool bReturn = false;try{//Set the Windows procedure filter.OutputDebugString(_T("nInstallWinProcHook:tWinProc Event Hooked."));g_hPreviousWinProcHook = SetWindowsHookEx(WH_CALLWNDPROC,&WinProcHookProcedure,g_hInstance,0);if(NULL == g_hPreviousWinProcHook){TCHAR szError[ARRAY_SIZE] = {0};wsprintf(szError,_T("Last Error : %d"),GetLastError());OutputDebugString(_T("nInstallWinProcHook:tFailed to Hook WinProc Event.n"));OutputDebugString(szError);bReturn = false;}else{OutputDebugString(_T("nInstallWinProcHook:tWinProc Event Hooked.n"));bReturn = true;}}catch(...){OutputDebugString(_T("nInstallWinProcHook:tException caught in InstallWinProcHook."));bReturn = false;}return bReturn;}


在安装窗口HOOK的API函数 SetWindowsHookEx 时360安全卫士报告有异常!(这种情况怎么避免呢?知道的读者能告知我解决方法吗?)

//Set the message hook (Filter).bool InstallMessageHook(void){bool bReturn = false;try{//Set the message hook (Filter).g_hPreviousMsgHook = SetWindowsHookEx(WH_GETMESSAGE,&MessageHookProcedure,g_hInstance,0);if(NULL == g_hPreviousMsgHook){OutputDebugString(_T("nInstallMessageHook:tFailed to Hook Messages.n"));bReturn = false;}else{OutputDebugString(_T("nInstallMessageHook:tMessages Hooked.n"));bReturn = true;}}catch(...){OutputDebugString(_T("nInstallMessageHook:tException caught in InstallMessageHook."));bReturn = false;}return bReturn;} 2、响应窗口切换、启动应用程序、新建窗口动作

 

//Switch between desktops.bool CDesktopManager::SwitchDesktop(TCHAR *pszDesktopName){bool bReturn = false;try{if (NULL == pszDesktopName){OutputDebugString(_T("nCDesktopManager::SwitchDesktop:tNULL DesktopName in CDesktopManager::SwitchToDesktop"));throw false;}/*if( !_tcsicmp(_T("Winlogon"), szDesktopName) || !_tcsicmp(_T("Disconnect"), szDesktopName)){TCHAR szErrorMsg[ARRAY_SIZE] = {_T("You can not switch to ")};_tcscat_s(szErrorMsg, ARRAY_SIZE -1, szDesktopName);_tcscat_s(szErrorMsg, ARRAY_SIZE -1, _T(" Desktop."));MessageBox(NULL, szErrorMsg, TXT_MESSAGEBOX_TITLE, MB_ICONINFORMATION);throw false;}*///Open desktop handle to switch to.HDESK hDesktopToSwitch = OpenDesktop(pszDesktopName, DF_ALLOWOTHERACCOUNTHOOK, TRUE, GENERIC_ALL);if(NULL == hDesktopToSwitch){TCHAR *pszError = NULL;TCHAR szErrorMsg[ARRAY_SIZE] = {0};int iErrorCode = GetLastError();if(5 == iErrorCode){FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, iErrorCode, 0, (LPWSTR) &pszError, 0, NULL);wsprintf(szErrorMsg, _T("Failed to switch to %s desktop.nt %s"), pszDesktopName, pszError);MessageBox(NULL, szErrorMsg, TXT_MESSAGEBOX_TITLE, MB_ICONINFORMATION | MB_TOPMOST | MB_TASKMODAL);OutputDebugString(pszError);}wsprintf(szErrorMsg, _T("nCDesktopManager::SwitchDesktop:tOpenDesktop Failed in CDesktopManager::SwitchToDesktop. Last Error : %s"), pszError);OutputDebugString(szErrorMsg);throw false;}//Switch the desktop.if(FALSE == ::SwitchDesktop(hDesktopToSwitch)){OutputDebugString(_T("nCDesktopManager::SwitchDesktop:tSwitchDesktop Failed in CDesktopManager::SwitchToDesktop"));throw false;} //Close the desktop handle.CloseDesktop(hDesktopToSwitch);bReturn = true;}catch(bool bThrownVal){bReturn = bThrownVal;}catch(...){bReturn = false;DebugPrintErrorMessage(_T("nCDesktopManager::SwitchDesktop:tException caught in CDesktopManager::SwitchToDesktop"));}return bReturn;}


 

//Creates the new desktop (Adds new desktop)void CVirtualDesktopDlg::OnBnClickedAddNewDesktop(){// TODO: Add your control notification handler code hereTCHAR szCaption[ARRAY_SIZE] = {0};m_AddNewDesktop.GetWindowText(szCaption, ARRAY_SIZE - 1);if(_tcsicmp(szCaption, _T("&New"))){m_DesktopNameControl.GetWindowText(szCaption, ARRAY_SIZE -1);//Left trimming the string.while(' ' == szCaption[0])_tcscpy_s(szCaption, ARRAY_SIZE - 1, szCaption + 1);int iLen = (int) _tcslen(szCaption);//Right trimming the string.while(' ' == szCaption[--iLen])szCaption[iLen] = '';if(_tcslen(szCaption)){//Check the desktop name in the list.if(-1 != m_DesktopListControl.SelectString(0, szCaption)){MessageBox(_T("Desktop already created !"), TXT_MESSAGEBOX_TITLE, MB_ICONEXCLAMATION | MB_TOPMOST | MB_TASKMODAL);}//Create the desktopif(CDesktopManager::CreateDesktop(szCaption)){if(IDYES == MessageBox(_T("New Desktop is been created.nWould you like to switch to new desktop ?"), TXT_MESSAGEBOX_TITLE, MB_YESNO | MB_ICONINFORMATION | MB_TOPMOST | MB_TASKMODAL))SwitchDesktopTo(szCaption);m_DesktopListControl.AddString(szCaption);m_DesktopListControl.SelectString(0, szCaption);OnLbnSelchangeDesktopList();UpdateHotKeys();}}else{MessageBox(_T("Please enter Desktop Name"), TXT_MESSAGEBOX_TITLE, MB_ICONEXCLAMATION | MB_TOPMOST | MB_TASKMODAL);m_DesktopNameControl.SetWindowText(_T("")); m_DesktopNameControl.SetFocus();}}else{m_AddNewDesktop.SetWindowText(_T("&Add"));m_DesktopNameControl.SetWindowText(_T(""));m_DesktopNameControl.EnableWindow(TRUE);m_SwitchToDesktop.EnableWindow(FALSE);m_DesktopNameControl.SetFocus();}}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。