Solved

MouseEnter and MouseLeave on a DLL form

Posted on 2003-11-13
8
738 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
Industry Leaders: 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
QRReport  TQrmemo vertical stretching 1 65
Convert a string into a TDateTime 5 79
Convert MS Word document to a PDF file 9 132
TAction.OnAfterExecute? 2 30
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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