PDA

Click to See Complete Forum and Search --> : Weird Handle help


ChimpFace9000
Feb 16th, 2001, 04:19 PM
Ok im making an app to go with netzero that will send messages to the ad bar so it will bot kick you off the net. Ive got it to where i can send the message, then the default web browser opens. Now i need to automaticly close that newly opened browser. Any ideas?

Technocrat
Feb 16th, 2001, 04:30 PM
Do they always have something the same in the title bar? Like "Netzero Add" or something?

Feb 16th, 2001, 05:38 PM
Nope, its different with every add. Is there some way to get the newest window that has opened?

Technocrat
Feb 16th, 2001, 05:40 PM
Hmm you could keep a list of all the current window handles when your app starts, then with a timer continue to check for handles that is not part of the previous list, then send it your message when it finds one.

Feb 16th, 2001, 06:33 PM
How do i get a list of all the window handles?

Technocrat
Feb 16th, 2001, 06:37 PM
Here but its going to be in MFC, but I am sure you can weed that stuff out. It is right now set to search for every window with "Instant Message", just set it to be "" instead.


BOOL CALLBACK CFindWindows::SearchFor(HWND hWnd, LPARAM lParam)
{
char strBuffer[MAX_PATH]; //Buffer To Hold The Window Title
CString strComp; //The String The Holds The String To Find (Instant Message)
CString strFound; //Holds The Buffer String To Allow Searching
int ret = 0;

::GetWindowText(hWnd,strBuffer,MAX_PATH); //Gets Window Title On Each Enum

strFound = strBuffer; //Gets The Buffer String To Allow CString Searching

if (strFound == "") //If The String Is Empty Quit Function
return true;

strComp = "Instant Message"; //Sets The Search String
ret = strFound.Find(strComp,0); //Search For The Search String

if (!(ret == -1)) //If Search String Is Found
{
CFindWindows::InArray(hWnd);
}

return true;
}

void CFindWindows::StartFind()
{

CSendMessages tmp;

if (tmp.CheckTextOut() == true) //Insure That Message Text Is There
::EnumWindows(SearchFor,(LPARAM)this); //Enum Every Window

}

bool CFindWindows::InArray(HWND hWnd)
{

int ret; //Used To Hold The Array Size
int i; //Used For The For Loop
bool Found = false; //Used To Check If The Window Already Exists

ret = PreWindows.GetSize(); //Gets Array Size

if (ret == 0) //If Array = 0
{
PreWindows.Add(hWnd); //Add To The Array
Found = true; //Keep From Adding Again

CSendMessages tmp; //Sets tmp To CSendMessages Class

tmp.MsgOut(hWnd); //Runs The MsgOut Function
}
else
{
for (i=0; i < ret; i++) //Searchs The Array To Insure There Is No Repeating
{
if (PreWindows[i] == hWnd)
{
Found = true;
}
}
}

if (Found == false)
{
PreWindows.Add(hWnd);

CSendMessages tmp;

tmp.MsgOut(hWnd);
}

return true;

}