Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if a window i open

Status
Not open for further replies.

WebStar

Programmer
May 1, 2002
69
DE
how can I make a program that checks to see if a window is opend and if so, send a message with that window's name? This program must be a resident or what? i don't need the whole programm but only the ideea...
 
These should work in most cases.

HWND hwnd = FindWindow( NULL, windows_name )
if(hwnd)
PostMessage( hwnd, msg,0 ,0 )

//Syntaxe for "FindWindow":
HWND FindWindow(
LPCTSTR lpClassName, // class name
LPCTSTR lpWindowName // window name
);


//Syntaxe for "PostMessage":
BOOL PostMessage(
HWND hWnd, // handle to destination window
UINT Msg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);

 
OK thanx,
but how can I make this programm to work always? it must be in a separate thread and use a while(1) loop, or how? I want to listen always and if some particular window is opend, the programm should close it immediatly.
 
Ok,if you want to close an open window,you can use this:
HWND hwnd = FindWindow( NULL, windows_name )
if( hwnd )
PostMessage( hwnd, WM_SYSCOMMAND, SC_CLOSE, NULL )

i'am not sure if i know how to check for always if a particular window is open.But i might say that if you want to use the procedure describe below,in order to make it work you need to have the window's title first( window's name) once you have it,it's quiet easy to close it.
Perhaps if you have some code,it would a good idea to post it,so i can get a clear idea of what you are trying to achieve.
 
Well I tried this but it gives me an error:

BOOL CTestApp::OnIdle(LONG lCount)
{
EnumWindows(EnumWindowsProc, NULL);
return TRUE;
}

BOOL CALLBACK CTestApp::EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
char String[255];
char *MyCheck;
if (!hWnd)
return TRUE; // Not a window
if (!::IsWindowVisible(hWnd))
return TRUE; // Not visible
if (!SendMessage(hWnd, WM_GETTEXT, sizeof(String), (LPARAM)String))
return TRUE; // No window title
MyCheck = strstr(String, "C:\\");
if (MyCheck != NULL)
// MessageBox("Access Denied!");
DestroyWindow(hWnd);
return TRUE;
}

The error that it gives me is:
error C2664: 'EnumWindows' : cannot convert parameter 1 from 'int (struct HWND__ *,long)' to 'int (__stdcall *)(struct HWND__ *,long)'
I just find out that should be a good ideea to use hooks, but i guess i would get more complicated, and i dont even know how to use this hooks (SetWindowsHookEx())
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top