Solved

Right Mouse Click - Events

Posted on 2000-02-28
10
221 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

14 Experts available now in Live!

Get 1:1 Help Now