-
Handle
Code:
case WM_COMMAND:
{
if(LOWORD(wParam) == BN_CLICKED && (HWND)lParam == hbtnGetHandle)
{
char * caption = "";
caption = (char *)GetWindowText(htxtGetWindow,
(LPTSTR) caption, 25);
new_hwnd = FindWindow(NULL, (LPCTSTR)caption);
}
}
break;
There is something wrong here. It does not seem to create a handle from the caption of the app the user entered. :( I don't think the type-casts i made are right. Can anyone please help me fix that :) Thanks
-
Code:
int len = GetWindowTextLength(hWnd);
TCHAR *pcBuf = new TCHAR[len+1];
GetWindowText(hWnd, pcBuf, len);
// use pcBuf -- possibly in FindWindow
delete[] pcBuf;
-
Ahhh
-
Parksie...
-
Somehow I thought you'd ask that ;)
Normally, you're using ASCII/ANSI. In this, all characters are represented by a single byte (char). For Unicode, it's a 16-bit character set, requiring two bytes (unsigned short). If you look at the definitions for any text-handling functions in the API they have definitions for GetWindowTextA, GetWindowTextW :) A is ANSI, W is Wide (Unicode). TCHAR swaps between char and unsigned short depending on compile options.
-
Hrmm
-
Yes. If you define _UNICODE and UNICODE in your preprocessor project settings it will do it all for you. Unfortunately it'll then give loads of compiler errors on your no-doubt un-localised string literals ;)
I'm going now anyway, but look up TCHAR and character sets on MSDN for detailed information.
-
confused...
This one does not use the A or the W. (sorry, but that is the thing i need to work on :))
-
Instead of using char, I should use TCHAR?
-
annoying.....
this won't change the caption, like it should do:
Code:
//get the length of the typed-caption
int cpt_len = GetWindowTextLength(htxtGetWindow);
//int wnd_len; //caption of the alien window
TCHAR *pcBuf = new TCHAR[cpt_len];//edit text holder
//retrieve the text from the edit box
GetWindowText(htxtGetWindow, pcBuf, cpt_len);
//finally, get the handle
new_hwnd = FindWindow(0, (LPCTSTR)pcBuf);
//retrieve the caption of the alien window, so it can
//be restored later...
/*wnd_len = GetWindowTextLength(new_hwnd);
pcOldCaption = new TCHAR[wnd_len + 1];
GetWindowText(new_hwnd, pcOldCaption, wnd_len);*/
SetWindowText(new_hwnd, "mmmmm");
I don't see why it won't change the caption to mmmmmm.
-
Look at the definitions in the headers. GetWindowText is actually a macro that points to GetWindowTextA/W depending on compile options. This is why all the VB definitions have A appended to them :)
Yes, you should use TCHAR, _T("string"), and all the rest of the nice gibberish that comes with internationalisation :)
Are you sure that the window you specified exists?