You are here:

C++/Win32 WinProc - wParam

Advertisement


Question
-------------------------
Followup To
Question -
Hi, I am doing Win32 programming. I read the message from this argument wParam. I type lowercase letter on my key board, it keep storing uppercase letter. Could you tell me how to convert to lowercase letter as I type a lowercase letter. Because if I type uppercase or lowercase letter result in the same value in the wParam parameter, how can I know that the user typing uppercase or lowercase letter.

Please help, thank you God bless you.
Answer -
Hello Junaidi, thanks for the question.

The easy way to do this is the following in the WM_KEYDOWN message in your WinProc:

// in the WndProc function

case WM_KEYDOWN
{

switch(wParam)
{
case 'a':
case 'A':
// code
break;

case 'q':
case 'Q':
// code
break;
}

}

and so on like that, that way both cases are caught and handled by the same code statements in the switch. Another couple of ways to tell in case you are trying to find out the case of the letter outside of your WndProc is to use the getch() and toUpper() and toLower() functions. getch() reads in a specific characted from the input stream. toUpper() and toLower() will convert the case for you. If you need further information, you can look those up in the MSDN. If you don't use visual studio, you can find it at msdn.msn.com.

I hope this information was helpful.

- Eddie


I tried already your solution Eddie, but the wParam only store uppercase letter even I press lowercase letter.
The following is part of my code:

  case WM_KEYDOWN:
     switch (wParam)
     {
     case 'a':
        if (strlen(command) < 20)
        {
         command[comLen] = wParam;
         command[comLen + 1] = '\0';
        }
  ...
  ...
  // print the string "command" somewhere

When I press "a" not "A", it does not get inside that case, so the char pointer command eventually always an empty string. But if I change that case to case 'A', even I press 'a' or 'A' it catch both of them and the command will contain "AAA...". As if, it scan uppercanse/lowercase and convert them to uppercase and then store the letter to wParam, that's what I think.
I hope you understand my problem, I really appreciate that you could help.

Thanks and good luck.

Answer
Hello Junaidi, thanks for the question.

Sorry it has taken me longer than normal to get back to you, I spent all last night and some of today testing different ways of trying to accomplish what you want to accomplish. I even tried using GetAsyncKeyState with passing it the ASCII value of 'a' (97) in the main windows message loop. It appears it is not possible to store the lower case of wParam because the compiler only registers the uppercase version of the letter. I don't want to say it's definitely not possible, but I couldn't figure it out. Maybe one of the other experts might have 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.