Click here to Skip to main content
13,296,823 members (38,699 online)
Click here to Skip to main content
Add your own
alternative version


150 bookmarked
Posted 10 Feb 2005

Capturing Window Controls and Modifying their properties

, 19 Feb 2005
Rate this:
Please Sign up or sign in to vote.
A Spy tool program like MS Spy++ that lets you capture window controls and modify their properties. Useful for learning window handles and their properties.

Sample Image - windowspy.gif


I was interested to have a tool such as Spy++ in Microsoft Visual Studio, but I'd like that the tool can modify window controls. For instance, some times, we need to enable some inactive controls in a program during run-time. MS Spy++ does not have any facilities to do this, and so I made it by myself.

This program is useful to obtain a window handle, caption, class name, style, and size. Moreover, it facilitates changing caption name, style, and extended style of victim window control in run-time load.

The application is a Win32 project without using MFC. It hooks the target window by WindowFromPoint() user32 API. There is an algorithm to seek on child and parent window to capture child windows inside a program by using GetWindowRect() and GetWindow() in a tricky way. It applies GetWindowLong() to obtain window properties and SetWindowLong() to modify them.

Hooking target window

We can hook victim window through WM_MOUSEMOVE mouse event:

if (bSeeking)
  HWND hWindowUnderTheMouse;
  //HWND hWindowUnderTheMouseChild;
  points = MAKEPOINTS(lParam); 
  hWindowUnderTheMouse = WindowFromPoint(point);
  if(hWindowUnderTheMouse != hSeekedWindow)
    hSeekedWindow = hWindowUnderTheMouse;
    // update the twin window
  points = MAKEPOINTS(lParam); 

It seeks the correct window target by searching through its parent and its children by SeekDumpWindow() which is defined in <DumpSeek.h> inside the program.

Modifying target window

It is very easy to modify the victim window by its handle. If you have the window handle, you can obtain and change styles very easily by GetWindowLong() and SetWindowLong() and also window caption by using SetWindowText() and SendDlgItemMessage(). By looking inside UpdateFlags() in the program, you will find the code which performs this to modify the target window:

  HWND_TOPMOST, 0, 0, 0, 0,
  HWND_NOTOPMOST, 0, 0, 0, 0,
if(BACKdwID!=dwID) SetWindowLong(hHandle, GWL_ID, dwID);
if(BACKdwStyle!=dwStyle)SetWindowLong(hHandle, GWL_STYLE, dwStyle);
SetWindowLong(hHandle, GWL_EXSTYLE, dwExtendedStyle);

The code to change caption depends on the type of window control. To change caption of Edit Control and Box Control, it has to use SendDlgItemMessage() instead of SetWindowText() in other window controls:

  HWND hWndParent=GetParent(hHandle);


I hope this tool clarifies window classes and their manipulation for people who are beginners in this field. This would be an introduction to make window Spy tools and work with handles.

Eventually, I should appreciate you if you would kindly take the time to mention your ideas, suggestions, and any bugs you may find in this program.


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

No Biography provided

You may also be interested in...


Comments and Discussions

QuestionTo most Pin
Nguyen Luong Son20-Oct-14 2:03
memberNguyen Luong Son20-Oct-14 2:03 
QuestionManually enter handle Pin
Nguyen Luong Son28-Aug-14 18:33
memberNguyen Luong Son28-Aug-14 18:33 
QuestionStay on top .... Pin
Member 51837411-Oct-13 1:41
memberMember 51837411-Oct-13 1:41 
GeneralMy vote of 5 Pin
Yiannis Spyridakis10-May-12 2:06
memberYiannis Spyridakis10-May-12 2:06 
QuestionGood job! Pin
DH00081-Mar-12 4:53
memberDH00081-Mar-12 4:53 
GeneralInstance of ClassName Pin
charleslambert1424-Mar-11 6:12
membercharleslambert1424-Mar-11 6:12 
GeneralGreat! Pin
yulinxie16-May-10 5:22
memberyulinxie16-May-10 5:22 
GeneralOne Pblm Pin
Naveen.R10-Sep-07 19:23
memberNaveen.R10-Sep-07 19:23 

Me too was trying to create some application like this and in between I had a problem in finding the window just below the mouse. So I searched the net and finally reached here. But your application also have same problem. Check the following secnario.

In a dialog place a frame and label control one over the other( the label should be kep inside the frame ).
Arrange the tab order so that frame is first and label is second. Now your application cannot identify the label which is inside the frame. But SPY++ does. I have found some other applications like WinID also finds this window. Do you have any solutions?

