Windows program design: Zero-Based Self-Learning _ 6 _ keyboard _-based keyboard processing

Source: Internet
Author: User
Tags printable characters

I don't know what happened to my education in China. One thing that happened to me two days ago left me speechless, it reminds me of the classic "Ctrl + C" and "Ctrl + V" movie clips.

Two days ago, a colleague of mine had a computer operating system and had to reinstall it. Then he asked me to help him. Then I helped him. After the system was installed, I found that there was no hardware driver. What should I do? Work only

In a hurry, I explained to him that there is no way to install a driver for him. He can only wait for the company and then copy the driver from other colleagues.Program(The unified dell

E5410), and then install it by yourself. Suddenly, he came up with a way to copy the hardware driver from my PC to his Dell Computer.

I didn't laugh at him because I knew it wasn't his fault (my colleague graduated from college ). I know him.

It's impossible to know how to download the driver from the official website, or what kind of driver should be copied from other colleagues. There is no way I can only download the driver from the Dell official website and install it for him.

After this incident, I suddenly discovered that education in China, it's a sad reminder ................................

I am really sad and speechless ............................. ...........

I found that sometimes I am really poor ......................

Let's continue with the content of the previous windows program. The last time we talked about some of the content of GDI, we had some things about it, but we have all said the basic principles,

The rest is some system functions and simple content. If you don't talk about it now, you will have the opportunity to add some content about GDI ............ recently, I am a little busy, tired, and a little lazy.

Ah, how do you say this person? Naturally, they all have la s .................

6. keyboard
6.1 keyboard Basics
In a Windows program, input the window message processing program that passes programs in the form of messages.
In Windows, eight different messages are used to transmit different Keyboard Events. Some of the content that can be ignored in the Application
Keyboard Message. The work of processing the keyboard is to identify the messages that are important, and those do not need to respond.
6.1.1 ignore keyboard messages
The keyboard is the main input source for users in Windows programs, but the program does not have to respond to all messages.
Windows can also handle many keyboard functions.
You can ignore key messages of system functions. ALT is usually used for system function keys. The program does not need to monitor the next button message,
Windows will notify the application of the function of the button.
Although the buttons in the call procedure menu will pass the window message processing program, it is usually set
Pass to def1_sproc, and the final window message handler receives a message, indicating that a menu item is selected.
Applications can use keyboard shortcuts to start common menu items. The shortcut key is usually a combination of function keys or letters with the ctrl key.
These keyboard shortcuts are defined in the program resource file together with the program menu. Windows converts the keyboard shortcuts to menu
Messages without application conversion.
The dialog box also has a keyboard interface, but when the dialog box is active, the application usually does not have to monitor the keyboard. Keyboard interface
For Windows processing, Windows sends the message about the key-Pressing function to the application.
6.1.2 focus
In Windows, computer hardware is shared by the operating system and all applications executed in windows. Sometimes
There may be multiple windows, and the keyboard must be shared by all windows of the application.

In the message loop, the program uses the MSG structure variable to retrieve the application message from the message queue. The MSG struct includes the hwnd field,
The hwnd field stores the control code of the received message. In the message loop, the dispatchmessage function sends the message to the window message processing program,
In this window, the message processing function is associated with the window for the message. When you press the key on the keyboard, only one window message processing program is connected
The receiving keyboard receives the keyboard message, and the message includes the control code for receiving the message.

The window for receiving a specific Keyboard Message has an input focus. The concept of the input focus is similar to that of the activity window. Input focus
Is the derived window of the activity window or activity window (the Child Window of the activity window or the Child Window of the activity window ).

It is usually easy to identify the active window, which is usually a top-level window-that is, her parent window handle is null. If the activity window has a title
Bar, Windows will highlight the title bar. If the active window has a dialog frame instead of a title bar, Windows highlights the frame. For example
If the active window is minimized, Windows will highlight the item in the work column, which is displayed as a pressed button.

If the activity window has a subwindow, the window with the input focus can be either an activity window or a subwindow.
Common subwindows have controls similar to the following:
1. Buttons displayed in the dialog box
2. Single-choice button
3. Check box
4. scroll bar
5. Edit the square
6. list box
Tip:
The subwindow cannot be an activity window by itself. Only when the subwindow is a derivative window of the activity window can the subwindow have the input focus.
The child window control usually displays a flickering insert symbol or uses a dotted line to indicate that it has an input focus.

Sometimes the input focus is not in any window, which occurs when all programs are minimized. In this case, Windows will continue
The keyboard message is sent in the activity window, but the Keyboard Message is different from the one sent to the activity window in non-Minimum words.

The window message processing program intercepts wm_setfocus and wm_killfocus messages to determine when the window has the input focus.
Wm_setfocus indicates that the window is receiving the input focus, and wm_killfocus indicates that the window is losing the input focus.

6.1.3 queue and Synchronization
Keyboard Message Processing Process:
Press and release the buttons on the keyboard --> Windows and keyboard drivers convert the hardware scan code to a formatted message.
Messages in the format are not stored in the application message queue, but stored in the Windows Maintenance System message queue.

system message queue:
it is an independent Message Queue maintained by windows. It is used to preliminarily save information input by the user from the keyboard or mouse.
Windows extracts the next message from the system message queue only after the previous user input message is processed by the Windows application.
, and put it into the application queue.
two steps:
1) Save the message in the system message queue
2) Transfer the message from the system message queue to the application Message Queue
cause: the keyboard event messages that require message synchronization
6.1.3 buttons and characters
are divided into:
1) buttons (messages)
2) character (Message)
you can view the keyboard as a set of keys.
Exp:
the key is unique on the keyboard. Press the key and release the key.
the keyboard can also generate printable or control characters.
Exp:
according to capslock, A can generate multiple characters: 'A' and 'A'

Tip:
For key combinations that generate printable characters, Windows not only sends a key message to the program, but also sends a character message.
For keys that do not generate characters, such as shift, function key, cursor move key, and special character key insert and delete
Windows only generates key messages.

6.2 key message
When you press the next key, Windows puts the wm_keydown or wm_syskeydown message into the message queue of the window with the input focus,
When a key is released, Windows puts the wm_keyup or wm_syskeyup messages into the message queue of the window with the input focus.
Tip:
Press the key to release
Non-system key wm_keydown wm_keyup
System key wm_syskeydown wm_syskeyup

The message is usually pressed and released in pairs. However, when you press a key, the function will be automatically restarted. When the last key is released
Windows will send a series of wm_keydown or wm_syskeydown messages and a wm_keyup (or wm_syskeyup)
Message.
The same key message has time information. By calling the getmessagetime function, you can obtain the relative relationship between the key being pressed and the key being released.
Time.

6.2.1 System and non-system Keys
Sys in wm_syskeydown and wm_syskeydown indicates the system. It indicates that the key is more effective than the application in windows.
Important.
Wm_syskeydown and wm_syskeyup messages are often generated by keys combined with alt. These buttons start the program menu or
Options on the system menu, or system functions such as switching activity windows. It can also be used as a shortcut for the System menu (Alt key and a function)
Key combination, ALT + F4 is used to close the application)
Programs usually ignore wm_syskeydown and wm_syskeyup messages and pass them to defwindowproc.
Because Windows processes all the alt-key functions, applications generally do not need to process these messages.

Wm_keydown and wm_keyup messages are usually generated when you press or do not contain the Alt key. Windows does not process
These messages can be returned or ignored in the application.
Wm_keydown wm_keyup wm_syskeydown wm_syskeyup
Quasi-KeyCode, Indicates the key to be pressed or released, and lparam contains other data of the key.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.