How to get handle to window in system Windows.

I found the code that prints the names of all the windows open in the system. But I still can not get handle to any window in the system. My function always returns false. Why?

1
2
3
4
5
6
7
8

// HWND hWin;
	bool _WindowOperation::getWindow(char nameWindow[1024]){
		if ( !( nphWnd = FindWindow( (LPCWSTR)nameWindow, NULL ) ) )
			return false;
		return true;
	}
 
Last edited on
what kind of window you are talking about? windows open in system?

for processes, you can get a handle to the task manager and can get the full list of processes running.
I talking about open window in system. I need this handle to the window to enter text into it. I want that because i make virtual keyboard.
Last edited on
oh.. to make a virtual keyboard their is an easy technique... look for windows hooks. you just need to hook the key board and in the hook function, just change the character to what you want.

now when your hook program runs, who ever writes using the keyboard will get what your program will produce.
If you have time write me a few lines of code
Your problem is because your cast is bad

1
2
3
4
5
	bool _WindowOperation::getWindow(char nameWindow[1024]){  // a char pointer
		if ( !( nphWnd = FindWindow( (LPCWSTR)nameWindow, NULL ) ) )  // is NOT a LPCWSTR!!!!!
			return false;
		return true;
	}


The compiler was giving you an error for a reason. Your cast didn't solve the error, it just told the compiler to shut up.

Don't cast around compiler errors!

The solution here is to be Unicode friendly, or to not use the Unicode version of these functions. IE: remove the cast, and call FindWindowA instead of FindWindow.

Read this for more details:

http://www.cplusplus.com/forum/articles/16820/
Last edited on
Thanks for the tips.
I find error in my code, correct is...

1
2
3
4
5
6
7
8
9
bool _WindowOperation::getWindow(TCHAR* title){

		if (!( hWin = FindWindow( NULL, title)))
 
			return false;

		return true;

	}

Topic archived. No new replies allowed.