GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Dec-2007, 22:44
SimonP SimonP is offline
New Member
 
Join Date: Dec 2007
Posts: 6
SimonP is on a distinguished road

Retrieving a handle to a window with a particular text in the title bar


Hi guys, I am attempting to retrieve a handle to a window based upon the text in its title bar. For the sake of example let us presume that I am trying to retrieve a handle to the "Calculator" window. So far I have the following code:

CPP / C++ / C Code:
#include "stdafx.h"
#include <iostream>

const int MAX_STRING = 1000;
const char* WINDOW_TITLE_BAR_TEXT = "Calculator";

int _tmain(int argc, _TCHAR* argv[])
{
	bool foundWindow = false;
	LPWSTR titleBar;
	HWND hWnd = GetWindow(GetDesktopWindow(), GW_CHILD);
	while (!foundWindow && (hWnd != NULL)) {
		GetWindowText(hWnd, titleBar, MAX_STRING-1);
		std::cout << titleBar << std::endl;
		if (strncmp(WINDOW_TITLE_BAR_TEXT, *titleBar, strlen(WINDOW_TITLE_BAR_TEXT)) == 0) {
			foundWindow = true;
			std::cout << "Found the calculator!"<< std::endl;
		} else {
			hWnd = GetWindow(hWnd, GW_HWNDNEXT);
		}
	}
	return 0;
}

However when I attempt to compile this I get the following error message:
Code:
error C2664: 'strncmp' : cannot convert parameter 2 from 'WCHAR' to 'const char *'

Please can you recommend how I fix this? Other than the above error, should my program work OK?

Sincerely,

Simon Pearson
  #2  
Old 28-Dec-2007, 11:41
TurboPT's Avatar
TurboPT TurboPT is online now
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,006
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Retrieving a handle to a window with a particular text in the title bar


Taking a hint from the 2nd arg type of tmain, probably need the same type applied to your string: change the 'char' portion to _TCHAR.

See the Visual studio help for _TCHAR type mapping, there's a table that shows the difference depending on what is defined.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with a console menu system BullBuchanan C++ Forum 6 20-Aug-2006 15:46
moving a window without using the title bar markiv MS Visual C++ / MFC Forum 1 07-Jun-2006 13:50
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 21:30
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 11:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 12:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:40.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.