Bonjour à tous :
en réalité, je ne sais pas si mon problème est du à une barre de status, mais étant donné qu'il est apparu après la création de celle-ci, bah voilà quoi....
Alors enfaite, j'ai le code suivant :
#include <windows.h> // Obliger pour les fenêtres
#include <commctrl.h>
#define ID_STATUSBAR 1000
// 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
HWND g_hStatusBar;
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_WINDOW+1);
wc.lpfnWndProc=(WNDPROC)ChildProc;
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",
"Fenêtre mère - MDI Frame",
WS_VISIBLE | WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
500,
400,
NULL,
NULL,
hInst,
0);
/** Création de la fenêtre fille **/
hMDIChild = CreateWindowEx(
WS_EX_CLIENTEDGE,
"MDI Child",
"Fenêtre fille - MDI Child",
WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW, // Ne pas oublier le WS_CHILD
0,
0,
350,
300,
hMDIClient,
NULL,
hInst,
0);
ShowWindow(hMDIChild,SW_SHOW);
SetFocus(hMDIChild);
MSG msg;
while( GetMessage(&msg,NULL,0,0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK FrameProc(HWND hFrame,UINT Message,WPARAM wParam,LPARAM lParam)
{
int iStatusWidths[] = {150, -1};
switch(Message)
{
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=GetSubMenu(GetMenu(hMDIFrame),0);
css.idFirstChild=0;
/****** Création de la zone client ******/
hMDIClient = CreateWindow(
"MDICLIENT",
(LPCSTR)NULL,
WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_CLIPCHILDREN, // Ne pas oubliez le WS_CHILD
15,
15,
150,
100,
hFrame,
NULL,
hInst,
(LPSTR)&css);
ShowWindow(hMDIClient,SW_SHOW);
g_hStatusBar = CreateWindowEx(0, STATUSCLASSNAME, NULL,
WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0,
hFrame, (HMENU)ID_STATUSBAR, hInst, NULL);
if(g_hStatusBar==NULL){
MessageBox(hFrame,"Initialisation de la barre de status","Erreur",MB_OK | MB_ICONERROR);
PostQuitMessage(1);
}
SendMessage(g_hStatusBar, SB_SETPARTS, 2, (LPARAM)iStatusWidths);
return 0;
case WM_SIZE:
SendMessage(g_hStatusBar, WM_SIZE, 0, 0);
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_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_PAINT:
{
PAINTSTRUCT ps;
HDC hDC = BeginPaint(hChild, &ps);
MoveToEx(hDC, 0, 120, NULL);
LineTo(hDC, 120,120);
EndPaint(hChild, &ps);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefMDIChildProc(hChild,Message,wParam,lParam);
}
}
J'ai trouvé un code des plus basiques ici, pour créer une application MDI. Comme je prévois d'utiliser cette méthode, je regarde un peu ce que je peux faire, etc... et quand j'ajoute une barre de status, je m'apercois que la fenetre fille est fille de la zone client, au lieu d'être fille de la fenetre principal.
Compilez mon code, vous verrez, c'est mieux que mes explications vaseuses ^^
Ci vous trouvez l'erreur...
Merci