ponti
asked on
Transparent Bitmap on a MDIParentForm
How can i paint or add centered a transparent bitmap on a mdiparentform in delphi 1?
And how can i put a text on the mdiparentform in a specific font?
And how can i put a text on the mdiparentform in a specific font?
ASKER
I tried to put a label or bitmap on the mdiparentform but nothing is displayed when starting the application. How can i show a text centered on a mdiparentform? I tried to use the windows api call "textout", but how can you assign a specific font?
If you use textout you've to change the font via the canvas....
Canvas.Font.Style ......
Regards, Zif.
Canvas.Font.Style ......
Regards, Zif.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The code is nearly useful. My problem is to set a specific font via the api function selectobject. With tfont.handle it work nearly fine, except that the font color i have set doesnot work. the text is always painted black on white background, whatever i set.
Also a new brush or pen does not help.
Also a new brush or pen does not help.
Can you send a piece of your code?
ASKER
Here is a piece of my code. The problem is the color property of tfont, which does not affect the output of the text. It is always painted black on white background.
What is wrong?
class MyClass
...
private
fClientInstance, fPrevClient: TFarProc;
procedure ClientWindow(var aMessage: TMessage);
end;
procedure TMyClass.ClientWindow(var aMessage: TMessage);
var row, col: word; dc: hDC;
mybrush: TBrush;
mypen: TPen;
myFont: TFont;
begin
with aMessage do
case Msg of
WM_ERASEBKGND:
begin
dc:= TWMEraseBkGnd(aMessage).dc ;
mybrush:= TBrush.Create;
mybrush.Color:= clBtnFace;
mybrush.style:= bsSolid;
mypen:= TPen.Create;
mypen.Color:= clBtnFace;
myfont:= TFont.Create;
myfont.color:= clGray;
myfont.size:= 32;
myfont.name:= 'Arial';
WinProcs.SelectObject(dc, mybrush.Handle);
WinProcs.SelectObject(dc, mypen.Handle);
WinProcs.Rectangle( dc, 0, 0, ClientWidth, ClientHeight );
WinProcs.SelectObject(dc, myfont.Handle);
WinProcs.TextOut(dc, 200, 200, 'My Output', 10);
mybrush.free;
mypen.free;
myfont.free;
result:=1;
end;
else result:= CallWindowProc(fPrevClient , Clienthandle, Msg, wParam, lParam);
end;
end;
At beginning:
fClientInstance:= MakeObjectInstance(ClientW indow);
fPrevClient:= Pointer(GetWindowLong(Clie ntHandle, GWL_WNDPROC));
SetWindowLong(ClientHandle , GWL_WNDPROC, Longint(fClientInstance));
At the end:
SetWindowLong(ClientHandle , GWL_WNDPROC, Longint(fPrevClient));
FreeObjectInstance(fClient Instance);
What is wrong?
class MyClass
...
private
fClientInstance, fPrevClient: TFarProc;
procedure ClientWindow(var aMessage: TMessage);
end;
procedure TMyClass.ClientWindow(var aMessage: TMessage);
var row, col: word; dc: hDC;
mybrush: TBrush;
mypen: TPen;
myFont: TFont;
begin
with aMessage do
case Msg of
WM_ERASEBKGND:
begin
dc:= TWMEraseBkGnd(aMessage).dc
mybrush:= TBrush.Create;
mybrush.Color:= clBtnFace;
mybrush.style:= bsSolid;
mypen:= TPen.Create;
mypen.Color:= clBtnFace;
myfont:= TFont.Create;
myfont.color:= clGray;
myfont.size:= 32;
myfont.name:= 'Arial';
WinProcs.SelectObject(dc, mybrush.Handle);
WinProcs.SelectObject(dc, mypen.Handle);
WinProcs.Rectangle( dc, 0, 0, ClientWidth, ClientHeight );
WinProcs.SelectObject(dc, myfont.Handle);
WinProcs.TextOut(dc, 200, 200, 'My Output', 10);
mybrush.free;
mypen.free;
myfont.free;
result:=1;
end;
else result:= CallWindowProc(fPrevClient
end;
end;
At beginning:
fClientInstance:= MakeObjectInstance(ClientW
fPrevClient:= Pointer(GetWindowLong(Clie
SetWindowLong(ClientHandle
At the end:
SetWindowLong(ClientHandle
FreeObjectInstance(fClient
Try to use this with your canvas... Yo do use the same canvas I hope?
var
OldBkMode : integer;
begin
with Form1.Canvas do begin
Brush.Color := clRed;
FillRect(Rect(0, 0, 100, 100));
Brush.Color := clBlue;
TextOut(10, 20, 'Not Transparent!');
OldBkMode := SetBkMode(Handle, TRANSPARENT);
TextOut(10, 50, 'Transparent!');
SetBkMode(Handle, OldBkMode);
end;
end;
regards, ZiF.
var
OldBkMode : integer;
begin
with Form1.Canvas do begin
Brush.Color := clRed;
FillRect(Rect(0, 0, 100, 100));
Brush.Color := clBlue;
TextOut(10, 20, 'Not Transparent!');
OldBkMode := SetBkMode(Handle, TRANSPARENT);
TextOut(10, 50, 'Transparent!');
SetBkMode(Handle, OldBkMode);
end;
end;
regards, ZiF.
ASKER
I have found out how i can do it. I assign the dc to the canvas.handle and it works.
But i will also try your version.
Thanks for helping
But i will also try your version.
Thanks for helping
Thanks For helping...
MDIParentForm is always at the background --> why transparent bitmap?
Text in a specific font??? Where ? On form? Use a Label?
ZiF.