首页 > 代码库 > Delphi7 API之 MDI窗口创建
Delphi7 API之 MDI窗口创建
继续上节,我们还是用工程文件创建一个MDI窗口。代码如下:
program MDIApp;uses Windows, Messages;var TheMessage:TMsg; FrameWindow,ClientWindow,ChildWindow:HWND;const IDCHILDWND = 100; //第一个MDI子窗口ID{$R *.RES}//回调函数function FrameWindowProc(TheFrameWindow:HWND;TheMessage,WParam,LParam:LongInt):LongInt;stdcall;var ClientStruct:TClientCreateStruct;begin case TheMessage of WM_CREATE: begin ClientStruct.hWindowMenu:=0; ClientStruct.idFirstChild:=IDCHILDWND; ClientWindow := CreateWindowEx(0, ‘MDICLIENT‘, nil, WS_CHILD or WS_CLIPCHILDREN or WS_VISIBLE, 0, 0, 0, 0, TheFrameWindow, 0, HInstance, @ClientStruct); if ClientWindow = 0 then begin MessageBox(0,‘createwindow faild‘,nil,MB_OK); Exit; end; end; WM_DESTROY: begin PostQuitMessage(0); Exit; end; end; Result := DefFrameProc(TheFrameWindow,ClientWindow,TheMessage,WParam,LParam);end;//注册主窗口function RegisterFrameClass:Boolean;var WindowClass:TWndClass;begin WindowClass.style:=CS_HREDRAW or CS_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;//注册子窗口function RegisterChildClass: Boolean;var WindowClass:TWndClass;begin WindowClass.style := CS_HREDRAW or CS_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;//开始主程序begin if not RegisterFrameClass then begin MessageBox(0,‘RegisterFrameClass faild‘,nil,MB_OK); Exit; end; FrameWindow := CreateWindowEx(0, ‘FrameClass‘, ‘Frame Window‘, WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, HInstance, nil); if FrameWindow <> 0 then begin ShowWindow(FrameWindow,SW_SHOWNORMAL); UpdateWindow(FrameWindow); end else begin MessageBox(0,‘CreateFrameWindow failed‘,nil,MB_OK); Exit; end; if not RegisterChildClass then begin MessageBox(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); if ChildWindow <> 0 then begin ShowWindow(ChildWindow,SW_SHOWNORMAL); UpdateWindow(ChildWindow); end else begin MessageBox(0,‘CreateChildWindow falid‘,nil,MB_OK); Exit; end; while GetMessage(TheMessage,0,0,0) do begin TranslateMessage(TheMessage); DispatchMessage(TheMessage); end;end.
效果如下:
Delphi7 API之 MDI窗口创建
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。