Reputation: 2441
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.
Upvotes: 0
Views: 485
Reputation: 149075
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
Upvotes: 2