简体   繁体   中英

Convert LOWORD(wParam) to const wchar_t*

I develop calculator app as a homework and and I check which digit is pressed like this:

if (LOWORD(wParam) == buttonDigit0) {
    writeToOperand(L"0");
}
else if (LOWORD(wParam) == buttonDigit1) {
    writeToOperand(L"1");
}
else if (LOWORD(wParam) == buttonDigit2) {
    writeToOperand(L"2");
}
// ...

Where writeToOperand is void writeToOperand(const wchar_t* digit);

And I want to minify it like this:

if (LOWORD(wParam) >= 100 && LOWORD(wParam) <= 109) {
   writeToOperand(LOWORD(wParam));
}

Where 100 is id of button #define buttonDigit0 100 and 109 is #define buttonDigit9 109 . But I don't follow how can I convert LOWORD(wParam) to const wchar_t* for my writeToOperand function.

You just have to use a local wchar_t array variable to store the computed digit:

wchar_t digit[2] = {0}; // reserve place for terminating null...
if (LOWORD(wParam) >= 100 && LOWORD(wParam) <= 109) {
   digit[0] = static_cast<wchar_t>('0' + LOWORD(wParam) - 100); // explicit cast to avoid a warning
   writeToOperand(digit);
}

But you must compute the actual value and store it into a local array to be able to pass the address to writeToOperand

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM