Convert CString to UINT
-
:eek:Hi to everybody, I am developing a HotKey for my application. The RegisterHotKey function has following parameters: RegisterHotKey( HWND hWnd, // handle to window int id, // hot key identifier UINT fsModifiers, // key-modifier options UINT vk // virtual-key code ); I have values of fsModifier and vk in CString data type and I want to use those value in RegisterHotkey I tried using UINT fsModifier = atoi(ModifierKey); //ModifierKey is CString type but it didnot worked . Can some body tell me how to convert CString to UINT ?? Waiting for the reply Rohit
-
:eek:Hi to everybody, I am developing a HotKey for my application. The RegisterHotKey function has following parameters: RegisterHotKey( HWND hWnd, // handle to window int id, // hot key identifier UINT fsModifiers, // key-modifier options UINT vk // virtual-key code ); I have values of fsModifier and vk in CString data type and I want to use those value in RegisterHotkey I tried using UINT fsModifier = atoi(ModifierKey); //ModifierKey is CString type but it didnot worked . Can some body tell me how to convert CString to UINT ?? Waiting for the reply Rohit
Rohit Divas wrote: but it didnot worked . You have to be more specific about the problem. I will have to guess. Is there a compile error? Try this:
UINT fsModifier = atoi((LPTSTR)(LPCSTR)ModifierKey);
John
-
Rohit Divas wrote: but it didnot worked . You have to be more specific about the problem. I will have to guess. Is there a compile error? Try this:
UINT fsModifier = atoi((LPTSTR)(LPCSTR)ModifierKey);
John
I mean to say that there were no errors in the program . Still it didnot worked. I debugged the application. The value of fsModifier in UINT fsModifier = atoi(ModifierKey); is coming 0. I tried your way also but the result is the same. Is there any alternative way to convert CString to UINT ? Rohit
-
:eek:Hi to everybody, I am developing a HotKey for my application. The RegisterHotKey function has following parameters: RegisterHotKey( HWND hWnd, // handle to window int id, // hot key identifier UINT fsModifiers, // key-modifier options UINT vk // virtual-key code ); I have values of fsModifier and vk in CString data type and I want to use those value in RegisterHotkey I tried using UINT fsModifier = atoi(ModifierKey); //ModifierKey is CString type but it didnot worked . Can some body tell me how to convert CString to UINT ?? Waiting for the reply Rohit
I use atoi() fine. Check that there are no leading spaces, that would make it fail. CString::TrimLeft() will do it. Elaine :rose: The tigress is here :-D
-
I mean to say that there were no errors in the program . Still it didnot worked. I debugged the application. The value of fsModifier in UINT fsModifier = atoi(ModifierKey); is coming 0. I tried your way also but the result is the same. Is there any alternative way to convert CString to UINT ? Rohit
What does 'ModifierKey' contain? It does contain and begin with an integer doesn't it? Otherwise atoi will return 0. n!
-
I mean to say that there were no errors in the program . Still it didnot worked. I debugged the application. The value of fsModifier in UINT fsModifier = atoi(ModifierKey); is coming 0. I tried your way also but the result is the same. Is there any alternative way to convert CString to UINT ? Rohit
There are other ways but this is the best way. Like the other people asked are you sure that the value in the string is an integer? Any errors in the conversion will result in 0. John