[C++11 - win32] - how can i compare the strings?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int GetMenuPosition(HMENU menu, string caption)
    {
        int i=0;
        for(i=0; i<GetMenuItemCount(menu)-1;i++)
        {
            MENUITEMINFO  s= {0};
            s.cbSize=sizeof(MENUITEMINFO );
            s.fMask=MIIM_STRING;
            s.cch=strlen(strCaption.c_str());
            //s.dwTypeData=(LPSTR)strCaption.c_str();
            GetMenuItemInfo (menu,i, true, &s);
            string b=(char*)s.dwTypeData;

            if(b==caption)
                 break;
        }
        MessageBox(NULL,to_string(i).c_str(),"menuposition", MB_OK);
        return i-1;
    }

i'm getting problems for compare the strings :(
can anyone explain to me?
I think s.dwTypeData is a "wide" string rather than a normal one as you are trying to treat it. Try converting caption to a std::wstring or a std::basic_string<wchar_t> as I think that is what a LPTSTR uses.
now works fine ;)
1
2
3
4
5
6
7
8
9
10
11
12
int GetMenuPosition(HMENU menu, string caption)
    {
        int i=0;
        int menucount=GetMenuItemCount(menu);
        for(i=0; i<menucount;i++)
        {
            char s[256];
            GetMenuString(menu,i,s,256, MF_BYPOSITION);
            if(s==caption)
                return i;
        }
    }

thanks for all
Topic archived. No new replies allowed.