Using BitBlt-Function when mouse-key is pressed

Hi,

I want to ask if there is a way to use the BitBlt (or similiar) function when a mousekey is pressed. BitBlt works fine for me but when I try to capture something while a mouse-button is pressed, the function is executed as recently as I release the mouse button. That's to late. I need to capture something when the mouse-button is pressed. How can that be done?

Greets and big THX,
Dawn
SnodyAsked:
Who is Participating?
 
A. Cristian CsikiConnect With a Mentor Senior System AdministratorCommented:
hy Snody,
like here but few adds   : http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21838717.html

my final code is:

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    HWNDTxt: TEdit;
    WindowNameTxt: TEdit;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    hLibGI: THandle;
    procedure HookMsgKey(var Msg1: TMessage); message WM_USER+1627;
    procedure HookMsgMse(var Msg1: TMessage); message WM_USER+1628;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
      uses shellapi;
{$R *.dfm}

      procedure TForm1.HookMsgKey(var Msg1: TMessage);
begin
Memo1.Perform(WM_CHAR, Msg1.wParam, 0);
end;


procedure TForm1.HookMsgMse(var Msg1: TMessage);
var
Str1: String;

begin
{below are most of the mouse messages
WM_LBUTTONDBLCLK
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_MBUTTONDBLCLK
WM_MBUTTONDOWN
WM_MBUTTONUP
WM_MOUSEACTIVATE
WM_MOUSEMOVE
WM_MOUSEWHEEL
WM_NCLBUTTONDBLCLK
WM_NCLBUTTONDOWN
WM_NCLBUTTONUP
WM_NCMBUTTONDBLCLK
WM_NCMBUTTONDOWN
WM_NCMBUTTONUP
WM_NCMOUSEMOVE
WM_NCRBUTTONDBLCLK
WM_NCRBUTTONDOWN
WM_NCRBUTTONUP
WM_RBUTTONDBLCLK
WM_RBUTTONDOWN
WM_RBUTTONUP }


// because WM_MOUSEWHEEL is different I have it first
if Msg1.wParamLo = WM_MOUSEWHEEL then
  begin
  Str1 := 'mouseWheel - '+IntToStr(SmallInt(Msg1.wParamHi));
  //' at x:'+IntToStr(SmallInt(Msg1.LParamLo))+
  //      ' y:'+IntToStr(SmallInt(Msg1.LParamHi));
  Memo1.Lines.Add(Str1);
  Exit;
  end else
case Msg1.wParamLo of
  WM_LBUTTONDOWN: Str1 := 'Left Button Down';
  WM_LBUTTONUP: Str1 := 'WM_LBUTTONUP';
  WM_MBUTTONDOWN: Str1 := 'WM_MBUTTONDOWN';
  WM_MBUTTONUP: Str1 := 'WM_MBUTTONUP';
  //WM_MOUSEMOVE: Str1 := 'WM_MOUSEMOVE';
  WM_NCLBUTTONDOWN: Str1 := 'WM_NCLBUTTONDOWN';
  WM_RBUTTONDOWN: Str1 := 'WM_RBUTTONDOWN';
  WM_RBUTTONUP: Str1 := 'WM_RBUTTONDOWN';
  else Exit; // Warning, I just exit here to avoid all of the WM_MOUSEMOVE messages in memo
  end;

Str1 :=  Str1;
Memo1.Lines.Text:=str1;
if (memo1.Lines.Text='WM_LBUTTONUP') and  (WindowNameTxt.Text='Senza nome - Blocco note') then showmessage('merge!@');

{ i've got italian windows, so my notepad display "Senza nome - Blocco note" when i start it, but in english is "text document - notepad"
also here you can put your desired application name: ex: "Yahoo! Messenger with Voice" }


nd;
 
procedure TForm1.Button1Click(Sender: TObject);
var
StartHook: function(FormHandle: THandle): Integer;
Re: Integer;
MsgStr: String;
begin
shellexecute(application.MainForm.Handle,'','C:\windows\notepad.exe','','',1);
MsgStr := 'FAILED to Load Library';
hLibGI := LoadLibrary('Project2.dll');   {<--put the dll name in the same directory or put the hole location; you make the dll from the exemple                                                        from the topic i refered to you}
if hLibGI > 0 then
  begin
  @StartHook := GetProcAddress(hLibGI,'StartHook');
  if @StartHook <> nil then
    begin
    Re := StartHook(Handle);
    if Re = 0 then
      MsgStr := 'Success - Hooks Are Running'
      else
      MsgStr := 'ERROR - Hooks NOT Started, Error code is '+IntToStr(Re);
    end else
    begin
    FreeLibrary(hLibGI);
    MsgStr := 'ERROR - StartHook function NOT in Library';
    end;
  end;


ShowMessage(MsgStr);

end;

procedure TForm1.Timer1Timer(Sender: TObject);
var P : TPoint;
buff : Array[0..255] of char;
begin
GetCursorPos(P); //Gets The X, Y Axis Of Your Mouse For WindowFromPoint To Use
HwndTxt.Text := IntToStr(WindowFromPoint(P)); // Converts A Integer To A String, And Gets The Handle From Your Mouse X,Y Axis
GetWindowText(StrToInt(HwndTxt.Text),Buff,255); //Stores The Name Of The Window In Buff
If Buff <> '' then //If Its Window Caption Is No Blank
WindowNameTxt.Text := buff;  
end;

hope this helps you.
0
 
A. Cristian CsikiSenior System AdministratorCommented:
hy there, like this?

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
showmessage('hy!');
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
bitbtn1.Click;
end;
0
 
SnodyAuthor Commented:
Sorry perhaps is my english to bad (I'm not native speaker) but I think you missunderstood me.

The mouseclick is outside of my application. You've posted a workaround but that doesn't helps me with my problem. I try to explain it again, I hope you get what I mean:

I want to capture an area of a program which isn't my own application. That works without any problem but when a mousekey is pressed, the capure is done as recently as the mousebutton is released. But I wan't to capure while the MOUSEbutton is pressed too.

Thanks anyway,
Snody
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
A. Cristian CsikiSenior System AdministratorCommented:
hy snody,
sorry for missunderstanding. Some days before a similar case was resolved:
check it, maybe might help:
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21838717.html

regards nodramas
0
 
SnodyAuthor Commented:
Hi Nodramas,

Thanks for your answer, but I don't think that solves my problem.

Greets and THX again,
Andy
0
 
atul_parmarCommented:
Can you show the code snippet what shows when and how you are handling your mouse traps?
0
 
Slick812Commented:
hello Snody , , I have no Idea of what kind of answer you want here?, , I have no Idea about why you ask about the BitBlt function? As far as I know the bitBlt function will get the screen when you call it, and all other raster copy functions (as far as I know) will also do their work when called. .  so I would guess that you need to call the BitBlt on mouse Down instead of mouse Up. but this seems so obvious, that there must be some thing I do not understand. You give no information at all about what code methods you use for your to execute - - " the function is executed as recently as I release the mouse button ", so I do not know what can be a proble m or a fix. . .

I would guess that you have a "Hook" in a library  DLL that calls this -

hMseHook := SetWindowsHookEx(WH_MOUSE, @MseHookFunc, hInstance, 0);

if that is the case, then you need to get the  WM_LBUTTONDOWN  message, instead of the  WM_LBUTTONUP
0
 
SnodyAuthor Commented:
Sorry it was my fault. My application had a Bug, but I give the points to nodramas who tried to help me as good as he can.

Thanks a lot to everyone :)

Greets,
Snody
0
All Courses

From novice to tech pro — start learning today.