Results 1 to 10 of 10

Thread: FindWindow Weird Error

  1. #1

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335

    FindWindow Weird Error

    Hi im getting a error:
    PHP Code:
    error C2440'=' cannot convert from 'class CWnd *' to 'struct HWND__ *'
            
    Types pointed to are unrelatedconversion requires reinterpret_castC-style cast or function-style cast
    Error executing cl
    .exe
    My Code is:
    PHP Code:
        HWND i;
        
    HWND x;
        
        
    FindWindow("Program",0); 
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You're mixing MFC and API.

    Use ::FindWindow(...).
    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
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Since you're already using MFC:
    Code:
    CWnd *pWnd;
    
    pWnd = FindWindow("Program", 0);
    Don't forget that the CWnd pointer is not valid any longer than the function you're in. After that it might get deleted at any time.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    ok i got it using parksies' way. Now can you tell me how do i convert the HWND to Char ?
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Why would you want to do that? (maybe you can just cast it)
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  6. #6

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    How do i cast it ? What is casting it?
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  7. #7
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    First please explain me why you want to convert it to a char?

    Code:
    MessageBox(myhWnd,(LPSTR)myhWnd, "Casting!", MB_OK);
    that's casting what's happening over there at the bold part.
    I know this example won't work, but it's just to illustrate how casting works. It kinda tells the compiler that you want it to send the HWND as a LPSTR to the MessageBox function.

    damn my explaining is totally blurry today, hope you understand what I mean.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Mine is more MFC-like...


    Whatever. You can't convert HWND (32-bit) to char (8-bit) without loss of most the data you want. If you however (as I assume) want to convert the HWND to a string of some kind then you have three options.

    The first I'd recommend the least:
    Code:
    // To decimal:
    char decimalbuf[12];
    sprintf(decimalbuf, "%i", hwnd);
    // To hex:
    char hexbuf[12];
    sprintf(hexbuf, "0x%8x", hwnd);
    The second is the most MFC-like as it uses the MFC string class CString:
    Code:
    // To decimal:
    CString strDecimal;
    strDecimal.Format("%i", hwnd);
    // To hex:
    CString strHex;
    strHex.Format("0x%8x", hwnd);
    The third is under normal circumstances (that is, if you're not using MFC) the best and uses the STL classes. Requires <sstream>, <iomanip> and <string> to be included.
    Code:
    ostringstream ss;
    // To decimal:
    ss << hwnd;
    string strDecimal = ss.str();
    // Reset ss:
    ss.str("");
    // To Hex:
    ss << setbase(16) << hwnd;
    string strHex = ss.str();
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Jop, be careful, he might really try what you're posting.

    Casting only works to some extent. The above is likely to result in an access violation. If not it would only output garbage.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Hehe that wasn't my intention, and while I was posting it I was sure that I wasn't explaining things clearly, so I thought I would illustrate it, which made it even worse just ignore my post JasonLpz!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

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