Article View: borland.public.cppbuilder.nativeapi
Article #15482Re: about get window by pos.
From: Siney San
Date: Tue, 01 Jul 2003 02:02
Date: Tue, 01 Jul 2003 02:02
269 lines
9053 bytes
9053 bytes
Please post *your* actual code that does not work for you. And please
> explain, in detail, exactly how you are testing it, exactly what you are
> trying to do with it, and exactly how you are determining that it does not
> work.
>
here is my entire code below:
cpp
//--------------------------------------------------------------------------
-
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "IdGlobal.hpp"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
bool bMouseDown;
bool bScrollFlag;
const int crMy=1;
HANDLE hWindow,hOldWindow;
TRect ClassRect,OldClassRect;
//--------------------------------------------------------------------------
-
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
hWindow=NULL;
hOldWindow=NULL;
bScrollFlag=false;
}
//--------------------------------------------------------------------------
-
void __fastcall TMainForm::ImageDragMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(Button==mbLeft)
{
hWindow=NULL;
hOldWindow=NULL;
::SetCursor(LoadCursor(HInstance,"MyCur"));
bMouseDown=true;
ImageDrag->Hide();
//SetCapture(Handle);
}
}
//--------------------------------------------------------------------------
-
void __fastcall TMainForm::ImageDragMouseUp(TObject *Sender, TMouseButton
Button,
TShiftState Shift, int X, int Y)
{
if(bMouseDown)
{
if(hOldWindow!=NULL)
{
Canvas->Handle=GetWindowDC(hOldWindow);
Canvas->Pen->Width=4;
Canvas->Pen->Mode=pmNotXor;
Canvas->Brush->Style=bsClear;
Canvas->Rectangle(0,0,OldClassRect.Width(),OldClassRect.Height());
}
::SetCursor(LoadCursor(NULL,IDC_ARROW));
ImageDrag->Cursor=crHandPoint;
bMouseDown=false;
ImageDrag->Show();
//ReleaseCapture();
}
}
//--------------------------------------------------------------------------
-
void __fastcall TMainForm::ImageDragMouseMove(TObject *Sender, TShiftState
Shift,
int X, int Y)
{
POINT MousePoint,p1,p2;
char bufClassName[255],bufClassCaption[255];
int TextLength;
if(bMouseDown)
{
GetCursorPos(&MousePoint);
if (hWindow==WindowFromPoint(MousePoint))
return;
hWindow=GetRealWindow(MousePoint);
if(!hWindow)
return;
if(GetRealParent(hWindow)!=Handle)
{
if(hOldWindow!=NULL)
{
Canvas->Handle=GetWindowDC(hOldWindow);
Canvas->Pen->Width=4;
Canvas->Pen->Mode=pmNotXor;
Canvas->Brush->Style=bsClear;
Canvas->Rectangle(0,0,ClassRect.Width(),ClassRect.Height());
}
GetWindowRect(hWindow,&ClassRect);
if(hWindow!=NULL)
{
Canvas->Handle=GetWindowDC(hWindow);
Canvas->Pen->Width=4;
Canvas->Pen->Color=clBlack;
Canvas->Pen->Mode=pmNotXor;
Canvas->Brush->Style=bsClear;
Canvas->Rectangle(0,0,ClassRect.Width(),ClassRect.Height());
}
OldClassRect=ClassRect;
hOldWindow=hWindow;
GetClassName(hWindow,bufClassName,255);
TextLength=SendMessage(hWindow,WM_GETTEXTLENGTH,0,0);
if(TextLength>256) TextLength=255;
if(TextLength>0)
{
SendMessage(hWindow,WM_GETTEXT,TextLength+1,(LPARAM)&bufClassCaption[0]);
EditCaption->Text=String(bufClassCaption);
}
else
EditCaption->Text="NONE";
EditRect->Text="(" + String(ClassRect.Left) + "," +
String(ClassRect.Top) + ")(" + String(ClassRect.Right) +
"," + String(ClassRect.Bottom)+")";
EditClassName->Text=String(bufClassName);
}
}
}
//--------------------------------------------------------------------------
-
void __fastcall TMainForm::WMGETMINMAX(TWMGetMinMaxInfo& msg)
{
//TODO: Add your source code here
msg.MinMaxInfo->ptMinTrackSize.x=395;
msg.MinMaxInfo->ptMinTrackSize.y=281;
msg.MinMaxInfo->ptMaxTrackSize.x=395;
msg.MinMaxInfo->ptMaxTrackSize.y=281;
}
//**************************************************************************
********
HWND TMainForm::GetRealWindow(POINT ptPoint)
{
//HWND hParent = HWND_DESKTOP;
HWND hParent = WindowFromPoint(ptPoint);
::ScreenToClient(hParent,&ptPoint);
HWND hChild = ::ChildWindowFromPoint(hParent, ptPoint);
while( (hChild) && (hChild != hParent) )
{
::MapWindowPoints(hParent, hChild, &ptPoint, 1);
hParent = hChild;
hChild = ChildWindowFromPointEx(hParent, ptPoint,CWP_ALL);
}
return hChild;
}
//***********************************************my key code here
HWND TMainForm::GetRealParent(const HWND child)
{
//TODO: Add your source code here
HWND sub=child;
while(GetParent(sub)!=NULL)
sub=GetParent(sub);
return sub;
}
void __fastcall TMainForm::SpeedButton1Click(TObject *Sender)
{
SetWindowText(hWindow,EditCaption->Text.c_str());
}
//--------------------------------------------------------------------------
-
h
//--------------------------------------------------------------------------
-
#ifndef Unit1H
#define Unit1H
//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <Buttons.hpp>
#include <Dialogs.hpp>
#include <ComCtrls.hpp>
#include <ToolWin.hpp>
//--------------------------------------------------------------------------
-
class TMainForm : public TForm
{
__published: // IDE-managed Components
TPanel *PanelCenter;
TLabel *LabelCaption;
TLabel *LabelClassName;
TEdit *EditCaption;
TEdit *EditClassName;
TLabel *Label2;
TEdit *EditRect;
TPanel *pnlImage;
TImage *ImageDrag;
TToolBar *ToolBar1;
TPageControl *pgExt;
TTabSheet *TabSheet1;
TSpeedButton *SpeedButton1;
TLabel *Label1;
TLabel *Label3;
TEdit *edtparent;
TEdit *edtowner;
void __fastcall ImageDragMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall ImageDragMouseUp(TObject *Sender, TMouseButton
Button,
TShiftState Shift, int X, int Y);
void __fastcall ImageDragMouseMove(TObject *Sender, TShiftState
Shift,
int X, int Y);
void __fastcall SpeedButton1Click(TObject *Sender);
private: // User declarations
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(WM_NCHITTEST,TMessage,OnNcHitTest)
VCL_MESSAGE_HANDLER(WM_GETMINMAXINFO, TWMGetMinMaxInfo,
WMGETMINMAX)
END_MESSAGE_MAP(TForm);
//void __fastcall OnNcHitTest(TMessage& Msg);
void __fastcall WMGETMINMAX(TWMGetMinMaxInfo& msg);
public: // User declarations
__fastcall TMainForm(TComponent* Owner);
HWND GetRealWindow(POINT ptPoint);
HWND GetRealParent(const HWND child);
};
//--------------------------------------------------------------------------
-
extern PACKAGE TMainForm *MainForm;
//--------------------------------------------------------------------------
-
#endif
i want to writting a program like spy, so drag-move mouse to grab window.my
code in my computer can get any window except disabled window,but yours(in
my computer or my application) can't get some normal window. my test method
is drag-move mouse and try to grab window. using your code, i try to grab
window of bcb ide, but it's failure sometimes.
test environment: bcb6+sp4, win2k pro.
Technical Details
Message-ID:
<3f00eba5@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!feeder.buzzardnews.com!news.astraweb.com!news-small.astraweb.com!newspeer1.nwr.nac.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3efbf96b@newsgroups.borland.com> <3efc70d0@newsgroups.borland.com> <3efd6a06@newsgroups.borland.com> <3efdf892@newsgroups.borland.com> <3efe571b@newsgroups.borland.com> <3efe7016@newsgroups.borland.com> <3efefd50@newsgroups.borland.com> <3eff23a0$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,5a7ad1e748c52c2b X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-06-30 19:23:57 PST Reply-To: "Siney San" <siney@yeah.net> From: "Siney San" <siney@yeah.net> Newsgroups: borland.public.cppbuilder.nativeapi References: <3efbf96b@newsgroups.borland.com> <3efc70d0@newsgroups.borland.com> <3efd6a06@newsgroups.borland.com> <3efdf892@newsgroups.borland.com> <3efe571b@newsgroups.borland.com> <3efe7016@newsgroups.borland.com> <3efefd50@newsgroups.borland.com> <3eff23a0$1@newsgroups.borland.com> Subject: Re: about get window by pos. Date: Tue, 1 Jul 2003 10:02:08 +0800 Lines: 273 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 202.100.9.1 Message-ID: <3f00eba5@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1057024933 202.100.9.1 (30 Jun 2003 19:02:13 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!feeder.buzzardnews.com!news.astraweb.com!news-small.astraweb.com!newspeer1.nwr.nac.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail