Results 1 to 11 of 11

Thread: Handle

  1. #1

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    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.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  3. #3

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Red face Ahhh

    Ok, thanks a lot
    Amon Ra
    The Power of Learning.

  4. #4

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Parksie...

    What is TCHAR for?
    Amon Ra
    The Power of Learning.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  6. #6

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Wink Hrmm

    So it can be either?
    Amon Ra
    The Power of Learning.

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  8. #8

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    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.

  9. #9

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    Instead of using char, I should use TCHAR?
    Amon Ra
    The Power of Learning.

  10. #10

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Unhappy 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.

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width