|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionI 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 Hooking target windowWe can hook victim window through case WM_MOUSEMOVE: if (bSeeking) { HWND hWindowUnderTheMouse; //HWND hWindowUnderTheMouseChild; points = MAKEPOINTS(lParam); point.x=points.x; point.y=points.y; ClientToScreen(hDlg,&point); hWindowUnderTheMouse = WindowFromPoint(point); if((hwndMain==hWindowUnderTheMouse)|| (hwndMain==GetParent(hWindowUnderTheMouse))) { break; } //------------------------------ hChildFound=NULL; SeekDumpWindow(hWindowUnderTheMouse,point); if((IsWindow(hChildFound))&&(hChildFound!=NULL)) { hWindowUnderTheMouse=hChildFound; } //------------------------------ if(hWindowUnderTheMouse != hSeekedWindow) { // FrameWindow(hSeekedWindow); hSeekedWindow = hWindowUnderTheMouse; FrameWindow(hSeekedWindow); // update the twin window strcpy(szSeekedWindow,"0x"); _itoa((DWORD)hSeekedWindow,szSeekedWindow+2,16); CharUpperBuff(szSeekedWindow+2,(DWORD)strlen(szSeekedWindow)); SetDlgItemText(hDlg,IDC_WINDOWHANDLE,szSeekedWindow); GetWindowInfo(hSeekedWindow); } } else { points = MAKEPOINTS(lParam); point.x=points.x; point.y=points.y; } break; It seeks the correct window target by searching through its parent and its children by Modifying target windowIt 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 if(TopMost) { dwExtendedStyle|=WS_EX_TOPMOST; SetWindowPos(hHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE); } else { dwExtendedStyle&=~WS_EX_TOPMOST; SetWindowPos(hHandle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE); } //---------------------------------------------- if(BACKdwID!=dwID) SetWindowLong(hHandle, GWL_ID, dwID); if(BACKdwStyle!=dwStyle)SetWindowLong(hHandle, GWL_STYLE, dwStyle); if(BACKdwExtendedStyle=dwExtendedStyle) SetWindowLong(hHandle, GWL_EXSTYLE, dwExtendedStyle); if(Visible) { ShowWindow(hHandle,SW_HIDE); ShowWindow(hHandle,SW_SHOW); } else { ShowWindow(hHandle,SW_SHOW); ShowWindow(hHandle,SW_HIDE); } UpdateWindow(GetParent(hHandle)); 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 if((strstr(_szClassName,"EDIT")==NULL)&&(strstr(_szClassName,"BOX")==NULL)) { SetWindowText(hHandle,szTitle); } else { HWND hWndParent=GetParent(hHandle); SendDlgItemMessage(hWndParent,dwID,WM_SETTEXT,0,(LPARAM)szTitle); } ConclusionI 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.
|
||||||||||||||||||||||