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
|
#include<windows.h>
#define IDM_QUIT 1
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE hinst;
/****************************Programme Principal**************************/
int WINAPI WinMain (HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hwnd; /*Handle de la fenetre principal*/
WNDCLASS wc;
MSG msg;
hinst=hinstance; /*Handle de l'application (fenetre d'edition)*/
HMENU hMenu, hSousMenu; /*Handle du menu et sous menu*/
wc.style = 0;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hinstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
wc.lpszMenuName = NULL;
//wc.lpszClassName = "MaWinClass";
RegisterClass (&wc); /*Enregistrement structure au niveau du systeme*/
hSousMenu=CreateMenu ();
AppendMenu(hSousMenu, MF_STRING, IDM_QUIT, "Quitter");
hMenu=CreateMenu ();
AppendMenu(hMenu, MF_POPUP, (UINT)hSousMenu, "Fichier");
/*Creation de la fenetre et de ses differents parametres*/
hwnd = CreateWindow("MaWinClass", "Titre", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, hMenu, hinstance, NULL);
if (!hwnd) returnfalse;
ShowWindow (hwnd, nCmdShow); /*Pour rendre fenetre visible*/
UpdateWindow (hwnd); /*Rafraichissements*/
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
/**************************Fonction de traitement des messages********************/
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
static HWND hEdit;
bool EditNotChg;
switch (umsg)
{
case WM_CREATE:
HFONT hFont;
hEdit =CreateWindow("edit", "Vous pouvez écrire",
WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL,
0, 0, 0, 0, hwnd, NULL, hinst, NULL);
SendMessage(hEdit,WM_SETFONT,(UINT)hFont,true);
/*Envoie d'un message pour limiter les marges a 5 pixels*/
SendMessage(hEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(5,5));
return (0);
case WM_CLOSE :
/*Si vous avez fini de saisir du texte demmande de sauvegarde avant de quitter*/
if (EditNotChg || MessageBox(hwnd,"Voulez-vous sauvegarder les changements"
" avant de quitter l'application?",
"Quitter.",MB_YESNO | MB_ICONQUESTION)==IDYES)
DestroyWindow(hwnd); /*Fermeture de l'application*/
return (0);
case WM_COMMAND :
if (LOWORD(wParam)==IDM_QUIT) PostMessage(hwnd,WM_CLOSE, 0, 0);
if (HIWORD(wParam)==EN_CHANGE) EditNotChg=false;
return (0);
case WM_SIZE :
/*Si changement de taille fenetre parent alors changement de taille fenetre enfant*/
MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), true);
return (0);
case WM_DESTROY :
PostQuitMessage (0); /*Fermeture de la fenetre*/
return (0);
default :
return DefWindowProc(hwnd, umsg, wParam, lParam);
}
}
|
Partager