Thread: Problems with appendMenu

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    17

    Problems with appendMenu

    Hi all,

    Im having problems with the below code. I am trying to add a new menu option to a menu. With the below code I get the menu, but its name is 4 squares (the unprintable control characters I believe?).

    Can anyone help me out?

    Code:
    int CreateModuleMenu(HWND hWnd )
    {
        UINT_PTR uIDNewItem;
        LPCTSTR lpNewItem=NULL;
        
        char zName[9];
        strcpy(zName, "&Modules");
        lpNewItem = (LPCTSTR)zName;
        
        AppendMenu(GetMenu( hWnd ),MF_STRING,3,lpNewItem);
        lpNewItem = NULL;
    }

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    It looks like you are compiling as unicode. I'd suggest you do not compile as unicode until you are a little bit more experienced.

    Try to avoid casts unless you understand why the cast is needed.

    Try:
    Code:
    int CreateModuleMenu(HWND hWnd )
    {
        return AppendMenu(GetMenu(hWnd), MF_STRING, 3, TEXT("&Modules"));
    }
    >>but its name is 4 squares<<

    Each unicode character takes two chars. Therefore the 8 byte
    char * "&modules" is interpreted as a 4 character unicode string.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    17
    That did it, thanks anon.

    Im tweaking an open source Text editor to let me view some testing scripts in a readable format without changing their actual content.

    I didnt realize a unicode flag was set, but once I knew to look for it it was an easy fix. That cleared up some other cosmetic issues as well.

    Thanks for the tip.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  3. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  4. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM