ShowWindow(param, modeDAffichage); //Affiche la fenêtre par défaut
ShowWindow(param, SW_HIDE); //Masque la fenêtre
//Pour afficher la fenêtre enfant case ID_B_CONFIG: ShowWindow(param, SW_SHOW); //Affiche la fenêtre break; //... LRESULT CALLBACK procedureNewWND(HWND NewWND, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { //Pour masquer la fenêtre enfant case WM_QUIT: ShowWindow(NewWND, SW_SHOW); //Masque la fenêtre return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc(NewWND, message, wParam, lParam); } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question#include <windows.h> #define ID_B_CONFIG 0 #define ID_B_QUITTER 1 HINSTANCE cetteInstance; LRESULT CALLBACK procedureFenetrePrincipale(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK procedureNewWND(HWND, UINT, WPARAM, LPARAM); int CreateNewWND(); int WinMain (HINSTANCE cetteInstance, HINSTANCE precedenteInstance, LPSTR lignesDeCommande, int modeDAffichage) { HWND fenetrePrincipale,param; MSG message; WNDCLASS classeFenetre,classeEnfant; 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"; // au cas où ça échoue if(!RegisterClass(&classeFenetre)) return FALSE; classeEnfant.style = 0; classeEnfant.lpfnWndProc = procedureNewWND; classeEnfant.cbClsExtra = 0; classeEnfant.cbWndExtra = 0; classeEnfant.hInstance = NULL; classeEnfant.hIcon = LoadIcon(NULL, IDI_APPLICATION); classeEnfant.hCursor = LoadCursor(NULL, IDC_ARROW); classeEnfant.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE); classeEnfant.lpszMenuName = NULL; classeEnfant.lpszClassName = "classeE"; if(!RegisterClass(&classeEnfant)) return FALSE; fenetrePrincipale = CreateWindow("classeF", "Gestion Puissance", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640,480, NULL, NULL, cetteInstance, NULL); if (!fenetrePrincipale) return FALSE; ShowWindow(fenetrePrincipale, modeDAffichage); UpdateWindow(fenetrePrincipale); param = CreateWindow("classeE", "param", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 320,480, fenetrePrincipale, NULL, cetteInstance, NULL); if (!param) return FALSE; ShowWindow(param, modeDAffichage); UpdateWindow(param); 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[2] = {NULL}; switch (message) { case WM_COMMAND: switch(LOWORD(wParam)) { case ID_B_CONFIG: break; case ID_B_QUITTER: SendMessage(fenetrePrincipale, WM_DESTROY, 0, 0); break; } return 0; case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CREATE: boutons[0] = (HWND__*)CreateWindow("BUTTON", "Config", WS_CHILD | WS_VISIBLE,550, 5, 70, 30, fenetrePrincipale, ID_B_CONFIG, cetteInstance, NULL); boutons[1] = (HWND__*)CreateWindow("BUTTON", "Quitter", WS_CHILD | WS_VISIBLE,550, 40, 70, 30, fenetrePrincipale, (HMENU__*)ID_B_QUITTER, cetteInstance, NULL); return 0; default: return DefWindowProc(fenetrePrincipale, message, wParam, lParam); } } LRESULT CALLBACK procedureNewWND(HWND NewWND, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc(NewWND, message, wParam, lParam); } }
//Pour masquer la fenêtre enfant case WM_QUIT: ShowWindow(NewWND, SW_HIDE); //Masque la fenêtre return 0;