begin process at 2010 02 10 06:59:12
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Tutoriaux

 > TUTORIAL API #1 (FAIRE UNE FENÊTRE AVEC DU TEXTE)

TUTORIAL API #1 (FAIRE UNE FENÊTRE AVEC DU TEXTE)


 Information sur la source

Note :
Aucune note
Catégorie :Tutoriaux Niveau :Débutant Date de création :05/04/2002 Date de mise à jour :06/04/2002 15:33:38 Vu :3 476

Auteur : SmallToad

Ecrire un message privé
Site perso
Commentaire sur cette source (7)
Ajouter un commentaire et/ou une note

 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

AFFICHAGE D'UN TRIANGLE ISOCELE par nabche
Source avec Zip GESTION D'UNE BIBLOTHEQUE par leclerro19
[PSP]HELLO WORLD par Mario1095
Source avec Zip Source avec une capture UTILISER LA LIB DIRENT par Lemng
UN TABLEAU MULTIDIMENTIONNEL COMME PARAMETRE DE FONCTION EN ... par Mcjo

Commentaires et avis

Commentaire de DelphiCool le 06/04/2002 07:59:30 administrateur CS

Salut

je ne connais pas le c++
c'est koi #include "hello.h"
il faut quoi dedans?

Merci

Commentaire de SmallToad le 06/04/2002 15:29:02

Oups j'ai oublier le hello.h lol, je l'ai mis la =)

Commentaire de DelphiCool le 07/04/2002 08:41:53 administrateur CS

thanks

Commentaire de Supo le 02/05/2002 18:39:30

Je sais pas trop mais sa ressemble pas mal à ce que VC++ crée automatiquement

Commentaire de Mikonyx le 19/06/2002 21:34:57

c pa tré commenté surtout...snirf!

Commentaire de agentTMORT le 13/06/2004 22:23:41

fodrai peut etre que tu commente

Commentaire de agentTMORT le 13/06/2004 22:23:41

fodrai peut etre que tu commente

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,577 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales