隐藏任务栏及鼠标移动到底部实现任务栏切换
本帖最后由 夏日已末 于 2018-6-6 18:00 编辑隐藏前:
隐藏后:(黑色部分不属于桌面)
源码:
#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;
}
实现鼠标移动到底部中间部分实现任务栏切换
源码:// testProject.cpp : 定义控制台应用程序的入口点。//
#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;
intcx = GetSystemMetrics(SM_CXFULLSCREEN);
intcy = 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的如果要结束需要结束进程
@夏日已末
楼主你的代码有点长
#NoEnv; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%; Ensures a consistent starting directory.
hw_tray := DllCall( "FindWindowEx", "uint",0, "uint",0, "str","Shell_TrayWnd", "uint",0 )
MsgBox, % hw_tray
WinHide, ahk_id %hw_tray%
MsgBox, 隐藏
WinShow, ahk_id %hw_tray%
MsgBox, 显示
Return
;~ 简单版
WinHide ahk_class Shell_TrayWnd ;隐藏任务栏
WinShow ahk_class Shell_TrayWnd;显示任务栏
;可以拉伸桌面的版
F8::
VarSetCapacity( APPBARDATA, 36, 0 )
IfWinNotExist, ahk_class Shell_TrayWnd
{
NumPut( (ABS_ALWAYSONTOP := 0x2), APPBARDATA, 32, "UInt" ) ;Enable "Always on top" (& disable auto-hide)
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinShow ahk_class Shell_TrayWnd
}
Else
{
NumPut( ( ABS_AUTOHIDE := 0x1 ), APPBARDATA, 32, "UInt" ) ;Disable "Always on top" (& enable auto-hide to hide Start button)
DllCall( "Shell32.dll\SHAppBarMessage", "UInt", ( ABM_SETSTATE := 0xA ), "UInt", &APPBARDATA )
WinHide ahk_class Shell_TrayWnd
}
Return 前排支持 支持~虽然看不懂。。。。 厉害了,666 为什么要隐藏呢? 不错 有软件吗 看起来很高大上,但是看不懂! taotao8070 发表于 2018-6-6 15:52
为什么要隐藏呢?
一般都是结合第三方插件来美化的 C++代码看的脑壳痛