Author Topic: UpDown example in OxygenBasic  (Read 1435 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
UpDown example in OxygenBasic
« on: September 23, 2018, 04:24:24 AM »
There is lousy weather today, the TV program is not very interesting and at the moment there are no fruitless attacks in the forum, so I thought I could be a little more productive again.

This is a small example of an UpDown control combined with an edit control. It works very nice and it should be easy to understand this example, even if it is coded in OxygenBasic. It is created in a Main Window via CreateWindowEx, but of course it could be created in a Dialog too.

Code: OxygenBasic
  1. $ filename "UpDown.exe"
  2.  
  3. 'uses rtl32
  4. 'uses rtl64
  5.  
  6. uses WinUtil
  7. sys hInstance=inst
  8.  
  9. % UDM_SETRANGE=1125
  10. % UDM_SETBUDDY=1129
  11. % UDM_GETBUDDY=1130
  12. % UDM_SETPOS32=1137
  13. % UDS_SETBUDDYINT=2
  14. % UDS_ALIGNRIGHT=4
  15. % UDS_ARROWKEYS=32
  16.  
  17. macro makelong(lo,hi) { ( (lo) or ( (hi)<<16 ) ) }
  18.  
  19. function createControl(string ctlclass, string Text, sys hwnd, int id, x,y,w,h, int Style, optional ExStyle=0) as sys
  20.    sys hCtrl
  21.    hCtrl=CreateWindowEx(ExStyle, ctlclass, Text, Style, x,y,w,h,  hWnd, id, hInstance, null)
  22.    if hCtrl=null then mbox "Error: Cannot create " ctlclass
  23.    return hCtrl
  24. end function
  25.  
  26. % ID_Button = 1000
  27. % ID_Buddy  = 1001  'Edit as buddy
  28. % ID_UpDown = 1002
  29.  
  30. ' Initialize common controls.
  31. INITCOMMONCONTROLSEXt icex
  32.     icex.dwSize = sizeof(INITCOMMONCONTROLSEXt)
  33.     icex.dwICC = 0xffff
  34.     InitCommonControlsEx(&icex)
  35.  
  36.  
  37. MainWindow 500,300,WS_OVERLAPPEDWINDOW
  38.  
  39. function WndProc(sys hwnd, uint uMsg, sys wParam, lParam) as sys callback
  40.     sys hButton, hEdit, hUpDown
  41.    
  42.     select uMsg
  43.    
  44.         case WM_CREATE
  45.             SetWindowText(hwnd, "UpDown Example in OxygenBasic")
  46.            
  47.             hButton = CreateControl("Button", "Info", hwnd, ID_Button, 250, 100, 100, 30, WS_CHILD or WS_VISIBLE )
  48.             hEdit   = CreateControl("Edit", "", hwnd, ID_Buddy, 100, 100, 60, 30,
  49.                                     WS_CHILD or WS_VISIBLE or WS_TABSTOP or ES_NUMBER or ES_LEFT or ES_AUTOHSCROLL,
  50.                                     WS_EX_CLIENTEDGE )
  51.             hUpDown = CreateControl("MSCTLS_UPDOWN32", "", hwnd, ID_UpDown, 160, 100, 30, 30,
  52.                                      WS_CHILD or WS_VISIBLE or WS_TABSTOP or WS_BORDER or
  53.                                      UDS_ARROWKEYS or UDS_SETBUDDYINT or UDS_ALIGNRIGHT)
  54.  
  55.             'Set Edit control as Buddy Window
  56.            SendMessage(hUpDown, UDM_SETBUDDY, hEdit, 0)
  57.             'Set Range
  58.            SendMessage(hUpDown, UDM_SETRANGE, 0, makelong(20,-20))
  59.             'Set initial value
  60.            SendMessage(hUpDown, UDM_SETPOS32, 0,1)                                                
  61.  
  62.         case WM_COMMAND
  63.             int id = loword(wParam)
  64.             if id =ID_Button then
  65.                sys hBuddy = SendMessage(GetDlgItem(hwnd,ID_UpDown), UDM_GETBUDDY, 0,0)              
  66.                string text=nuls 32
  67.                GetWindowText(hBuddy, text, 32)
  68.                mbox text
  69.             end if
  70.  
  71.         case WM_CLOSE
  72.             DestroyWindow(hwnd)
  73.        
  74.         case WM_DESTROY
  75.             PostQuitMessage(0)
  76.        
  77.         case else
  78.             return DefWindowProc(hwnd, uMsg, wParam, lParam)
  79.            
  80.     end select
  81.    
  82.     return 0
  83. end function
  84.  
« Last Edit: September 23, 2018, 04:55:45 AM by Arnold »

Charles Pegge

  • Guest
Re: UpDown example in OxygenBasic
« Reply #1 on: September 26, 2018, 03:27:42 AM »
Many thanks for your WinApi examples, Roland.

I have added them to the collection. I hope I've got them all, and the next o2 should be free of the negative equate problem in 64bit binaries.