#include <windows.h> /***************************************************************** * Declaration des fonctions globales * *****************************************************************/ // Procédure traitant les messages de la fenêtre principale LRESULT CALLBACK FrameProc(HWND hFrame,UINT Message,WPARAM wParam,LPARAM lParam); // Procédure traitant les messages de la fenêtre fille LRESULT CALLBACK ChildProc(HWND hChild,UINT Message,WPARAM wParam,LPARAM lParam); /***************************************************************** * Declaration des variables globales * *****************************************************************/ HINSTANCE hInst; HWND hMDIFrame; // Handle de la fenêtre principale HWND hMDIClient; // Handle de la zone client HWND hMDIChild; // Handle de la fenêtre fille HWND ToolsStatic1; HWND ToolsStatic2; /***************************************************************** * Point d'entrée de l'application * *****************************************************************/ int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { MSG messages; WNDCLASSEX wincl; hInst = hThisInstance; wincl.hInstance = hThisInstance; wincl.lpszClassName = "MDI_Frame"; wincl.lpfnWndProc = FrameProc; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = GetSysColorBrush(COLOR_BACKGROUND); if (!RegisterClassEx (&wincl)) return 0; wincl.lpszClassName = "MDI_Child"; wincl.lpfnWndProc = ChildProc; wincl.style = CS_DBLCLKS; wincl.hbrBackground = GetSysColorBrush(COLOR_BTNFACE); if (!RegisterClassEx (&wincl)) return 0; hMDIFrame = CreateWindowEx (0, "MDI_Frame", "RobotSim", WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 544, 375, HWND_DESKTOP, NULL, hThisInstance, NULL); ShowWindow (hMDIFrame, nFunsterStil); UpdateWindow(hMDIFrame); while (GetMessage(&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam; } /************************************************************************************ * Traitement des messages de la fenêtre principale * ************************************************************************************/ LRESULT CALLBACK FrameProc(HWND hFrame, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: CLIENTCREATESTRUCT ccs; MDICREATESTRUCT mcs; ToolsStatic1=CreateWindow("STATIC","STATIC 1",WS_CHILD | WS_VISIBLE, 0,0,150,500,hFrame,0,0,0); ToolsStatic2=CreateWindow("STATIC","STATIC 2",WS_CHILD | WS_VISIBLE,155,0,640,500,hFrame,0,0,0); ccs.hWindowMenu = NULL; ccs.idFirstChild = 0; hMDIClient = CreateWindowEx(WS_EX_CLIENTEDGE, "mdiclient", NULL, WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, ToolsStatic2, NULL, hInst, (LPVOID)&ccs); mcs.szTitle = "Nom de fenetre fille"; mcs.szClass = "MDI_Child"; mcs.hOwner = hInst; mcs.x mcs.y CW_USEDEFAULT; mcs.cx mcs.cy 300; mcs.style = MDIS_ALLCHILDSTYLES; hMDIChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LONG)&mcs); break; case WM_SIZING: { LPRECT rect=(LPRECT)lParam; int dx=rect->right-rect->left; int dy=rect->bottom-rect->top; MoveWindow(ToolsStatic1, 0, 0, 150,dy, TRUE); MoveWindow(ToolsStatic2,155, 0, dx-155,dy, TRUE); MoveWindow(hMDIClient,0, 0, dx-155,dy, TRUE); } break; case WM_SIZE: { int dx=LOWORD(lParam); int dy=HIWORD(lParam); MoveWindow(ToolsStatic1, 0, 0, 150,dy, TRUE); MoveWindow(ToolsStatic2,155, 0, dx-155,dy, TRUE); MoveWindow(hMDIClient,0, 0, dx-155,dy, TRUE); } break; case WM_DESTROY: PostQuitMessage (0); break; default: return DefFrameProc(hFrame, hMDIClient, message, wParam, lParam); } return 0; } /************************************************************************************ * Traitement des messages de la fenêtre fille * ************************************************************************************/ LRESULT CALLBACK ChildProc(HWND hChild, UINT Message, WPARAM wParam, LPARAM lParam) { HWND button; switch(Message) { case WM_CREATE: button = CreateWindow( "BUTTON", "Class Options", BS_LEFT|BS_PUSHBUTTON| WS_VISIBLE| WS_CHILD, 10, 10, 105, 100, hChild, NULL, hInst, NULL); break; case WM_CLOSE: MessageBox(hChild,"Ben pourquoi la femer ???\nElle est bien là !","Bah pourquoi ???", MB_OK|MB_ICONEXCLAMATION); DestroyWindow(hChild); break; } return DefMDIChildProc(hChild, Message, wParam, lParam); }
#include <windows.h> // Obliger pour les fenêtres #include <commctrl.h> #include <stdio.h> #include <stdlib.h> #include <GL/gl.h> #include <GL/glu.h> #include <math.h> #include <time.h> // Procédure traitant les messages de la fenêtre principale LRESULT CALLBACK FrameProc(HWND hFrame,UINT Message,WPARAM wParam,LPARAM lParam); // Procédure traitant les messages de la fenêtre fille LRESULT CALLBACK ChildProc(HWND hChild,UINT Message,WPARAM wParam,LPARAM lParam); HINSTANCE hInst; HWND hMDIFrame; // Handle de la fenêtre principale HWND hMDIClient; // Handle de la zone client HWND hMDIChild; // Handle de la fenêtre fille int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nSowhCmd) { hInst = hInstance; // Globalise l'instante WNDCLASSEX wc; // Classe pour fenêtre InitCommonControls(); /** Classe pour la fenêtre principale **/ wc.cbSize=sizeof(wc); wc.cbClsExtra=0; wc.cbWndExtra=0; wc.style=0; wc.hInstance=hInst; wc.hCursor=LoadCursor(NULL,IDC_ARROW); wc.hIcon=LoadIcon(NULL,IDI_APPLICATION); wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION); wc.lpfnWndProc=(WNDPROC)FrameProc; wc.lpszMenuName=NULL; wc.lpszClassName="MDI Frame"; wc.hbrBackground=(HBRUSH) (COLOR_APPWORKSPACE+1); if( !RegisterClassEx(&wc) ) return 0; /** Classe pour les fenêtre fille **/ /* wc.hbrBackground=(HBRUSH) (COLOR_BTNFACE+1); wc.lpfnWndProc=(WNDPROC)ChildProc; wc.lpszClassName="MDI Child";*/ wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS; wc.lpfnWndProc = (WNDPROC)ChildProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_3DSHADOW+1); // Background color (Only seen if OGL fails) wc.lpszMenuName = NULL; wc.lpszClassName = "MDI Child"; if( !RegisterClassEx(&wc) ) return 0; /** Création de la fenêtre mère (principale) **/ hMDIFrame = CreateWindowEx( WS_EX_CLIENTEDGE, "MDI Frame", "RobotSim", WS_VISIBLE|WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 400, NULL, NULL, hInst, 0); /** Création de la fenêtre fille **/ /* hMDIChild = CreateWindowEx( WS_EX_TOOLWINDOW, "MDI Child", "Tools", WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW, // Ne pas oublier le WS_CHILD 0, 0, 200, 150, hMDIClient, NULL, hInst, 0);*/ CREATESTRUCT cs; ZeroMemory(&cs, sizeof(CREATESTRUCT)); hMDIChild= CreateWindowEx( WS_EX_MDICHILD, "MDI Child", "Tools", WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hMDIClient, NULL, hInst, &cs ); PIXELFORMATDESCRIPTOR pfd; ZeroMemory(&pfd, sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cDepthBits = 16; pfd.iLayerType = PFD_MAIN_PLANE; int iFormat = ChoosePixelFormat(GetDC(hMDIFrame), &pfd); SetPixelFormat(GetDC(hMDIFrame), iFormat, &pfd); // Set pixel format for this child HGLRC hRC = wglCreateContext(GetDC(hMDIFrame)); // Set childs rendering context wglMakeCurrent(GetDC(hMDIFrame), hRC); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glClearColor(0.0, 0.0, 0.0, 0.0); glClearDepth(1.0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); float fMatAmbient[] = {0.8, 0.8, 0.8, 1.0}; float fMatDiffuse[] = {0.8, 0.8, 0.8, 1.0}; float fMatSpecular[] = {0.9, 0.9, 0.9, 1.0}; float fMatEmmision[] = {0.0, 0.0, 0.0, 1.0}; float fMatShininess[] = {100.0}; glMaterialfv(GL_FRONT, GL_AMBIENT, fMatAmbient); glMaterialfv(GL_FRONT, GL_DIFFUSE, fMatDiffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, fMatSpecular); glMaterialfv(GL_FRONT, GL_EMISSION, fMatEmmision); glMaterialfv(GL_FRONT, GL_SHININESS, fMatShininess); float fLightAmbient[] = {0.2, 0.2, 0.2, 1.0}; glLightfv(GL_LIGHT0, GL_AMBIENT, fLightAmbient); float fLightPosition[] = {200.0, 0.0, 0.0, 1.0}; glLightfv(GL_LIGHT0, GL_POSITION, fLightPosition); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_TEXTURE_2D); ShowWindow(hMDIChild,SW_SHOW); SetFocus(hMDIChild); MSG msg; while( GetMessage(&msg,NULL,0,0) != NULL ) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK FrameProc(HWND hFrame,UINT Message,WPARAM wParam,LPARAM lParam) { switch(Message) { case WM_PAINT: { int iThisChild; PAINTSTRUCT ps; BeginPaint(hFrame, &ps); SwapBuffers(GetDC(hFrame)); EndPaint(hFrame, &ps); } break; case WM_CREATE: /****** Quand la fenêtre principale se créée, il faut créer la zone client pour y mettre les fenêtre fille ******/ CLIENTCREATESTRUCT css; // Inconvénient : je ne sais toujours pas à quoi sert cette structure ! css.hWindowMenu=NULL; css.idFirstChild=0; /****** Création de la zone client ******/ hMDIClient = CreateWindowEx(WS_EX_CLIENTEDGE, "MDICLIENT", (LPCSTR)NULL, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, // Ne pas oubliez le WS_CHILD CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hFrame, NULL, hInst, (LPSTR)&css); ShowWindow(hMDIClient,SW_SHOW); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefFrameProc(hFrame,hMDIClient,Message,wParam,lParam); } } LRESULT CALLBACK ChildProc(HWND hChild,UINT Message,WPARAM wParam,LPARAM lParam) { switch(Message) { /* case WM_CREATE: { HWND button = CreateWindow( "BUTTON", "Class Options", BS_LEFT|BS_PUSHBUTTON| WS_VISIBLE| WS_CHILD, 10, 10, 105, 100, hMDIChild, NULL, hInst, NULL); /* HWND hstatic = CreateWindow("STATIC", "MyPicture", WS_CHILD | WS_VISIBLE, 10, 10, 100, 100, hMDIChild, NULL, hInst, NULL); */ /* return 0; } */ case WM_CLOSE: // C'est juste une petite touche d'intéractivité MessageBox(hMDIFrame,"Ben pourquoi la femer ???\nElle est bien là !","Bah pourquoi ???",MB_OK|MB_ICONEXCLAMATION); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefMDIChildProc(hChild,Message,wParam,lParam); } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question