Message Boxes

This is a discussion on Message Boxes within the Windows Programming forums, part of the Platform Specific Boards category; I am having trouble getting a MessageBox to compile in my program. My code looks like this: Code: MessageBox(hWnd, "this ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    27

    Message Boxes

    I am having trouble getting a MessageBox to compile in my program. My code looks like this:
    Code:
    MessageBox(hWnd,
                         "this is string 1"
                         "this is string 2", MB_OK);
    I understand that parameter 1 is the window handle, and that parameters 2 and 3 are strings to display in the title bar and the body of the message box. When I try to compile, I will get a message "cannot convert constant char [#] to LPCWSTR". I try to use pointers to string objects or to char* arrays and I get "string undeclared identifier" or "cannot convert LPCWSTR to char__*64" (something like that, anyhow). I really hope this is something stupid that I am missing because message boxes will really help me out a lot. Thanks.

  2. #2
    Registered User
    Join Date
    Jan 2006
    Location
    Latvia
    Posts
    102
    Code:
    MessageBox(hWnd,
                         L"this is string 1",
                         L"this is string 2", MB_OK);

  3. #3
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308
    Sounds that you are using VS 2005...you can also remove the unicode type in your project settings. Search the forums, there are similar topics.
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Compiling as non-Unicode is an option, but making your program Unicode-compatible is a better one.

    TEXT("this is string 1")
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    May 2007
    Posts
    27
    Unicode......*scratches head* Don't know anything about that yet. *

    So far, using
    Code:
    MessageBox(hWnd,TEXT("string 1"),L"string 2",MB_OK);
    either method that you guys presented works. The problem is now, I cannot get any function that requires a string argument to accept a variable; all string arguments must be inserted explicitly. It works BUT it is a pain in the neck. I am also programming with DirectX so being able to use filenames in variables would be handy. I tried using reinterpret_cast or LPWSTR("string") but that turns it into gibberish. Thanks for your help so far.

  6. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    variable should be TCHAR* not char*
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 07:38 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  3. Making a script language?
    By Blackroot in forum Game Programming
    Replies: 10
    Last Post: 02-16-2006, 01:22 AM
  4. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21