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
TECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PCTECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PC par ROMELARD Fabrice
Speakers: Thierry Rapatout, Antoine Petit et Xavier Trebbia Cette session entre dans le cadre des RDV Décideurs des TechDays 2012, elle est liée à la consumérisation de l'IT et la mise en place du "DeskTop as a Service" dans de plus en ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLETECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLE par ROMELARD Fabrice
Speakers: Julien Marechal, Gautier Confiant, Sébastien MEYER La session débute par le positionnement de la solution System Center par rapport aux concepts d'organisation ITIL. Le portail du catalogue de se...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : PLEINIèRE SECOND JOURTECHDAYS PARIS 2012 : PLEINIèRE SECOND JOUR par ROMELARD Fabrice
Après une première journée dédiée aux développeurs, cette seconde journée est dédiée au monde des entreprises et de ses applications. Ainsi, cette pleinière est dédiée à faire un 360 de l'évolution des applications Business aux demandes ac...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : RETOUR D'EXPéRIENCE SUR LA MISE EN PLACE D'UN CLOUD PRIVéTECHDAYS PARIS 2012 : RETOUR D'EXPéRIENCE SUR LA MISE EN PLACE D'UN CLOUD PRIVé par ROMELARD Fabrice
Speaker : Guillaume Rochette Cette session est dédiée à fournir le retour sur la mise en place d'un cloud privé (IaaS) par Osiatis pour son compte ou celui de ses clients. Ce projet s'est déroulé sur 4 mois et a permis de faire évoluer...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYSTECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYS par ROMELARD Fabrice
Speakers : Lionel Limozin et Alain Marty La session commence par une découverte de SharePoint à travers la mise en place d'un environnement SharePoint pour la gestion des Sessions animées par BeWise. Le besoin est très ba...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
AUMLAUML par sassion
Cliquez pour lire la suite par sassion
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|