最近在考慮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;