C++/Unicode

Advertisement


Question
Hello,
I have a doubt in progrmming.
I need to get unicode values of PageUp and PageDown in C/C++
How to get it??
Can u give me hint in coding???

Thanks,
Kannan

Answer
Hello Kannan, thank you for the question.

Sorry about the delay, I have never worked with Unicode before, so I wanted to test this solution a good bit to make sure it works. This was test in Microsoft Visual C++.NET 2003. It also uses the Microsoft virtual key codes for the PageUp and PageDown. First, we convert the integer virtual key value to a multi byte string. Then, we convert the multi byte string to a Unicode string. Then, we test to make sure it succeeded:

// int main()
#define SIZE 64

char str[SIZE] = {0};
WCHAR wstr[SIZE] = {0};

itoa(VK_PRIOR, str, SIZE);

int result = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,str,  sizeof(char) * SIZE,
wstr, sizeof(WCHAR) * SIZE);

if(result == ERROR_INSUFFICIENT_BUFFER ||
result == ERROR_INVALID_FLAGS ||
result == ERROR_INVALID_PARAMETER ||
result == ERROR_NO_UNICODE_TRANSLATION)
std::cout << "Error\n";
     
std::cout << "The value is: " << *wstr <<
" at address: " << wstr << '\n';

The virtual key code for PageUp is VK_NEXT. The function MultiByteToWideChar converts your string to a Unicode string, and can pretty much be used for the solution.

I hope this information was helpful.

- Eddie

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Eddie

Expertise

I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.

Experience

I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 About.com. All rights reserved.