throbber
Part Windows Programmhig Basics
`
`Figure 3-12 continued
`
`4g4Fq Agr
`
`MumI2ttmIm1iIEIImiwm
`
`$jqL$
`
`jpp
`
`ri
`
`cA
`
`138
`
`1tir
`jj3
`
`Page 00161
`
`

`
`chapter
`
`Input Keyboard Stylus and Menus
`
`1/
`II Termlnstance
`
`/1
`
`Program cleanup
`
`mt Termlristance NINSTANCE
`
`hlnstance mt nDefRC
`
`return nDefRC
`
`/___________
`
`II Message
`
`handling procedures for MainWindow
`
`II
`II MainWndproc
`
`Callback function
`
`for application window
`
`II
`LREStJLT CALLBACK MainWndProc
`
`INT
`
`HWND
`hWnd
`UINT wMsg WPARAM wParam
`LPARAM lParam
`
`II Search message list
`in list
`II message
`If
`/1
`
`to see if
`we need
`call procedure
`
`to handle
`
`this
`
`for
`
`dimMalnMessages
`if wMsg MainMessages
`return MainMessages wMsg wParam iParam
`
`return DefWindowProc
`
`hWrid wMsg wParam lParam
`
`II
`II DoCreateMain
`
`//
`
`Process WM_CREATE message
`
`for window
`
`LRESULT DoCreateMain
`
`HWND
`UINT wMsg WPARAM wParam
`hWnd
`LPARAM iParam
`
`HWND hwndCB
`HICON hlcon
`
`/1 Create
`
`command bar
`CommandBar_Create hlnst
`hwndCB
`II Add the menu
`hwndC8 hlnst
`CommandBar_InsertMenubar
`II Add exit button to command bar
`CommandBar_AddAdornments hwndC8
`
`hWnd
`
`IDC_CMDBAR
`
`ID_MENU
`
`hlcon
`if hlcon
`
`hlcon
`
`HICON SendMessage
`
`hWnd WM_GETICON
`
`Loadimage hlnst MAKEINTRESOURCE
`16 16
`IMAGE_ICON
`
`ID_ICON
`
`CIIilgcd
`
`139
`
`Page 00162
`
`

`
`Part Windows Programming Basics
`
`Figure 3-12 continued
`
`1qL
`
`V1L
`
`pd
`
`flptP
`
`riW
`
`4N
`
`Vi
`
`ipp
`
`Mi
`
`tfP
`
`Id
`
`140
`
`Page 00163
`
`

`
`Chapter
`
`Input Keyboard Stylus and Menus
`
`RECT rect
`FIFONT hFont hOldFont
`ICHAR szPromptC32
`HDC hdc
`
`the size of
`
`the client
`
`rect
`
`to take into account
`
`II Adjust
`the command bar height
`II
`hWnd rect
`GetCllentRect
`CommandRar_Height GetDlgltem hWrjd
`
`rect.top
`
`IDC_CMDBAR
`
`hdc
`
`BeginPaint hWnd ps
`
`/1 Draw the board
`DrawBoard hdc rectBoard
`
`to the screen
`II Write the prompt
`SYSTEM_FONT
`GetStockObject
`hFont
`SelectObject hdc hFont
`hOldFont
`
`if bTurn
`LoadString hlnst
`
`else
`
`IDS_XTURN
`
`szPrompt sizeof szPrompt
`
`LoadString hlnst
`
`IDS_OTURN
`
`szPrompt sizeof szPrompt
`
`Drawlext hdc szPrompt
`rectPrompt
`DT_CENTER
`DT_VCENTER
`DT_SINGLELINE
`
`SelectObject hdc hOldFont
`hWnd ps
`EndPaint
`
`return
`
`ii
`
`II DolnitMenuPopMain
`
`Process WM_INITMENUPOPUP
`
`message for window
`
`If
`
`LRESULT DolnitMenuPopMain
`
`HMENU
`
`hMenu
`
`HWND
`UINT wMsg WPARAM wParam
`hWnd
`LPARAM lParani
`
`hMenu
`
`CommandBar_GetMenu
`
`GetDlgltem hWnd IDC_CMDBAR
`
`if
`
`-1
`bLastHove
`EnableMenultem hMenu
`
`else
`
`EnableMenultem hMenu
`return
`
`1DM_UNDO
`
`ME_BYCOMMAND
`
`ME_GRAYED
`
`1DM_UNDO
`
`MF_BYCOMMAND
`
`MF_ENABLED
`
`continued
`
`141
`
`Page 00164
`
`

`
`Part Whidows Programmng Bascs
`
`Figure 3-12 continued
`
`iu
`
`iç
`
`1k
`
`aac
`%bi
`ir$4 r94i
`kIJ1
`
`wp
`
`q$441i
`ge
`4ç
`fIpA
`
`Xk
`
`M1Ih W1rC
`f4W
`
`Jk
`
`id
`
`17L
`
`ft
`
`142
`
`Page 00165
`
`

`
`Chap/er
`
`Input Keyboard Stylus and Menus
`
`it with mark
`
`II Find row
`pt.y
`nCell
`
`cy
`
`fill
`
`If cell empty
`II
`if b8oardEnCell
`if blurn
`bBoardnCelfl
`
`blurn
`
`elsebBoerd
`
`bTurn
`
`the cell
`for the undo
`/1 Save
`bLastMove
`nCell
`
`command
`
`to be repainted
`Force the screen
`II
`hWnd NULL
`FALSE
`InvalidateRect
`
`else
`
`//
`
`Inform the user of
`
`the filled cell
`
`MessageBeep
`return
`
`return
`
`II
`
`1/ DoDestroyMain
`
`Process WM_DESTROV message for window
`
`II
`
`LRESULT
`
`000estroyMain HWND
`UINT wMsg WPARAM wParam
`hWnd
`LPARAM lParam
`
`PostOuitMessage
`return
`
`II Command handler
`
`routines
`
`/1
`
`1/
`/1 DoMainCommandWewGame
`
`II
`LPARAM DoMainCommandNewGame
`
`INT
`
`rc
`
`Process
`
`New Game command
`
`HWND
`hWnd
`WORD wNotifyCode
`
`WORD
`
`idltem I4WND hwndCtl
`
`11
`
`II Count
`
`the number of used spaces
`
`for
`
`if bBoard
`
`continued
`
`143
`
`Page 00166
`
`

`
`Part Wndows Pogrammhig Bscs
`
`Figure 3-12 continued
`
`97P
`
`pI
`
`ft
`
`ijM
`
`tipPfiti1$
`1iP
`
`41I
`
`I4pInr
`III$1IJ
`
`iia
`
`LL
`
`1I hnV
`
`1W8
`
`144
`
`Page 00167
`
`

`
`Chapter
`
`Input Keyboard Stylus and Menus
`
`void ResetGame void
`TNT
`
`Initialize
`
`II
`
`for
`
`the board
`dimthBoard
`
`bBoard
`
`blurn
`
`bLastMove
`
`return
`
`-1
`
`/1
`II DrawXO
`
`Draw
`
`single
`
`or
`
`in
`
`square
`
`void DrawXO HOC hdc
`
`POINT pt
`
`TNT cx cy
`RECT rect
`
`HPEN hPen
`
`RECT prect
`
`TNT nCell
`
`TNT nType
`
`cx
`
`cy
`
`prect-right
`prect-bottom
`
`prect-left/3
`prect-top/3
`
`II Compute
`
`rect.left
`
`rect.right
`
`rect.top
`rect.bottom
`
`the dimensions of
`nel1
`cx
`rect.left
`nCell
`
`cx
`
`cy
`
`rect.top
`
`cy
`
`the target cell
`prect1eft
`20
`prect-top
`20
`
`10
`
`10
`
`II Draw an
`
`Polyline hdc pt
`
`if nlypept rect.left
`pt rect.top
`pt rect.rlght
`pt rect.bottom
`pt rect.right
`pt rect.left
`
`Polyline hdc pt
`Flow about
`an
`
`1/
`
`else if nlype
`Ellipse hdc rect.left
`
`11
`
`rect.top rect.right
`
`rect.bottom
`
`return
`
`II
`
`conlinued
`
`145
`
`Page 00168
`
`

`
`Part
`
`ra
`
`rng asc
`
`Figure 3-12 continued
`
`pt
`
`pt
`
`fo
`
`46
`
`Page 00169
`
`

`
`Chapter
`
`Input Keyboard Stylus and Menus
`
`SelectObject hdc hOldPen
`fleleteObject hPen
`return
`
`in
`
`simply calls the reset game
`which is the default
`returns
`
`The biggest change in TicTac2 is the addition of WM_COMMAND handler
`program might end up han
`the form of the routine OnGoinmandMain Because
`large number of different menu items and other controls
`extend the table
`dling
`lookup design of the window procedure to another table lookup for command IDs
`from menus and accelerators For TicTac2
`use three command handlers one for
`each of the menu items This results in another table of IDs and procedure pointers
`that associates menu IDs with handler procedures Again this way of using
`table
`isnt necessary or specific to Win
`lookup instead of the standard switch statement
`dows CE Its simply my programming style
`The first menu handler OnCommandNewGame
`routine to clear the game structures The routine itself
`value for WM_COMMAND handler
`The OnCommandUndo command handler
`isnt always
`is interesting in that it
`enabled TicTac2 handles an additional message WM_INITMENUPOPUP which is sent
`to window immediately before the window menu is displayed This gives the win
`dow
`chance
`the menu items In this case the routine
`to initialize
`any of
`looks to see whether the bLastMove field contains
`OnlnitMenuPopMain
`valid cell
`the routine disables the Undo menu item using
`value
`through
`If not
`EnableMenultem This action also disables the keyboard accelerator for that menu
`item as well
`The final command handler OnCommandExit sends WM_CLOSE message
`to the main window Closing the window eventually results in Windows sending
`WM_DESTROY message which results in
`call that terminates the
`PostQuitMessage
`program Sending WM_CLOSE message is by the way the same action that results
`from clicking on the Close button on the command bar
`Other changes from the first TicTac example include modification of the mes
`sage loop to provide for keyboard accelerators and the addition of code in the
`OnCreateMain routine to load and assign window icon Also the string prompts
`for whose turn it
`is are loaded from the resource file
`Looking at the OnCommandNewGame handler introduces one last new func
`tion If the game isnt complete the program asks the players whether they really want
`to clear the game board This query is accomplished by calling
`mt MessageBox
`
`HWND
`hWnd
`UINT uType
`
`LPCTSTR
`
`lpText
`
`LPCTSTR
`
`lpCaption
`
`147
`
`Page 00170
`
`

`
`Part Whidows Programmhig Bscs
`
`message box
`simple dialog box with definable text and
`This function displays
`limited series of buttons
`buttons
`message box can display message along with
`Message boxes are often used to query users for
`simple response or to notify them
`of some event The
`to select different but
`Type parameter allows the programmer
`and simply OK You
`such as Yes/No OK/Cancel Yes/No/Cancel
`ton configurations
`can also select an icon to appear in the message box that signals the level of impor
`tance of the answer
`simple method
`poor mans dialog box It offers
`message box is essentially
`in how the dialog box is configured Now
`of querying the user but
`that weve introduced the subject of dialog boxes its time to take
`closer look at
`them and other types of secondary and child windows
`
`flexibility
`
`little
`
`148
`
`Page 00171
`
`

`
`Chapter
`
`Windows Controls
`and Dialog Boxes
`
`Understanding how windows work and relate to each other is the key to understanding
`the user interface of the Microsoft Windows operating system whether it be Microsoft
`Windows 98 Microsoft Windows NT or Microsoft Windows CE Everything you see
`on Windows display is window The desktop is window the taskbar is win
`dow even the Start button on the taskbar is window Windows are related to one
`another according to one relationship model or another
`they may be in parent/child
`sibling or owner/owned relationships Windows supports
`number of predefined
`window classes called controls These controls simplify the work of programmers
`button or
`range of predefined user interface elements as simple as
`by providing
`as complex as multiline text editor Windows CE supports the same standard set of
`built-in controls as the other versions of Windows These built-in controls shouldnt
`be confused with the complex controls provided by the common control
`talk about those controls in Chapter
`Controls are usually contained in dialog boxes sometimes simply referred to
`as dialogs These dialog boxes constitute method for
`program to query users for
`specialized form of dialog named property sheet
`information the program needs
`program to display multiple but related dialog boxes in an overlapping style
`allows
`is equipped with an identifying tab Property sheets are
`each box or property sheet
`particularly valuable given the tiny screens associated with Windows CE devices
`
`library Ill
`
`149
`
`Page 00172
`
`

`
`Part Whidows Programming asics
`
`Finally Windows CE supports
`subset of the common dialog library available
`under Windows NT and Windows 98 Specifically Windows CE supports versions of
`the common dialog boxes File Open File Save Color and Print These dialogs are
`somewhat different on Windows CE Theyre reformatted for the smaller screens and
`arent as extensible as their desktop counterparts
`
`CHILD WINDOWS
`Each window is connected
`parent/child relationship scheme Applications cre
`via
`ate main window with no parent called
`top-level window That window might
`or might not contain windows called child windows
`child window is clipped to
`is no part of
`child window is visible beyond the edge of its parent
`its parent That
`Child windows are automatically destroyed when their parent windows are destroyed
`Also when
`parent window moves its child windows move with it
`Child windows are programmatically
`to top-level windows You use
`identical
`the Create Window or Create WindowEx function to create them each has window
`procedure that handles the same messages as its top-level window and each can in
`turn contain its own child windows To create
`child window use the WS_CHILD
`window style in the dwStyle parameter of Create Window or Create WindowEx
`addition the hMenu parameter unused in top-level Windows CE windows passes
`an ID value that you can use to reference the window
`Under Windows CE theres one other major difference between top-level win
`dows and child windows Windows sends WM_HIBERNATE
`messages only to top-
`level windows that have the WS_OVERLAPPED
`and WS_VISIBLE styles Window
`window can be vis
`visibility in this case has nothing to do with what
`user sees
`ible to the system and still not be seen by the user if other windows are above it
`the Z-order This means that child windows and most dialog boxes arent sent
`WM_HIBERNATE
`messages Top-level windows must either manually send
`WM_HIBERNATE
`message to their child windows
`the
`as necessary or perform all
`tasks themselves to reduce the applications memory footprint On Win
`necessary
`dows CE systems such as the H/PC that support application buttons on the taskbar
`the rules for determining the target of WM_HIBERNATE
`messages are also used to
`determine what windows get buttons on the taskbar
`In addition to the parent/child relationship windows also have an owner/owned
`relationship Owned windows arent clipped to their owners However
`they always
`appear above in Z-order the window that owns them If
`the owner window is
`minimized all windows it owns are hidden Likewise if window is destroyed all
`windows it owns are destroyed. Windows CE 1.0 supports window ownership only
`for dialog boxes but from version 2.0 on Windows CE provides full support for owned
`windows
`
`In
`
`in
`
`150
`
`Page 00173
`
`

`
`Chapter
`
`Windows Controls and Dialog Boxes
`
`Window Management Functions
`
`Given the windows-centric nature of Windows
`its not surprising that you can choose
`from number of functions that enable window to interrogate its enviromnent
`that it might determine its location in the window family tree To find its parent
`window can call
`
`so
`
`HWND GetParent
`
`HWND
`
`hWnd
`
`This function is passed window handle and returns the handle of the calling windows
`the function returns NULL
`parent window If
`the window has no parent
`
`Enumerating windows
`Get Window prototyped as
`
`HWND GetWindow
`
`HWND
`
`hWnd
`
`UINT uCmd
`
`is an omnibus function that allows window to query its children owner and sib
`lings The first parameter is the windows handle while the second is
`constant
`that
`indicates the requested relationship The GW_CHILD constant
`handle to the
`returns
`first child window of window Get Window returns windows in Z-order so the first
`the window has no
`window in this case is the child window highest in the Z-order If
`child windows this function returns NULL The two constants GW_HWNDFIRST
`and
`GWJIDLAST return the first and last windows in the Z-order If the window handle
`return the first and last topmost win
`top-level window these constants
`passed is
`dows in the Z-order
`If the window passed is
`child window the GetWindow function
`returns the first and last sibling window The GW_HWNDNEXT
`and GWJ-IWNDPREV
`constants return the next lower and next higher windows in the Z-order These con
`stants allow window to iterate through all
`the sibling windows by getting the next
`window then using that window handle with another call
`to Get Window to get
`the
`next and so on Finally the GW_OWNER
`returns the handle of the owner
`constant
`of window
`Another way to iterate through
`
`series of windows is
`
`BOOL EnumWindows
`
`WNDENUMPROC
`
`ipEnurliFunc
`
`LPARAM lParam
`
`once for each
`This function calls the callback function pointed to by ipEnumFunc
`top-level window on the desktop passing the the handle of each window in turn
`value which is also passed to the enu
`The iParam value is an application-defined
`Get Window loop
`meration function This function is better than iterating through
`to find the top-level windows because it always returns valid window handles its
`Get Window iteration loop will get window handle whose window
`possible that
`to Get Window can occur However
`is destroyed before the next call
`since
`Enum Windows works only with top-level windows Get Window still has
`place when
`series of child windows
`iterating through
`
`151
`
`Page 00174
`
`

`
`Part Windows Programming asics
`
`window
`Finding
`the handle of
`To get
`
`specific window use the function
`
`HWND FindWindow LPCTSTR
`
`lpClassName LPCTSTR
`
`lpWindowName
`
`This function can find window either by means of its window class name or by means
`of windows title
`text This function is handy when an application is iust starting
`up it can deiermine whether another copy of the application is already running All
`an application has to do is call Find Window with the name of the window class for
`the main window of the application Because an application almost always has main
`window while its running
`NULL returned by Find Window indicates that the func
`locate another window with the specified window classtherefore its
`tion cant
`almost certain that another copy of the application isnt running
`
`Editing the window structure values
`The pair of functions
`
`LONG GetWindowLong
`
`HWND
`
`hWnd mt nlndex
`
`and
`
`LONG SetWindowLong
`
`HWND
`
`hWnd mt nlndex LONG dwNewLong
`
`allow an application to edit data in the window structure for window Remember
`the WNDCLASS structure passed to the RegisterClass function has
`field cbWndExtra
`that controls the number of extra bytes that are to be allocated after the structure If
`you allocated extra space in the window structure when the window class was reg
`istered you can access
`those bytes using the Get WindowLong and Set WindowLong
`functions Under Windows CE the data must be allocated and referenced in 4-byte
`integer sized and aligned blocks So if window class was registered with 12 in
`the cbWndExtra field an application can access
`those bytes by calling Get WindowLong
`or Set WindowLong with the window handle and by setting values of
`and
`the nlndex parameter
`Get WindowLong and Set WindowLong support
`set of predefined index values
`that allow an application access to some of the basic parameters of window Here
`list of the supported values for Windows CE
`
`in
`
`is
`
`GWL_STYLE
`
`The style flags for the window
`
`GWL_EKSTYLE
`
`The extended style flags for the window
`
`GWLJ12NDPROC
`
`The pointer
`
`to the window procedure for the window
`
`GWL_ID
`
`The ID value for the window
`
`GWL_USERDATA
`
`An application-usable
`
`32-bit value
`
`152
`
`Page 00175
`
`

`
`Chapter
`
`Windows Controls and Dialog Boxes
`
`Dialog box windows support
`
`the following additional values
`
`DWL_DLGPROC
`
`The pointer
`
`to the dialog procedure for the window
`
`DWL_MSGRESULT
`
`The value rettirned when the dialog box function
`
`returns
`
`DWL_USER
`
`An application-usable
`
`32-bit value
`
`the GWL_HINSTANCE
`Windows CE doesnt support
`values supported by Windows NT and Windows 98
`
`and GWL_HWNDPARENT
`
`Scroll Bars and the FontList2 Example Program
`
`To demonstrate
`
`child window we return to the FontList program
`handy use for
`scroll bar were
`As you might remember the problem was that if
`from Chapter
`attached to the main window of the application the scroll bar would extend upward
`past the right side of the command bar The reason for this is that
`scroll bar attached
`to window is actually placed in the nonclient area of that window Because the com
`mand bar lies in the client space we have no easy way to properly position the two
`controls in the same window
`child window We place the child
`An easy way to solve this problem is to use
`fills all of the client area of the top-level window not covered by
`window so that it
`the command bar The scroll bar can then be attached to the child window so that it
`appears on the right side of the window but stops just beneath the command bar
`Figure 4-1 shows the Fontlist2 window Notice that the scroll bar now fits properly
`underneath the command bar Also notice that the child window is completely un
`by the user
`detectable
`
`Times New Roman Point24
`
`Family Symbol Number ol
`floun12
`
`E6o flour14
`
`lonts2
`
`Family Anal Number of font6
`Anal Point1
`
`Anal Point11
`Anal Point12
`Anal Point13
`Anal Point18
`
`Font Liet
`
`________
`307 PM
`
`Figure 4-1 The FontList2 window with the scroll bar properly positioned just beneath
`the command bar
`
`153
`
`Page 00176
`
`

