首页 > 代码库 > [游戏模版2] Win32最小框架

[游戏模版2] Win32最小框架

 

>_<:Just the minimum Win32  frame don‘t have any other special function.

 1 //{{NO_DEPENDENCIES}}
 2 // Microsoft Visual C++ generated include file.
 3 // Used by FE.RC
 4 //
 5 #define IDR_MAINFRAME                    128
 6 #define IDD_FE_DIALOG        102
 7 #define IDD_ABOUTBOX                    103
 8 #define IDS_APP_TITLE                    103
 9 #define IDM_ABOUT                        104
10 #define IDM_EXIT                        105
11 #define IDS_HELLO                        106
12 #define IDI_FE                107
13 #define IDI_SMALL                        108
14 #define IDC_FE                109
15 #define IDC_MYICON                        2
16 #define IDC_STATIC                        -1
17 // Next default values for new objects
18 //
19 #ifdef APSTUDIO_INVOKED
20 #ifndef APSTUDIO_READONLY_SYMBOLS
21 
22 #define _APS_NEXT_RESOURCE_VALUE        129
23 #define _APS_NEXT_COMMAND_VALUE         32771
24 #define _APS_NEXT_CONTROL_VALUE         1000
25 #define _APS_NEXT_SYMED_VALUE           110
26 #endif
27 #endif
resourse.h 资源ID文件
 1 // stdafx.h : include file for standard system include files,
 2 //  or project specific include files that are used frequently, but
 3 //      are changed infrequently
 4 //
 5 
 6 #if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
 7 #define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_
 8 
 9 #if _MSC_VER > 1000
10 #pragma once
11 #endif // _MSC_VER > 1000
12 
13 #define WIN32_LEAN_AND_MEAN        // Exclude rarely-used stuff from Windows headers
14 
15 
16 // Windows Header Files:
17 #include <windows.h>
18 
19 // C RunTime Header Files
20 #include <stdlib.h>
21 #include <malloc.h>
22 #include <memory.h>
23 #include <tchar.h>
24 
25 // Local Header Files
26 
27 // TODO: reference additional headers your program requires here
28 
29 //{{AFX_INSERT_LOCATION}}
30 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
31 
32 #endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
StdAfx.h 头文件和系统及设置

