?
Solved

MouseEnter and MouseLeave on a DLL form

Posted on 2003-11-13
8
Medium Priority
?
747 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

770 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