Thread: Displaying Handle in Messagebox?

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    5

    Displaying Handle in Messagebox?

    How do I display a window handle in Messagebox after using the CreateWindowEx function?

    This is how I'm using Messagebox:
    MessageBox(NULL, hListbox, "Window Handle!", MB_OK);

    And it gives the following error:
    error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'struct HWND__ *' to 'const char *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Look into sprintf( ).
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    char str[56];
    wsprintf(str, "0x%x", hListBox);
    ::MessageBox(NULL, str, "Window Handle!", MB_OK);
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    5
    Thanks, just tried that, but now it gives 2 error's =o( :

    error C2065: 'hListBox' : undeclared identifier
    error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'struct HWND__ *' to 'const char *'

    It's a point in the right direction though.

  5. #5
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Originally posted by Knight Chat X
    error C2065: 'hListBox' : undeclared identifier
    That's the variable name you were trying to output. If the variable doesn't exist, that explains this error.

    Originally posted by Knight Chat X
    error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'struct HWND__ *' to 'const char *'
    This means you have an HWND in your MessageBox() call still. You didn't do what I did.


    edit: I just looked at your variable name, it's different in capitalization. Just make the proper spelling fix.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    5
    Here's how I have it now:

    //Global Variable.
    HWND hListbox=0;

    //Create Listbox.
    hListbox = CreateWindowEx(WS_EX_CLIENTEDGE, Listbox_Class, NULL, WS_VSCROLL | WS_VISIBLE | WS_BORDER | WS_CHILD | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT, 0, 0, LB_WIDTH, LB_HEIGHT, hParent, NULL, hInst, NULL);

    char str[56];

    wsprintf(str, "0x%x", hListBox);

    //Display listbox handle in messagebox.
    ::MessageBox(NULL, hListBox, "Window Handle!", MB_OK);

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    5
    Ok, just got your other post after I already sent the last post, oops!!! lol =o)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  2. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. Delete files that are used
    By Yuri in forum C++ Programming
    Replies: 8
    Last Post: 10-18-2005, 01:48 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM