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

📄 passshowdlg.cpp

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

#include "stdafx.h"
#include "PassShow.h"
#include "PassShowDlg.h"

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


/////////////////////////////////////////////////////////////////////////////
// CPassShowDlg dialog

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

void CPassShowDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPassShowDlg)
	DDX_Control(pDX, IDC_STATIC1, m_static1);
	DDX_Text(pDX, IDC_STATIC2, m_strStatic2);
	DDX_Text(pDX, IDC_STATIC3, m_strStatic3);
	DDX_Text(pDX, IDC_STATIC4, m_strStatic4);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPassShowDlg, CDialog)
	//{{AFX_MSG_MAP(CPassShowDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPassShowDlg message handlers

BOOL CPassShowDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	//--------------------------------------------------------------
    m_bmpBackground.LoadBitmap(IDB_BITMAPBACKGROUND);// load窗体背景图片
	CWnd *pWnd=GetDlgItem(IDC_EDIT_PASS);
    m_hook.StartHook(pWnd->GetSafeHwnd());//install hook,起动HOOK
	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
//----------------------初始化光标变量--------------------
	CWinApp* pApp = AfxGetApp();
	ASSERT(pApp);
	if (pApp)
	{
		VERIFY(m_Cursor1 = pApp->LoadCursor(IDC_SHOWPW));
		VERIFY(m_Cursor2 = pApp->LoadCursor(IDC_HAND));
	}
	//窗体保持在最前方
	SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | WS_EX_TOPMOST);
//-----------------------------------------------------------	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPassShowDlg::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 CPassShowDlg::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();
	  CPaintDC dc(this); //对话框的dc
      CDC dcMem;
      dcMem.CreateCompatibleDC(&dc); //创建与对话框dc兼容的内存dc

      CRect rect;
      GetClientRect(&rect);

      BITMAP bitMap;
      m_bmpBackground.GetBitmap(&bitMap);

      CBitmap *pbmpOld = dcMem.SelectObject(&m_bmpBackground); //将背景位图选入内存dc中

      dc.StretchBlt(0, 0, rect.Width(), rect.Height(), &dcMem, 0, 0,
                      bitMap.bmWidth, bitMap.bmHeight, SRCCOPY);//将内存dc中的位图拉伸显示在对话框的dc中
	}
}

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

void CPassShowDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	CWnd* pWnd = ChildWindowFromPoint(point);	//确定属于CWnd的子窗口中含有指定的点
	if(m_set)
	{
		if (pWnd && pWnd->GetSafeHwnd() == m_static1.GetSafeHwnd())
		{
			SetCapture();	//捕捉,使所有鼠标输入都被发送到当前的 CWnd 对象
			SetCursor(m_Cursor1);//设置光标
			HBITMAP hBitmap=::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_SHOWPW2));
			m_static1.SetBitmap(hBitmap);
			m_set=false;
		}
		else
		{	//单击除了窗口标题栏以外的区域使窗口移动
			PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));	
			m_set=true;
		}
	}
	CDialog::OnLButtonDown(nFlags, point);
}

void CPassShowDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(!m_set)
	{
		ReleaseCapture();	//释放,使其他窗口能够接受鼠标输入
		HBITMAP hBitmap=::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_SHOWPW1));
		m_static1.SetBitmap(hBitmap);
	}
	m_set=true;	
	CDialog::OnLButtonUp(nFlags, point);
}

void CPassShowDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if (!m_set)
	{
		ClientToScreen(&point);//取得屏幕坐标

		m_strStatic4.Format("X=%ld,Y=%ld", point.x,point.y);//坐标
		m_strStatic2 = _T("[空]");	//Class Name
		m_strStatic3 = _T("[空]");	//Class Style

		CWnd* pWnd = CWnd::WindowFromPoint(point);//获取含有指定点的窗口
		if (pWnd)
		{
			HWND hwndCurr = pWnd->GetSafeHwnd();//返回一个窗口的句柄

			if ((::GetWindowThreadProcessId (GetSafeHwnd(), NULL))!= (::GetWindowThreadProcessId (hwndCurr, NULL))) 
			{
				m_strStatic3.Format("%ld", hwndCurr);// 获得句柄 
		
				char lpClassName[255];
				if (::GetClassName(hwndCurr, lpClassName, 255))
				{
					m_strStatic2 = lpClassName;	// 获得 class name
				}
			}
		}

		UpdateData(FALSE);
	}
	else
	{
		CWnd* pWnd = ChildWindowFromPoint(point);//确定属于CWnd的子窗口中含有指定的点
		if (pWnd && pWnd->GetSafeHwnd() == m_static1.GetSafeHwnd())
		{
			SetCursor(m_Cursor2);
		}
	}	
	CDialog::OnMouseMove(nFlags, point);
}

void CPassShowDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	m_hook.StopHook();//stop hook,停止HOOK
	// TODO: Add your message handler code here
	
}

⌨️ 快捷键说明

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