Sign in to follow this  
Marusu

Win32 GUI

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
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
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

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