Solved

Right Mouse Click - Events

Posted on 2000-02-28
10
222 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 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