main.cpp

  1 #include "stdafx.h"
  2 #include "resourse.h"
  3 
  4 #define MAX_LOADSTRING 100
  5 
  6 // Global Variables:
  7 HINSTANCE hInst;                                // current instance
  8 TCHAR szTitle[MAX_LOADSTRING];                                // The title bar text
  9 TCHAR szWindowClass[MAX_LOADSTRING];                                // The title bar text
 10 
 11 // Foward declarations of functions included in this code module:
 12 ATOM                MyRegisterClass(HINSTANCE hInstance);
 13 BOOL                InitInstance(HINSTANCE, int);
 14 LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
 15 LRESULT CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
 16 //========================================================================================
 17 int APIENTRY WinMain(HINSTANCE hInstance,
 18                      HINSTANCE hPrevInstance,
 19                      LPSTR     lpCmdLine,
 20                      int       nCmdShow)
 21 {
 22      // TODO: Place code here.
 23     MSG msg;
 24 
 25     MyRegisterClass(hInstance);//调用函数向系统注册窗口类别,输入参数hInstance是目前运行程序的对象代码;
 26 
 27     // 调用InitInstance函数,进行初始化操作;
 28     if (!InitInstance (hInstance, nCmdShow))
 29     {
 30         return FALSE;
 31     }
 32 
 33     // 消息循环(通过消息循环来获取信息,
 34     //进行必要的键盘信息转换而后将控制权交给操作系统,
 35     //有操作系统决定哪个程序的消息处理函数处理消息
 36     while (GetMessage(&msg, NULL, 0, 0)) //获取程序消息
 37     {
 38             TranslateMessage(&msg);//转换伪码及字符
 39             DispatchMessage(&msg);//将控制权交给系统,再有系统决定负责处理消息的程序;
 40     }
 41 
 42     return msg.wParam;
 43 }
 44 //=====================================================================================
 45 
 46 
 47 
 48 //=============================================================================================
 49 //在建立程序窗口实体之前,必须先定义一个窗口类别,其中包含所要建立窗口的信息,
 50 //并向系统注册,这里的MyRegisterClass函数就是进行定义及注册窗口类别的函数。
 51 //==============================================================================================
 52 ATOM MyRegisterClass(HINSTANCE hInstance)
 53 {
 54     WNDCLASSEX wcex;            //申请一个窗口类别“WNDCLASSEX”和结构”wcex“
 55                                 //--------------------------------------------------------------
 56                                 //定义vcex结构的各项信息,其中设定信息处理函数(lpfnWndProc)
 57                                 //为WNDPROC,类别名称为(lpszClassName)为”fe";
 58                                 //--------------------------------------------------------------
 59     wcex.cbSize = sizeof(WNDCLASSEX);
 60 
 61     wcex.style            = CS_HREDRAW | CS_VREDRAW;
 62     wcex.lpfnWndProc    = (WNDPROC)WndProc;
 63     wcex.cbClsExtra        = 0;
 64     wcex.cbWndExtra        = 0;
 65     wcex.hInstance        = hInstance;
 66     wcex.hIcon            = NULL;
 67     wcex.hCursor        = LoadCursor(NULL,IDC_ARROW);
 68     wcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
 69     wcex.lpszMenuName    = NULL;
 70     wcex.lpszClassName    = "fe";
 71     wcex.hIconSm        = NULL;
 72 
 73     return RegisterClassEx(&wcex);//调用RegisterClassEx函数注册类别,返回一个“ATOM"形态的字符串
 74                                   //此字符串即为类别名称”fe";
 75 }
 76 //============================================================================================
 77 
 78 
 79 //============================================================================================
 80 //按照前面所定义的窗口类别来建立并显示实际的程序窗口
 81 //============================================================================================
 82 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
 83 {
 84    HWND hWnd;
 85 
 86    hInst = hInstance; // 把instance handle 储存在全局变量中;
 87 
 88    hWnd = CreateWindow("fe","绘图窗口",WS_OVERLAPPEDWINDOW,
 89       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
 90                       //-----------------------------------------------
 91                       //调用CreateWindow函数来建立一个窗口对象
 92                       //第一个参数就是窗口建立依据的类别名称
 93                       //-----------------------------------------------
 94    if (!hWnd)
 95    {
 96       return FALSE;
 97    }
 98    //------------------------------------------------
 99    //设定窗口的位置及窗口的大小,然后绘制显示在设备上
100    //------------------------------------------------
101    MoveWindow(hWnd,10,10,600,450,true);//位置及大小
102    ShowWindow(hWnd, nCmdShow);//改定窗口显示时的状态
103    UpdateWindow(hWnd);//将窗口绘制在显示设备上
104    return TRUE;
105 }
106 //============================================================================================
107 
108 
109 //============================================================================================
110 //在前面定义类别的时候把WndProc定义为消息处理函数(当某些外部消息发生时,会按消息的类型
111 //来决定该如何进行处理。此外该函数也是一个回叫函数(CALLBACK)(windows系统函数)每一个
112 //程序都会接收信息,选择性接受、处理;
113 //============================================================================================
114 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
115 {
116     PAINTSTRUCT ps;
117     HDC hdc;
118 
119     switch (message)                   //判断消息类型
120     {
121         case WM_PAINT:                //窗口重绘制
122             hdc = BeginPaint(hWnd, &ps);
123             EndPaint(hWnd, &ps);
124             break;
125         case WM_DESTROY:              //处理窗口结束消息
126             PostQuitMessage(0);
127             break;
128         default:
129             return DefWindowProc(hWnd, message, wParam, lParam);
130    }
131    return 0;
132 }
133 //============================================================================================