`
`Parti
`
`The code for this fix which isnt that much more complex than the original
`FontList example is shown in Figure 4-2 Instead of one window procedure there
`are flow two one for the top-level window which
`have labeled the Frame win
`dow and one for the child window separated the code for these two windows into
`two different source files FontList2.c
`and ClientWnd.c ClientWrid.c also contains
`function InitGlient which registers the client window class
`
`FontList2h/__II Header
`
`file
`
`II Written for the
`
`II Copyright
`
`number of elements
`/1 Returns
`define dinix sizeofx
`
`size
`
`1/
`1/ Generic defines
`II
`
`struct decodeiilNT
`UINT Code
`
`and data
`
`types
`
`LRESULT FxnHWNQ
`
`decodoCMD
`struct
`UINT Code
`LRESULT FxnHWF4D WORD
`
`HWND
`
`WORD
`
`associates
`
`on
`
`II
`
`II Generic defines used by appli
`define
`IDC_CMDBAR
`define
`
`TOC_CLIENT
`
`ID
`Command bar
`Client window ID
`
`and defines
`
`II
`II Window prototypes
`II
`define FAMILYMAX
`typedef struct
`mt nNumFonts
`TCHAR szFontFamily
`
`24
`
`FONTFAMSTRUT
`
`Figure 4-2 The FonlLisr2progrwn
`
`154
`
`Page 00177
`
`

`
`Chapter
`
`Windows Controls and Dialog Boxes
`
`typedef
`
`FONTFAMSTRUCT
`
`PFONTFAMSTRIJCT
`
`typedef struct
`TNT yCurrent
`MDC hdc
`PAINTFONTINFO
`typedef PAINTFONTINFC
`
`PPAINTFONTINFO
`
`define CLIENTWINDOW
`
`TEXT ClientWnd
`
`mt InitClient HINSTANCE
`mt TermClient HINSTANCE
`
`int
`
`II
`
`II Function prototypes
`
`//
`
`mt InitApp HINSTANCE
`Initinstance HINSTANCE
`LPWSTR
`HWND
`mt Terminstance HINSTANCE int
`
`int
`
`II Window procedures
`CALLBACK FrameWndProc
`LRESULT
`CALLBACK ClientWndProc
`
`LRESULT
`
`HWND
`UTNT WPARAM
`HWND UINT WPARAM
`
`LPARAM
`LPARAM
`
`1/ Message
`handlers
`HWND UINT WPARAM
`LPARAM
`LRESULT DoCreateFrame
`LRESULT DoSizeFrame HWND
`LPARAM
`hINT WPARAM
`HWND
`hINT WPARAM
`LPARAM
`LRESULT DoDestroyFrame
`
`HWND UINT WPARAM
`LRESULT DoCreateClient
`HWND
`hINT WPARAM
`LRESULT DoPaintClient
`LRESULT DoVScrollClient HWND UINT WPARAM
`
`LPARAM
`LPARAM
`LPARAM
`
`FontList2.c
`
`II FontList2
`
`Lists the available fonts
`
`in the system
`
`//
`Ii Written
`
`II Copyright
`
`for the book Programming Windows
`1998 Douglas Boling
`
`CE
`
`include windows.h
`include commctrl.h
`include FontList2.h
`
`II
`
`For all
`
`II Command bar
`
`that Windows stuff
`includes
`
`II Program-specific
`
`stuff
`
`continued
`
`155
`
`Page 00178
`
`

`
`Part Whidows Programming Basics
`
`Figure 4-2 continued %dwi
`_SItr
`
`aq
`
`11 _4Lq
`Wi Sri
`
`vr
`
`rtr
`
`1jr
`
`4j
`
`zr
`dHbi LvwISp
`bM btkJ1p %i
`
`i1K
`
`1Ip
`
`r42L
`
`Mfr
`st 4fP P1
`
`jJ
`
`ioILkf
`
`i6UISr
`
`rdt 4% 8j
`
`ii
`
`156
`
`Page 00179
`
`

`
`Chapter
`
`Windows Controls and Dialog Boxes
`
`wc.style
`
`wc.lpfnWndProc
`wc.cbClsExtra
`wc.cbWndExtra
`wc.hlnstance
`wc.hlcon
`wc.hCursor
`
`NULL
`NULL
`wc.hbr8ackground
`wc.lpszMenuName
`wc.lpszCassName
`
`FrameWndProc
`
`hlnstance
`
`HBRUSH GetStockObject
`NULL
`
`szAppName
`
`1/ Window style
`1/ Callback function
`II Extra class data
`II Extra window data
`II Owner handle
`II Application icon
`II Default
`
`cursor
`
`WI4ITE._.BRUSH
`
`/1 Menu
`name
`II Window class name
`
`if RegisterClass wc
`
`return
`
`II
`
`if
`
`client window class
`Initialize
`InitClient hinstance
`return
`
`return
`
`1/
`
`II
`
`II
`
`Initinstance
`
`Instance initialization
`
`HWND
`
`Initlnstance
`hWnd
`
`HWND
`
`HINSTANCE
`
`hlnstance LPWSTR
`
`lpCmdLine mt nCmdShow
`
`II
`
`Save program instance handle
`hlnstance
`hlnst
`
`in global variable
`
`II Create frame window
`CreateWindow szAppName
`hWnd
`TEXT Font List
`WS_VISIBLE
`CW_USEDEFAULT
`CW_USEDEFAULT
`CW_USEDEFAULT
`CW_USEOEFAULT
`NULL
`NULL
`
`hlnstance
`NULL
`
`1/ Return
`fail
`code
`llsWindow hWnd
`
`if
`
`if window not created
`return
`
`show and update calls
`II Standard
`hWnd nCmdShow
`ShowWindow
`Updatewindow hWnd
`return hWnd
`
`II Window class
`
`II Window title
`
`1/ Style flags
`II
`
`position
`
`II
`
`II
`
`1/
`
`position
`Initial width
`
`Initial
`
`height
`
`If Parent
`II Menu must be null
`II Application instance
`II Pointer to create
`
`ii parameters
`
`continued
`
`157
`
`Page 00180
`
`

