Introduction
I have written this article for the beginner programmer who have just started programming in VC++. Most of them are not aware of the tools come with VC++. I know that because I am also the novice player here(Just 3 months) and wasn't aware of these tools before.
I will show you the little bit use of Spy++(tool) and how we can have fun with it. I have used this tool to get the handle of Start Button and Desktop.
Using my application you will be able to do the following things.
- Hide/Show the Start Button
- Hide/Show the System Clock
- Hide/Show the Quick Lunch
- Hide/Show the Tray Icons
- Hide/Show the Desktop and Much More...
- Change the Caption of Start Button (Win Xp Only, Not Working in Win2000)
Background
I have used two functions from Win32 API. They are as below. If your not aware of that please check it in MSDN for Help
- FindWindow()
- FindWindowEx().
Using the Spy++
If you are well aware of SPy++ you can directly jump to next topic.
Spy++ is one of the tools that comes with Visual Studio. So if you still haven't seen it, start your Visual Stdio and open Spy++ from Tool menu.
Its a vary nice tool through which you can retrieve the information about any window which is currently running. Information means Handle of the window, handle of its next and parent window, Its style, Class name, Process Id and much more.
I am using spy++ to retrieve the handles of Start Button,Quick Launch, System Clock etc...
Here I will show you how to use the tool to find the handle of any currently running window or control.
For Example say you have to find the handle of Start Button(Control).Actually we can directly watch the handle of Start Button in Spy++, but we can't use this because it is in digits. But we can retrieve the handle of this using its class name and the function I mention above. Here is what you can do to retrieve the Handle of Start Button.
As we all know to retrieve the handle of any Control we need to have the Handle of its parent window. But how can we find out which is the parent window of Start button ? easy ! using Spy++.
Open the Spy++ and open Find (Only Find not Find Window). Then drag the Finder on Start Button and press OK. On pressing OK you will be directed to the Tree List View. Where you will be able to Find which is the parent of Start Button. It will be Shell_TrayWnd.
Now right click on the Shell_TrayWnd and open properties. There you will Find its Class name.
Use that class name and Function FindWindow()
to Find the handle of Shell_TrayWnd
Then use the above handle, Class name of Start Button in the function FindWindowEx()
to retrieve the handle of Start Button.
Using the code
Here I can hope that you are able to use the Spy++. If not please read the previous topic.
Below is the lines of code will retrieve the handle of start button which is the control under Shell_TrayWnd. I have retrieved the class names of Start Button and its parent window using Spy++.
HWND hStart,hTray;
hTray = ::FindWindow(L"Shell_TrayWnd", NULL);
if(hTray)
{
hStart = ::FindWindowEx( hTray, NULL, L"Button", NULL);
}
Below is the lines of code I have used to Hide the Start Button and to Change the its Text (Caption).
ShowWindow(hStart,FALSE); ShowWindow(hTray,TRUE);
WCHAR Text[10];
To retrieve the Text from Edit Box
GetDlgItemText(hWndDlg,IDC_StartTxt,Text,10);
SendMessage(hStart,WM_SETTEXT,0,(LPARAM)Text);
You can Even Directly Use the Handle
After Submitting the article I come to know that you can even Directly use the handle, you find with Spy++.
For exapmle When you will Find the handle of Start button it will look like this 00020048. Its a Hexadecimal value. You can use the followind line of code to assign it to HWND.
HWND hStart = (HWND)0x00020048;
ShowWindow(hStart,FALSE);
ShowWindow(hStart,TRUE);
Thanx for Reading the article. This is my second article to Code Project. So please tell how I have explained the article, anything you think about this. And if you like it please vote it.