How to convert CString to decimal value

mousumi majumder 20 Reputation points
2023-04-26T19:10:03.39+00:00

I want to convert Cstring to decimal value in mfc application.

This is my code looks like

CString keyvalue = _T("SHIFT");

for (int i = 0 ; i < keyvalue.Getlength(); i++)

{

int decvalue = keyvalue[i];

}

so now I got decvalue is 83 which is for S It is giving me decimal value for single character but not the entire string so I need entire string value like for shift decimal value is 16 so I want to get 16

someone please look into that

I have tried that above scenario but not able to get the decimal of whole string

Developer technologies C++
Developer technologies Visual Studio Other
{count} votes

Accepted answer
  1. Minxin Yu 13,501 Reputation points Microsoft External Staff
    2023-04-27T02:54:40.5166667+00:00

    Hi,

    I found a similar thread: How to convert vk_shift value to decimal value?

    Please check the document: Virtual-Key Codes

    The value of the virtual key is defined by macro. You can use map to bind relationship between CString and decimal value.

    #define VK_SHIFT 0x10

    	std::map<CString, int > vk_key = {
    			{  (CString)"SHIFT",VK_SHIFT}
    	};
    
    
    	CString keyvalue = _T("SHIFT");
    	int vaule = vk_key[keyvalue];
    

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. RLWA32 49,536 Reputation points
    2023-04-26T23:49:18.81+00:00

    As far as I know there is no Windows API function that accepts the name of a key and returns the virtual-key code.

    However, the GetKeyNameTextW function will return the name of a key associated with a scan code and the MapVirtualKeyExW function can return the scan code for a virtual-key code.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.