`
`Part Windows Programming Basics
`
`Figure 4-2 continued 4ei 31MI
`
`MJIIN
`
`W4
`
`41
`rFir1$ frhi1Ijb
`iMi rr
`
`frhj
`
`1b
`
`Eaw Ir
`
`frm%nIirpp
`$i
`
`11
`
`ie
`
`diJii
`
`158
`
`Page 00181
`
`

`
`Chapter
`
`Windows Controls and Dialog Boxes
`
`hwndClient
`
`TEXT
`
`CreateWindow CLIENTWINDOW
`WS_VISIBLE
`WS_VSCROLL
`WS_CHILD
`lpcs-x lpcs-y
`sHeight
`lpcs-cx lpcs-cy
`sHeight
`hWnd
`HMENUIDCCLIENT
`lpcs-hlnstance NULL
`
`II Destroy frame if client window not created
`IsWindow hwndClient
`if
`DestroyWindow hWnd
`return
`
`II
`II DoSizeFrame
`1/
`
`Process WM_STZE message for window
`
`LRESULT DoSizeFrame
`RECT rect
`
`INT
`
`HWND
`
`hWnd
`
`UINT wMsg WPARAM wParam LPARAM iParam
`
`hWnd rect
`GetClientRect
`CommadBar_Height GetDlgltem hWnd
`rect.top
`
`IDC_CMDBAR
`
`SetWindowPos GetDlgltem hWnd
`NULL rect.left
`rDc_cLIENT
`rect.left
`rect.bottom
`rect.top
`rect.right
`SWPNOZORDER
`
`rect.top
`
`return
`
`II
`II DoDestroyFrame
`
`II
`
`Process WM_DESTROY message for window
`
`LRESULT
`
`DoDestroyFrame
`
`HWND
`UINT wMsg WPARAM wParam
`hWnd
`LPARAM iParam
`
`PostQuitMessage
`return
`
`1MM
`
`Client Wndc
`
`1/ ClientWnd
`
`Client window code
`
`for FontList2
`
`If Written for
`
`1/ Copyright
`
`the book Programming Windows
`1998 Douglas Boling
`
`CE
`
`cotinzwd
`
`159
`
`Page 00182
`
`

`
`Part Whidows Programming Bcs
`
`Figure 4-2 continued
`
`_1i1%MItJ
`4.PaPd
`
`d1IiLiL 4j
`
`iIrt
`
`1r
`
`iV zit rir
`
`iP
`
`j4j
`
`$64
`
`4r
`
`IiiMi
`
`160
`
`ft
`
`Page 00183
`
`

`
`Chapter
`
`Windows Controls and Dialog Boxes
`
`mt Termtlient HINSTANcE
`
`hlnstance irit
`
`nDefRC
`
`Font callback
`
`functions
`
`II
`
`II
`
`1/ FontFamilycallback
`families
`
`II
`
`Callback function
`
`that enumerates
`
`the font
`
`return nOefRC/tZ_
`lstrcpyffs lplf-lfFaceName
`
`int CALLBACK FontFamilyCallback
`
`mt
`
`rc
`
`lplf
`CONST LOGFONT
`lpntm
`CONSI TEXTMETRIC
`DWORD nForitlype LPARAM iParam
`
`II Stop enumeration if array filled
`FAMILYMAX
`sFamilyCnt
`if
`return
`
`II Copy
`
`face name of
`
`font
`
`return rc
`
`1/
`
`II EnumsingleFontFamily
`families
`
`/1
`
`Callback
`
`function
`
`that enumerates
`
`the font
`
`lplf
`int CALLBACK EnumSingleFontFamily CONST LOGFONT
`CONST TEXTMETRIC lpntm
`DWORD nFontlype LPARAM iParam
`
`PFONTFAMSTRUCT pffs
`
`PFONTFAMSTRUCT
`pffs
`pffs-nNumFonts
`return
`
`II
`
`II PaintSingleFontFamily
`families
`
`II
`
`iParam
`Increment count of
`
`//
`
`fonts in family
`
`Callback function
`
`that enumerates
`
`the font
`
`lplf
`int CALLBACK PaintSingleFontFamily CONSI
`LOGFONT
`CONST TEXTMETRIC lpntm
`OWORD nFontType LPARAM lParam
`
`PPAINTFONTINFO ppfi
`TCHAR szOut
`INT nFontHeight
`TEXTMETRIC
`
`tin
`HFONT hFont hOldFont
`
`nPointSize
`
`continued
`
`161
`
`Page 00184
`
`

`
`Part Windows Progammhig Basics
`
`kPb
`pt3PV
`
`4td
`
`ir
`
`iw
`
`Figure 4-2 continued
`
`ppt
`
`h$on
`
`2it
`
`v1
`
`tf 4uL
`
`1Jdia
`
`uri
`
`TWT
`
`162
`
`mp4u$3
`tw
`N1r11
`..r tt
`i1pérIiVtw
`
`4i1_%LkM1i1II1
`
`nt
`MJ
`
`4iar ijjPL
`
`rIrIII44jmU
`
`rn
`
`Page 00185
`
`

