Code:
// blah.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <math.h>
#include <windows.h>
using namespace std;
/*
bool minimized = false;
bool maximized = true;
*/
bool msgHide = false;
bool msgShow = false;
int _tmain( HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
//Afx:00400000:b:00010011:00000000:00000000 --> This is VERY odd, but it's the handle to the ShoreWare Agent Tool Bar
HWND hWnd = FindWindow("Afx:00400000:b:00010011:00000000:00000000", NULL );
/*Local Variables*/
WINDOWPLACEMENT wd;
UINT nCurShow;
//We do a while loop (this allows the program to run in the background)
while(1)
{
// Stealth mode so we don't see the command prompt window
/* Hmm screws up my code argh :S (will look into later)
HWND stealth;
AllocConsole();
stealth=FindWindowA("ConsoleWindowClass",NULL);
ShowWindow(stealth,0);
*/
// jajajaja
//If you hit Esc, it will close the program
if((GetAsyncKeyState(VK_ESCAPE)&1))
return 0;
//Check if the window handle exists
if(hWnd)
{
/*Local Variables declared to get a Process Handle ont he Window Object*/
DWORD ProcessID;
GetWindowThreadProcessId( hWnd, &ProcessID );
HANDLE Process = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID );
//Check if the process exists
if(Process)
{
/*More local variables declared. These variables will hold the read information from the memory address*/
BYTE data;
DWORD datasize = sizeof(data);
//Read the data from memory
ReadProcessMemory(Process,(void *)0x005556FC, &data, datasize, 0);
/*
We can check to see what state the agent toolbar is in by reading the data from memory
Information:
Toggle between release\resume state: 0x005556FC <--- This is the address where the states are stored
BYTE data = *(int*)0x005556FC;
DWORD datasize = sizeof(data);
Now we check the values. We know that the value will either be 0 or 1.
0 = release - green
1 = resume - flashing red
Release mode - green
00 01 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00
Resume mode - red flashing
01 01 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
/*
NOTE:
There are 2 ways to do this. Method 1 seems to run a bit better, but I still need to find a way to optimize the code so it runs more smoothly.
*/
/*Method 1*/
/*
//We are checking to see whether or Shoretel is in Resume Mode & whether or not the Window is already minimized
if((int)data == 1 && minimized == true)
{
//Assuming the above statement is true, we go ahead and check to make sure if the Window is minimized
if((ShowWindow(hWnd, SW_MINIMIZE)))
{
//Maximize the window
ShowWindow(hWnd, SW_SHOWNORMAL);
maximized = true;
minimized = false;
//This is optional, but the sole purpose of this is to popup a messagebox & let the user know what's going on
if(msgShow != true)
{
MessageBoxA(NULL,"Maximized now","Mnfo",MB_OK);
msgShow = true;
msgHide = false;
}
}
}
else if((int)data == 0 && maximized == true)
{
if((ShowWindow(hWnd, SW_SHOWNORMAL)))
{
//Minimize the window
ShowWindow(hWnd, SW_MINIMIZE);
minimized = true;
maximized = false;
//This is optional, but the sole purpose of this is to popup a messagebox & let the user know what's going on
if(msgHide != true)
{
MessageBoxA(NULL,"Minimized now","Info",MB_OK);
msgHide = true;
msgShow = false;
}
}
}
*/
/*This is just for testing purposes*/
//printf("Value for 0x005556FC is = %i \n", (int) data);
/*Method 2*/
//This is another way to check the state the Window is in
if(GetWindowPlacement( hWnd, &wd ))
{
//We store the variable inside nCurShow
nCurShow = wd.showCmd;
//We check to see if Window is minimized & whether Shoretel is in resume mode
if((int)data == 1 /*&& minimized == true */&& nCurShow == SW_MINIMIZE)
{
//Maximize the Window and set the foreground
ShowWindow( hWnd, SW_SHOWNORMAL);
SetForegroundWindow(hWnd);
//This is optional, but the sole purpose of this is to popup a messagebox & let the user know what's going on
if(msgShow != true)
{
MessageBoxA(NULL,"maximized now","info",MB_OK);
msgShow = true;
msgHide = false;
}
}
else if((int)data == 0 /*&& maximized == true */&& nCurShow == SW_SHOWNORMAL)
{
//Minimize the Window and set the foreground
ShowWindow( hWnd, SW_MINIMIZE );
SetForegroundWindow(hWnd);
//This is optional, but the sole purpose of this is to popup a messagebox & let the user know what's going on
if(msgHide != true)
{
MessageBoxA(NULL,"minimized now","info",MB_OK);
msgHide = true;
msgShow = false;
}
}
}
else
{
//The default state it should be in is ShowNormal, which sets the application in a default state.
ShowWindow( hWnd, SW_SHOWNORMAL );
SetForegroundWindow(hWnd);
}
/*We want to make sure we close the Process handle so that we don't corrupt the memory access or cause any unexpected errors*/
CloseHandle(Process);
}
}
}
//On Exit, restore the window
ShowWindow(hWnd, SW_SHOWNORMAL);
return 0;
}