简单实例一

#include "PredefineClass.h"

CMyApp theApp;

BOOL CMyApp::InitInstance()
{
	m_pMainWnd = new CMainWindow;
	m_pMainWnd->ShowWindow( m_nCmdShow );
	return TRUE;

}

CMainWindow::CMainWindow()
{
	LPCTSTR lpszClassName = AfxRegisterWndClass( CS_HREDRAW|CS_VREDRAW,
		::LoadCursor(NULL, IDC_ARROW), (HBRUSH)(COLOR_3DFACE+1));

	CreateEx( WS_EX_CLIENTEDGE, lpszClassName, 
		"Hello world!", WS_OVERLAPPEDWINDOW, 
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL );

}

BEGIN_MESSAGE_MAP( CMainWindow, CWnd )
	ON_WM_CREATE()
END_MESSAGE_MAP()

void CMainWindow::PostNcDestroy()
{
	delete this;
}

BOOL CMainWindow::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
	::CreateWindowEx( 0, "button", "push button", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
		50, 30, 110, 30, m_hWnd, (HMENU)IDC_BUTTON, AfxGetApp()->m_hInstance, NULL );
	::CreateWindowEx( 0, "button", "radio button", WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,
		50, 70, 110, 30, m_hWnd, (HMENU)IDC_RADIO, AfxGetApp()->m_hInstance, NULL );
	::CreateWindowEx( 0, "button", "check box", WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,
		50, 110, 110, 30, m_hWnd, NULL, AfxGetApp()->m_hInstance, NULL);

	::CreateWindowEx( 0, "static", "static text", WS_CHILD|WS_VISIBLE|SS_SUNKEN,
		50, 150, 150, 60, m_hWnd, (HMENU)IDC_STATIC, AfxGetApp()->m_hInstance, NULL);
	
	::CreateWindowEx( 0, "edit", "edit text", WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,
		50, 220, 150, 60, m_hWnd, (HMENU)IDC_EDITTEXT, AfxGetApp()->m_hInstance, NULL);

	return TRUE;

}

BOOL CMainWindow::OnCommand( WPARAM wParam, LPARAM lParam )
{
	switch( LOWORD( wParam ))
	{
	case IDC_BUTTON:
		::MessageBox( m_hWnd, "Hello EveryBody!", "button", MB_OK );
		break;
		
	case IDC_RADIO:
		{
			BOOL bChecked = ::IsDlgButtonChecked( m_hWnd, IDC_RADIO );
			::EnableWindow( ::GetDlgItem( m_hWnd, IDC_BUTTON), bChecked );
			::CheckDlgButton( m_hWnd, IDC_RADIO, !bChecked );
		}
		break;

	case IDC_EDITTEXT:
		{
			
			if( HIWORD( wParam ) == EN_CHANGE )
			{
				char sz[256];
				::GetWindowText( ::GetDlgItem( m_hWnd, IDC_EDITTEXT), sz, 256 );
				::SetWindowText( ::GetDlgItem( m_hWnd, IDC_STATIC), sz );
				//::MessageBox( m_hWnd, "Hello EveryBody!", "button", MB_OK );
			}
		}
		break;

	}

	return 0;
}


#define IDC_BUTTON 10
#define IDC_RADIO 11
#define IDC_CHECKBOX 12
#define IDC_STATIC 13
#define IDC_EDITTEXT 14

#include "afxwin.h"

class CMyApp : public CWinApp	
{
public:
	virtual BOOL InitInstance();

};

class CMainWindow : public CWnd
{
public:
	CMainWindow();
protected:
	virtual BOOL OnCommand( WPARAM wParam, LPARAM lParam );
	virtual void PostNcDestroy();
	afx_msg BOOL OnCreate( LPCREATESTRUCT );
	DECLARE_MESSAGE_MAP()
};
http://www.pythonschool.com/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘华世(Moments)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值