Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MouseEnter and MouseLeave on a DLL form

Posted on 2003-11-13
8
Medium Priority
?
755 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 510 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

618 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