Code:
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
int main(int argc, char* argv[])
{
HWND taskBar,sysTray,expandTray;
int i = 1;
while ((taskBar = FindWindow("Shell_TrayWnd",""))==NULL)//First argument is the CLASS NAME, Second is the CAPTION of the window
{
Sleep(500);
}
printf("%x \n",taskBar);
while ((sysTray = FindWindowEx(taskBar,0,"TrayNotifyWnd",""))==NULL)
{
Sleep(500);
}
printf("%x \n",taskBar);
while ((expandTray = FindWindowEx(sysTray,0,"Button",""))==NULL)
{
Sleep(500);
}
printf("%x \n",expandTray);
PostMessage(expandTray,BM_CLICK,0,0);
return 0;
}
This is some code altered from a snippit a friend showed me that clicked the start bar. I am using Windows Spy, which is a MicroSoft built application that shows all Window classes, and their children, running. This code was supposed to click the "Expand Tray" button in the bottom right, but it never gets passed finding/declaring the first Window, "taskBar'.
The odd part is, the section to find the "taskBar" window class was never altered from the original snippet, but yet loops forever.
I have debugged the program, and it indeed loops on the first process. Another strange occurance, when the program runs, the expand tray button disappears, but the tray doesn't expand.