| View previous topic :: View next topic |
| Author |
Message |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Sat Mar 01, 2008 4:11 pm Post subject: Unicode question |
|
|
Hey,
I'm coding a pointless program atm and I stuck.
I'm using
| Code: | LPTSTR name;
...
SetWindowText(h, name); |
But to get the name I'm using cin >>. But it's not working.
Any suggestions? |
|
| Back to top |
|
 |
systat Advanced Cheater
Reputation: 0
Joined: 15 Feb 2008 Posts: 54
|
Posted: Sat Mar 01, 2008 4:46 pm Post subject: |
|
|
u can try something like this:
| Code: |
string name;
SetWindowText(h,LPTSTR(name));
|
_________________
uuuuuuuuuuuuu |
|
| Back to top |
|
 |
Heartless I post too much
Reputation: 0
Joined: 03 Dec 2006 Posts: 2436
|
Posted: Sat Mar 01, 2008 4:58 pm Post subject: |
|
|
I though you just use L. _________________
What dosen't kill you, usually does the second time. |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Sat Mar 01, 2008 5:01 pm Post subject: |
|
|
Hey,
I already tried this with "char name;" this will just do nothing and close the application then.
With string it says "Can't convert string to LPTSTR" or so.
| HornyAZNBoy wrote: | | I though you just use L. |
Ye me too. But how would you do that with variables? L(name) does not work.
Last edited by Reak on Sat Mar 01, 2008 5:01 pm; edited 1 time in total |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Mar 01, 2008 5:01 pm Post subject: |
|
|
| systat wrote: | u can try something like this:
| Code: |
string name;
SetWindowText(h,LPTSTR(name));
|
|
Not how you do it in C++
it would be "SetWindowText( hWnd, (LPTSTR)name );
but i doubt that would work.
use TCHAR's?
#include <tchar.h>
TCHAR Name[MAX_PATH];
std::cin >> Name;
SetWindowText( hWnd, Name );
??
Edit: LOL 666 post's
| HornyAZNBoy wrote: | | I though you just use L. |
Thats defining a string as unicode.
E.g. LPTSTR Name = L"Kyle";
LPTSTR = LPWSTR if UNICODE charecter set is in place. else LPTSTR is defined as LPSTR (ASCII) _________________
Last edited by lurc on Sat Mar 01, 2008 5:06 pm; edited 1 time in total |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Sat Mar 01, 2008 5:05 pm Post subject: |
|
|
Thanks lurc, but this didn't work either  |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Mar 01, 2008 5:13 pm Post subject: |
|
|
Works
| Code: | #include <tchar.h>
#include <windows.h>
#include <iostream>
TCHAR Name[MAX_PATH];
int main( int argc, char* argv )
{
wprintf( L"Choose a name!\n" );
wscanf( L"%s", &Name );
wprintf( L"Your Name is %s", Name );
// Get Your hWnd, whatever.
hWnd = FindWindow( L"w/e class name or", L"w/e window name" );
SetWindowText( hWnd, Name );
std::cin.sync();
std::cin.ignore();
return 0;
} |
_________________
|
|
| Back to top |
|
 |
systat Advanced Cheater
Reputation: 0
Joined: 15 Feb 2008 Posts: 54
|
Posted: Sat Mar 01, 2008 5:15 pm Post subject: |
|
|
This works 100% for me, i am using VS 2008, set project setting to use multibyte set.
| Code: | char *ZZZ="Haha";
HWND hwnd=FindWindow(0,"Untitled - Notepad");
SetWindowText(hwnd,LPCSTR(ZZZ)); |
_________________
uuuuuuuuuuuuu |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Sat Mar 01, 2008 5:41 pm Post subject: |
|
|
Hey,
Well the problem wasn't the USING of the variable, it was how to set the variable.
I tried lurc's version with "cin >> name", it didn't work.
But
| Code: | | wscanf( L"%s", &Name ); |
Works, thanks  |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Mar 01, 2008 5:45 pm Post subject: |
|
|
cin only works for ASCII im pretty sure...
so tchar has all the input/output precedures mapped out with the prefix _t or w that allows you to use old input/output functions but with unicode support. _________________
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Mar 02, 2008 7:08 am Post subject: |
|
|
You can convert the 'string' to a char array using something like this:
strTestString.c_str();
For example:
| Code: | #include <windows.h>
#include <iostream>
#include <string>
int main()
{
std::string strWindowName;
printf( "Enter your window name: " );
scanf( "%s", strWindowName.c_str() );
HWND hWnd = FindWindow( "notepad", NULL );
SetWindowText( hWnd, strWindowName.c_str() );
std::cin.sync();
std::cin.ignore();
return 0;
} |
_________________
- Retired. |
|
| Back to top |
|
 |
|