好友
阅读权限25
听众
最后登录1970-1-1
|
夏日已末
发表于 2018-6-6 15:21
本帖最后由 夏日已末 于 2018-6-6 18:00 编辑
隐藏前:
隐藏后:(黑色部分不属于桌面)
源码:
[C++] 纯文本查看 复制代码 #include <stdio.h>
#include <iostream>
#include <windows.h>
#include <atlstr.h>
using namespace std;
int main(int argc, char* argv[])
{
HWND button, task,startmenu;
//desktop = FindWindow(L"ProgMan", NULL);
task = FindWindow(L"Shell_TrayWnd", NULL); //任务栏窗口号
//startmenu = FindWindow(L"TrayNotifyWnd", NULL); //开始菜单窗口号
button = FindWindow(L"button", NULL);
//for (int i = 0; i < 20; i+=2)
//{
// startmenu = (HWND)((int)task + i);
// LPWSTR PerfData = (LPWSTR)malloc(255);
// GetClassName(startmenu, PerfData, 255);
// printf(CW2A(PerfData));
// printf("\n");
// system("pause");
// ShowWindow(startmenu, SW_SHOW);//显示
//}
APPBARDATA apBar;
memset(&apBar, 0, sizeof(apBar));
apBar.cbSize = sizeof(apBar);
apBar.hWnd = task;
LPARAM lParam = SHAppBarMessage(ABM_GETSTATE, &apBar);
//if (lParam == ABS_AUTOHIDE)
//{
// apBar.lParam = ABS_ALWAYSONTOP;
// SHAppBarMessage(ABM_SETSTATE, &apBar);
//}
//else
//{
// apBar.lParam = ABS_AUTOHIDE | ABS_ALWAYSONTOP;
// SHAppBarMessage(ABM_SETSTATE, &apBar);
//}
if (IsWindowVisible(task) || IsWindowVisible(button))
{
apBar.lParam = ABS_AUTOHIDE | ABS_ALWAYSONTOP;
SHAppBarMessage(ABM_SETSTATE, &apBar);
ShowWindow(task, SW_HIDE);//隐藏任务栏
ShowWindow(button, SW_HIDE);//隐藏任务栏
}
else
{
ShowWindow(task, SW_SHOW);//显示任务栏
ShowWindow(button, SW_SHOW);//显示任务栏
Sleep(500);
apBar.lParam = ABS_ALWAYSONTOP;
SHAppBarMessage(ABM_SETSTATE, &apBar);
}
//LPRECT rect=(LPRECT)malloc(10);
//GetWindowRect(task, rect);
//MoveWindow(task, 0, 0, 0, 0, 0);
//ShowWindow(desktop, SW_HIDE);//隐藏桌面
//Sleep(3000);
//ShowWindow(task, SW_SHOW);//显示
//ShowWindow(desktop, SW_SHOW);//显示
//system("pause");
return 0;
}
实现鼠标移动到底部中间部分实现任务栏切换
源码:[C++] 纯文本查看 复制代码 // testProject.cpp : 定义控制台应用程序的入口点。[/backcolor]//
#include "stdio.h"
#include <iostream>
#include<windows.h>
#include <conio.h>
//#include <conio.h>
//#include <string>
using namespace std;
BOOL CtrlHandler(DWORD fdwCtrlType);
int main()
{
SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE);
//cout << "控制鼠标移动的程序已经开始运行^_^" << endl;
//DEVMODE DevMode;
//EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &DevMode);
//DevMode.dmPelsWidth;
//DevMode.dmPelsHeight;
double width = 0.4;
int cx = GetSystemMetrics(SM_CXFULLSCREEN);
int cy = GetSystemMetrics(SM_CYFULLSCREEN);
//cout << cx << " " << cy << endl;
HWND hwndnew,hwndtemp;
HWND hwndold=GetForegroundWindow();
hwndnew = hwndold;
ShowWindow(hwndold,SW_HIDE); //将cmd窗口隐藏起来,让程序在后台运行
POINT last_p;
bool ifpressed=0;
int left = cx*width;
int right = cx*(1 - width);
while (true)
{
GetCursorPos(&last_p);//获取鼠标坐标
Sleep(100);
//cout << last_p.x << " " << last_p.y << endl;
if (last_p.x >= left&&last_p.x <= right && last_p.y >= cy)
{
//cout << last_p.x << "," << last_p.y << endl;
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0);
keybd_event(VK_TAB, MapVirtualKey(VK_TAB, 0), 0, 0);
keybd_event(VK_TAB, MapVirtualKey(VK_TAB, 0), KEYEVENTF_KEYUP, 0);
ifpressed = 1;
while (1)
{
GetCursorPos(&last_p);
Sleep(100);
if (last_p.x<left || last_p.x>right || last_p.y < cy)
break;
}
}
if (ifpressed)
{
if (GetKeyState(0x0001) & 0x8000)
{
while (1)
{
if (!(GetKeyState(0x0001) & 0x8000))
break;
}
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);
ifpressed = 0;
//GetCursorPos(&last_p);
//mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
if (_kbhit())
{
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);
ifpressed = 0;
}
}
hwndtemp = GetForegroundWindow();
bool state = 0;
if (hwndtemp != hwndnew &&hwndtemp!= hwndold)
{
hwndold = hwndnew;
hwndnew = hwndtemp;
state = 1;
}
if (last_p.x == 0 && last_p.y == 0)
{
if (hwndtemp == hwndold)
{
ShowWindow(hwndnew, SW_SHOW);
SetForegroundWindow(hwndnew);
}
else if (hwndtemp == hwndnew)
{
ShowWindow(hwndold, SW_SHOW);
SetForegroundWindow(hwndold);
}
while (1)
{
GetCursorPos(&last_p);
Sleep(100);
if (last_p.x!=0 ||last_p.y !=0 )
break;
}
}
//if (state)
//{
// cout << "hwndold:" << hwndold << endl;
// //cout << "hwndtemp:" << hwndtemp << endl;
// cout << "hwndnew:" << hwndnew << endl;
//}
}
return 0;
}
BOOL CtrlHandler(DWORD fdwCtrlType)
{
switch (fdwCtrlType)
{
// /* handle the CTRL-C signal */
//case CTRL_C_EVENT:
// printf("CTRL-C event\n");
// Beep(750, 300);
// return TRUE;
// /* handle the CTRL-BREAK signal */
//case CTRL_BREAK_EVENT:
// printf("CTRL-BREAK event\n");
// Beep(900, 200);
// return TRUE;
/* handle the CTRL-CLOSE signal */
case CTRL_CLOSE_EVENT:
printf("点击了控制台右上角的“X”\n");
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);
//Beep(600, 200);
return TRUE;
/* handle the CTRL-LOGOFF signal */
//case CTRL_LOGOFF_EVENT:
// printf("CTRL-LOGOFF event\n");
// Beep(1000, 200);
// return TRUE;
// /* handle the CTRL-SHUTDOWN signal */
//case CTRL_SHUTDOWN_EVENT:
// printf("CTRL-SHUTDOWN event\n");
// Beep(750, 500);
// return TRUE;
default:
return FALSE;
}
}
release版本,直接运行不知道会不会提示缺少文件
hidetask执行过后不会有进程,再次执行就能显示任务栏了,tab的如果要结束需要结束进程
Desk.zip
(11.53 KB, 下载次数: 126)
|
免费评分
-
查看全部评分
|