Solved

MouseEnter and MouseLeave on a DLL form

Posted on 2003-11-13
8
739 Views
Last Modified: 2010-04-05
Hello every one. This is my first question here on this site which btw seems like a blast.

I have this form on a dll (IRForm), and when I show it, I can't get the MouseEnter and MouseLeave events on my labels in the DLLForm.

I call it like this on my main form:

   ShowDllIRForm(MainForm.Handle).ParentWindow := MainPanel.Handle;
   ShowDllIRForm(MainForm.Handle).Show;
   SetForegroundWindow(ShowDllIRForm(MainForm.Handle).Handle);

And the ShowDllIRForm in my dll looks like this

function ShowDllIRForm(hApp: THandle): TCustomForm; stdcall;
begin
 Application.Handle := hApp;
  if not assigned(IRForm) then
    IRForm := TIRForm.Create(Application);
  result := IRForm;
end;

Like this, the MouseEvents won't work
procedure TIRForm.Label1MouseEnter(Sender: TObject);
begin
label1.Font.Color := clBlue;
end;

But if I switch the DLLForm call from 'show' to 'showmodal' I get those mouse-events. BUT, the DLLForm is docked on my mainform and on the mainform there is a menu which I can't get access to on showmodal.

How shall I solve this problem? Is there a way to get the mouse-events when you use 'show' and not 'showmodal'?

thanks in advance

Helgesen
0
Comment
Question by:Darth_helge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 17

Expert Comment

by:geobul
ID: 9739500
Hi,

Replace MainForm.Handle with Application.Handle in your calls and try again. Let me know what is the result.

Regards, Geo
0
 
LVL 5

Author Comment

by:Darth_helge
ID: 9739599
hi geo.

I replaced my:

   ShowDllIRForm(MainForm.Handle).ParentWindow := MainPanel.Handle;
   ShowDllIRForm(MainForm.Handle).Show;
   SetForegroundWindow(ShowDllIRForm(MainForm.Handle).Handle);

with this:

   ShowDllIRForm(Application.Handle).ParentWindow := MainPanel.Handle;
   ShowDllIRForm(Application.Handle).Show;
   SetForegroundWindow(ShowDllIRForm(Application.Handle).Handle);

but it still doesn't work
other events in my DLLForm like Label1Click works like a dream, but not the mouseenter and mouseleave.

thanks for trying
0
 
LVL 17

Expert Comment

by:geobul
ID: 9739674
I don't have such events in my Delphi 5 so I can't test that. I have OnMouseMove event which works just fine.

Try this one also (almost the same):

  windows.SetParent(ShowDllIRForm(Application.Handle).Handle,Panel1.Handle);
  SetWindowPos(ShowDllIRForm(Application.Handle).Handle, 0, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOZORDER); // set it to the left-upper corner of the panel
  ShowDllIRForm(Application.Handle).Show;
  SetForegroundWindow(ShowDllIRForm(Application.Handle).Handle);

Regards, Geo
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:Darth_helge
ID: 9739778
windows.SetParent(ShowDllIRForm(Application.Handle).Handle,MainPanel.Handle);
  SetWindowPos(ShowDllIRForm(Application.Handle).Handle, 0, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOZORDER
  ShowDllIRForm(Application.Handle).Show;
  SetForegroundWindow(ShowDllIRForm(Application.Handle).Handle);

This works exactly like my code.
Can it be a bug in delphi?

OnMouseMove on my TLabel worked just fine for me too, but not the mouseenter and mouseleave.

There this code I have that should execute only when the mouse enters the label, and another code executes only when the mouse leaves the label. can we simulate this with the OnMouseMove event? Or perhaps simulate it with other events?

0
 
LVL 5

Author Comment

by:Darth_helge
ID: 9739789
but isn't this strange that it works when you use showmodal?
0
 
LVL 17

Accepted Solution

by:
geobul earned 170 total points
ID: 9739910
Simulating MouseEnter MouseLeave with MouseMove:
Note: Form1 is the parent of the labels. If you have a label over a panel over a form then things become complicated.

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    procedure Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  FormEnter: boolean;

implementation

{$R *.DFM}

procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if FormEnter then begin
    FormEnter := false;
    Label1.Font.Color := clBlue;
  end;
end;

procedure TForm1.Label2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if FormEnter then begin
    FormEnter := false;
    Label2.Font.Color := clRed;
  end;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if not FormEnter then begin
    FormEnter := true;
    Label1.Font.Color := clBlack;
    Label2.Font.Color := clBlack;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FormEnter := true;
end;

end.

Regards, Geo
0
 
LVL 5

Author Comment

by:Darth_helge
ID: 9740141
okey, this i kind of a workaround, but it'll do until I find out the mouseenter and leave problem.

thanks geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 9740272
You are welcome.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question