Solved

MouseEnter and MouseLeave on a DLL form

Posted on 2003-11-13
8
720 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
  • 4
  • 4
8 Comments
 
LVL 17

Expert Comment

by:geobul
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 5

Author Comment

by:Darth_helge
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 5

Author Comment

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

Accepted Solution

by:
geobul earned 170 total points
Comment Utility
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
Comment Utility
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
Comment Utility
You are welcome.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now