Jeffrey&Lynny

一个温馨小家庭的.Net生活

导航

Windows硬件输入模型Extra Info

Some Window Concept:
1. Focused Window:
Only one window at a time can receive keyboard input; that window is said to have the keyboard focus.
2. Active Window:
An active window is the top-level window of the application (Thread level)with which the user is currently working.
3. Foreground and Background Windows:
Each process can have multiple threads of execution, and each thread can create windows. The thread that created the window with which the user is currently working is called the foreground thread, and the window is called the foreground window. All other threads are background threads, and the windows created by background threads are called background windows.

Jeffrey Richter的《Windows核心编程》的最后一章讲述了硬件输入模型。其中有关各个函数的调用影响比较复杂,但是其实都是比较好理解的(结合LISLab这个试验程序)。

一个UI线程包含线程局部状态变量:
Keyboard:
Which window has keyboard focus
Which window is active
Which keys are considered pressed down
The state of the caret
Mouse:
Which window has mouse capture
The shape of the mouse cursor
The visibility of the mouse cursor

所以,SetFocus, SetActiveWindow两个函数改变的是一个线程的局部状态变量,所以这两个函数不能够跨线程调用(也就是说不能够改变另外一个线程的局部变量),但是改变当前线程的局部变量的操作总是能够成功的。
而SetForegroundWindow,SetWindowPos ,BringWindowToTop三个函数改变的是系统全局的属性:Foreground Window和Z-order,所以可以跨越线程及其进程,但是由于Windows防止突然的一个窗口跳至屏幕的Foreground,所以背景线程调用SetForegroundWindow产生的将是任务栏闪烁效果,而BringWindowToTop和SetWindowPos (TOP)在没有连接到RIT的时候则干脆不起效果。但是需要注意的是SetWindowPos(BOTTOM)还是有效果的(因为不违反Windows的这个约束)。

最后,在LISLab里面的后台调用SetFocus指定本程序,为什么ComboBox将会获得Focus,这是因为:The control receiving the default input focus is always the first control specified in the template that is visible, not disabled, and has the WS_TABSTOP style。

posted on 2005-01-29 18:02  比尔盖房  阅读(678)  评论(0编辑  收藏  举报