Continue to the previous section, we still create an MDI window with the project file. The code is as follows:
ProgramMdiapp;usesWindows, Messages;varthemessage:tmsg; Framewindow,clientwindow,childwindow:hwnd;ConstIdchildwnd= -; //First MDI child window ID{$R *. RES}//callback functionfunctionFramewindowproc (Theframewindow:hwnd; Themessage,wparam,lparam:longint): Longint;stdcall;varclientstruct:tclientcreatestruct;begin CaseThemessage ofwm_create:beginClientstruct.hwindowmenu:=0; Clientstruct.idfirstchild:=Idchildwnd; Clientwindow:= CreateWindowEx (0, 'mdiclient', Nil, Ws_childorWs_clipchildrenorws_visible,0, 0, 0, 0, Theframewindow,0, HINSTANCE, @ClientStruct); ifClientwindow =0 Then beginMessageBox (0,'CreateWindow faild',Nil, MB_OK); Exit; End; End; Wm_destroy:beginPostQuitMessage (0); Exit; End; End; Result:=Defframeproc (theframewindow,clientwindow,themessage,wparam,lparam);End;//Register the main windowfunctionRegisterframeclass:boolean;varWindowclass:twndclass;beginWindowclass.style:=cs_hredraworCs_vredraw; Windowclass.lpfnwndproc:=@FrameWindowProc; Windowclass.cbclsextra:=0; Windowclass.cbwndextra:=0; Windowclass.hinstance:=hinstance; Windowclass.hicon:= LoadIcon (0, Idi_winlogo); Windowclass.hcursor:= LoadCursor (0, Idc_arrow); Windowclass.hbrbackground:=Color_window; Windowclass.lpszmenuname:=Nil; Windowclass.lpszclassname:='Frameclass'; Result:= Windows. RegisterClass (Windowclass) <>0;End;//Registering child windowsfunctionRegisterchildclass:boolean;varWindowclass:twndclass;beginWindowclass.style:= Cs_hredraworCs_vredraw; Windowclass.lpfnwndproc:=@DefMDICHildProc; Windowclass.cbclsextra:=0; Windowclass.cbwndextra:=0; Windowclass.hinstance:=hinstance; Windowclass.hicon:= LoadIcon (0, idi_application); Windowclass.hcursor:= LoadCursor (0, Idc_arrow); Windowclass.hbrbackground:=Color_window; Windowclass.lpszmenuname:=Nil; Windowclass.lpszclassname:='ChildClass'; Result:= Windows. RegisterClass (Windowclass) <>0;End;//start the main programbegin if notRegisterframeclass Then beginMessageBox (0,'Registerframeclass faild',Nil, MB_OK); Exit; End; FrameWindow:= CreateWindowEx (0, 'Frameclass', 'Frame Window', Ws_overlappedwindoworWs_clipchildren, Cw_usedefault, Cw_usedefault, Cw_usedefault, Cw_usedefault, 0, 0, HINSTANCE,Nil); ifFrameWindow <>0 Then beginShowWindow (Framewindow,sw_shownormal); UpdateWindow (FrameWindow); End Else beginMessageBox (0,'Createframewindow failed',Nil, MB_OK); Exit; End; if notRegisterchildclass Then beginMessageBox (0,'Registerchildclass failed',Nil, MB_OK); Exit; End; ChildWindow:= Createmdiwindow ('ChildClass', 'Child Window', Ws_visible, Cw_usedefault, Cw_usedefault, Cw_usedefault, Cw_usedefault, Clientwindow, HINSTANCE,0); ifChildWindow <>0 Then beginShowWindow (Childwindow,sw_shownormal); UpdateWindow (ChildWindow); End Else beginMessageBox (0,'Createchildwindow Falid',Nil, MB_OK); Exit; End; whileGetMessage (Themessage,0,0,0) Do beginTranslateMessage (themessage); DispatchMessage (themessage); End;End.
The effect is as follows:
Delphi7 API's MDI window creation