Jump to content
  • Advertisement
Sign in to follow this  
simon_brown75

Listbox problem

This topic is 2303 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I've recently switched from Visual C++ 6 Pro to Visual C++ 2010 Express and I'm having problems bringing an old program up-to-date.

The code in question is-

char str [255] = "";
sprintf ( str, "%d x %d - 32 bit - %d Hz", g_pAdapters[current].AdapterModes[n].Width,
g_pAdapters[current].AdapterModes[n].Height, g_pAdapters[current].AdapterModes[n].RefreshRate );
SendDlgItemMessage ( hwnd, ID_LB2, LB_ADDSTRING, 0, (LPARAM)str );


First thing, VC++ is warning me to use sprintf_s, so I change the code to this-

char str [255] = "";
sprintf_s ( str, 255, "%d x %d - 32 bit - %d Hz", g_pAdapters[current].AdapterModes[n].Width,
g_pAdapters[current].AdapterModes[n].Height, g_pAdapters[current].AdapterModes[n].RefreshRate );
SendDlgItemMessage ( hwnd, ID_LB2, LB_ADDSTRING, 0, (LPARAM)str );


The problem - whether I use sprintf or sprintf_s, my listbox is just full of gibberish (see attached image). I've no idea what's going on. Btw the values in Width, RefreshRate etc are all correct because I output them to a text file later in the code. Obviously either sprintf_s isn't doing what I'm expecting, or I'm sending the add string request to the dialogue box wrong.

Please help,
Simon.

Share this post


Link to post
Share on other sites
Advertisement
Didn't do Windows UI for several years, so here I can only give my guess.
SendDlgItemMessage is Ansi or Unicode version?
I guess it's Unicode version in 2010 by default?

Can you try,
1, call SendDlgItemMessageA instead of SendDlgItemMessage in your current code?
2, or pass a wide string, such as L"abc" to SendDlgItemMessage and test again.

To nail down your problem you can use some simple text to test instead of sprintf.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!