Bonjour tout le monde, voilà je commence en C et j'ai un programme (Dev c++) qui me fournit un code qui permet d'avoir une fenêtre vide, mes questions étaient comment fait-on pour y ajouter boutons, textes, formulaires ... ? Merci.


Voici le code concerné :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <windows.h>

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure&#40;HWND, UINT, WPARAM, LPARAM&#41;;
/* Make the class name into a global variable */
char szClassName&#91; &#93; = "Mathieu !";
int WINAPI WinMain&#40;HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil&#41;

&#123;
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof&#40;WNDCLASSEX&#41;;

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon&#40;NULL, IDI_APPLICATION&#41;;
    wincl.hIconSm = LoadIcon&#40;NULL, IDI_APPLICATION&#41;;
    wincl.hCursor = LoadCursor&#40;NULL, IDC_ARROW&#41;;
    wincl.lpszMenuName = NULL; /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use light-gray as the background of the window */
    wincl.hbrBackground = &#40;HBRUSH&#41; GetStockObject&#40;LTGRAY_BRUSH&#41;;

    /* Register the window class, if fail quit the program */
    if&#40;!RegisterClassEx&#40;&wincl&#41;&#41; return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx&#40;
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Mathieu !",         /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           &#41;;

    /* Make the window visible on the screen */
    ShowWindow&#40;hwnd, nFunsterStil&#41;;
    /* Run the message loop. It will run until GetMessage&#40; &#41; returns 0 */
    while&#40;GetMessage&#40;&messages, NULL, 0, 0&#41;&#41;
    &#123;
           /* Translate virtual-key messages into character messages */
           TranslateMessage&#40;&messages&#41;;
           /* Send message to WindowProcedure */
           DispatchMessage&#40;&messages&#41;;
    &#125;

    /* The program return-value is 0 - The value that PostQuitMessage&#40; &#41; gave */
    return messages.wParam;
&#125;

/* This function is called by the Windows function DispatchMessage&#40; &#41; */
LRESULT CALLBACK WindowProcedure&#40;HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam&#41;
&#123;
    switch &#40;message&#41;                  /* handle the messages */
    &#123;
           case WM_DESTROY&#58;
           PostQuitMessage&#40;0&#41;;        /* send a WM_QUIT to the message queue */
           break;
           default&#58;                   /* for messages that we don't deal with */
           return DefWindowProc&#40;hwnd, message, wParam, lParam&#41;;
    &#125;
    return 0;
&#125;
[[Deplacé depuis le forum C]]