📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "SimulateKeyboard.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
//Add code
Get_flag = false;
Save_flag = false;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return false;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////////
// Search Text
// Add code
struct EnumClassInfo
{
HWND *m_pHwnd;
int m_pCount;
int m_pFound;
LPCTSTR pClassName;
};
BOOL CALLBACK __EnumClassProc(HWND hwnd, LPARAM lParam)
{
EnumClassInfo *pECI = (EnumClassInfo *)lParam;
if (pECI->m_pFound >= pECI->m_pCount)
{
return false;
}
TCHAR szClassName[MAX_PATH];
if ((GetClassName(hwnd, szClassName, MAX_PATH) > 0) &&
(_tcscmp(pECI->pClassName, szClassName) == 0))
{
pECI->m_pHwnd[pECI->m_pFound++] = hwnd;
}
return true;
}
int EnumWindowsClass(HWND hwndParent, LPCTSTR pClassName, HWND *m_pHwnd, int m_pCount)
{
EnumClassInfo m_pECI;
m_pECI.m_pHwnd = m_pHwnd;
m_pECI.m_pCount = m_pCount;
m_pECI.m_pFound = 0;
m_pECI.pClassName = pClassName;
if (hwndParent)
{
EnumChildWindows(hwndParent, __EnumClassProc, (LPARAM)&m_pECI);
}
else
{
EnumWindows(__EnumClassProc, (LPARAM)&m_pECI);
}
return m_pECI.m_pFound;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
bool CMainFrame::GetText()
{
//Add code
for(int i=0;i<LENTH;i++)
{
TextData[i]=0;
}
const int MAX_HWND = 100;
HWND pHwnds1[MAX_HWND];
HWND m_pHwnd1 = NULL;
HWND m_pHwnd2 = NULL;
HWND m_pHwnd3 = NULL;
TCHAR szClassMain[] = _T("Notepad");
int len = EnumWindowsClass(NULL, szClassMain, pHwnds1, MAX_HWND);
if (len > 0)
{
for (int i = 0; i < len; i++)
{
TCHAR szClassFrame[] = _T("Edit");
HWND pHwnds2[MAX_HWND];
int len2 = EnumWindowsClass(pHwnds1[i], szClassFrame, pHwnds2, MAX_HWND);
if (len2 == 1)
{
m_pHwnd2 = pHwnds2[0];
break;
}
else
{
;
}
}
}
if (m_pHwnd2)
{
::SendMessage(m_pHwnd2, WM_GETTEXT, LENTH, (LPARAM)TextData);
Get_flag = true;
}
return Get_flag;
}
bool CMainFrame::SaveText()
{
//Add code
int i;
if(Get_flag)
{
FILE *fp;
if((fp=fopen("c:\\key.txt", "wb")) == NULL)
{
return false;
}
for(i=0;i<LENTH;i++)
{
fwrite(&TextData[i], sizeof(BYTE), 1, fp);
}
fclose(fp);
Save_flag = true;
}
return Save_flag;
}
void CMainFrame::OutText()
{
//Add code
Out_flag = false;
if(!Out_flag)
{
HWND pHwnd1 = NULL;
HWND pHwnd2 = NULL;
if(pHook->StartHook(pHwnd1, pHwnd2))
{
SetTimer(1, 250, NULL);
}
}
else
{
pHook->StopHook();
}
Out_flag = !Out_flag;
}
bool CMainFrame::StopHook()
{
//Add code
::KillTimer(NULL, 1);
pHook->StopHook();
return true;
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//Add code
switch(nIDEvent)
{
case 1:
{
if(pCount>=LENTH)
{
::KillTimer(NULL, 1);
}
if(pCount<LENTH)
{
HWND pHwnd1 = NULL;
HWND pHwnd2 = NULL;
keybd_event(0X78, 0, 0, 0);
keybd_event(0X78, 0, KEYEVENTF_KEYUP, 0);
pCount++;
}
}
default:
break;
}
CFrameWnd::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -