C++/Unicode
Expert: Eddie - 3/20/2005
QuestionHello,
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
AnswerHello 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