Multi CreateWindowEx

coockiesch Messages postés 2268 Date d'inscription mercredi 27 novembre 2002 Statut Membre Dernière intervention 13 septembre 2013 - 1 nov. 2003 à 12:12
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019 - 1 nov. 2003 à 12:33
Hello!!!

J'ai un programme qui a une fenêtre crée avec CreateWindowEx.

Après un click sur un boutton dans celle-ci, je la ferme ai en crée une autre, aussi avec CreateWindowEx. Le problème est que la deuxième est crée mais que l'application quit juste derrière...
Pk?
Merci

@++

Raf

"On dit que seulement 10 personnes au monde comprenaient Einstein. Personne ne me comprends. Suis-je un génie???"

3 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
1 nov. 2003 à 12:16
Salut coockiesch, c'est pas le site de la meteo ici, donc tres peu de devins. Si on n'a pas le code, comment rouver le malaise.
BruNews, ciao...
0
coockiesch Messages postés 2268 Date d'inscription mercredi 27 novembre 2002 Statut Membre Dernière intervention 13 septembre 2013 4
1 nov. 2003 à 12:22
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???"
0
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
1 nov. 2003 à 12:33
Passe moi ton proj par mail parce que la c'est un peu confus pour voir le deroulement.
BruNews, ciao...
0
Rejoignez-nous