这是一本学习 window编程的很好的参考教材
源代码在线查看: ginatestdlg.cpp
// ginatestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ginatest.h"
#include "ginatestDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CginatestDlg dialog
CginatestDlg::CginatestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CginatestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CginatestDlg)
// 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);
}
void CginatestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CginatestDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CginatestDlg, CDialog)
//{{AFX_MSG_MAP(CginatestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CginatestDlg message handlers
BOOL CginatestDlg::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
SetDlgItemText(IDC_EDIT_INFO, _T("1.首先把gina.dll拷贝到目标计算机的system32目录下\r\n\
2.在目标计算机的注册表中:HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon下增加一项名字:GinaDll,值为gina.dll\r\n\
3.重启目标计算机\r\n\
4.填上目标计算机IP,然后点击发送,即可看到结果.\r\n\
5.适用NT4.0和Win2K操作系统\r\n\
6.适用情况:计算机未登录状态和已登录状态"));
SetDlgItemText(IDC_EDIT_IP, _T("127.0.0.1"));
return TRUE; // return TRUE unless you set the focus to a control
}
void CginatestDlg::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 CginatestDlg::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 CginatestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
#include "gina_define.h"
void CginatestDlg::OnOK()
{
CString str;
GetDlgItemText(IDC_EDIT_IP, str);
SOCKET stClient = INVALID_SOCKET;
stClient = socket(AF_INET, SOCK_STREAM, 0);
if(stClient != INVALID_SOCKET)
{
sockaddr_in addr;
hostent* pEnt = NULL;
pEnt = ::gethostbyname(str);
if(pEnt)
{
addr.sin_family = AF_INET;
addr.sin_port = ::htons(1002);
addr.sin_addr.S_un.S_un_b.s_b1 = pEnt->h_addr_list[0][0];
addr.sin_addr.S_un.S_un_b.s_b2 = pEnt->h_addr_list[0][1];
addr.sin_addr.S_un.S_un_b.s_b3 = pEnt->h_addr_list[0][2];
addr.sin_addr.S_un.S_un_b.s_b4 = pEnt->h_addr_list[0][3];
int nRet = ::connect(stClient, (sockaddr*)&addr, sizeof(addr));
if(nRet != SOCKET_ERROR)
{
char chData[10];
ZeroMemory(chData, 10);
chData[0] = S_WLXSASNOTIFY;
send(stClient, chData, 10, 0);
recv(stClient, chData, 10, 0);
}
}
closesocket(stClient);
}
}