QuestionSpy++ Pin
Bourtree7-Mar-07 10:26
memberBourtree7-Mar-07 10:26 
GeneralNice article, but cannot compile with VS.Net 2005 Pin
yjagota18-Feb-07 10:38
memberyjagota18-Feb-07 10:38 
QuestionCan it capture a label in vb6 program? Pin
pctimhk30-Sep-06 9:24
memberpctimhk30-Sep-06 9:24 
GeneralGoogle Earth Toolbar Pin
Todd Wilder22-Jul-06 17:55
memberTodd Wilder22-Jul-06 17:55 
GeneralExtra Ordinary Pin
AsheshVashi9-May-06 20:56
memberAsheshVashi9-May-06 20:56 
GeneralMsDos Pin
roberto1979es8-Feb-06 5:15
memberroberto1979es8-Feb-06 5:15 Pin
roberto1979es7-Feb-06 12:10
memberroberto1979es7-Feb-06 12:10 
GeneralRe: Pin
Ashkbiz Danehkar7-Feb-06 13:07
memberAshkbiz Danehkar7-Feb-06 13:07 
GeneralRe: Pin
Tutu7-Jun-06 21:51
memberTutu7-Jun-06 21:51 
Generalwindows controls Pin
B!Z16-Jan-06 23:13
memberB!Z16-Jan-06 23:13 
GeneralModifing Window Title name Pin
Vitoto7-Dec-05 12:10
memberVitoto7-Dec-05 12:10 
GeneralRe: Modifing Window Title name Pin
Ashkbiz Danehkar7-Feb-06 13:19
memberAshkbiz Danehkar7-Feb-06 13:19 
GeneralFound bug and fix - nice app Pin
drudru2-Aug-05 20:54
memberdrudru2-Aug-05 20:54 
GeneralRe: Found bug and fix - nice app Pin
Ashkbiz Danehkar7-Feb-06 13:09
memberAshkbiz Danehkar7-Feb-06 13:09 
Generalmay be a bug Pin
Amilan29-Jun-05 7:17
memberAmilan29-Jun-05 7:17 
GeneralJust what I want Pin
ispring24-Jun-05 1:30
memberispring24-Jun-05 1:30 
GeneralXP related question Pin
CodeBuddy2612-Jun-05 8:59
memberCodeBuddy2612-Jun-05 8:59 
GeneralRe: XP related question Pin
JackyFrost26-Aug-05 15:02
memberJackyFrost26-Aug-05 15:02 
GeneralPorting to WindowsCE Pin
hgode9-Jun-05 1:55
memberhgode9-Jun-05 1:55 
GeneralRe: Porting to WindowsCE Pin
hgode9-Jun-05 3:40
memberhgode9-Jun-05 3:40 
GeneralRe: Porting to WindowsCE Pin
foobar715-Oct-05 6:57
memberfoobar715-Oct-05 6:57 
GeneralRe: Porting to WindowsCE Pin
Ashkbiz Danehkar7-Feb-06 13:22
memberAshkbiz Danehkar7-Feb-06 13:22 
GeneralRe: Porting to WindowsCE [modified] Pin
Prabhat.Singh30-Sep-07 2:01
memberPrabhat.Singh30-Sep-07 2:01 
QuestionWhere is the input focus? Pin
Free to Go21-Mar-05 10:35
memberFree to Go21-Mar-05 10:35 
GeneralTiz the sweet nectar... Pin
Mark (Code6) Belles15-Mar-05 12:54
memberMark (Code6) Belles15-Mar-05 12:54 
GeneralSend Messages plans Pin
Peter Ritchie12-Feb-05 7:39
memberPeter Ritchie12-Feb-05 7:39 
GeneralRe: Send Messages plans Pin
Ashkbiz Danehkar13-Feb-05 6:59
memberAshkbiz Danehkar13-Feb-05 6:59 
GeneralWell, I must say, something innovative! Pin
Polite Programmer11-Feb-05 8:47
memberPolite Programmer11-Feb-05 8:47 
GeneralRe: Well, I must say, something innovative! Pin
ThatsAlok11-Feb-05 18:54
memberThatsAlok11-Feb-05 18:54 
GeneralRe: Well, I must say, something innovative! Pin
Ashkbiz Danehkar13-Feb-05 7:19
memberAshkbiz Danehkar13-Feb-05 7:19 
GeneralGreat Article! Pin
ThatsAlok10-Feb-05 19:23
memberThatsAlok10-Feb-05 19:23 
GeneralRe: Great Article! Pin
Ashkbiz Danehkar13-Feb-05 7:14
memberAshkbiz Danehkar13-Feb-05 7:14 
GeneralRe: Great Article! Pin
f211-Apr-05 7:10
memberf211-Apr-05 7:10 
GeneralRe: Great Article! Pin
Ashkbiz Danehkar12-Apr-05 8:00
memberAshkbiz Danehkar12-Apr-05 8:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171207.1 | Last Updated 19 Feb 2005
Article Copyright 2005 by Ashkbiz Danehkar
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid