📄 aionshoutdlg.cpp
字号:
// AIONShoutDlg.cpp : implementation file
//
#include "stdafx.h"
#include "AIONShout.h"
#include "AIONShoutDlg.h"
#include "HideProcess.h"
#include <windowsx.h>
#include "winio.h"
#include <windows.h>
#include <tchar.h>
#include <TLHELP32.H>
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//#pragma link "winio.lib"//预编译指令: 指定可执行文件的目标代码链接的文件,
//你可以指定详细路径和扩展名,默认路径为当前路径,扩展名为".obj"
const int KBC_KEY_CMD = 0x64;//键盘命令端口
const int KBC_KEY_DATA = 0x60;//键盘数据端口
#define MsgInf(str) ::MessageBox(0,TEXT(str),TEXT("信息"),MB_OK | MB_ICONINFORMATION);
#define MsgErr(str) ::MessageBox(0,TEXT(str),TEXT("错误"),MB_OK | MB_ICONERROR);
//定义系统热键
#define ID_F9 1501
#define ID_F10 1502
#define TIMER1 1
#define TIMER2 2
#define MAX_KEY 100
HWND GlobalWndHandle[MAX_KEY]={0};
UINT Global_i=0;
BOOL HideOrVisitableFlag=0;//
/////////////////////////////////////////////////////////////////////////////
// CAIONShoutDlg dialog
CAIONShoutDlg::CAIONShoutDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAIONShoutDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAIONShoutDlg)
m_time = 3;
m_content = _T("HELLO");
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CAIONShoutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAIONShoutDlg)
DDX_Control(pDX, IDC_EDIT2, m_ContentCtr);
DDX_Control(pDX, IDC_STATIC1, m_MyStatic);
DDX_Text(pDX, IDC_EDIT1, m_time);
DDX_Text(pDX, IDC_EDIT2, m_content);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAIONShoutDlg, CDialog)
//{{AFX_MSG_MAP(CAIONShoutDlg)
ON_WM_TIMER()//
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_EN_SETFOCUS(IDC_EDIT2, OnSetfocusEdit2)
ON_BN_CLICKED(IDC_BUTTON1, OnShout)
ON_WM_CTLCOLOR()//设置static text的颜色
ON_BN_CLICKED(IDC_BTN_EXIT, OnCancel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAIONShoutDlg message handlers
BOOL CAIONShoutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
InitializeWinIo();//初始化WinIo
RegSysHotkey(); //注册系统热键
m_font.CreatePointFont(120,"楷体_GB2312");//设置static text的字体,字号
//m_brush.CreateSolidBrush(RGB(0,255,0));//背景色
// HideProcess();//隐藏进程
// SetTimer(TIMER2,100,NULL);//InjectRemoteDLL
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CAIONShoutDlg::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();
}
}
HCURSOR CAIONShoutDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CAIONShoutDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg -> message == WM_KEYDOWN)
{
if(pMsg -> wParam == VK_ESCAPE)//屏蔽ESC(取消)键
return TRUE;
if(pMsg -> wParam == VK_RETURN)//屏蔽ENTER(回车)键
return TRUE;
}
HWND hWnd = this->m_hWnd;//**
switch (pMsg->message)
{
case WM_HOTKEY://处理系统热键WM_HOTKEY消息
// switch(pMsg->wParam)
// {
// case ID_F9:
// break;
// case ID_F10:
KillTimer(TIMER1);//停止定时器
ShowWindow(SW_SHOW);//显示窗口
// break;
// }
break;
}
return CDialog::PreTranslateMessage(pMsg);//重载
}
void CAIONShoutDlg::RegSysHotkey()
{
HWND hWnd = this->m_hWnd;//
// RegisterHotKey(hWnd, ID_F9, 0, 120); //F9
RegisterHotKey(hWnd, ID_F10, 0, 121); //F10
}
//应用程序定义的回调函数
BOOL CAIONShoutDlg::EnumWindowsProc(HWND hwnd,LPARAM lParam)
{ //枚举窗口: 置顶 聚焦 粘贴 发送
char buff[256];
//////////////////////////////////////////////////////////////
::GetWindowText(hwnd,buff,255);
if(lstrcmp(buff,"AION Client"))
return 1;//如果不是“AION Client”,则返回
//////////////////////////////////////////////////////////////
/* ::GetWindowText(hwnd,buff,255);
if(lstrcmp(buff,"AION - 记事本"))
return 1;//如果不是“AION - 记事本”,则返回*/
//////////////////////////////////////////////////////////////
/*
::GetWindowText(hwnd,buff,255);
if(!lstrcmp(buff,"Program Manager"))//不处理 桌面
return 1;//如果是桌面,则返回
::GetClassName(hwnd,buff,255);//必要
if(!lstrcmp(buff,"Shell_TrayWnd"))//不处理 任务栏
return 1;
::GetWindowText(hwnd,buff,255);//必要
if(!lstrcmp(buff,"AIONShout"))//不处理 AIONShout
return 1;
::GetWindowText(hwnd,buff,255);//必要
if(!lstrcmp(buff,"StatusWnd"))//不处理 StatusWnd
return 1;
*/
if(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE)//必要
{ //对WS_VISIBLE的检查很重要,因为
//有些应用创建多个不可见的顶层窗口。
// ::SetForegroundWindow(hwnd); //必要
CWnd::FromHandle(hwnd)->SetForegroundWindow();
// ::SetFocus(hwnd);
//驱动级模拟 记事本:切换,且喊话 游戏:///////////////////////////
VxdKeyHit(VK_RETURN);
VxdKeyHit('H');
VxdKeyHit('E');
VxdKeyHit('L');
VxdKeyHit('L');
VxdKeyHit('O');
// VxdKeyDown(VK_CONTROL);
// VxdKeyDown('V');
// VxdKeyUp('V');
// VxdKeyUp(VK_CONTROL);
VxdKeyHit(VK_RETURN);
//keybd_event记事本:切换,且喊话 游戏:切换,不喊话///////////////
/* keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);
keybd_event('H', MapVirtualKey('H', 0), 0, 0);
keybd_event('H', MapVirtualKey('H', 0), KEYEVENTF_KEYUP, 0);
keybd_event('E', MapVirtualKey('E', 0), 0, 0);
keybd_event('E', MapVirtualKey('E', 0), KEYEVENTF_KEYUP, 0);
keybd_event('L', MapVirtualKey('L', 0), 0, 0);
keybd_event('L', MapVirtualKey('L', 0), KEYEVENTF_KEYUP, 0);
keybd_event('L', MapVirtualKey('L', 0), 0, 0);
keybd_event('L', MapVirtualKey('L', 0), KEYEVENTF_KEYUP, 0);
keybd_event('O', MapVirtualKey('O', 0), 0, 0);
keybd_event('O', MapVirtualKey('O', 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
keybd_event('V', MapVirtualKey('V', 0), 0, 0);
keybd_event('V', MapVirtualKey('V', 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);*/
//PostMessage记事本:切换,不喊话//////////////////////////////
/*
::PostMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);
::PostMessage(hwnd,WM_KEYUP,VK_RETURN,0);
::PostMessage(hwnd,WM_KEYDOWN,VK_CONTROL,0);
::PostMessage(hwnd,WM_KEYDOWN,'V',0);
::PostMessage(hwnd,WM_KEYUP,'V',0);
::PostMessage(hwnd,WM_KEYUP,VK_CONTROL,0);
::PostMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);
::PostMessage(hwnd,WM_KEYUP,VK_RETURN,0);*/
//SendInput 记事本:切换,且喊话 游戏:不切换,不喊话//////////////
// OneKey(VK_RETURN,50);
// TwoKey(VK_CONTROL,'V',50);
// OneKey(VK_RETURN,50);
//////////////////////////////////////////////////////////////
//全局钩子 不用OnTimer()而用Sleep()行不行呢?(未试)
GlobalWndHandle[Global_i]=hwnd;//Global_i=0
Global_i++;//逐个 处理窗口会用到
}
return 1;
}
void CAIONShoutDlg::OnTimer(UINT nIDEvent)
{
HWND hWnd = this->m_hWnd;//
switch(nIDEvent)
{
case 1:
HideOrVisitableFlag=!HideOrVisitableFlag;//初始为0
if(HideOrVisitableFlag)//=1,枚举
{
EnumWindows(CAIONShoutDlg::EnumWindowsProc,NULL);
}
if(!HideOrVisitableFlag)
{
// int j=0;
// while(j<Global_i)
while(Global_i>0)
{
Global_i--;
//下一句必要
::SetForegroundWindow(GlobalWndHandle[Global_i]);
::SetFocus(GlobalWndHandle[Global_i]);
// ::SetForegroundWindow(GlobalWndHandle[j]);
// ::SetFocus(GlobalWndHandle[j]);
//驱动级模拟 记事本:切换,且喊话 游戏:///////////////////////////
VxdKeyHit(VK_RETURN);
VxdKeyHit('H');
VxdKeyHit('E');
VxdKeyHit('L');
VxdKeyHit('L');
VxdKeyHit('O');
// VxdKeyDown(VK_CONTROL);
// VxdKeyDown('V');
// VxdKeyUp('V');
// VxdKeyUp(VK_CONTROL);
VxdKeyHit(VK_RETURN);
//keybd_event记事本:切换,且喊话 游戏:切换,不喊话///////////////
/* keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);
keybd_event('H', MapVirtualKey('H', 0), 0, 0);
keybd_event('H', MapVirtualKey('H', 0), KEYEVENTF_KEYUP, 0);
keybd_event('E', MapVirtualKey('E', 0), 0, 0);
keybd_event('E', MapVirtualKey('E', 0), KEYEVENTF_KEYUP, 0);
keybd_event('L', MapVirtualKey('L', 0), 0, 0);
keybd_event('L', MapVirtualKey('L', 0), KEYEVENTF_KEYUP, 0);
keybd_event('L', MapVirtualKey('L', 0), 0, 0);
keybd_event('L', MapVirtualKey('L', 0), KEYEVENTF_KEYUP, 0);
keybd_event('O', MapVirtualKey('O', 0), 0, 0);
keybd_event('O', MapVirtualKey('O', 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
keybd_event('V', MapVirtualKey('V', 0), 0, 0);
keybd_event('V', MapVirtualKey('V', 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);*/
//PostMessage记事本:切换,不喊话//////////////////////////////
/*
::PostMessage(GlobalWndHandle[Global_i],WM_KEYDOWN,VK_RETURN,0);
::PostMessage(GlobalWndHandle[Global_i],WM_KEYUP,VK_RETURN,0);
::PostMessage(GlobalWndHandle[Global_i],WM_KEYDOWN,VK_CONTROL,0);
::PostMessage(GlobalWndHandle[Global_i],WM_KEYDOWN,'V',0);
::PostMessage(GlobalWndHandle[Global_i],WM_KEYUP,'V',0);
::PostMessage(GlobalWndHandle[Global_i],WM_KEYUP,VK_CONTROL,0);
::PostMessage(GlobalWndHandle[Global_i],WM_KEYDOWN,VK_RETURN,0);
::PostMessage(GlobalWndHandle[Global_i],WM_KEYUP,VK_RETURN,0);*/
//SendInput 记事本:切换,且喊话 游戏:不切换,不喊话//////////////
// OneKey(VK_RETURN,50);
// TwoKey(VK_CONTROL,'V',50);
// OneKey(VK_RETURN,50);
//////////////////////////////////////////////////////////////
// j++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -