Date: 02-16-2022
Return to Index
created by gbSnippets
'There are essentially 5 parts to creating a window:
'A data structure is filled out with the window properties and the CreateWindowEx
'API is used to register the window, then the ShowWindow/UpdateWindow API are used
'to display the window. A message loop keeps the window on the screen and a message
'function is used to respond to messages sent to the window (including sending a
'PostQuitMessage() to end the message loop and close the application.
1. Define
2. Register
3. Show
4. Message Loop
5. Message Response
'5. Message Response
'The message loop sends application messages to the PowerBASIC application function
'that was given in the following statement (see http://gbl_00353), as part of defining
'the window to be created using an SDK approach. The message handler is typically
'called "WndProc", but any name will do.
myWin.lpfnWndProc = CodePTR(WndProc)
'Here's an SDK-style PowerBASIC application skeleton, including the WndProc function.
Function WinMain (ByVal hInst As Dword, ByVal hPrevInstance As Dword,
_ByVal lpCmdLine As Asciiz PTR, ByVal iCmdShow As Long) As Long
'... content
'... message loop
End Function
Function WndProc (ByVal hWnd AS Dword, ByVal wMsg AS Dword,
_ByVal wParam AS Dword, ByVal lParam As Long) EXPORT As Long
'... content
End Function
'The WndProc is called by the message loop whenever an application-specific message is
'received. WndProc can process the message, or pass it on to a the default window procedure
'that is built into Windows.
Message Handler
'The SDK message handler works exactly like the DDT DlgProc, with two exceptions. The
'SDK message handler function MUST include the arguments, and the PowerBASIC CB statements
'are not available for use.
'In particular, take a look at these snippets for information on messages, and handling of same:
http://www.gbl_00015 http://www.gbl_00315 http://www.gbl_00299 http://www.gbl_0010
'from the reference category in this snippet library.
'Here's a sample skeleton message handler. Just as with a DDT window procedure, the
'technique is to examine the Msg argument to identify the type of message being received.
'Then the content of the lParam and wParam variables are examined to determine what
'action needs to be taken.
'This skeleton contains about 2 dozen of the most likely Msg values you will use as a PowerBASIC
'programmer. Your specific program might contain code to respond to only one, or even all, of
'these messages. The messages are grouped into categories of similar events.
Function WndProc (ByVal hWnd AS Dword, ByVal wMsg AS Dword,
_ByVal wParam AS Dword, ByVal lParam As Long) EXPORT As Long
Select Case wMsg
'life-cycle
Case %WM_Create 'when an application requests that a window be created
'after window is created, but before it becomes visible
Case %WM_InitDialog 'immediately before a dialog box is displayed
'typically used to initialize controls and carry out any other
'initialization tasks that affect the appearance of the dialog box.
Case %WM_Destroy 'window is being destroyed
'after windows is removed from screen (children still exist)
'control notifications
Case %WM_Command 'user selects a command item from a menu
'control sends a notification message to its parent window
'accelerator keystroke is translated.
Case %WM_Notify 'by control to its parent window when an event has occurred
'resize
Case %WM_Size 'after its size has changed.
Case %WM_GETMINMAXINFO 'size/position of window is about to change
'mouse click
Case %WM_PARENTNOTIFY 'sent to parent when child window is create/destrory
'sent to parent when user clicks mouse button over child
Case %WM_SYSCOMMAND 'user choose command from Window menu, max/min/restore/close buttons
'mouse movement
Case %WM_SETCURSOR 'sent if mouse causes cursor to move
Case %WM_MouseMove 'when cursor moves
'keyboard
Case %WM_Char 'to window with keyboard focus when WM_KEYDOWN message is translated
'by the TranslateMessage function. contains the character code of the
'key that was pressed.
Case %WM_GETDLGCODE 'intercept keyboard input to child control
'application status
Case %WM_ActivateApp 'focus returns to app from another app
Case %WM_Activate 'sent to both the window being activated and the window
'being deactivated.
Case %WM_NCActivate 'sent to window when its nonclient area needs to be changed
'to indicate an active or inactive state.
'graphic/drawing events
Case %WM_ERASEBKGND 'sent when the window background must be erased (such as resizing)
Case %WM_Paint 'set when request is made to paint a portion of an application's window.
'recurring events
Case %WM_Timer 'when a timer expires
'menu activity
Case %WM_INITMENUPOPUP 'when pop-up menu is about to become active
Case %WM_CONTEXTMENU 'user clicked the right mouse button (right-clicked) in a window.
Case %WM_MENUSELECT 'sent when user selects a menu item
'user action
Case %WM_PASTE 'application sends a WM_PASTE message to an edit control or combobox
Case %WM_DROPFILES 'sent when user drops file on application that's is registered as file recipient
End Select
End Function
'gbs_00357
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm