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

📄 passobtaindlg.cpp

📁 vc++高级编程源代码
💻 CPP
字号:
// PassObtainDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PassObtain.h"
#include "PassObtainDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPassObtainDlg dialog
HHOOK CPassObtainDlg::m_hkPass;
BOOL CPassObtainDlg::m_bFinding;
CPassObtainDlg::CPassObtainDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPassObtainDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPassObtainDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_bFinding = FALSE;
}

void CPassObtainDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPassObtainDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPassObtainDlg, CDialog)
	//{{AFX_MSG_MAP(CPassObtainDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_SETCURSOR()
	ON_BN_CLICKED(IDC_CHECK_TOP, OnCheckTop)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPassObtainDlg message handlers

BOOL CPassObtainDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
	((CStatic *)GetDlgItem(IDC_OBTAIN))->SetIcon(AfxGetApp()->LoadIcon(IDI_OBTAIN));

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPassObtainDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		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 CPassObtainDlg::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 CPassObtainDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

BOOL CPassObtainDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	// TODO: Add your message handler code here and/or call default
	if (m_bFinding)
		::SetCursor(AfxGetApp()->LoadCursor(IDC_CHOOSE));
	else
		CDialog::OnSetCursor(pWnd,nHitTest,message);
	return TRUE;
}

#define PASSLENGTH 188
LRESULT CALLBACK CPassObtainDlg::PassObtainProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	::SetCursor(AfxGetApp()->LoadCursor(IDC_CHOOSE));

	// 显示当前鼠标的位置
	CString strPos;
	strPos.Format("%3d",((MOUSEHOOKSTRUCT *)lParam)->pt.x);
	AfxGetMainWnd()->SetDlgItemText(IDC_EDIT_X,strPos);
	strPos.Format("%3d",((MOUSEHOOKSTRUCT *)lParam)->pt.y);
	AfxGetMainWnd()->SetDlgItemText(IDC_EDIT_Y,strPos);

	// 得到接收鼠标消息的窗体句柄
	HWND hWnd = ((MOUSEHOOKSTRUCT *)lParam)->hwnd;

	// 显示该窗体的位置
	CRect rcOver;
	::GetWindowRect(hWnd,&rcOver);
	strPos.Format("%3d",rcOver.left);
	AfxGetMainWnd()->SetDlgItemText(IDC_EDIT_LEFT,strPos);
	strPos.Format("%3d",rcOver.right);
	AfxGetMainWnd()->SetDlgItemText(IDC_EDIT_RIGHT,strPos);
	strPos.Format("%3d",rcOver.top);
	AfxGetMainWnd()->SetDlgItemText(IDC_EDIT_TOP,strPos);
	strPos.Format("%3d",rcOver.bottom);
	AfxGetMainWnd()->SetDlgItemText(IDC_EDIT_BOTTOM,strPos);

	// 若该窗体是密码框则显示密码的内容
	LONG lStyle = ::GetWindowLong(((MOUSEHOOKSTRUCT *)lParam)->hwnd,GWL_STYLE);
	TCHAR cPass[PASSLENGTH];
	if (wParam == WM_MOUSEMOVE&& (lStyle & ES_PASSWORD))
	{
		::GetWindowText(hWnd,(LPTSTR)cPass,PASSLENGTH);
		AfxGetMainWnd()->SetDlgItemText(IDC_EDIT_PASS,cPass);
	}

	// 在其它窗体区域放开左键时也能及时注销钩子
	else if (wParam == WM_LBUTTONUP)
		AfxGetMainWnd()->PostMessage(WM_LBUTTONUP,0,0);

	// 让其它钩子函数也处理发生的事件
	return CallNextHookEx(m_hkPass,nCode,wParam,lParam);
}

void CPassObtainDlg::OnCheckTop() 
{
	// TODO: Add your control notification handler code here
	CButton *pCheck = (CButton *)GetDlgItem(IDC_CHECK_TOP);
	if (pCheck->GetState() & 0x0003)
	{
		// 选中状态
		this->SetWindowPos(&wndTopMost,0,0,0,0,
			SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
	}
	else
	{
		// 未选中状态
		this->SetWindowPos(&wndBottom,0,0,0,0,
			SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
		this->SetWindowPos(&wndTop,0,0,0,0,
			SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
	}
}

void CPassObtainDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	// 获得“启动标志”所在的位置
	CRect rcObtain;
	GetDlgItem(IDC_OBTAIN)->GetWindowRect(&rcObtain);
	this->ScreenToClient(rcObtain);
	rcObtain.NormalizeRect();

	// 若鼠标点中了“标志”则设置钩子
	if (rcObtain.PtInRect(point))
	{
		m_bFinding = TRUE;
		m_hkPass = SetWindowsHookEx(WH_MOUSE,PassObtainProc,NULL,
			AfxGetThread()->m_nThreadID);
		((CStatic *)GetDlgItem(IDC_OBTAIN))->SetIcon(AfxGetApp()->LoadIcon(IDI_ERASE));
		::SetCursor(AfxGetApp()->LoadCursor(IDC_CHOOSE));
	}

	CDialog::OnLButtonDown(nFlags, point);
}

void CPassObtainDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if (m_bFinding)
	{
		m_bFinding = FALSE;
		UnhookWindowsHookEx(m_hkPass);
		((CStatic *)GetDlgItem(IDC_OBTAIN))->SetIcon(AfxGetApp()->LoadIcon(IDI_OBTAIN));
		SetDlgItemText(IDC_EDIT_X,"");
		SetDlgItemText(IDC_EDIT_Y,"");
		SetDlgItemText(IDC_EDIT_LEFT,"");
		SetDlgItemText(IDC_EDIT_RIGHT,"");
		SetDlgItemText(IDC_EDIT_TOP,"");
		SetDlgItemText(IDC_EDIT_BOTTOM,"");
		::SetCursor(::LoadCursor(NULL,IDC_ARROW));
		return;
	}

	CDialog::OnLButtonUp(nFlags, point);
}

⌨️ 快捷键说明

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