Vu que le tutorial #1 s'adonne pour les débutants, c'est très simple comme programme. =)
Source / Exemple :
/*hello.cpp:
-------------------------------------------------------------------------------*/
#include "hello.h"
int WINAPI WinMain
(HINSTANCE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow)
{
char className [] = "Hello";
WinClass winClass (WindowProcedure, className, hInst);
winClass.Register ();
WinMaker win ("Hello World!", className, hInst);
win.Show (cmdShow);
MSG msg;
int status;
while ((status = ::GetMessage (&msg, 0, 0, 0)) != 0)
{
if (status == -1)
return -1;
::DispatchMessage (&msg);
}
return msg.wParam;
}
WinClass::WinClass (WNDPROC wndProc, char const * className, HINSTANCE hInst)
{
_class.style = 0;
_class.lpfnWndProc = wndProc; // window procedure: mandatory
_class.cbClsExtra = 0;
_class.cbWndExtra = 0;
_class.hInstance = hInst; // owner of the class: mandatory
_class.hIcon = 0;
_class.hCursor = ::LoadCursor (0, IDC_ARROW); // optional
_class.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); // optional
_class.lpszMenuName = 0;
_class.lpszClassName = className; // mandatory
}
WinMaker::WinMaker
(char const * caption, char const * className, HINSTANCE hInstance)
{
_hwnd = ::CreateWindow (
className, // name of a registered window class
caption, // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // x position
CW_USEDEFAULT, // y position
CW_USEDEFAULT, // witdh
CW_USEDEFAULT, // height
0, // handle to parent window
0, // handle to menu
hInstance, // application instance
0 ); // window creation data
}
// Window Proc called by Windows
LRESULT CALLBACK WindowProcedure
(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
::PostQuitMessage (0);
return 0;
}
return ::DefWindowProc (hwnd, message, wParam, lParam );
}
/*hello.h:
-------------------------------------------------------------------------------*/
#if !defined HELLO_H
#define HELLO_H
#include <windows.h>
LRESULT CALLBACK WindowProcedure
(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
class WinClass
{
public:
WinClass (WNDPROC wndProc, char const * className, HINSTANCE hInst);
void Register ()
{
::RegisterClass (&_class);
}
private:
WNDCLASS _class;
};
class WinMaker
{
public:
WinMaker (): _hwnd (0) {}
WinMaker (char const * caption, char const * className, HINSTANCE hInstance);
void Show (int cmdShow)
{
::ShowWindow (_hwnd, cmdShow);
::UpdateWindow (_hwnd);
}
protected:
HWND _hwnd;
};
#endif
Conclusion :
Bon, pour moi c'est assez claire. J'ai mis des commentaires en anglais, les termes sont anglais alors ca fite mieu =)
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.