2008 November 10th Monday (十一月 十日 月曜日)

 For all mapping modes, Windows translates window (logical) coordinates to viewport (device) coordinates by
the use of two formulas,

  xViewport = (xWindow - xWinOrg) * (xViewExt / xWinExt) + xViewOrg
  yViewport = (yWindow - yWinOrg) * (yViewExt / yWinExt) + yViewOrg

where (xWindow, yWindow) is a logical point to be translated and (xViewport, yViewport) is the translated point
in device coordinates, most likely client-area coordinates.  These formulas use two points that specify an "origin"
of the window and the viewport. The point (xWinOrg, yWinOrg) is the window origin in logical coordinates; the point
(xViewOrg, yViewOrg) is the viewport origin in device coordinates. By default, these two points are set to (0, 0),
but you can change them. The formulas imply that the logical point (xWinOrg, yWinOrg) is always mapped to the device
point (xViewOrg, yViewOrg).

  The formulas also include two points that specify "extents": the point (xWinExt, yWinExt) is the window extent in
logical coordinates; (xViewExt, yViewExt) is the viewport extent in device coordinates. In most mapping modes, the
extents are implied by the mapping mode and cannot be changed. Each extent means nothing by itself, but the ratio of
the viewport extent to the window extent is a scaling factor for converting logical units to device units.

  Windows can also translate from viewport (device) coordinates to window (logical) coordinates:

  xWindow = (xViewport - xViewOrg) * (xWinExt / xViewExt) + xWinOrg
  yWindow = (yViewport - yViewOrg) * (yWinExt / yViewExt) + yWinOrg

Queues and Synchronization

  As the user presses and releases keys on the keyboard, Windows and the keyboard device driver translate the hardware
scan codes into formatted messages. However, these messages are not placed in an application's message queue right away.
Instead, Windows stores these messages in something called the system message queue. The system message queue is a single
message queue maintained by Windows specifically for the preliminary storage of user input from the keyboard and the mouse.
Windows will take the next message from the system message queue and place it in an application's message queue only when
a Windows application has finished processing a previous user input message.

  The reasons for this two-step process-storing messages first in the system message queue and then passing them to the
application message queue-involves synchronization. As we just learned, the window that is supposed to receive keyboard input
is the window with the input focus. A user can be typing faster than an application can handle the keystrokes, and a particular
keystroke might have the effect of switching focus from one window to another. Subsequent keystrokes should then go to another
window. But they won't if the subsequent keystrokes have already been addressed with a destination window and placed in an
application message queue.

  A program can determine if it has the input focus by processing the WM_SETFOCUS and WM_KILLFOCUS messages. As the names
imply, a window procedure receives a WM_SETFOCUS message when it receives the input focus and a WM_KILLFOCUS message when
it loses the input focus. These messages occur in pairs: A window procedure will always receive a WM_SETFOCUS message before
it receives a WM_KILLFOCUS message, and it always receives an equal number of WM_SETFOCUS and WM_KILLFOCUS messages over
the course of the window's lifetime.

  The main rule for using the caret is simple: a window procedure calls CreateCaret during the WM_SETFOCUS message and
DestroyWindow during the WM_KILLFOCUS message.

  There are a few other rules: The caret is created hidden. After calling CreateCaret, the window procedure must call
ShowCaret for the caret to be visible. In addition, the window procedure must hide the caret by calling HideCaret whenever
it draws something on its window during a message other than WM_PAINT. After it finishes drawing on the window, the program
calls ShowCaret to display the caret again. The effect of HideCaret is additive: if you call HideCaret several times without
calling ShowCaret, you must call ShowCaret the same number of times before the caret becomes visible again.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值