Author Topic: Windows buttons for 32 and 64 bit IDE - Take 2  (Read 8046 times)

0 Members and 1 Guest are viewing this topic.

Offline mpgcan

  • Newbie
  • Posts: 26
    • View Profile
Windows buttons for 32 and 64 bit IDE - Take 2
« on: October 11, 2021, 06:21:01 am »
With the release of QB64 v2.0  a seperate manifest nolonger required for Windows controls:
"Automatically embeds a manifest file when compiling an exe with $VersionInfo, so that Common Controls v6.0 gets linked at runtime."

Regarding windows controls,  I  found this page  https://www.qb64.org/forum/index.php?topic=3217.msg124966#msg124966  informative and useful. Seems it was never completed which is a shame!  However it is easy to comment and be critical of others, hence  I wrote an upgrade to give something back.

Talking about comments, you will notice  there are several lines that have comments, these are alternatives for doing the same thing. Comment an active line to disable it,  un-comment an alternative line if available to see what it does.

Save the following files and place them in your QB64 folder:

window_controls_7.bas
Code: QB64: [Select]
  1. DefStr A-Z
  2. $VersionInfo:Comments=This uses Controls! 'Creates flat controls remove for 3D
  3. Do: Loop Until _ScreenExists '             before using _WindowHandle or _title
  4. ' A Simple Window for QB64 32 & 64 bit
  5. ' window_controls_7.bas
  6. ' MPG 30-9-2021
  7. '
  8. '---------------------------------------------------------------
  9. 'NOTE:
  10. 'Create a new file WIN.h with the following content (Remove the comments '):
  11. '---Start of file contents:---
  12. 'ptrszint FUNC_WINDOWPROC(ptrszint*_FUNC_WINDOWPROC_OFFSET_HWND,uint32*_FUNC_WINDOWPROC_ULONG_UMSG,uptrszint*_FUNC_WINDOWPROC_UOFFSET_WPARAM,ptrszint*_FUNC_WINDOWPROC_OFFSET_LPARAM);
  13.  
  14. 'LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  15. ' return FUNC_WINDOWPROC((ptrszint *) (& hwnd), & uMsg, & wParam, (ptrszint *) (& lParam));
  16. '}
  17.  
  18. 'void * GetWindowProc() {
  19. ' return (void *) WindowProc;
  20. '}
  21. '---End of file contents---
  22. 'Your program uses the WIN.h file to get the WindowProc. Note: Place above file in your working folder (The QB64 folder).
  23. '----------------------------------------------------------------
  24.  
  25. '--Constants
  26.      
  27. Const IDC_ARROW = &H7F00
  28. Const COLOR_WINDOW = 5
  29.  
  30. Const WS_OVERLAPPED = 0
  31. Const WS_EX_CLIENTEDGE = &H00000200
  32. Const WS_CAPTION = &H00C00000
  33. Const WS_SYSMENU = &H00080000
  34. Const WS_THICKFRAME = &H00040000
  35. Const WS_MINIMIZEBOX = &H00020000
  36. Const WS_MAXIMIZEBOX = &H00010000
  37. Const WS_VSCROLL = &H00200000
  38. Const WS_HSCROLL = &H00100000
  39. 'Const WS_OVERLAPPEDWINDOW = WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX
  40. Const WS_OVERLAPPEDWINDOW = WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU
  41. Const WS_TABSTOP = &H00010000
  42. Const WS_VISIBLE = &H10000000
  43. Const WS_CHILD = &H40000000
  44. Const WS_GROUP = &H00020000
  45.  
  46. Const CW_USEDEFAULT = &H80000000
  47.  
  48. Const WM_CLOSE = &H0010
  49. Const WM_CREATE = 1
  50. Const WM_DESTROY = 2
  51. Const WM_COMMAND = &H0111
  52. Const WM_SETTEXT = &H000C
  53. Const WM_GETTEXT = &H000D
  54.  
  55. Const SW_SHOWDEFAULT = &HA
  56.  
  57. Const BS_PUSHBUTTON = 0 '     Standard button
  58. Const BS_AUTOCHECKBOX = 3 '   Multi-Checkbox button
  59. Const BN_CLICKED = 0
  60. Const BS_RADIOBUTTON = 4 '     Single Radio button
  61. Const BS_AUTORADIOBUTTON = 9 ' Multi-radio buttons
  62. Const BS_GROUPBOX = 7 '        Group box "eye candy"
  63.  
  64. Const BM_GETCHECK = &HF0
  65. Const BST_CHECKED = &H1
  66. Const BM_CLICK = &H00F5
  67. Const BM_SETCHECK = &HF1
  68.  
  69. Const ES_LEFT = 0
  70. Const EM_SETPASSWORDCHAR = &HCC
  71.  
  72. Const ES_NUMBER = &H2000
  73. Const ES_PASSWORD = &H0020
  74.  
  75. Const ES_MULTILINE = 4
  76. Const ES_AUTOVSCROLL = &H0040
  77. Const ES_AUTOHSCROLL = &H0080
  78. Const ES_WANTRETURN = &H1000
  79.  
  80.  
  81. '--Types
  82.     As Long x
  83.     As Long y
  84.  
  85. Type MSG
  86.     As _Offset hwnd
  87.     As _Unsigned Long message
  88.     As _Unsigned _Offset wParam 'unsigned pointer sized integer
  89.     As _Offset lParam 'pointer sized integer
  90.     As _Unsigned Long time
  91.     As POINT pt
  92.  
  93. Type WNDCLASSA
  94.     As _Unsigned Long style
  95.     $If 64BIT Then
  96.         As String * 4 padding
  97.     $End If
  98.  
  99.     As _Offset lpfnWndProc
  100.     As Long cbClsExtra, cbWndExtra
  101.     As _Offset hInstance, hIcon, hCursor, hbrBackground, lpszMenuName, lpszClassName
  102.  
  103. '--Libaries
  104.     Function GetWindowProc%& ()
  105.  
  106.     Function SendMessageA%& (ByVal hWnd As _Offset, Byval Msg As _Unsigned Long, Byval wParam As _Unsigned _Offset, Byval lParam As _Offset)
  107.     Function DefWindowProcA%& (ByVal hWnd As _Offset, Byval Msg As _Unsigned Long, Byval wParam As _Unsigned _Offset, Byval lParam As _Offset)
  108.     Sub PostQuitMessage (ByVal nExitCode As Long)
  109.     Function LoadCursorW%& (ByVal hInstance As _Offset, Byval lpCursorName As _Offset)
  110.     Function RegisterClassA~% (ByVal lpWndClass As _Offset)
  111.     Function CreateWindowExA%& (ByVal dwExStyle As Long, Byval lpClassName As _Offset, Byval lpWindowName As _Offset, Byval dwStyle As Long, Byval X As Long, Byval Y As Long, Byval nWidth As Long, Byval nHeight As Long, Byval hWndParent As _Offset, Byval hMenu As _Offset, Byval hInstance As _Offset, Byval lpParam As _Offset)
  112.     Function ShowWindow& (ByVal hWnd As _Offset, Byval nCmdShow As Long)
  113.     Function UpdateWindow& (ByVal hWnd As _Offset)
  114.     Function GetMessageA% (ByVal lpMsg As _Offset, Byval hWnd As _Offset, Byval wMsgFilterMin As _Unsigned Long, Byval wMsgFilterMax As _Unsigned Long)
  115.     Function TranslateMessage& (ByVal lpMsg As _Offset)
  116.     Function DispatchMessageA%& (ByVal lpmsg As _Offset)
  117.     Sub DestroyWindow (ByVal hWnd As _Offset)
  118.     Function PostMessageA%& (ByVal hWnd As _Offset, Byval Msg As _Unsigned Long, Byval wParam As _Unsigned _Offset, Byval lParam As _Offset)
  119.     Function SetWindowTextA& (ByVal hWnd As _Offset, Byval lpString As _Offset)
  120.     Function GetWindowLongA& (ByVal hwnd As _Offset, Byval nIndex As Long)
  121.     Function SetWindowLongA& (ByVal hwnd As _Offset, Byval nIndex As Long, Byval dwNewLong As Long)
  122.  
  123.     Function GetModuleHandleW%& (ByVal lpModuleName%&)
  124.     Function GetLastError~& ()
  125.  
  126.  
  127. '--Variables
  128.  
  129. Dim Shared hi As _Offset '   Handle to application instance
  130. Dim Shared wc As WNDCLASSA ' define wc as WNDCLASSEX structure
  131. Dim msg As MSG
  132. Dim Shared hw As _Offset '    Handle to window created
  133.  
  134. Dim Shared hwb0 As _Offset '  Handle to window button created
  135. Dim Shared hwb1 As _Offset '  Handle to window button created
  136. Dim Shared hwb2 As _Offset '  Handle to window button created
  137.  
  138. Dim Shared hwcb0 As _Offset ' Handle to window checkbox button created
  139. Dim Shared hwcb1 As _Offset ' Handle to window checkbox button created
  140. Dim Shared hwcb2 As _Offset ' Handle to window checkbox button created
  141.  
  142. Dim Shared hwgb1 As _Offset ' Handle to group box 1
  143. Dim Shared hwr11 As _Offset ' Handle to window radio botton
  144.  
  145. Dim Shared hwgb2 As _Offset ' Handle to group box 2
  146. Dim Shared hwr21 As _Offset ' Handle to window radio botton
  147.  
  148. Dim Shared hwLabel1 As _Offset
  149. Dim Shared hwLabel2 As _Offset
  150.  
  151. Dim Shared hwe1 As _Offset 'Single line edit control
  152. Dim Shared hwe2 As _Offset 'Multiline edit control
  153. Dim Shared hwLB As _Offset 'Handle to list box
  154. Dim Shared hwCB As _Offset 'Handle to combo drop-down list box
  155.  
  156. Dim Shared discardb As Long 'Dummy variable
  157. Dim Shared discardp As _Offset 'Dummy variable
  158. Dim Shared t0 As String 'Type of component
  159. Dim Shared t1 As String 'Title or componets text
  160. Dim Shared buf1 As String * 64 'Single line edit buffer
  161. Dim Shared buf2 As String * 4096 'Multi line edit buffer
  162.      
  163. Dim Shared MainClassName As String * 5
  164. MainClassName = "main" + Chr$(0)
  165.  
  166. Dim CrLf As String * 2 '    define as 2 byte STRING
  167. CrLf = Chr$(13) + Chr$(10) 'carriage return&line feed
  168.  
  169.  
  170. Dim Shared As String className '       Variable className stores name of our window class
  171. className = "myWindowClass" + Chr$(0) 'Used in wc. which in turn is used to register window class with the system.
  172.  
  173. hi = GetModuleHandleW(0) 'Handle to application instance
  174.  
  175. '---Step 1: Registering the Window Class
  176. 'Fill out the members of WNDCLASSEX structure (wc) and call RegisterClassA
  177.  
  178. wc.style = 0 '                            Class Styles (CS_*), not Window Styles (WS_*) This is usually be set to 0.
  179. wc.lpfnWndProc = GetWindowProc '          Pointer to the window procedure for this window class. (see WIN.h)
  180. wc.cbClsExtra = 0 '                       Amount of extra data allocated for this class in memory. Usually 0.
  181. wc.cbWndExtra = 0 '                       Amount of extra data allocated in memory per window of this type. Usually 0.
  182. wc.hInstance = hi '                       Handle to application instance .
  183. wc.hIcon = 0 '                            Large (usually 32x32) icon shown when the user presses Alt+Tab. Set to 0
  184. wc.hCursor = LoadCursorW(0, IDC_ARROW) '  Cursor that will be displayed over our window.
  185. wc.hbrBackground = COLOR_WINDOW 'was +1   Background Brush to set the color of our window. '
  186. wc.lpszMenuName = 0 '                     Name of a menu resource to use for the windows with this class.
  187. wc.lpszClassName = _Offset(className) '   Name to identify the class with.
  188.  
  189. If RegisterClassA(_Offset(wc)) = 0 Then
  190.     Print "RegisterClassA failed:"; GetLastError
  191.     End
  192.     'Else Print "OK"
  193.  
  194. '--Step 2: Creating the Windows
  195.  
  196. '--Main window
  197. 'After registering the class, create a window with it using CreateWindowExA.
  198.  
  199. 'HWND CreateWindowExA(
  200. '  DWORD     dwExStyle,     0                     Extended windows style. Not used set to 0
  201. '  LPCSTR    lpClassName,  _Offset(className)     Tells the system what kind of window to create.
  202. '  LPCSTR    lpWindowName, _Offset(t1)            Text displayed in the Caption or Title Bar.
  203. '  DWORD     dwStyle,      WS_OVERLAPPEDWINDOW... Window Style parameters see constants
  204. '  int       X,            CW_USEDEFAULT          Top left corner of your window. Let windows choose
  205. '  int       Y,            CW_USEDEFAULT          Top left corner of your window. Let windows choose
  206. '  int       nWidth,       432                    Width and
  207. '  int       nHeight,      400                    height of the window
  208. '  HWND      hWndParent,     0                    No parent window set handle to 0
  209. '  HMENU     hMenu,          0                    Not menu set to 0
  210. '  HINSTANCE hInstance,     hi                    Module instance handle associated with the window.
  211. ' LPVOID    lpParam         0                    Used with MDI child window not used set to 0
  212. ')
  213.  
  214. t1 = "Window Ref 1" + Chr$(0)
  215. 'hw = CreateWindowExA(0, _Offset(className), _Offset(t1), WS_HSCROLL Or WS_OVERLAPPEDWINDOW Or WS_VSCROLL, CW_USEDEFAULT, CW_USEDEFAULT, 432, 400, 0, 0, hi, 0): If 0 = hw Then System
  216. hw = CreateWindowExA(0, _Offset(className), _Offset(t1), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 432, 520, 0, 0, hi, 0): If 0 = hw Then System
  217.  
  218. '--Standard Controls: Button, Edit, List Box etc
  219. 'Controls are just child windows. They have a procedure, a class etc... that is registered by the system.
  220. 'Anything you can do with a normal window you can do with a control.
  221.  
  222. '-Standard Buttons require style BS_PUSHBUTTON
  223.  
  224. t0 = "BUTTON" + Chr$(0) '  Set: Window control is BUTTON predefined class
  225. t1 = "Button 0" + Chr$(0) 'Set: Button display text
  226. hwb0 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_TABSTOP Or WS_VISIBLE Or WS_CHILD Or BS_PUSHBUTTON, 10, 10, 75, 23, hw, 0, hi, 0): If 0 = hwb0 Then System
  227.  
  228. t0 = "BUTTON" + Chr$(0) '  Set: Window control is BUTTON predefined class
  229. t1 = "Button 1" + Chr$(0) 'Set: Button display text
  230. hwb1 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_TABSTOP Or WS_VISIBLE Or WS_CHILD Or BS_PUSHBUTTON, 10, 37, 75, 23, hw, 0, hi, 0): If 0 = hwb1 Then System
  231.  
  232. t0 = "BUTTON" + Chr$(0) '  Set: Window control is BUTTON
  233. t1 = "Button 2" + Chr$(0) 'Set: Button display text
  234. hwb2 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_TABSTOP Or WS_VISIBLE Or WS_CHILD Or BS_PUSHBUTTON, 10, 64, 75, 23, hw, 0, hi, 0): If 0 = hwb2 Then System
  235.  
  236. '-Checkbox Buttons require style BS_AUTOCHECKBOX
  237. t0 = "BUTTON" + Chr$(0) '  Set: Window control is BUTTON
  238. t1 = "ChkBox0" + Chr$(0) 'Check box label display text
  239. hwcb0 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_TABSTOP Or WS_VISIBLE Or WS_CHILD Or BS_AUTOCHECKBOX, 10, 91, 90, 23, hw, 0, hi, 0): If 0 = hwcb0 Then System
  240.  
  241. t0 = "BUTTON" + Chr$(0) '  Set: Window control is BUTTON
  242. t1 = "ChkBox1" + Chr$(0) 'Check box label display text
  243. hwcb1 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_TABSTOP Or WS_VISIBLE Or WS_CHILD Or BS_AUTOCHECKBOX, 10, 118, 90, 23, hw, 0, hi, 0): If 0 = hwcb1 Then System
  244.  
  245. t0 = "BUTTON" + Chr$(0) '  Set: Window control is BUTTON
  246. t1 = "ChkBox2" + Chr$(0) 'Check box label display text
  247. hwcb2 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_TABSTOP Or WS_VISIBLE Or WS_CHILD Or BS_AUTOCHECKBOX, 10, 145, 90, 23, hw, 0, hi, 0): If 0 = hwcb2 Then System
  248.  
  249.  
  250. 'Standard Radio Buttons require style BS_RADIOBUTTON (single) or BS_AUTORADIOBUTTON (group)
  251. 'First button of a group must have following styles WS_TABSTOP WS_GROUP
  252. 'The first control after last group must have style WS_GROUP to terminate last group
  253. 'Note: A BS_GROUPBOX is "eye candy" and does not contribute to a radio box group.
  254. ' The crucial parameter to control radio or check box grouping is the style WS_GROUP
  255.  
  256. '--Bank 1: Group box1
  257. t0 = "BUTTON" + Chr$(0) 'predefined class
  258. t1 = "Group box1" + Chr$(0)
  259. hwgb1 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_VISIBLE Or WS_CHILD Or BS_GROUPBOX, 100, 10, 300, 50, hw, 0, hi, 0): If 0 = hwgb1 Then System
  260. t1 = "Radio 11" + Chr$(0)
  261. hwr11 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_VISIBLE Or WS_CHILD Or BS_AUTORADIOBUTTON Or WS_TABSTOP Or WS_GROUP, 105, 30, 90, 23, hw, 0, hi, 0): If 0 = hwr11 Then System
  262. t1 = "Radio 12" + Chr$(0)
  263. hwr12 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_VISIBLE Or WS_CHILD Or BS_AUTORADIOBUTTON, 200, 30, 90, 23, hw, 0, hi, 0): If 0 = hwr12 Then System
  264. t1 = "Radio 12" + Chr$(0)
  265. hwr13 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_VISIBLE Or WS_CHILD Or BS_AUTORADIOBUTTON, 300, 30, 90, 23, hw, 0, hi, 0): If 0 = hwr13 Then System
  266.  
  267. '--Bank 2: Group box2
  268. t0 = "BUTTON" + Chr$(0) 'predefined class
  269. t1 = "Group box2" + Chr$(0)
  270. hwgb2 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_VISIBLE Or WS_CHILD Or BS_GROUPBOX, 100, 70, 300, 50, hw, 0, hi, 0): If 0 = hwgb2 Then System
  271. t1 = "Radio 21" + Chr$(0)
  272. hwr21 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_VISIBLE Or WS_CHILD Or BS_AUTORADIOBUTTON Or WS_TABSTOP Or WS_GROUP, 105, 90, 90, 23, hw, 0, hi, 0): If 0 = hwr21 Then System
  273. t1 = "Radio 22" + Chr$(0)
  274. hwr22 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_VISIBLE Or WS_CHILD Or BS_AUTORADIOBUTTON, 200, 90, 90, 23, hw, 0, hi, 0): If 0 = hwr22 Then System
  275. t1 = "Radio 23" + Chr$(0)
  276. hwr23 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_VISIBLE Or WS_CHILD Or BS_AUTORADIOBUTTON, 300, 90, 90, 23, hw, 0, hi, 0): If 0 = hwr23 Then System
  277.  
  278. '--Label1
  279. t0 = "STATIC" + Chr$(0) 'predefined class
  280. t1 = "Label1 Enter your score:" + Chr$(0)
  281. hwLabel1 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_VISIBLE Or WS_CHILD, 100, 125, 372, 16, hw, 0, hi, 0): If 0 = hwLabel1 Then System
  282.  
  283. '--Label2
  284. t0 = "STATIC" + Chr$(0) 'predefined class
  285. t1 = "Label2 Enter your name:" + Chr$(0)
  286. hwLabel2 = CreateWindowExA(0, _Offset(t0), _Offset(t1), WS_VISIBLE Or WS_CHILD, 100, 142, 372, 16, hw, 0, hi, 0): If 0 = hwLabel2 Then System
  287.  
  288. '--Edit single line
  289.  
  290. t0 = "EDIT" + Chr$(0) 'predefined class
  291. t1 = "This is a edit control." + Chr$(0)
  292. hwe1 = CreateWindowExA(WS_EX_CLIENTEDGE, _Offset(t0), _Offset(t1), WS_TABSTOP Or WS_VISIBLE Or WS_CHILD Or ES_LEFT, 12, 175, 372, 26, hw, 0, hi, 0): If 0 = hwe1 Then System
  293.  
  294. '---Edit  multiline control
  295.  
  296. t0 = "EDIT" + Chr$(0) 'predefined class
  297. t1 = "This is a" + CrLf + "multiline edit control." + CrLf + "Click in me and type." + CrLf + "It should scroll automatically in both directions, but there aren't any scroll bars." + CrLf + "Close the window to see the text printed to the console." + Chr$(0)
  298. hwe2 = CreateWindowExA(WS_EX_CLIENTEDGE, _Offset(t0), _Offset(t1), WS_VSCROLL Or WS_HSCROLL Or WS_TABSTOP Or WS_VISIBLE Or WS_CHILD Or ES_AUTOHSCROLL Or ES_AUTOVSCROLL Or ES_LEFT Or ES_MULTILINE Or ES_WANTRETURN, 10, 210, 400, 120, hw, 0, hi, 0): If 0 = hwe2 Then System
  299.  
  300. '---List box control
  301. Const LBS_NOTIFY = 1
  302. t0 = "LISTBOX" + Chr$(0) 'predefined class
  303. hwLB = CreateWindowExA(WS_EX_CLIENTEDGE, _Offset(t0), 0, WS_CHILD Or WS_VISIBLE Or LBS_NOTIFY Or WS_VSCROLL Or ES_AUTOVSCROLL, 10, 340, 150, 120, hw, 0, hi, 0): If 0 = hwLB Then System
  304.  
  305. '---Combo drop-down List control
  306. Const CBS_READONLY = &H1000 'Remove to edit selection
  307. Const CBS_NOTIFY = &H0008
  308. Const CBS_DROPDOWN = 2
  309. Const CBS_DROPDOWNLIST = 3
  310. t0 = "COMBOBOX" + Chr$(0) 'predefined class
  311. hwCB = CreateWindowExA(WS_EX_CLIENTEDGE, _Offset(t0), 0, WS_CHILD Or WS_VISIBLE Or CBS_DROPDOWNLIST Or CBS_READONLY, 170, 340, 150, 110, hw, 0, hi, 0): If 0 = hwCB Then System
  312.  
  313. '--hwCB Add items to combo box
  314. Const CB_ADDSTRING = 323
  315. For j = 1 To 10
  316.     t0 = "Combo box Item" + Str$(j) + Chr$(0)
  317.     discardp = SendMessageA(hwCB, CB_ADDSTRING, 0, _Offset(t0)) ' Add text
  318. '--End hwCB Add items to combo box
  319.  
  320. '--hwCB Initialize combo control default selection. Note -1 no selection
  321. Dim Shared CB_selected_item As Long 'Ref selection
  322. CB_selected_item = 7 'set initial selection value
  323.  
  324. 'Zero index. Note index 2 selects the third element
  325. Const CB_SETCURSEL = 334 'Set selection
  326. discardp = SendMessageA(hwCB, CB_SETCURSEL, CB_selected_item, 0)
  327. 'discardp = SendMessageA(hwCB, CB_SETCURSEL, -1, 0) 'No selection
  328. '---End combo control
  329.  
  330.  
  331. '--hwLB Add items to list box
  332. Const LB_ADDSTRING = &H180
  333. For i = 1 To 10
  334.     t0 = "List Box Item" + Str$(i) + Chr$(0)
  335.     discardp = SendMessageA(hwLB, LB_ADDSTRING, 0, _Offset(t0)) ' Add text
  336. '--End hwLB Add items to list box
  337.  
  338. '--hwLB Initialize list control default selection. Note -1 no selection
  339. 'Zero index. Note index 2 selects the third element
  340. Const LB_SETCURSEL = &H186 'Set selection
  341. Dim Shared LB_selected_item As Long 'Ref selection
  342. LB_selected_item = 8 'set initial selection value
  343. discardp = SendMessageA(hwLB, LB_SETCURSEL, LB_selected_item, 0)
  344. 'discardp = SendMessageA(hwLB, LB_SETCURSEL, -1, 0) 'No selection
  345. '---End list control
  346.  
  347. '--Initialize set initial conditions
  348. discardp = SendMessageA(hwcb1, BM_SETCHECK, BST_CHECKED, 0) 'Set check box
  349. discardp = SendMessageA(hwr13, BM_SETCHECK, BST_CHECKED, 0) 'Set radio button
  350. discardp = SendMessageA(hwr23, BM_SETCHECK, BST_CHECKED, 0) 'Set radio button
  351.  
  352. t0 = "CLOSE" + Chr$(0) '  Text to send to buttton Button2
  353. 'discardp = SetWindowTextA&(hwb2, _Offset(t0)) '             Method 1 Change button text from Button2 to Close
  354. discardp = SendMessageA(hwb2, WM_SETTEXT, 0, _Offset(t0)) '  Method 2 Alternative
  355.  
  356. t0 = "Label2 text changed ?" + Chr$(0) '    Text to send to Label2
  357. 'discardp = SetWindowTextA&(hwLabel2, _Offset(t0)) '             Method 1
  358. discardp = SendMessageA(hwLabel2, WM_SETTEXT, 0, _Offset(t0)) ' Method 2 Alternative
  359.  
  360. t0 = "Edit control:" + Chr$(0) '             Text to send to Edit control
  361. 'discardp = SetWindowTextA&(hwe1, _Offset(t0)) '            Method 1
  362. discardp = SendMessageA(hwe1, WM_SETTEXT, 0, _Offset(t0)) ' Method 2 Alternative
  363.  
  364. 'discardp = SendMessageA(hwe1, EM_SETPASSWORDCHAR, 0, 0) '        Edit control Remove password character
  365. 'discardp = SendMessageA(hwe1, EM_SETPASSWORDCHAR, Asc("*"), 0) ' Edit control Set password character
  366.  
  367. 'Dim Shared winstyle As Long 'current window style variable
  368. Const GWL_STYLE = -16 'Window style command
  369.  
  370. 'winstyle = GetWindowLongA(hwe1, GWL_STYLE)
  371. 'discardp = SetWindowLongA(hwe1, GWL_STYLE, winstyle Or ES_NUMBER) '     Add number style
  372.  
  373. 'winstyle = GetWindowLongA(hwe1, GWL_STYLE)
  374. 'discardp = SetWindowLongA(hwe1, GWL_STYLE, winstyle And Not ES_NUMBER) 'Remove number style
  375.  
  376. '--End Initialize set initial conditions
  377.  
  378. '----How to set top/bottom margins of a Win32 Edit control "hwe2"
  379.     Function GetWindowRect& (ByVal hWnd As _Offset, Byval lpRect As _Offset)
  380.     Function GetClientRect& (ByVal hWnd As _Offset, Byval lpRect As _Offset)
  381.     Function InflateRect& (ByVal lpRect As _Offset, Byval x As Long, Byval y As Long)
  382. Type RECT
  383.     As Long left, top, right, bottom
  384. Dim As RECT rect
  385. Const EM_SETRECT = &H00B3
  386. If GetClientRect(hwe2, _Offset(rect)) Then
  387.     Print rect.left, rect.top, rect.right, rect.bottom
  388.  
  389.     If InflateRect(_Offset(rect), -5, -5) Then
  390.         Print rect.left, rect.top, rect.right, rect.bottom
  391.         ' Edit control set margin
  392.         If SendMessageA(hwe2, EM_SETRECT, 0, _Offset(rect)) Then ' Edit control set margin
  393.             Print "margin set hwe2"
  394.         End If
  395.     End If
  396.  
  397.  
  398. 'Display and Update window to ensure it has properly redrawn itself on the screen.
  399. discardb = ShowWindow(hw, SW_SHOWDEFAULT)
  400. discardb = UpdateWindow(hw)
  401.  
  402. '-- Step 3: The Message Loop
  403. While GetMessageA(_Offset(msg), 0, 0, 0) > 0 '   gets a message from your application's message queue.
  404.     discardb = TranslateMessage(_Offset(msg)) '  performs some additional processing on keyboard events
  405.     discardp = DispatchMessageA(_Offset(msg)) '  sends the message out to the window that the message was sent to
  406.  
  407.  
  408. Print "End"
  409. '####== End program ==###
  410.  
  411. '-- Step 4: the Window Procedure
  412. Function WindowProc%& (hWnd As _Offset, uMsg As _Unsigned Long, wParam As _Unsigned _Offset, lParam As _Offset)
  413.     Dim As String a, srch, replace
  414.  
  415.     Select Case uMsg
  416.  
  417.         ' Case WM_CREATE
  418.         '     WindowProc = 0
  419.  
  420.         Case WM_CLOSE
  421.             discardp = SendMessageA(hwe2, WM_GETTEXT, Len(buf2), _Offset(buf2)) 'Get text
  422.             Print: Print "First part of the edit control text:": Print
  423.  
  424.             a$ = _Trim$(buf2) '                      Remove spaces
  425.             a$ = Left$(a$, InStr(a$, Chr$(0)) - 1) ' Buffer contains a null terminated string. Find position of null.
  426.             buf2 = "" '                              Extract characters upto this null character. Clear buffer
  427.  
  428.             '----Remove unwanted CRLF---
  429.             srch$ = Chr$(13) + Chr$(10)
  430.             replace$ = Chr$(10)
  431.             Do While InStr(a$, srch$)
  432.                 a$ = Mid$(a$, 1, InStr(a$, srch$) - 1) + replace$ + Mid$(a$, InStr(a$, srch$) + Len(srch$))
  433.             Loop
  434.             '-----END remove-------------
  435.  
  436.  
  437.             Print a$
  438.  
  439.             Print "Radio 11: 0x"; Hex$(SendMessageA(hwr11, BM_GETCHECK, 0, 0))
  440.             Print "Radio 12: 0x"; Hex$(SendMessageA(hwr12, BM_GETCHECK, 0, 0))
  441.             If SendMessageA(hwcb1, BM_GETCHECK, 0, 0) = BST_CHECKED Then
  442.                 Print: Print "Check box is checked:": Print
  443.             End If
  444.  
  445.  
  446.             DestroyWindow (hWnd) 'Destroy window and child windows
  447.             WindowProc = 0
  448.  
  449.         Case WM_DESTROY
  450.             PostQuitMessage 0 'Want to exit the program
  451.             WindowProc = 0
  452.  
  453.         Case WM_COMMAND
  454.             '===============
  455.  
  456.             '---Respond to Listbox selection
  457.             Const LBN_SELCHANGE = 1
  458.             Const LB_GETCURSEL = &H188 ' get index of currently selected item in listbox
  459.             Const LB_GETTEXT = &H189 '   get selected item text
  460.  
  461.             Dim LBwParm As Long
  462.             Dim selectedIndexLB As _Offset 'item selected returned as offset
  463.             Dim tempLB As Long '            temp variable
  464.             Dim textBuffLB As String * 32 ' Buffer to store selected string
  465.  
  466.             LBwParm = ConvertOffset&&(wParam) ' Convert to long
  467.  
  468.             'listbox hwLB selection changed
  469.             If (HIWORD(LBwParm) = LBN_SELCHANGE) And (lParam = hwLB) Then
  470.                 selectedIndexLB = SendMessageA(hwLB, LB_GETCURSEL, 0, 0) 'Get current selection
  471.                 tempLB = ConvertOffset&&(selectedIndexLB) '               convert to long
  472.                 '--Get item text store in buffer
  473.                 discardp = SendMessageA(hwLB, LB_GETTEXT, tempLB, _Offset(textBuffLB))
  474.  
  475.                 Print "LBzzzzzzz", LBwParm, HIWORD(LBwParm)
  476.                 Print "List box selection = "; tempLB
  477.                 Print textBuffLB
  478.                 WindowProc = 0
  479.             End If
  480.             '---End Respond to Listbox selection
  481.  
  482.  
  483.             '---Respond to Combo Listbox selection
  484.             Const CBN_SELCHANGE = 1
  485.             Const CB_GETCURSEL = 327 ' get index of currently selected item in combo listbox
  486.             Const CB_GETLBTEXT = 328 ' get selected item text
  487.  
  488.             Dim CBwParm As Long
  489.             Dim selectedIndexCB As _Offset 'item selected returned as offset
  490.             Dim tempCB As Long '            temp variable
  491.             Dim textBuffCB As String * 32 ' Buffer to store selected string
  492.  
  493.             CBwParm = ConvertOffset&&(wParam) 'Convert to long
  494.  
  495.             'Combo listbox hwCB selection changed
  496.             If (HIWORD(CBwParm) = CBN_SELCHANGE) And (lParam = hwCB) Then
  497.                 selectedIndexCB = SendMessageA(hwCB, CB_GETCURSEL, 0, 0) 'Get current selection
  498.                 tempCB = ConvertOffset&&(selectedIndexCB) '               convert to long
  499.                 '--Get item text store in buffer
  500.                 discardp = SendMessageA(hwCB, CB_GETLBTEXT, tempCB, _Offset(textBuffCB))
  501.  
  502.                 Print "CBxxxxxx", LBwParm, HIWORD(LBwParm)
  503.                 Print "Combo box selection = "; tempCB
  504.                 Print textBuffCB
  505.                 WindowProc = 0
  506.             End If
  507.             '---End Respond to Combo Listbox selection
  508.  
  509.  
  510.             '=====================
  511.             If wParam = BN_CLICKED Then
  512.                 Select Case lParam
  513.                     'A button was clicked test each one
  514.  
  515.                     '---Three standard buttons---
  516.                     Case hwb0
  517.                         Print "Button 0 pressed"
  518.                         WindowProc = 0
  519.                     Case hwb1
  520.                         'Get input text and copy to buffer (1)
  521.  
  522.                         discardp = SendMessageA(hwe1, WM_GETTEXT, Len(buf1), _Offset(buf1)) 'Read text from Edit control into buf1
  523.                         Print "Button 1 pressed"
  524.                         a$ = Left$(buf1, InStr(buf1, Chr$(0)) - 1) 'Buffer contains a null terminated string. Find position of null.
  525.                         Print "Button 1 pressed. Text read from edit control: ### " + a$ + " ###" '                  Extract characters upto this null character.
  526.                         buf1 = "" '                                 Clear buffer
  527.  
  528.                         WindowProc = 0
  529.                     Case hwb2
  530.                         Print "Button 2 pressed Also used as close button"
  531.                         discardp = PostMessageA(hWnd, WM_CLOSE, 0, 0) 'Use a button close Close
  532.                         WindowProc = 0
  533.                         '---End standard buttons---
  534.  
  535.                         '---Three checkbox standard buttons---
  536.                     Case hwcb0
  537.                         Print "Check box 0 click"
  538.                         If SendMessageA(hwcb0, BM_GETCHECK, 0, 0) = BST_CHECKED Then
  539.                             Print "Check box 0 is checked:"
  540.                         Else
  541.                             Print "Check box 0 is un-checked:"
  542.                         End If
  543.                         WindowProc = 0
  544.                     Case hwcb1
  545.                         Print "Check box 1 click"
  546.                         WindowProc = 0
  547.                     Case hwcb2
  548.                         Print "Check box 2 click"
  549.                         WindowProc = 0
  550.                         '---End checkbox standard buttons---
  551.  
  552.                         '---Bank 1 - Radio buttons---
  553.                     Case hwr11
  554.                         Print "Radio 11 clicked"
  555.                         WindowProc = 0
  556.                     Case hwr12
  557.                         Print "Radio 12 clicked"
  558.                         WindowProc = 0
  559.                     Case hwr13
  560.                         Print "Radio 13 clicked"
  561.                         WindowProc = 0
  562.                         '---End Bank 1 - Radio buttons---
  563.  
  564.                         '---Bank 2 - Radio buttons---
  565.                     Case hwr21
  566.                         Print "Radio 21 clicked"
  567.                         If SendMessageA(hwr21, BM_GETCHECK, 0, 0) = BST_CHECKED Then
  568.                             Print: Print "Button Radio 21 is checked:": Print
  569.                         End If
  570.                         WindowProc = 0
  571.                     Case hwr22
  572.                         Print "Radio 22 clicked"
  573.                         WindowProc = 0
  574.                     Case hwr23
  575.                         Print "Radio 23 clicked"
  576.  
  577.                         '---End Bank 2 - Radio buttons---
  578.  
  579.                 End Select
  580.             Else
  581.                 'Not our message send back to system for processing
  582.                 WindowProc = DefWindowProcA(hWnd, uMsg, wParam, lParam)
  583.             End If
  584.  
  585.             WindowProc = DefWindowProcA(hWnd, uMsg, wParam, lParam)
  586.         Case Else
  587.             'Not our message send back to system for processing
  588.             WindowProc = DefWindowProcA(hWnd, uMsg, wParam, lParam)
  589.     End Select
  590.  
  591. Function ConvertOffset&& (value As _Offset)
  592.     Dim m As _MEM 'Define a memblock
  593.     m = _Mem(value) 'Point it to use value
  594.     $If 64BIT Then
  595.         Dim temp As _Integer64
  596.         'On 64 bit OSes, an OFFSET is 8 bytes in size.  We can put it directly into an Integer64
  597.         _MemGet m, m.OFFSET, temp
  598.         ConvertOffset = temp
  599.     $Else
  600.         Dim temp As Long
  601.         'However, on 32 bit OSes, an OFFSET is only 4 bytes.  We need to put it into a LONG variable first
  602.         _MemGet m, m.OFFSET, temp 'Like this
  603.         ConvertOffset = temp 'And then assign that long value to ConvertOffset&&
  604.     $End If
  605.     _MemFree m 'Free the memblock
  606.  
  607. Function HIWORD% (dw As Long)
  608.     If dw And &H80000000 Then
  609.         HIWORD = (dw \ 65535) - 1
  610.     Else
  611.         HIWORD = dw \ 65535
  612.     End If
  613.  
  614. Function LOWORD% (dw As Long)
  615.     If dw And &H8000& Then
  616.         LOWORD = &H8000 Or (dw And &H7FFF&)
  617.     Else
  618.         LOWORD = dw And &HFFFF&
  619.     End If
  620.  
