新建win32
程序
建立空项目
然后编写如下代码//hello.cpp
#include
<afxwin.h>
//
说明应用程序类
class
CHelloApp
:
public
CWinApp
{
public:
virtual
BOOL
InitInstance()
}
//
建立应用程序类的实例
CHelloApp
HelloApp
//
说明主窗口类
class
CHelloWindow
:
public
CFrameWnd
{
CStatic*
cs
public:
CHelloWindow()
}
//
每当应用程序首次执行时都要调用的初始化函数
BOOL
CHelloApp::InitInstance()
{
m_pMainWnd
=
new
CHelloWindow()
m_pMainWnd->ShowWindow(m_nCmdShow)
m_pMainWnd->UpdateWindow()
return
TRUE
}
//
窗口类的构造函数
CHelloWindow::CHelloWindow()
{
//
建立窗口本身
Create(NULL,
"Hello
World!",
WS_OVERLAPPEDWINDOW,
CRect(0,0,200,200))
//
建立静态标签
cs
=
new
CStatic()
cs->Create("hello
world",
WS_CHILD|WS_VISIBLE|SS_CENTER,
CRect(50,80,150,150),
this)
}
这样就出来了。
http://www.xici.net/b304234/d17269213.htm
你可以看这篇文章,非常好的入门文章
首先,新建对话框,拖拽几个控件,包括2个输入框,"登录"和"取消"按钮,下边是一个登陆框的例子。#if !defined(AFX_LOGINDLG_H__5FFFF6A5_8CF5_411A_9796_A597EB8FE9A4__INCLUDED_)#define AFX_LOGINDLG_H__5FFFF6A5_8CF5_411A_9796_A597EB8FE9A4__INCLUDED_#if _MSC_VER >1000
#pragma once
#endif // _MSC_VER >1000
// LoginDlg.h : header file
//
#include "BtnST.h"
/////////////////////////////////////////////////////////////////////////////
// CLoginDlg dialog
typedef struct _tagUser
{
char name[18]
int oper
char password[16]
}USERINFOclass CLoginDlg : public CDialog
{
// Construction
public:
CLoginDlg(CWnd* pParent = NULL) // standard constructor
DWORD GetUserInfo()constCButtonST m_btnButton2
CButtonST m_btnButton3// Dialog Data
//{{AFX_DATA(CLoginDlg)<br>enum { IDD = IDD_LOGIN }
// NOTE: the ClassWizard will add data members here
CComboBox m_uList
CString m_pas
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CLoginDlg)<br>protected:<br>virtual void DoDataExchange(CDataExchange* pDX) // DDX/DDV support<br>//}}AFX_VIRTUAL// Implementation
protected:
virtual BOOL OnInitDialog()
virtual void OnOK()// Generated message map functions
//{{AFX_MSG(CLoginDlg)<br> // NOTE: the ClassWizard will add member functions here<br>DWORD m_dwUser<br>DWORD m_times<br>//}}AFX_MSG
DECLARE_MESSAGE_MAP()
}//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_LOGINDLG_H__5FFFF6A5_8CF5_411A_9796_A597EB8FE9A4__INCLUDED_)
CPP文件 // LoginDlg.cpp : implementation file
//#include "stdafx.h"
#include "SuperWords.h"
#include "LoginDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__
#endif/////////////////////////////////////////////////////////////////////////////
// CLoginDlg dialog
CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLoginDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLoginDlg)<br> // NOTE: the ClassWizard will add member initialization here<br> m_times = 2<br>m_dwUser = 0<br>m_pas = _T("")<br>//}}AFX_DATA_INIT
}
void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX)
//{{AFX_DATA_MAP(CLoginDlg)<br> // NOTE: the ClassWizard will add DDX and DDV calls here<br>DDX_Control(pDX, IDC_DLOG_CUSER, m_uList)<br>DDX_Text(pDX, IDC_DLOG_CPASWORD, m_pas)<br>DDV_MaxChars(pDX, m_pas, 16)<br>//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
//{{AFX_MSG_MAP(CLoginDlg)<br> // NOTE: the ClassWizard will add message map macros here<br>//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CLoginDlg message handlers
DWORD CLoginDlg::GetUserInfo() const
{
return m_dwUser
}
BOOL CLoginDlg::OnInitDialog()
{
CDialog::OnInitDialog()
USERINFO theUser
char * strOper[] = { {"信息录入员"},{"系统管理员"} }
UINT size = sizeof(USERINFO)
LPBYTE bt = new unsigned char[sizeof(theUser)]
CString strID
strID.Format("User%04u",0)
int lastID
lastID = AfxGetApp()->GetProfileInt("用户","LastID",0)
for(int i=0i<lastID &&AfxGetApp()->GetProfileBinary("用户",strID,&bt,&size)i++)
{
memcpy(&theUser,bt,sizeof(theUser))
CString strInfo
strInfo.Format("%s [%s]",theUser.name,strOper[theUser.oper])
m_uList.AddString(strInfo)
strID.Format("User%04u",i+1)
}
if(lastID >0)
m_uList.SetCurSel(0)
delete [] btm_btnButton2.SubclassDlgItem(IDOK, this)
m_btnButton2.SetIcon(IDI_ICON1)
m_btnButton3.SubclassDlgItem(IDCANCEL, this)
m_btnButton3.SetIcon(IDI_ICON2)
return TRUE
}
void CLoginDlg::OnOK()
{
UpdateData()
USERINFO theUser
UINT size = sizeof(theUser)
LPBYTE bt = new unsigned char[sizeof(theUser)]
CString strID
int id = m_uList.GetCurSel()
strID.Format("User%04u",id)
if(AfxGetApp()->GetProfileBinary("用户",strID,&bt,&size))
{
memcpy(&theUser,bt,sizeof(theUser))
delete [] bt
if(!m_pas.Compare(theUser.password))
{
m_dwUser = theUser.oper
CDialog::OnOK()
return
}
}
else
{
delete [] bt
MessageBox("没有该用户的信息,请与系统管理员联系。","读取用户数据错误",MB_OK|MB_ICONSTOP)
return
}
if(m_times)
{
m_times--
MessageBox("用户密码不正确!请再次尝试...","登陆失败...",MB_OK|MB_ICONSTOP)
GetDlgItem(IDC_DLOG_CPASWORD)->SetFocus()
}
else
{
MessageBox("用户密码不正确!\n您的登陆失败次数已达三次,程序将退出。\n请与系统管理员联系。","登陆失败...",MB_OK|MB_ICONSTOP)
CDialog::OnCancel()
}
}
在windows上你可以在winmain里面检测是否已经有实例在运行,在wm上是否有类似的全局变量来控制是否启动新实例,我没有wm的程序,以前搞过全忘了,你可以贴一点启动部分的代码来看看在windows上你可以在winmain里面检测是否已经有实例在运行,在wm上是否有类似的全局变量来控制是否启动新实例,我没有wm的程序,以前搞过全忘了,你可以贴一点启动部分的代码来看看欢迎分享,转载请注明来源:内存溢出
评论列表(0条)