|
-
Jun 21st, 2001, 04:45 PM
#1
Thread Starter
Hyperactive Member
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
Amon Ra
The Power of Learning.
-
Jun 21st, 2001, 05:17 PM
#2
Monday Morning Lunatic
Code:
int len = GetWindowTextLength(hWnd);
TCHAR *pcBuf = new TCHAR[len+1];
GetWindowText(hWnd, pcBuf, len);
// use pcBuf -- possibly in FindWindow
delete[] pcBuf;
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 21st, 2001, 05:21 PM
#3
Thread Starter
Hyperactive Member
Ahhh
Ok, thanks a lot
Amon Ra
The Power of Learning.
-
Jun 21st, 2001, 05:23 PM
#4
Thread Starter
Hyperactive Member
Amon Ra
The Power of Learning.
-
Jun 21st, 2001, 05:25 PM
#5
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 21st, 2001, 05:28 PM
#6
Thread Starter
Hyperactive Member
Hrmm
Amon Ra
The Power of Learning.
-
Jun 21st, 2001, 05:30 PM
#7
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 21st, 2001, 05:31 PM
#8
Thread Starter
Hyperactive Member
confused...
This one does not use the A or the W. (sorry, but that is the thing i need to work on )
Amon Ra
The Power of Learning.
-
Jun 21st, 2001, 05:33 PM
#9
Thread Starter
Hyperactive Member
Instead of using char, I should use TCHAR?
Amon Ra
The Power of Learning.
-
Jun 21st, 2001, 06:02 PM
#10
Thread Starter
Hyperactive Member
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.
Amon Ra
The Power of Learning.
-
Jun 22nd, 2001, 07:36 AM
#11
Monday Morning Lunatic
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?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|