WIN.h
Code: QB64: [Select]
  1. ptrszint FUNC_WINDOWPROC(ptrszint*_FUNC_WINDOWPROC_OFFSET_HWND,uint32*_FUNC_WINDOWPROC_ULONG_UMSG,uptrszint*_FUNC_WINDOWPROC_UOFFSET_WPARAM,ptrszint*_FUNC_WINDOWPROC_OFFSET_LPARAM);
  2.  
  3. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  4.  return FUNC_WINDOWPROC((ptrszint *) (& hwnd), & uMsg, & wParam, (ptrszint *) (& lParam));
  5. }
  6.  
  7. void * GetWindowProc() {
  8.  return (void *) WindowProc;
  9. }
  10.  
Result shown below:
 
window_controls_7.png


Note: For an example of subclassing a control see the edit control on the following page: https://www.qb64.org/forum/index.php?topic=4111.msg136749#msg136749




Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Windows buttons for 32 and 64 bit IDE - Take 2
« Reply #1 on: October 11, 2021, 08:05:40 am »
You're doing excellent work, @mpgcan !
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Windows buttons for 32 and 64 bit IDE - Take 2
« Reply #2 on: October 11, 2021, 09:46:04 am »
Wow multi-line edit control, my holy grail! So is this like GUI in about 1K LOC?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Windows buttons for 32 and 64 bit IDE - Take 2
« Reply #3 on: October 11, 2021, 10:05:44 am »
I am trying out code way over my head, what's this about?
Quote
In file included from ..\\temp\\regsf.txt:1,
                 from qbx.cpp:1131:
..\\temp\\..\\..\\win.h: In function 'LRESULT WindowProc(HWND, UINT, WPARAM, LPARAM)':
..\\temp\\..\\..\\win.h:4:2: error: 'RETURN' was not declared in this scope
  RETURN FUNC_WINDOWPROC((ptrszint *) (& hwnd), & uMsg, & wParam, (ptrszint *) (& lParam));
  ^~~~~~
compilation terminated due to -Wfatal-errors.


FellippeHeitor

  • Guest
Re: Windows buttons for 32 and 64 bit IDE - Take 2
« Reply #4 on: October 11, 2021, 10:07:58 am »
mpg can added the c++ code above in a QB64 code box, which turned "return" into "RETURN". That's the problem.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Windows buttons for 32 and 64 bit IDE - Take 2
« Reply #5 on: October 11, 2021, 10:28:47 am »
@mpgcan

This is absolutely famous. Perfect. Useful. As soon as I finish my work, I will study your code. The first compilation did not work correctly because the C ++ code for the win.h file is inserted as QB64 source code and has been formatted, which is not possible because C ++ is known to be case sensitive. I had to take a source block in C ++ in the source code with QB64 and uncomment it in the editor and then save it as win.h

Then the compilation went smoothly in the latest IDE QB64 2.0

Good job. Thanks for sharing.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Windows buttons for 32 and 64 bit IDE - Take 2
« Reply #6 on: October 11, 2021, 10:53:24 am »
Holy controls! I can copy/paste from Multi-Edit Control to here!!!