`
`Chapter
`
`Windows Controls and Dialog Boxes
`
`return IlefWindowProc
`
`hWnd wMsg wParam iParam
`
`II
`
`If OoCreateClient
`
`Process WM_CREATE message for window
`
`/1
`
`LRESULT DoCreateClient
`
`HDC hdc
`INT
`
`rc
`
`HWND
`hWnci UINT wMsg WPARAM wParam
`LPARAM iParam
`
`I/Enumerate the available fonts
`GetDC hWnd
`hdc
`EnumFontFamiies HDChdc
`
`rc
`
`LPTSTRNULL
`
`FontFamilyCallback
`
`EnumFontFamjlies HDChdc ffs
`
`for
`
`sFamilynt
`ffsti.nNumFonts
`
`rc
`
`EnumSingleFontFamj3y
`LPARAM PFONTFAMSTRUCTffs
`
`ReleaseDc hWnd hdc
`return
`
`II
`
`II QoPaintcljent
`
`Process WM._PAINT message for window
`
`hWnd
`HWND
`UINT wMsg WPARAM wParam
`LPARAM iParam
`
`//
`
`LRESULT DoPaintClient
`
`ps
`
`PAINTSTRIJCT
`RECT rect
`HOC hdc
`tm
`TEXIMETRIC
`INT nFontHeight
`TCHAR szOutf256
`PAINTFONTINFO pfi
`SCROLLINFO si
`
`hdc
`
`BeginPaint hWnd ps
`hWnd rect
`
`GetClientRect
`
`II Get
`
`the height of
`
`the default
`
`GetTextMetrics hdc tm
`
`font
`
`nFontHeight
`
`tm.tmHeight
`
`tm.tmExternalLeading
`
`continued
`
`163
`
`Page 00186
`
`

`
`Part Whidows Prorammflg Bascs
`
`Figure 4-2 continued
`
`Il%M
`
`iii L4d
`
`164
`
`Page 00187
`
`

`
`Chapter
`
`Windows Controls and Dialog Boxes
`
`switch LOWORD wParam
`case SB_LINEUP
`10
`sVPos
`
`break
`
`case SB_LINEDOWN
`10
`sVPos
`
`break
`
`case SB_PAGEUP
`rect.bottom
`sVPos
`
`break
`
`rect.top
`
`case
`
`SB_PAGEDOWN
`sVPos
`
`rect.bottoni
`
`break
`
`rect.top
`
`case SB_THUMBPOSITION
`HIWORD wParam
`sVPos
`
`break
`
`1/ Check
`
`range
`
`if
`
`if
`
`II
`
`//
`
`if
`
`sVPos
`sVPos
`
`sVPos
`sVPos
`
`sVMax
`sVMax
`
`If scroll position changed
`force redraw of window
`sVPos
`sOldPos
`
`sizeof Si
`
`si.cbSize
`
`update scroilbar and
`
`si.nPos
`
`sVPos
`SIF_POS
`si.fMask
`hWnd SBVERT si TRUE
`SetScrolllnfo
`
`InvalidateRect
`
`hWnd NULL TRUE
`
`return
`
`The window procedure for the frame window is quite simple Just as in the
`the command
`original FontList program in Chapter
`bar
`WM_CREATE message handler DoCreateFrame Now however
`this procedure also
`calls CreateW indow to create the child window in the area underneath the command
`bar The child window is created itb three style flags WS_VTSIBLE so that
`the win
`dow is initially
`visible WS_CHILD required because it will be
`child window of the
`frame window and WS_VSCROLL to add the vertical scroll bar to the child window
`
`is created in the
`
`165
`
`Page 00188
`
`

`
`Part Whidows Programming Basics
`
`The majority of the work for the program is handled in the client window pro
`cedure Here the same font enumeration calls are made to query the fonts in the sys
`new characteristic it now bases
`tem The WM_PAJNT handler DoPaintClient has
`it paints on the new global variable sVPos which provides vertical positioning
`what
`in DoCreateClient and is changed in the handler for
`That variable is initialized to
`new message WM_VSCROLL
`
`Scroll bar messages
`vertical scroll bar any time the user
`WM_VSCROLL message is sent to the owner of
`complementary message WIVI_HSCROLL
`taps on the scroll bar to change its position
`horizontal scroll bar
`is identical to WM_VSCROLL but is sent when the user taps on
`For both these messages the wParam and iParam assignments are the same The
`code indicating why the message was
`low word of the wParam parameter contains
`diagram of horizontal and vertical scroll bars and how tap
`sent Figure 4-3 shows
`ping on different parts of the scroll bars results in different messages The high word
`of wParam is the position of the thumb but this value is valid only while youre pro
`and SB_ThUMBTRACK codes which Ill explain
`cessing the SB_THUMBPOSITION
`stand-alone control and not attached
`shortly If the scroll bar sending the message is
`to window the iParam parameter contains the window handle of the scroll bar
`
`SB_LINEUP
`ISB_PAGEUP
`ij
`
`SB_THUMBPOSITION
`SB_THUMBTRACK
`
`....psBLINEDowN
`
`SB_LINELEFT
`
`SB_THUMBPOSITION
`
`SB_LINERIGHT
`
`SB_PAGELEFT
`
`SB_THUMBTRACK
`
`SB_PAGERIGHT
`
`Figure 4-3 Scroll bars and their hot spots
`
`The scroll bar message codes sent by the scroll bar allow the program to react
`required by
`scroll bar The response
`the different user actions allowable by
`to all
`each code is listed in the following table Figure 4-4
`codes are pretty straightforward You move
`The SB_LINExxx and SB_PAGExvx
`time The SB_THUMBPOSITION
`and
`page at
`the scroll position either
`codes can be processed in one of two ways When the user drags
`SB_THUMBTRACK
`the scroll bar thumb the scroll bar sends SB_THUMBTRACK
`code so that
`program
`can interactively track the dragging of the thumb If your application is fast enough
`you can simply process the SB_THUMBTRACK code and interactively update the
`code however your application must be
`display If you field the SB_THUMBTRACK
`
`line or
`
`166
`
`Page 00189
`
`

