Date: 02-16-2022
Return to Index
created by gbSnippets
'Dialog New Pixels|Units,hParent,title,x,y,xx,yy,style,exstyle To hDlg
'hWndMain = CreateWindowEX exstyle,classname,title,style,x,y,w,h,hParent,hMenu,hInstance,ptrCreateStruct
'Dialog New CreateWindow()/CreateWIndowEX()
' exstyle dwExStyle
' - lpClassName
' title$ lpWindowName
' style dwStyle
' x X
' y Y
' w nWidth
' h nHeight
' hParent hwndParent
' - hMenu or ChildID
' - hInstance
' - lpParam
' Pixels|Units -
'CreateWindow()/CreateWIndowEX()
'ByVal dwExStyle As Dword 'CreateWindowEX only
'ByRef lpClassName As AsciiZ
'ByRef lpWindowName As AsciiZ
'ByVal dwStyle As Dword
'ByVal X As Long
'ByVal Y As Long
'ByVal nWidth As Long
'ByVal nHeight As Long
'Optional ByVal hwndParent As Dword
'Optional ByVal hMenu As Dword (Control ID for child windows)
'Optional ByVal hInstance As Dword
'Optional ByRef lpParam As Any
'Function PBMain() AS Long Function WinMain(hInst, hPreInstance, lpCmdLine, iCmdShow) As Long
' ? "Hello World" ? "Hello World"
'End Function End Funciton
'Function PBMain() AS Long Function WinMain(hInst, hPreInstance, lpCmdLine, iCmdShow) As Long
' Dialog New ... To hDlg hWndMain = CreateWindowEX ... CodePtr(hWndProc)...
' Dialog Show ... Call DlgProc ShowWindow hWndMain, iCmdShow
'End Function UpDateWindow hWndMain
' While GetMessage(Msg, %NULL, 0, 0) > 0
' If IsFalse TranslateAccelerator (hWnd, hAccel, Msg) Then
' If IsFalse ISDialogMessage (hDlg, Msg)) Then
' TranslateMessage Msg
' DispatchMessage Msg
' End If
' End If
' Wend
' End Function
'Callback Function hDlgProc() as Long 'Function WndProc(hWnd, wMsg, wParam, lParam)
'End Function 'End Function
'WM_COMMAND===================================================================================
'Source--------wParam (Hi Word)--------------------wParam (Lo Word)-----------------lParam
'Menu 0 Menu identifier (IDM_*) 0
'Accelerator 1 Accelerator identifier (IDM_*) 0
'Control Control-defined notification code Control identifier Handle to the control window
'WM_COMMAND===================================================================================
'hDlgProc WndProc
'Cb.Ctl Lo(Word,wParam) Identifer (Menu/Accelerator/Control)
'Cb.CtlMsg Hi(Word,wParam) 0/1/Notification code (Menu/Accelerator/Control)
'Cb.hndl lParam 0/0/Control Handle (Menu/Accelerator/Control)
'WM_NOTIFY===================================================================================
'hDlgProc WndProc
'Cb.NMID .idFrom (from NMHDR header structure)
'Cb.NMHDR lParam - Pointer to NMHDR structure
'Cb.NMHWND .hWndFrom
'CB.NMID .idFrom
'Cb.NNCODE .code
'Type NMHDR
' hWndFrom - control handle
' idFrom - control ID
' code - notification code
'End Type
'Message Loop structure - used by GetMessage()
'Type MSG
' hWnd
' message
' wParam
' lParam
' time
' pt
'End Type
Case %WM_Command Case %WM_Command
Select Case Cb.CtlID Select Case Lo(Word,wParam) 'Control ID
Case %IDC_Button Case %IDC_Button
Select Case Cb.CtlMsg Select Case Hi(Word,wParam) 'Notification code
Case %BN_Clicked Case %BN_Clicked
End Select End Select
Case %WM_Notify Case %WM_Notify
pnmhdr = lParam
Select Case CB.NMID Select Case @pnmhdr.idFrom 'Control ID
Case %IDC_Button Case %IDC_Button
Select CB.NMCode Select Case @pnmhdr.code 'Notification code
Case %NM_Click Case %NM_Click 'typical notification code
End Select End Select
End Select End Select
'Controls=============================================================
'http://msdn.microsoft.com/en-us/library/windows/desktop/bb773169%28v=vs.85%29.aspx
'MSDN Control Library Class Name PowerBASIC Control Type
1. Animation SysAnimate32 -
2. Button button Button, Check3State, CheckBox, Frame, ImgButton, ImgButtonX, Option
3. ComboBox combobox ComboBox
4. ComboBoxEx ComboBoxEx32 -
5. Date and Time Picker SysDateTimePick32 -
6. Edit Control edit TextBox
7. Flat Scroll Bar ? -
8. Header Control SysHeader32 Header
9. Hot Key msctls_hotkey32 -
10. ImageList ? ImageList
11. IP Address Control SysIPAddress32 -
12. ListBox listbox ListBox
13. ListView SysListView32 ListView
14. Month Calendar SysMonthCal32 -
15. Pager SysPager -
16. ProgressBar msctls_progress32 ProgressBar
17. Property Sheet ? -
18. Rebar ReBarWindow32 -
19. Rich Edit RichEdit50W -
Rich Edit RichEdit20A -
Rich Edit RichEdit -
20. ScrollBar scrollbar ScrollBar
21. Static Control static Graphic, Line, Label, Image, ImageX
22. StatusBar msctls_statusbar32 StatusBar
23. SysLink SysLink -
24. Tab SysTabControl32 TAB
25. Task Dialog ? -
26. Toolbar ToolbarWindow32 Toolbar
27. Tooltip tooltips_class32 -
28. Trackbar msctls_trackbar32 -
29. TreeView SysTreeView32 TreeView
30. Up-Down Control msctls_updown32 -
' Edit Control of ComboBox
' ListBox of ComboBox
' Edit Control of TreeView
' Page (Dialog) of TAB
' Button of Toolbar
' Header of ListView
'Not covered: Menu Bar, Text Window, Graphic Window
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
#Include "Win32API.inc"
#Resource Icon logo "test.ico"
Enum Equates Singular
IDC_Button = 500
IDC_ComboBox
IDC_Edit
IDC_ListBox
IDC_RichEdit
IDC_ScrollBar
IDC_Static
End Enum
Global hWndMain As Dword
Function WinMain (ByVal hInst As Dword, ByVal hPrevInstance As Dword, ByVal lpCmdLine As AsciiZ Ptr, ByVal iCmdShow As Long) As Long
'arguments to WinMain are provided by Windows - not defined by the programmer
'hInstance current instance of the application
'hPrevInstance previous instance (not used - returns %Null in Win32)
'lpCmdLine pointer to command line (whatever the user types in after MyApp.EXE). A null terminated string.
'iCmdShow used the first time ShowWindow is called to display the application main window
Local Msg As tagMsg
Local W As WndClassEx
Local szAppName As AsciiZ * 80
Local hWndButton As Dword
Local hAccel As Dword
Local WndStyle As Long
Local WndStyleX As Long
'register window class
szAppName = "HelloSDK"
W.cbSize = SizeOf(W)
W.Style = %CS_HREDRAW Or %CS_VREDRAW '%WS_OverlappedWindow Or %WS_HScroll Or %WS_VScroll '
W.lpfnWndProc = CodePtr(WndProc)
W.cbClsExtra = 0
W.cbWndExtra = 0
W.hInstance = hInst
W.hIcon = LoadIcon(hInst, "logo")
W.hCursor = LoadCursor(%NULL, ByVal %IDC_ARROW)
W.hbrBackground = %Color_BtnFace+1
W.lpszMenuName = %NULL
W.lpszClassName = VarPtr(szAppName)
W.hIconSm = LoadIcon(hInst, ByVal %IDI_APPLICATION) 'why not %NULL
RegisterClassEx W
'create window of that class
WndStyle = %WS_OverlappedWindow
WndStyleX = %WS_Ex_Left
hWndMain = CreateWindowEX( _
WndStyleX, _ 'dwStyle extended style of window
szAppName, _ 'lpClassName pointer to a null-terminated string (any registered name, including predefined system class names).
"SDK", _ 'lpWindowName pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
WndStyle, _ 'dwStyle style of window
500, _ 'x initial horizontal position (upper left screen, except for child is relative to parent window's client area)
400, _ 'y initial vertical position (upper left screen, except for child is relative to parent window's client area)
300, _ 'nWidth width in device units
400, _ 'nHeight height in device units
%Null, _ 'hWndParent handle to parent window (optional for a pop-up window)
%Null, _ 'hMenu handle to a menu or child window control ID
hInst, _ 'handle to instance of the module to be associated with the window
ByVal %Null _ 'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
)
CreateButton
'predefined lpClassName values: Button, ComboBox, Edit, ListBox, MDIClient, RichEdit, RichEdit_Class, Scrollbar, Static
'window not shown automatically. must show it manually
ShowWindow hWndMain, iCmdShow 'controls how window is to be shown. 1st must use iCmdShow
UpdateWindow hWndMain 'sends the window it's first WM_Create to display the window on the screen
'message pump - calls WndProc 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.
While GetMessage(Msg, %NULL, 0, 0) > 0
If IsFalse TranslateAccelerator (hWndMain, hAccel, Msg) Then
If IsFalse ISDialogMessage (hWndMain, Msg) Then
TranslateMessage Msg
DispatchMessage Msg
End If
End If
Wend
End Function
Function WndProc (ByVal hWnd As Dword, ByVal wMsg As Dword, ByVal wParam As Dword, ByVal lParam As Long) Export As Long
Local hDC As Dword, pPaint As PAINTSTRUCT, tRect As RECT
Local pnmhdr as NMHDR Ptr
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)
PostQuitMessage 0
Exit Function
'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.
Select Case Lo(Word,wParam)
Case %IDC_Button
Select Case Hi(Word,wParam)
Case %BN_Clicked
? "Clicked"
End Select
End Select
Case %WM_Notify 'by control to its parent window when an event has occurred
pnmhdr = lParam
Select Case @pnmhdr.idFrom 'Control ID
Case %IDC_Button
Select Case @pnmhdr.code 'Notification code
Case %NM_Click 'typical notification code
End Select
End Select
'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)
hDC = wParam
DrawGradient hDC ' Pass the DC of the region to repaint
Function = 1 : Exit Function
Case %WM_Paint 'set when request is made to paint a portion of an application's window.
hDC = BeginPaint(hWnd, pPaint)
GetClientRect hWnd, tRect
SetBkMode hDC, %TRANSPARENT
SetTextColor hDC, %White
DrawText hDC, "SDK is the Way!", -1, tRect, %DT_SINGLELINE Or %DT_CENTER Or %DT_VCENTER
EndPaint hWnd, pPaint
Function = 1 : Exit Function
'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
Function = DefWindowProc(hWnd, wMsg, wParam, lParam) 'if not handled above, pass to Windows default message handler.
End Function
Sub DrawGradient (ByVal hDC As Dword)
Local rectFill As RECT, rectClient As RECT, fStep As Single, hBrush As Dword, lOnBand As Long
GetClientRect WindowFromDC(hDC), rectClient
fStep = rectClient.nbottom / 200
For lOnBand = 0 To 199
SetRect rectFill, 0, lOnBand * fStep, rectClient.nright + 1, (lOnBand + 1) * fStep
hBrush = CreateSolidBrush(RGB(0, 0, 255 - lOnBand))
Fillrect hDC, rectFill, hBrush
DeleteObject hBrush
Next
End Sub
Sub CreateButton
Local WndStyle As Long, hWnd,hInstance As Dword
'create window of existing class "Button"
WndStyle = %WS_TabStop Or %WS_Visible Or %WS_Child Or %BS_DefPushButton
hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
'Control Add Button, hDlg, %IDC_Button,"Push", 50,10,100,20, Style, XStyle Call ButtonProc
hWnd= CreateWindow( _
"Button", _ 'lpClassName pointer to a null-terminated string (any registered name, including predefined system class names).
"Button", _ 'lpWindowName pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
WndStyle, _ 'dwStyle style of window
10, _ 'x initial horizontal position (upper left screen, except for child is relative to parent window's client area)
10, _ 'y initial vertical position (upper left screen, except for child is relative to parent window's client area)
80, _ 'nWidth width in device units
20, _ 'nHeight height in device units
hWndMain, _ 'hWndParent handle to parent window (optional for a pop-up window)
%IDC_Button, _ 'hMenu handle to a menu
hInstance, _ 'handle to instance of the module to be associated with the window
ByVal %Null _ 'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
)
End Sub
http://www.garybeene.com/sw/gbsnippets.htm