Quote
Hi Petr and Fellippe, thanks to your clues
I got this baby going!
I am very pleased to see this control works.
Now how do I get these contents into my QB64 program?
And what is the Console Screen telling me?

 
Testing Win Ctls have question.PNG

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Windows buttons for 32 and 64 bit IDE - Take 2
« Reply #7 on: October 11, 2021, 10:54:45 am »
PS how do you like my new IDE colors for V2.0?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Windows buttons for 32 and 64 bit IDE - Take 2
« Reply #8 on: October 11, 2021, 11:26:30 am »
@bplus wrote:
Quote
PS how do you like my new IDE colors for V2.0?

You have it nice :) i use dark blue scheme.

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: Windows buttons for 32 and 64 bit IDE - Take 2
« Reply #9 on: October 11, 2021, 11:31:43 am »
Very nice...
It looks to me like when i started to work on my windows include "awinh.inc" read same as .h files
ok..i am going to testing...
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Windows buttons for 32 and 64 bit IDE - Take 2
« Reply #10 on: October 11, 2021, 11:35:28 am »
I see too much blue already hanging out with johnn56 ;-))

@Petr thanks to your help, I tried the input_box again from what I learned here and got that going too!

I have learned along with .h files, .BI and .BM files can be stored in QB64.exe folder and source bas like the dem,bas file in separate folder bare naked, no support un-pathed .BI and .BM, and no need to path those either.

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: Windows buttons for 32 and 64 bit IDE - Take 2
« Reply #11 on: October 11, 2021, 11:42:07 am »
Quote
The first compilation did not work correctly because the C ++ code for the win.h file is inserted as QB64 source code and has been formatted, which is not possible because C ++ is known to be case sensitive. I had to take a source block in C ++ in the source code with QB64 and uncomment it in the editor and then save it as win.h

I saved C++ code as win.h...but compilation still not work ...
i will try with lower case win.h..to see is that problem ..hmmm
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: Windows buttons for 32 and 64 bit IDE - Take 2
« Reply #12 on: October 11, 2021, 11:46:38 am »
oh gee i don't get it C++
ahh i see i need to add return in lower case
( i am not sure that C have return but ok )

now is compiled..!!
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: Windows buttons for 32 and 64 bit IDE - Take 2
« Reply #13 on: October 11, 2021, 11:52:44 am »
oh..this is a type of programming i am familiar with
cool it work well...if i catch time i will try to add richEdit
(i am not sure but it looks that is used old WindowClassA older version but work)
qb64_1v5_Win_Gui.png
* qb64_1v5_Win_Gui.png (Filesize: 208.55 KB, Dimensions: 1263x911, Views: 125)
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Windows buttons for 32 and 64 bit IDE - Take 2
« Reply #14 on: October 11, 2021, 11:56:48 am »
@Aurel you have an AurelEdit version for QB64? well from screen shot I guess so. :)