//WinApp.h
/*
Name: WinApp.h
Copyright: (c) huyoo,changsha,hunan province,china
Author: huyoo
Email: [email protected]
Tel: 0731-4534289
Date: 10-10-04 01:28
Description: 封装Cpp
*/
#ifndef WINAPP_H__
#define WINAPP_H__
#pragma once
#include <windows.h>
//---------------------------------------------------------------------------
//定义应用程序类
class WinApp
{
public:
// 构造函数初始化应用程序类
WinApp(HINSTANCE hInst, char *ClasName, LPCTSTR MenuName = NULL);
// 注册应用程序类
void Register();
//定义静态回调窗口函数
static LRESULT CALLBACK MainWndProc(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam);
protected:
// 记录类信息
WNDCLASSEX _WndClsEx;
};
//---------------------------------------------------------------------------
#endif
看到上面的类,你就会问我,为什么要把这个窗口回调函数定义为静态的?
我的想法是它在应用程序中一个只用一个,而且应该也不允许修改的!!!
况且,当我不把它定义为静态的时候,编译通不过,所以我也没有办法,只好把它搞成静态的,希望大家原谅我!!~~
应用程序类在构造函数中初始化类成员:WNDCLASSEX _WndClsEx;
类实现:
//WinApp.cpp
/*
Name: WinApp.cpp
Copyright: (c) huyoo,changsha,hunan province,china
Author: huyoo
Email: [email protected]
Tel: 0731-4534289
Date: 10-10-04 01:28
Description: 封装Cpp
*/
#include "WinApp.h"
//---------------------------------------------------------------------------
WinApp::WinApp(HINSTANCE hInst, char *ClsName, LPCTSTR MenuName)
{
// 使用成员变量,来初始化应用程序类
_WndClsEx.cbSize = sizeof(WNDCLASSEX);
_WndClsEx.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
_WndClsEx.lpfnWndProc = MainWndProc;
_WndClsEx.cbClsExtra = 0;
_WndClsEx.cbWndExtra = 0;
_WndClsEx.hInstance = hInst;
_WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
_WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
_WndClsEx.hbrBackground = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
_WndClsEx.lpszMenuName = MenuName;
_WndClsEx.lpszClassName = ClsName;
_WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
}
//---------------------------------------------------------------------------
void WinApp::Register()
{
RegisterClassEx(&_WndClsEx);
}
//---------------------------------------------------------------------------
LRESULT CALLBACK WinApp::MainWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
{
switch(Msg)
{
case WM_CREATE:
return 0;
case WM_SIZE:
return 0;
case WM_PAINT:
return 0;
case WM_COMMAND:
return 0;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
return 0;
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
//---------------------------------------------------------------------------
今天就到这里吧,明天或者今天晚上我就把窗口类定义和实现弄出来,进一步创建出来一个窗口
并显示出来,让大家看看C++的威力,要知道C++干得一样好甚至比C语言更加好的!!
本文地址:http://com.8s8s.com/it/it26655.htm