Salut!!!
Voici ma WinMain
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd_log;
MSG msg;
// variable hInstance affecté à variable globale pour ré-utilisation
// ultérieur
hInst = hInstance;
// idem pour nCmdShow
nCmd = nCmdShow;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProcLog;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = "fenClassLog";
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Impossible de créer la classe fenêtre", szAppName, MB_OK | MB_ICONEXCLAMATION);
return 0;
}
hwnd_log = CreateWindowEx(WS_EX_CLIENTEDGE, "fenClassLog", "Login",
WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
50, 50, 300, 400,
NULL, NULL, hInstance, NULL);
if(hwnd_log == NULL)
{
MessageBox(NULL, "Echec lors de la création de la fenêtre", szAppName, MB_OK | MB_ICONEXCLAMATION);
return 0;
}
ShowWindow(hwnd_log, nCmdShow);
UpdateWindow(hwnd_log);
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
Et le code de création de la deuxième fenêtre (ds la proc de gestion de msgs de la 1e):
// Création de la fenêtre
WNDCLASSEX wc;
HWND hwnd_principale;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProcPrincipale;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = hInst;
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = "fenClassPrincipale";
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Impossible de créer la classe fenêtre", szAppName, MB_OK | MB_ICONEXCLAMATION);
exit(0);
}
hwnd_principale = CreateWindowEx(WS_EX_CLIENTEDGE, "fenClassPrincipale", "Fenêtre principale",
WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
50, 50, 300, 400,
NULL, NULL, hInst, NULL);
if(hwnd_principale == NULL)
{
MessageBox(NULL, "Echec lors de la création de la fenêtre", szAppName, MB_OK | MB_ICONEXCLAMATION);
exit(0);
}
DestroyWindow(hwnd);
ShowWindow(hwnd_principale, nCmd);
UpdateWindow(hwnd_principale);
Pour finir, la proc de msgs de la 2e:
// Fenêtre principale
LRESULT CALLBACK WndProcPrincipale(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
MessageBox(NULL, "Création deuxième fenêtre", szAppName, MB_OK | MB_ICONINFORMATION);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
MessageBox(NULL, "Destruction deuxième fenêtre", szAppName, MB_OK | MB_ICONINFORMATION);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
Info: "Création de la 2e fenêtre apparait".
Merci
@++
Raf
"On dit que seulement 10 personnes au monde comprenaient Einstein. Personne ne me comprends. Suis-je un génie???"