Sign in to follow this  

Listbox problem

This topic is 2089 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-

[code]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 );[/code]

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

[code]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 );[/code]

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
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
Thank you very much. SendDlgItemMessageA solved the problem [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]

My Win32 skills are 10+ years out of date it seems.

Share this post


Link to post
Share on other sites

This topic is 2089 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this