Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Visual Studio 2005

DonotaloDonotalo Member Posts: 715
[purple]i've started doing c/c++/windows programming using visual studio 2005 and stuck in some problems. can u pliz help me:

1) MessageBox(hwnd, "Text", "Caption", MB_OK);
compiler gives error for the above statement and tells it cannot convert those char[]'s to LPCWSTR type. but when i cust like this:

MessageBox(hWnd, (LPCWSTR) "Text", (LPCWSTR) "Caption", MB_OK);

i get garbled text both in the text area and in the caption. why?

2a) i'm unable to edit any resource file manually. how can i do that?
2b) how can i add a control to a dialog box without manually edit the resource file?

thanks in advance. :-)
[/purple]
[hr][purple]~Donotalo()[/purple]

Comments

  • LundinLundin Member Posts: 3,711
    : [purple]i've started doing c/c++/windows programming using visual studio 2005 and stuck in some problems. can u pliz help me:
    :
    : 1) MessageBox(hwnd, "Text", "Caption", MB_OK);
    : compiler gives error for the above statement and tells it cannot convert those char[]'s to LPCWSTR type. but when i cust like this:
    :
    : MessageBox(hWnd, (LPCWSTR) "Text", (LPCWSTR) "Caption", MB_OK);
    :
    : i get garbled text both in the text area and in the caption. why?
    :
    : 2a) i'm unable to edit any resource file manually. how can i do that?
    : 2b) how can i add a control to a dialog box without manually edit the resource file?
    :
    : thanks in advance. :-)
    : [/purple]
    : [hr][purple]~Donotalo()[/purple]
    :


    1) LPCWSTR = Unicode strings. MessageBox() expects LPCTSTR.
    The warning you get is likely because you have managed to declare your strings as unicode strings. Someone who knows about VS could probably tell you how to disable unicode, I'm not familiar with that compiler.

    2) You open up the .RC in a text editor and write. Then compile the .RC in a resource compiler to get a .RES which you link to the .EXE or .DLL. Not sure how do to it in Visual Studio, it has probably got some more automagical way.
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    [b][red]This message was edited by AsmGuru62 at 2007-3-3 5:12:30[/red][/b][hr]
    : [purple]i've started doing c/c++/windows programming using visual studio 2005 and stuck in some problems. can u pliz help me:
    :
    : 1) MessageBox(hwnd, "Text", "Caption", MB_OK);
    : compiler gives error for the above statement and tells it cannot convert those char[]'s to LPCWSTR type. but when i cust like this:
    :
    : MessageBox(hWnd, (LPCWSTR) "Text", (LPCWSTR) "Caption", MB_OK);
    :
    : i get garbled text both in the text area and in the caption. why?
    :
    : 2a) i'm unable to edit any resource file manually. how can i do that?
    : 2b) how can i add a control to a dialog box without manually edit the resource file?
    :
    : thanks in advance. :-)
    : [/purple]
    : [hr][purple]~Donotalo()[/purple]
    :
    [blue]Simply use the L"text" instead of just "text". Use it every time you calling the Win32 API, which requires to pass LPCTSTR. If you need to use text in your code - use WCHAR arrays and PWCHAR pointers. The time of the ANSI text is gone now. It will only slow your code - specifically, if you have text-heavy application.
    [/blue]
    [code]
    // #1:
    MessageBox (hWnd, L"Text", L"Caption", MB_OK);

    // #2:
    PWCHAR pstrCaption = L"Caption";
    MessageBox (hWnd, L"Text", pstrCaption, MB_OK);

    // #3:
    WCHAR strCaption [64];

    wcscpy (strCaption, L"Another Title");
    MessageBox (hWnd, L"Text", strCaption, MB_OK);

    // Use wide character versions of string library, like wcscpy(),wcscmp() and so on.
    [/code]

Sign In or Register to comment.