The purpose of writing this article is to use the C for object-oriented languages. Use everyone very familiar with the WIN32 API, developing a Windows program on the Windows platform, which is also my thoughts for a long time. Refer to some foreign websites I Encapsled the following categories:
Class WinApp; Class WINDOW;
A Windows program certainly does not have a WinMain () function, so we must also have a Winmain () function. I don't know how to pack, so I don't care about it. So the program is a WinMain (), a WinApp, A Window, do you feel enough? WinApp is used to register a window class, provide an instance sector, and respond to all window messages. Window is used to create a main window and other subsets from the already registered window class, and display the main window. My purpose is like this, pick up C , start it ~~!
1.Application class In order to run the program, of course we must first create an application class. It uses the WNDCLASS or WNDCLASSEX structure to give yourself a definition. Because WNDCLASSEX compares more features, we like new and tired WNDCLASS, then only use WNDCLASSEX, this declaration !!!! We know that the WNDCLASSEX structure has a member lpfnwndproc, pointing to a callback function WNDPROC, and in the C language Win32 API programming, everyone knows WNDPROC is used to handle processing The window message, this is why I want to encapsulate WndProc in the WinApp class ~~~ I hope everyone understands me. Below is the class definition: //winapp.h/* name: winapp.h Copyright: (c) huyoo, Changsha, Hunan Province, China Author: huyoo email: huyoo353@hotmail.com tel: 0731-4534289 date: 10-10-04 01:28 Date: 10-10-04 01:28 Date: 10-10-04 01:28 Date: 10-10-04 01:28 Date: 10-10-04 01:28 DESCRIPTION: Package CPP * / # iFNDef WINAPP_H __ # Define WinApp_H __ # Pragma Once
#include
/ / -------------------------------------------------------------------------------------------- --------------------------- // Define Application Class
Class WinApp
{
PUBLIC:
// Constructor Initialization Application WinApp (Hinstance Hinst, Char * ClasName, LPCTST Menuname = NULL);
// Register Application Class Void Register (); // Defines Static Torch Window Function Static Lresult Callback MainwndProc (HWND HWND, UINT MSG,
WPARAM WPARAM, LPARAM LPARAM;
protected:
// Record class information WNDCLASSEX _WNDCLSEX;
}
/ / -------------------------------------------------------------------------------------------- --------------------------- # Endif See the class above, you will ask me, why do you want to define this window callback function as Static? My idea is that it is only one in the app, and it should not be modified !!! Moreover, when I don't define it as static, I don't have a way, so I have no way. I have to make it static, I hope everyone will forgive me !! ~~ Applications in the constructor to initialize classes: WNDCLASSEX _WNDCLSEX; class implementation: //winapp.cpp/* name: WinApp.cpp Copyright: (c) Huyoo, Changsha, Hunan Province, China Author: huyoo email: huyoo353@hotmail.com tel: 10-10-04 01:28 Date: 10-10-04 01:28 Date: 10-10-04 01:28 Date: 10-10-04 01:28 DESCRIPTION: Package CPP * / / / / / -------------------------------------------------- ----------------------- WinApp :: WinApp (Hinstance Hinst, Char * Clsname, LPCTSTR MENUNAME)
{
// Use the member variable to initialize the application class _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 = loadingcursor (null, idc_arrow);
_Wndclsex.hbrbackground = static_cast
_Wndclsex.lpszMenuname = menuname;
_Wndclsex.lpszclassname = clsname;
_WndClsex.hiconsm = loading (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;
Return 0;
}
Return DefWindowProc (HWND, MSG, WPARAM, LPARAM);
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
Today, I will get here, tomorrow or I will make the window class definition and implementation, further create a window and display it, let everyone look at the power of C , know that C is as good as C language more than C language Ok!!