Results 1 to 6 of 6

Thread: Annoying...

  1. #1

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

    Unhappy Annoying...

    Code:
    			if(LOWORD(wParam) == BN_CLICKED && (HWND)lParam == hbtnGetHandle)
    			{
    				int input_len = GetWindowTextLength(htxtGetWindow);
    				TCHAR *pcBuf = new TCHAR[input_len];
    				GetWindowText(htxtGetWindow, pcBuf, input_len);
    				new_hwnd = NULL;
    				new_hwnd = FindWindow(NULL, pcBuf);
    				
    				if(new_hwnd == NULL)
    				{
    					MessageBox(hwnd,"No window with that title found!" ,"Hrmmm..." , 
    						MB_OK | MB_ICONEXCLAMATION);
    				}
    			}
    Why does not this recognize the "string" pcBuf?? It seems like the result of the line where it is filled(pcBuf) does not do anything, because when I pass to FindWindow, nothing happend. Notice the check after, to see if a handle was actually found. When i run the program, it always pops up the Message box, meaning something went wrong. But what?? Would it be the TCHAR stuff?
    Thanks for helping me fixing this
    Amon Ra
    The Power of Learning.

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    I have a working example if you want it.

    http://www.planetsourcecode.com/vb/s...txtCodeId=1944

    Sorry that one isn't commented too well but the one on my computer is, just ask me and I'll mail it or upload it.

  3. #3
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    but I don't really understand what you are doing...this is what worked basically for me.
    PHP Code:
    char buffer[100];
    GetWindowText(txtTitlebuffer100);
    FindWindow(NULLbuffer);
    //now you have your handle 

  4. #4
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    I think the problem is in here :
    PHP Code:
    new_hwnd NULL;
                    
    new_hwnd FindWindow(NULLpcBuf); 
    try this:

    PHP Code:
    new_hwnd NULL;
    FindWindow(NULLpcBuf);
    sprintf(new_hwndpcBuf); 

  5. #5

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

    Wink ok...

    Can you explain what this does? and apparently, i need a header with the declaration of sprintf. with the arguments, i think it is a conversion, but from what to what? Thanks
    Amon Ra
    The Power of Learning.

  6. #6

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

    Unhappy ok...

    I looked in the msdn, and found the header, but when i run the program, it says:
    Code:
    C:\My Documents\VC++ Projects\WinProg\Handle Fun\h_fun.cpp(44) : error C2664: 'sprintf' : cannot convert parameter 1 from 'struct HWND__ *' to 'char *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Amon Ra
    The Power of Learning.

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