Jump to content
  • Advertisement
Sign in to follow this  
Marusu

Win32 GUI

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

Hello, In my university we are working with old dos screen for result output (cout) and I wanted to add a normal windows screen for variety. The only problem is, that I don't know what is the best way to convert those strings to LPCSTR (const char*). Can you recommend me something that would be easy enough to use? Martin

Share this post


Link to post
Share on other sites
Advertisement
Convert what strings?

Do you mean how to display strings on a window? Or how to convert a std::string to a const char pointer?

You can use the GDI methods TextOut or DrawText to output to a valid HDC.

std::string has a c_str() method that returns a null terminated c-style char pointer to the text.

If that doesn't help, you'll need to clarify your question.

Share this post


Link to post
Share on other sites
I'm sorry.
I need to get something like this working.

std::string nn = "qwerty";
TextOut(hdcWindow, 0, 0, nn.c_str(), 6);

It appears that I need not simple char, but wide char (LPCWSTR).
I don't know how to convert strings to it. I will also need to convert integers and doubles to LPCWSTR.

Hope you'll understand me now. Thank you.

Share this post


Link to post
Share on other sites

// using stringstream constructors.
#include <iostream>
#include <sstream>
using namespace std;

int main () {

int val;
stringstream ss (stringstream::in | stringstream::out);

ss << "120 42 377 6 5 2000";

for (int n=0; n<6; n++)
{
ss >> val;
cout << val*2 << endl;
}

return 0;
}


source: http://www.cplusplus.com/reference/iostream/stringstream/stringstream/

you can search for std::stringw and MultiByteToWideChar Function
http://msdn.microsoft.com/en-us/library/dd319072%28VS.85%29.aspx

Share this post


Link to post
Share on other sites
Another alternative is to go to Project Properties->General and change Use Unicode Character Set to Use Multibyte Character Set.

OR

Just directly call TextOutA which is the ASCII version...

Share this post


Link to post
Share on other sites
You should work with std::wstring instead of std::string.
std::wstring nn = L"qwerty";
TextOut(hdcWindow, 0, 0, nn.c_str(), nn.length());


The main difference between std::string and std::wstring is that std::wstring is a STL template around wchar_t instead of char. You should get used to working in wide characters because no matter what country you deploy your application, people running it will be able to see non-mangled text.

However, if you only plan to work with English users it's probably safe to just use the ASCII variant of TextOut.

std::string nn = "qwerty";
TextOutA(hdcWindow, 0, 0, nn.c_str(), nn.length());

Share this post


Link to post
Share on other sites
You can also use MultiByteToWideChar to convert ansi strings to unicode, and WideCharToMultiByte to convert unicode to ansi.

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!