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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
| #include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "constantes.h"
#define ID_PUSHBUTTON_1 111
HINSTANCE instance;
LRESULT CALLBACK procedureFenetrePrincipale(HWND, UINT, WPARAM, LPARAM);
BOOL APIENTRY aPropos_procedure(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
BOOL APIENTRY Dialog1Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
BOOL APIENTRY Dialog2Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
int WinMain (HINSTANCE cetteInstance, HINSTANCE precedenteInstance,
LPSTR lignesDeCommande, int modeDAffichage)
{
HWND fenetrePrincipale;
MSG message;
WNDCLASS classeFenetre;
instance = cetteInstance;
classeFenetre.style = 0;
classeFenetre.lpfnWndProc = procedureFenetrePrincipale;
classeFenetre.cbClsExtra = 0;
classeFenetre.cbWndExtra = 0;
classeFenetre.hInstance = NULL;
classeFenetre.hIcon = LoadIcon(NULL, IDI_APPLICATION);
classeFenetre.hCursor = LoadCursor(NULL, IDC_ARROW);
classeFenetre.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
classeFenetre.lpszMenuName = NULL;
classeFenetre.lpszClassName = "classeF";
// On prévoit quand même le cas où ça échoue
if(!RegisterClass(&classeFenetre)) return FALSE;
fenetrePrincipale = CreateWindow("classeF", "Ma premiere fenetre winAPI !", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 500, 530, //largueur, longueur
NULL, LoadMenu(instance, "ID_MENU"), cetteInstance, NULL);
if (!fenetrePrincipale) return FALSE;
ShowWindow(fenetrePrincipale, modeDAffichage);
UpdateWindow(fenetrePrincipale);
while (GetMessage(&message, NULL, 0, 0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
LRESULT CALLBACK procedureFenetrePrincipale(HWND fenetrePrincipale, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND boutons[5] = {NULL};
HWND hEdit[2];
switch (message)
{
case WM_CREATE:
boutons[0] = CreateWindow("BUTTON", "Parler", WS_CHILD | WS_VISIBLE, 5, 5, 383, 30, fenetrePrincipale, (HMENU)ID_B_PARLER, instance, NULL);
boutons[1] = CreateWindow("BUTTON", "Quitter", WS_CHILD | WS_VISIBLE,5, 45, 383, 30, fenetrePrincipale, (HMENU)ID_B_QUITTER, instance, NULL);
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_B_APROPOS:
DialogBox(instance, "APROPOS", fenetrePrincipale, (DLGPROC)aPropos_procedure);
break;
case ID_B_PARLER:
MessageBox(fenetrePrincipale, "Clic", "Bonjour.", MB_ICONINFORMATION);
boutons[3]=CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|ES_CENTER|BS_TEXT,
20,130, /* espace à gauche, espace en haut*/ 120,20, //longueur hauteur
fenetrePrincipale,(HMENU)ID_PUSHBUTTON_1,instance, NULL);
boutons[4]=CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|ES_CENTER|BS_TEXT,
20,160, /* espace à gauche, espace en haut*/ 120,20, /*longueur hauteur*/
fenetrePrincipale,(HMENU)ID_PUSHBUTTON_1,instance, NULL);
break;
case ID_B_CALCUL:
if(LOWORD(wParam) == ID_B_PARLER)
DialogBox(instance, "DIALOG1" , boutons[3], Dialog1Proc);
if(LOWORD(wParam) == ID_B_PARLER)
DialogBoxParam(instance, "DIALOG2" , fenetrePrincipale, Dialog2Proc, (LPARAM)boutons[4]);
break;
case ID_B_QUITTER:
SendMessage(fenetrePrincipale, WM_DESTROY, 0, 0);
break;
default:
return DefWindowProc(fenetrePrincipale, message, wParam, lParam);
}
}
}
BOOL APIENTRY aPropos_procedure(HWND boiteDeDialogue,UINT message,WPARAM wParam,LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDCANCEL || LOWORD(wParam) == IDOK)
{
EndDialog(boiteDeDialogue,0);
return TRUE;
}
return 0;
default:
return FALSE;
}
}
BOOL APIENTRY Dialog1Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDCANCEL || LOWORD(wParam) == IDOK)
{
EndDialog(hDlg,0);
return TRUE;
}
default:
return FALSE;
}
}
/******************************************************************************/
BOOL APIENTRY Dialog2Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
static HWND hParent;
switch (uMsg)
{
case WM_INITDIALOG:
{
CHAR st[256];
hParent = (HWND)lParam;
GetWindowText(hParent, st, 256);
SetDlgItemText(hDlg, XXXX, st);
}
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK )
{
CHAR st[256];
GetDlgItemText(hDlg, XXX, st, 256);
SetWindowText(hParent,st);
EndDialog(hDlg,0);
return TRUE;
}
if (LOWORD(wParam) == IDCANCEL )
{
EndDialog(hDlg,0);
return TRUE;
}
default:
return FALSE;
}
} |
Partager