最近在考虑MIS系统界面的整体框架,决定使用MDI Form+模块中的MDI Child,但是MDI form的工作区总有讨厌的粗边。
昨天下午从网上查到C++版本的解决方法,就花了点时间翻译成delphi的,呵呵,供大家参考。
在MDI Form中写入如下代码:
interface
TFmMain = class(TForm)
...
procedure FormCreate(Sender: TObject);
...
private
...
procedure CreateDefWndProc();
PROCEDURE ClientWndProc(VAR Message: TMessage);
end;
implementation
...
procedure TFmMain.CreateDefWndProc;
var
hWnd1 : HWND;
ccs : TClientCreateStruct;
begin
ccs.hWindowMenu := 0;
ccs.idFirstChild := $FF00;
hWnd1 := CreateWindowEx(WS_EX_CLIENTEDGE,
'MDICLIENT', '', WS_CHILD or WS_VISIBLE or WS_GROUP or
WS_TABSTOP or WS_CLIPCHILDREN or WS_HSCROLL or WS_VSCROLL or
WS_CLIPSIBLINGS or MDIS_ALLCHILDSTYLES, 0, 0, ClientWidth,
ClientHeight, Handle, 0, HInstance, @ccs);
FClientInstance := pointer(GetWindowLong(hWnd1,GWL_WNDPROC));
DestroyWindow(hWnd1);
end;
procedure TFmMain.ClientWndProc(var Message: TMessage);
//VAR
// MyDC : hDC;
begin
if (Message.Msg = WM_ERASEBKGND) then
begin
//这儿模拟VCL的源程序用主窗口的背景色填充客户区,
//你也可以在客户区画一个图形。
FillRect(HDC(Message.WParam), ClientRect,Brush.Handle);
// MyDC := TWMEraseBkGnd(Message).DC;
//BitBlt(MyDC, (ClientWidth - imBack.Picture.Width)div 2,
// (ClientHeight - imBack.Picture.Height) div 2,
// imBack.Picture.Width, imBack.Picture.Height,
// imBack.Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY);
Message.Result := 1;
end
else
Message.Result := CallWindowProc(FClientInstance, ClientHandle,
Message.Msg, Message.WParam, Message.LParam);
end;
procedure TFmMain.FormCreate(Sender: TObject);
begin
//*******去除MDIchild粗边框**********
CreateDefWndProc();
SetWindowLong(ClientHandle, GWL_WNDPROC,
LongInt(MakeObjectInstance(ClientWndProc)));
SetWindowLong(ClientHandle,GWL_EXSTYLE,GetWindowLong(
ClientHandle,GWL_EXSTYLE) and (not WS_EX_CLIENTEDGE));
SetWindowPos(ClientHandle,0,0,0,0,0,SWP_FRAMECHANGED
or SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE or SWP_NOZORDER);
//***********************************
end;
本文地址:http://com.8s8s.com/it/it4174.htm