Solved

Right Mouse Click - Events

Posted on 2000-02-28
10
218 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

757 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

13 Experts available now in Live!

Get 1:1 Help Now