reset password
Author Message
asmiths
Posts: 12
Posted 22:48 Feb 14, 2013 |

Hey people,

I've been looking all over for the proper way to deal with changing an Image Source while code is running, and I can't find anything that both makes sense and has the proper header files or namespaces to go with it.  Since VC++ is meant to be used with programs that emphasize looks and design, I see no reason that this functionality isn't built in.  I've checked the VC++ documentation, stack overflow, and the rest of the internet and have come up empty-handed.

In particular, I am trying to change the Source of an Image Object on my xaml page so that it shows another image that I have in my Assets folder.  Both are PNGs, although I imagine that anyone using JPGs or other image formats would appreciate any relevant code since the Source set() function seems to really want bitmaps, but those files are definitely larger.  I imagine someone has figured this out already for their slot machine.

Thanks in advance for any help.

BryanYeh
Posts: 38
Posted 08:22 Feb 15, 2013 |

Here is a link to one of the groups in one of our class to their dropbox http://moourl.com/hsgas. Just look in the RandomCard folder and look for MainPage.xaml.cpp to see how it is done.

asmiths
Posts: 12
Posted 10:36 Feb 15, 2013 |

You get a super cookie.

Thank you.

rpuas
Posts: 29
Posted 20:19 Mar 09, 2013 |

Asmiths,

I think you did the presentation in class about your Triangle Calculator?

I was working on a Quadratic Formula Solver app and have been scratching my head for a day about how to validate the input...

i.e. numbers and not letters... remembered your presentation and the "_wtof()" code... that did it!!

float a = _wtof(varAInputBox->Text->Data());

kept stumbling on the validation and the code is so much simpler than using the wstringstream convertor.

Thanks, saved me a big headache.

asmiths
Posts: 12
Posted 22:47 Mar 09, 2013 |

Glad I could help.

Visual C++ (VC++) really emphasizes using wstring since the conversions form and to String^ are pretty simple once you understand them.  Also wstrings are waaaaaaaay more versatile than normal std::string.  Look into those functions, and, although they can be hard to swallow at first, they do far more things.

A couple notes on wstrings: an 'L' placed just outside the quotes of a string or char will tell the compiler that it is a wstring or wchar_t with which the wstrings are formed.

wstring myWstring = L"Some letters"

wchar_t myWchar = L'a'

Using length to make a for loop to traverse a wstring wont work when comparing it unless you use the signed int modifier like so:

for( int i = 0; i < signed int(yourWstring.length()); i++)

It returns the length as an unsigned int for some reason and the compiler can't make a comparison between signed and unsigned ints.  Also, for anyone else reading this, turning wstrings back into String^ or textBox text looks like:

String^ stringRef = ref new String(yourWstring.c_str())

textBox->text = ref new String(yourWstring.c_str())

and turning textBox input or String^ into a wstring looks like:

wstring yourWstring = textBox->text->Data()

wstring yourWstring = someStringHat->Data()

Last edited by asmiths at 22:54 Mar 09, 2013.