`
`Chapter
`
`Windows Controls and Dialog Boxes
`
`the thumb can be dragged without hesi
`quick enough to redraw the display so that
`tation or jumping of the scroll bar This is especially
`problem on the slower devices
`that run Windows CE
`
`Codes
`
`Response
`
`For WS_VSCROLL
`
`SB_LINEUP
`
`SB_LINEDOWN
`
`SB_PAGEUP
`
`SB_PAGEDOWN
`
`For WS_HSCROLL
`
`SB_LINELEFT
`
`SB_LINERIGHT
`
`SB_PAGELEFT
`
`SB_PAGERIGHT
`
`Program should scroll
`
`Program should scroll
`
`Program should scroll
`worth of data
`
`Program should scroll
`screens worth of data
`
`the screen up one line
`the screen down one line
`
`the screen up one screens
`
`the screen down one
`
`Program should scroll
`
`the screen left one character
`
`Program should scroll
`
`the screen right one character
`
`Program should scroll the screen left one screens
`worth of data
`
`Program should scroll
`worth of data
`
`the screen right one screens
`
`For both WS_VSCROLL and WS_HSCROLL
`SB_THUMBTRACK
`
`Programs with enough speed to keep up should
`update the display with the new scroll position
`
`SB_THUMBPOSITION
`
`SB_ENDSCROLL
`
`SB_TOP
`
`SB_BOTTOM
`
`Figure 4-4 Scroll codes
`
`Programs that cant update the display fast enough
`to keep up with the SB_THUMBTRACK message
`should update the display with the new scroll
`position
`This code indicates that the scroll bar has com
`pleted the scroll event No action is required by the
`program
`
`Program should set the display to the top or left end
`of the data
`
`Program should set
`right end of the data
`
`the display to the bottom or
`
`167
`
`Page 00190
`
`

`
`Part Windows Programming Basics
`
`If your application or the system its running on is too slow to quickly update
`code you can ignore the SB_ThUMBTRACK
`the display for every SB_THUMBTRACK
`code thats sent when the user drops the scroll
`and wait for the SB_THUMBPOSITION
`bar thumb Then you have to update the display only once after the user has fin
`ished moving the scroll bar thumb
`
`scroll bar
`Configuring
`scroll bar an application should first set the minimum and maximum val
`To use
`uesthe range of the scroll bar along with the initial position Windows CE scroll
`bars like their Win32 cousins support proportional thumb sizes which provide feed
`the size of the current visible page compared to the entire
`to the user about
`back
`these parameters Windows CE applications should use the
`scroll range To set all
`SetScrolllnfo function prototyped as
`
`mt SetScrolllnfo HWND
`
`hwnd mt fnBar
`
`LPSCROLLINFO ipsi
`
`BOOL fRedraw
`
`the scroll
`
`is either the handle of the window that contains
`The first parameter
`bar or the window handle of the scroll bar itself The second parameter fnBar is
`flag that determines the use of the window handle The scroll bar flag can be one of
`three values SB_HORZ for windows standard horizontal scroll bar SB_VERT for
`stand
`windows standard vertical scroll bar or SB_CTL if the scroll bar being set is
`the window handle is the handle of
`alone control Unless the scroll bar is
`control
`the handle is the win
`the window containing the scroll bar With SB_CTL however
`is JFedraw Bool
`dow handle of the scroll bar control
`itself The last parameter
`the scroll bar should be redrawn after the call has
`ean value that indicates whether
`been completed
`The third parameter is
`
`pointer to
`
`SCROLLINFO structure which is defined as
`
`tagSCROLLINFO
`typedef struct
`cbSize
`UINT
`UINT fMask
`mt
`nMin
`mt
`nMax
`UINT nPage
`mt
`nPos
`mt
`nTrackPos
`SCROLLINFO
`
`This structure allows you to completely specify the

This document is available on Docket Alarm but you must sign up to view it.


Or .

Accessing this document will incur an additional charge of $.

After purchase, you can access this document again without charge.

Accept $ Charge
throbber

Still Working On It

This document is taking longer than usual to download. This can happen if we need to contact the court directly to obtain the document and their servers are running slowly.

Give it another minute or two to complete, and then try the refresh button.

throbber

A few More Minutes ... Still Working

It can take up to 5 minutes for us to download a document if the court servers are running slowly.

Thank you for your continued patience.

This document could not be displayed.

We could not find this document within its docket. Please go back to the docket page and check the link. If that does not work, go back to the docket and refresh it to pull the newest information.

Your account does not support viewing this document.

You need a Paid Account to view this document. Click here to change your account type.

Your account does not support viewing this document.

Set your membership status to view this document.

With a Docket Alarm membership, you'll get a whole lot more, including:

  • Up-to-date information for this case.
  • Email alerts whenever there is an update.
  • Full text search for other cases.
  • Get email alerts whenever a new case matches your search.

Become a Member

One Moment Please

The filing “” is large (MB) and is being downloaded.

Please refresh this page in a few minutes to see if the filing has been downloaded. The filing will also be emailed to you when the download completes.

Your document is on its way!

If you do not receive the document in five minutes, contact support at support@docketalarm.com.

Sealed Document

We are unable to display this document, it may be under a court ordered seal.

If you have proper credentials to access the file, you may proceed directly to the court's system using your government issued username and password.


Access Government Site

We are redirecting you
to a mobile optimized page.





Document Unreadable or Corrupt

Refresh this Document
Go to the Docket

We are unable to display this document.

Refresh this Document
Go to the Docket