www.gusucode.com > VC星号密码探测显示程序源码程序 > VC星号密码探测显示程序源码程序\code\ShowPwDlg.cpp
// ShowPwDlg.cpp : implementation file // #include "stdafx.h" #include "ShowPw.h" #include "ShowPwDlg.h" #include "HyperLink.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // Download by http://www.NewXing.com ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; CHyperLink m_Mail1; CHyperLink m_Mail2; CHyperLink m_Web; //}}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) DDX_Control(pDX, IDC_STATIC3, m_Web); DDX_Control(pDX, IDC_STATIC2, m_Mail2); DDX_Control(pDX, IDC_STATIC1, m_Mail1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CShowPwDlg dialog CShowPwDlg::CShowPwDlg(CWnd* pParent /*=NULL*/) : CDialog(CShowPwDlg::IDD, pParent) { //{{AFX_DATA_INIT(CShowPwDlg) m_Edit1 = _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_Control(pDX, IDC_STATIC1, m_static1); DDX_Text(pDX, IDC_STATIC2, m_StrStatic2); DDX_Text(pDX, IDC_STATIC3, m_StrStatic3); DDX_Text(pDX, IDC_STATIC5, m_StrStatic5); DDX_Text(pDX, IDC_EDIT1, m_Edit1); //}}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_WM_LBUTTONUP() ON_WM_LBUTTONDOWN() ON_WM_MOUSEMOVE() ON_BN_CLICKED(IDC_BUTTON1, OnButton1) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CShowPwDlg message handlers BOOL CShowPwDlg::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 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 CShowPwDlg::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 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 CShowPwDlg::OnClose() { OnOK(); } void CShowPwDlg::OnLButtonDown(UINT nFlags, CPoint point) { 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 CShowPwDlg::OnLButtonUp(UINT nFlags, CPoint point) { if(!m_set) { ReleaseCapture(); //是其他窗口能够接受鼠标输入 HBITMAP hBitmap=::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_SHOWPW1)); m_static1.SetBitmap(hBitmap); } m_set=true; CDialog::OnLButtonUp(nFlags, point); } void CShowPwDlg::OnMouseMove(UINT nFlags, CPoint point) { if (!m_set) { ClientToScreen(&point);//取得屏幕坐标 m_StrStatic5.Format("X=%ld,Y=%ld", point.x,point.y);//坐标 m_StrStatic2 = _T("( None )"); //Class Name m_StrStatic3 = _T("( None )"); //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);// 获得 window's style char lpClassName[255]; if (::GetClassName(hwndCurr, lpClassName, 255)) { m_StrStatic2 = lpClassName; // 获得 class name } } if (m_StrStatic2.CompareNoCase("EDIT")==0) { LONG lStyle = ::GetWindowLong(hwndCurr, GWL_STYLE); if (lStyle & ES_PASSWORD ) { char szText[255]; ::SendMessage(hwndCurr, WM_GETTEXT, 255, (LPARAM)szText); m_Edit1 = szText; // 获得 PassWord } } else { m_Edit1= _T("( None )"); //PassWord } } UpdateData(FALSE); } else { CWnd* pWnd = ChildWindowFromPoint(point);//确定属于CWnd的子窗口中含有指定的点 if (pWnd && pWnd->GetSafeHwnd() == m_static1.GetSafeHwnd()) { SetCursor(m_Cursor2); } } CDialog::OnMouseMove(nFlags, point); } void CShowPwDlg::OnButton1() { CAboutDlg m_AboutDlg; m_AboutDlg.DoModal(); } BOOL CAboutDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_Mail1.SetURL(_T("mailto:srg77@sina.com")); m_Mail1.SetUnderline(FALSE); m_Mail2.SetURL(_T("mailto:srg77@elong.com")); m_Mail2.SetUnderline(FALSE); m_Web.SetURL(_T("http://webdiy.org/srg/")); m_Web.SetUnderline(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }