Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Unicode question

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Sat Mar 01, 2008 4:11 pm    Post subject: Unicode question Reply with quote

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
View user's profile Send private message
systat
Advanced Cheater
Reputation: 0

Joined: 15 Feb 2008
Posts: 54

PostPosted: Sat Mar 01, 2008 4:46 pm    Post subject: Reply with quote

u can try something like this:

Code:

string name;
SetWindowText(h,LPTSTR(name));

_________________
uuuuuuuuuuuuu
Back to top
View user's profile Send private message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Sat Mar 01, 2008 4:58 pm    Post subject: Reply with quote

I though you just use L.
_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Sat Mar 01, 2008 5:01 pm    Post subject: Reply with quote

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
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Mar 01, 2008 5:01 pm    Post subject: Reply with quote

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 Smile

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
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Sat Mar 01, 2008 5:05 pm    Post subject: Reply with quote

Thanks lurc, but this didn't work either Sad
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Mar 01, 2008 5:13 pm    Post subject: Reply with quote

Works Smile

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
View user's profile Send private message
systat
Advanced Cheater
Reputation: 0

Joined: 15 Feb 2008
Posts: 54

PostPosted: Sat Mar 01, 2008 5:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Sat Mar 01, 2008 5:41 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Mar 01, 2008 5:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Mar 02, 2008 7:08 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites