Accueil > > > TUTORIAL API #1 (FAIRE UNE FENÊTRE AVEC DU TEXTE)
TUTORIAL API #1 (FAIRE UNE FENÊTRE AVEC DU TEXTE)
Information sur la source
Description
Vu que le tutorial #1 s'adonne pour les débutants, c'est très simple comme programme. =)
Source
- /*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
-
/*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 =)
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
RE : WIN APIRE : WIN API par racpp
Cliquez pour lire la suite par racpp WIN APIWIN API par omarino_007
Cliquez pour lire la suite par omarino_007
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|