码迷,mamicode.com
首页 > Windows程序 > 详细

Delphi7 API之 MDI窗口创建

时间:2014-10-31 13:47:33      阅读:392      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   color   os   ar   sp   

继续上节,我们还是用工程文件创建一个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.

效果如下:

 bubuko.com,布布扣

Delphi7 API之 MDI窗口创建

标签:des   style   blog   http   io   color   os   ar   sp   

原文地址:http://www.cnblogs.com/delphi2014/p/4064804.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!