Link to home
Start Free TrialLog in
Avatar of craig_capel
craig_capel

asked on

Right Mouse Click - Events

 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...
Avatar of craig_capel
craig_capel

ASKER

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.
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.
No....ignore that.
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;
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
listening..
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.
ASKER CERTIFIED SOLUTION
Avatar of raidos
raidos

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Impressed!!!!!!!!!! THANKS sorry for shoutin, just over excited... lol been trying to get this sucker to work for ages.....


Thank - you....


Craig C.
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....