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

📄 pwdspydlg.cpp

📁 包括了一些VC编程实例
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// PwdSpyDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PwdSpy.h"
#include "PwdSpyDlg.h"
#include "PwdSpyHk.h"

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

// Register our Window Message
// This message is passed to us if the user tries to active multiple copies of the app
UINT CPwdSpyDlg::s_wmActivateApp = RegisterWindowMessage(CUSTOM_WNDMSG);

/////////////////////////////////////////////////////////////////////////////
// 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)
	virtual BOOL OnInitDialog();
	//}}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
}

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

	CString strUrl; strUrl.LoadString(IDS_URL);
	SetDlgItemText(IDC_URL, strUrl);

	return TRUE;
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPwdSpyDlg dialog

//***********************************************
CPwdSpyDlg::CPwdSpyDlg(CWnd *pParent)
	: CDialog(CPwdSpyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPwdSpyDlg)
	m_strMousePos = _T("");
	m_strHwnd = _T("");
	m_strCaption = _T("");
	m_strWndClass = _T("");
	m_strIsPwd = _T("");
	m_strPwd = _T("");
	//}}AFX_DATA_INIT

	// Load the icons and cursors
	m_hIconLarge = (HICON)LoadImage(AfxGetApp()->m_hInstance,
		MAKEINTRESOURCE(IDR_MAINFRAME),
		IMAGE_ICON,
		GetSystemMetrics(SM_CXICON),
		GetSystemMetrics(SM_CYICON),
		0);
	m_hIconSmall = (HICON)LoadImage(AfxGetApp()->m_hInstance,
		MAKEINTRESOURCE(IDI_SMALLICON),
		IMAGE_ICON,
		GetSystemMetrics(SM_CXSMICON),
		GetSystemMetrics(SM_CYSMICON),
		0);
	m_hIconBlank = (HICON)LoadImage(AfxGetApp()->m_hInstance,
		MAKEINTRESOURCE(IDI_BLANK_ICON),
		IMAGE_ICON,
		GetSystemMetrics(SM_CXICON),
		GetSystemMetrics(SM_CXICON),
		0);
	m_hIconScan = (HICON)LoadImage(AfxGetApp()->m_hInstance,
		MAKEINTRESOURCE(IDI_LOOK_ICON),
		IMAGE_ICON,
		GetSystemMetrics(SM_CXICON),
		GetSystemMetrics(SM_CXICON),
		0);
	m_hCursorScan = (HCURSOR)LoadImage(AfxGetApp()->m_hInstance,
		MAKEINTRESOURCE(IDC_LOOK_CUR),
		IMAGE_CURSOR,
		GetSystemMetrics(SM_CXCURSOR),
		GetSystemMetrics(SM_CXCURSOR),
		0);
	m_hCursorPrev = NULL;

	m_hWndPrev = m_hWndScanEx = NULL;
	m_bIsLooking = false;
	m_bAlwaysOnTop = true;
	m_nScanLevel = 0;

	// Use ScanEx if Win2K or WinXP
	m_bScanEx = (m_osi.IsNT() && m_osi.GetMajor() >= 5) ? true : false;

	m_wndPopupTip.Create(this);
}

//***********************************************
CPwdSpyDlg::~CPwdSpyDlg()
{
	// Make absolutely sure we unhook before closing
	RemoveHook();

	if(m_hIconLarge != NULL) DestroyIcon(m_hIconLarge);
	if(m_hIconSmall != NULL) DestroyIcon(m_hIconSmall);
	if(m_hIconBlank != NULL) DestroyIcon(m_hIconBlank);
	if(m_hIconScan != NULL) DestroyIcon(m_hIconScan);
	if(m_hCursorScan != NULL) DestroyCursor(m_hCursorScan);
}

//***********************************************
void CPwdSpyDlg::DoDataExchange(CDataExchange *pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPwdSpyDlg)
	DDX_Control(pDX, IDC_LOOK, m_ctrlLook);
	DDX_Text(pDX, IDC_EDIT_MOUSEPOS, m_strMousePos);
	DDX_Text(pDX, IDC_EDIT_HWND, m_strHwnd);
	DDX_Text(pDX, IDC_EDIT_CAPTION, m_strCaption);
	DDX_Text(pDX, IDC_EDIT_WNDCLASS, m_strWndClass);
	DDX_Text(pDX, IDC_EDIT_ISPWD, m_strIsPwd);
	DDX_Text(pDX, IDC_EDIT_PWD, m_strPwd);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPwdSpyDlg, CDialog)
	//{{AFX_MSG_MAP(CPwdSpyDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_WM_GETMINMAXINFO()
	ON_WM_COPYDATA()
	//}}AFX_MSG_MAP
	ON_REGISTERED_MESSAGE(s_wmActivateApp, OnActivateApp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPwdSpyDlg message handlers

//***********************************************
BOOL CPwdSpyDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// IDM_ALWAYS_ON_TOP must be in the system command range.
	_ASSERTE((IDM_ALWAYS_ON_TOP & 0xFFF0) == IDM_ALWAYS_ON_TOP);
	_ASSERTE(IDM_ALWAYS_ON_TOP < 0xF000);
	// 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)
	{
		// Remove the "Size" and "Maximize" menu options from the system menu
		pSysMenu->DeleteMenu(SC_SIZE, MF_BYCOMMAND);
		pSysMenu->DeleteMenu(SC_MAXIMIZE, MF_BYCOMMAND);

		// Append a separator, Always On Top, and About
		CString strMenu;
		pSysMenu->AppendMenu(MF_SEPARATOR);
		strMenu.LoadString(IDS_ALWAYS_ON_TOP);
		pSysMenu->AppendMenu(MF_STRING, IDM_ALWAYS_ON_TOP, strMenu);
		strMenu.LoadString(IDS_ABOUTBOX);
		_ASSERTE(!strMenu.IsEmpty());
		pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strMenu);
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIconLarge, TRUE);		// Set big icon
	SetIcon(m_hIconSmall, FALSE);		// Set small icon

	((CComboBox*)GetDlgItem(IDC_COMBO_LEVEL))->SetCurSel(m_nScanLevel);

	//窗口总在最上面
	OnAlwaysOnTop();

	return TRUE;
}

//***********************************************
void CPwdSpyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if((nID & 0xFFF0) == IDM_ALWAYS_ON_TOP)
	{
		m_bAlwaysOnTop ^= true;
		OnAlwaysOnTop();
	}
	else 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 CPwdSpyDlg::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_hIconLarge);
	}
	else
	{
		CDialog::OnPaint();
	}
}

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

//***********************************************
void CPwdSpyDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	CWnd *pWnd = ChildWindowFromPoint(point);

	if(pWnd != NULL && pWnd->GetSafeHwnd() == m_ctrlLook.GetSafeHwnd())
		StartLooking();

	CDialog::OnLButtonDown(nFlags, point);
}

//***********************************************
void CPwdSpyDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
	if(m_bIsLooking)
		StopLooking();

⌨️ 快捷键说明

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