Solved

Right Mouse Click - Events

Posted on 2000-02-28
10
230 Views
Last Modified: 2010-04-04
 private
    { Private declarations }
     Procedure WMNCHITTEST(var Msg : TMessage); message WM_NCHITTEST;


Procedure TForm1.WMNCHITTEST(var Msg : TMessage);
 begin
  DefaultHandler(Msg);
     if Msg.Result = HTClient then
    Msg.Result := HTCAPTION;
end;

Ok this code works, thats great i can move my form around.... etc etc, but while this code makes the form mover around, can anyone make the right mouse event work? or make the popup menu work?....... I dont think so...
0
Comment
Question by:craig_capel
[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
  • 2
  • 2
  • +2
10 Comments
 
LVL 2

Author Comment

by:craig_capel
ID: 2564493
and yeah this is what my program is, its going to be freeware like the rest of my programs.... so here ya go...

unit winampstalker1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, Menus, shellapi;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Timer1: TTimer;
    PopupMenu1: TPopupMenu;
    Close1: TMenuItem;
    CloseandCloseWinamp1: TMenuItem;
    Move1: TMenuItem;
    PlayAMusicFile1: TMenuItem;
    OpenDialog1: TOpenDialog;
    HideWinamp1: TMenuItem;
    ShowWinamp1: TMenuItem;
    procedure Timer1Timer(Sender: TObject);
    procedure PlayAMusicFile1Click(Sender: TObject);
    procedure HideWinamp1Click(Sender: TObject);
    procedure ShowWinamp1Click(Sender: TObject);
    procedure Close1Click(Sender: TObject);
    procedure Move1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure CloseandCloseWinamp1Click(Sender: TObject);
  private
    { Private declarations }
     Procedure WMNCHITTEST(var Msg : TMessage); message WM_NCHITTEST;
  public

    { Public declarations }
  end;

var
  Form1: TForm1;
 mousedownvar, wellwhat: boolean;
i1 : integer;
passfile,tmp1,s1,s2 : string;
wnd: hwnd;

tmp_chr: char;
n: integer;
len: integer;


implementation

{$R *.DFM}


procedure TForm1.Timer1Timer(Sender: TObject);
begin
wnd:=findwindow('winamp v1.x',nil);
if wnd=null then close;
i1 := SendMessage(wnd, WM_GETTEXTLENGTH, 0, 0);
SetLength(s1, i1 + 1);
SetLength(s1, SendMessage(wnd, WM_GETTEXT, i1 + 1,integer(s1)));
if s1<>s2 then
 begin
 wellwhat:=false;
  label1.caption:= s1+' ';
 end;
 s2:=s1;
 if (length(s1)<=1) and (wellwhat=false) then
   begin
     wellwhat:=true;
      label1.caption:='Winamp Not Running!!!  ';
   end;
form1.width:=label1.Width;

  tmp1:=label1.caption;
  len:=length(tmp1);
  tmp_chr:=tmp1[1];
  for n:=1 to len-1 do
     begin
        tmp1[n]:=tmp1[n+1];
     end;
   tmp1[len]:=tmp_chr;
label1.caption:=tmp1;
end;

procedure TForm1.PlayAMusicFile1Click(Sender: TObject);
begin
opendialog1.execute;
passfile:=opendialog1.filename;
shellExecute(handle,'open',pchar(passfile),'','',0);
end;

procedure TForm1.HideWinamp1Click(Sender: TObject);
var
 wnd2: hwnd;
begin
   wnd2:=findwindow('winamp V1.x',nil);
   showwindow(wnd2,sw_hide);

end;

procedure TForm1.ShowWinamp1Click(Sender: TObject);
var
 wnd2: hwnd;
begin
   wnd2:=findwindow('winamp V1.x',nil);
   showwindow(wnd2,sw_show);
   showwindow(wnd2,sw_restore);
   setforegroundwindow(wnd2);
end;

procedure TForm1.Close1Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Move1Click(Sender: TObject);
begin
  form1.borderstyle:=bsSizeable;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
form1.left:=23;
form1.top:=3;

end;

procedure TForm1.CloseandCloseWinamp1Click(Sender: TObject);
var
  wnd2: hwnd;
begin
   wnd2:=findwindow('winamp V1.x',nil);
   sendmessage(wnd2,wm_close,0,0);
   close;
end;


Procedure TForm1.WMNCHITTEST(var Msg : TMessage);
 begin
  DefaultHandler(Msg);
     if Msg.Result = HTClient then
    Msg.Result := HTCAPTION;
end;


end.


Well, DUH, you will need winamp..... :)
Thanks All

Craig C.
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2564518
Just slightly alter the procedure to capture the mouse click...

Procedure TForm1.WMNCHITTEST(var Msg : TMessage);
begin
  if Msg.Result = HTClient then
    Msg.Result := HTCAPTION
  else
            inherited;
end;

That brings up the popup menu (if there is one of course.)

John.
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2564524
No....ignore that.
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 8

Expert Comment

by:ZifNab
ID: 2564538
Well, it almost normal that this doesn't execpts right clicks anymore, isn't is.... you change the msg.result .... you should somewhere define when you allow the move of the form and otherwise except the mouseclicks.

Something like :

is canmove then
begin
  if msg.result = HTCLient ....
end;
0
 
LVL 3

Expert Comment

by:raidos
ID: 2564582
Hi.

If you put this on the MouseDown event of the form you should be able to move it around with MBLeft and do whatever on MBRight

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  If Button = MBRight then begin
    //Do Whatever
    Showmessage('Right click');
  End Else Begin
    ReleaseCapture;
    Form1.Perform(WM_Syscommand,$F012,0);
  End
end;

Good Luck.
//raidos
0
 
LVL 17

Expert Comment

by:inthe
ID: 2564716
listening..
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2564982
Ok.... that code  raidos posted, looked good but nah nothing..... so how about this...

http://members.xoom.com/craig_c/winampst.zip  This is the actuall source code, there is an exe in there cos that works good but i don't get the menu until i take out winchest... etc etc....

So could anyone be kind enough to see what its doing?  Thanks


P.s if you do fix it, is ok if you jost posted it on the screen (the source) , as barry wants to be nosey :)... "Listening!" ha....

Craig C.
0
 
LVL 3

Accepted Solution

by:
raidos earned 50 total points
ID: 2565218
Ohh...I See... It's the label...oh my..

Remove the WMNCHit...

And add this to onMouseDown event for the label..

If Button = MBLeft then begin
  ReleaseCapture;
  Form1.Perform(WM_Syscommand,$F012,0);
End;

That should do it...it worked like a charm for me when i tested it...

Menu on right button move on left..=))

Good luck...

//raidos
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2565453
Impressed!!!!!!!!!! THANKS sorry for shoutin, just over excited... lol been trying to get this sucker to work for ages.....


Thank - you....


Craig C.
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2565479
I am really going to have to learn not to make comments first them accpet  it as an answer, then go through it all again here..... wish this phone would shut up..., trying to get a party going here....
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses
Course of the Month7 days, 5 hours left to enroll

622 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