Ooops
November 28, 2020, 02:21:01 AM

Author Topic: [bmx] DateTimePicker by Henri [ 1+ years ago ]  (Read 517 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] DateTimePicker by Henri [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : DateTimePicker
Author : Henri
Posted : 1+ years ago

Description : Standard DateTime picker for Windows. Provided 'as is'. See code for example.

Code :
Code: BlitzMax
  1. Strict
  2.  
  3. Import maxgui.drivers
  4.  
  5. Extern "win32"
  6.         Function GetModuleHandle:Int (lpmodulehandlename:Byte Ptr)="GetModuleHandleW@4"
  7.         Function CreateWindowEx:Int (dwExstyle:Int,lpclassname:Byte Ptr,lpwindowname:Byte Ptr,dwStyle:Int,x:Int,y:Int,..
  8.                                                                 w:Int,h:Int,hwndparent:Int,hmenu:Int,hinstance:Int,lpparam:Int)="CreateWindowExA@48"
  9.         Function GetDateFormatA:Int(lpLocaleName:Int, dwFlags:Int,lpDate:Int,lpFormat:Byte Ptr,..
  10.                                                                 lpDateStr:Byte Ptr,cchDate:Int)
  11. End Extern
  12.  
  13. Const DATETIMEPICK_CLASSW:String        = "SysDateTimePick32"
  14. Const MONTHCAL_CLASSW:String            = "SysMonthCal32"
  15. Const DTM_GETSYSTEMTIME:Int                     = $1001
  16. Const DTM_SETSYSTEMTIME:Int                     = $1002
  17. Const DTM_SETFORMAT:Int                         = $1005
  18.  
  19.  
  20. 'EXAMPLE
  21. '------------------------------------------------------------------------------------
  22. Local win:tgadget = CreateWindow("test",0,0,300,250,Null,WINDOW_TITLEBAR|WINDOW_CENTER)
  23. Local dtp:Tdtpicker = Tdtpicker.Create(20,20,90,23,win,"dd MM yyyy") 'Format is optional
  24. Local button:tgadget = CreateButton("Get date",20,80,70,30,win)
  25. Repeat
  26.         WaitEvent()
  27.         Select EventID()
  28.         Case EVENT_WINDOWCLOSE          End
  29.         Case EVENT_GADGETACTION         Notify(dtp.Getdate())
  30.         EndSelect
  31. Forever
  32. '------------------------------------------------------------------------------------
  33.  
  34.  
  35. Type Tdtpicker
  36.         Field hwnd:Int
  37.         Field edit_hwnd:Int
  38.         Field p:tgadget
  39.         Field format:String=""
  40.        
  41.         Function Create:Tdtpicker(x:Int, y:Int, width:Int, height:Int, group:tgadget, format:String="")
  42.                 Local d:Tdtpicker = New Tdtpicker
  43.                 d.p = CreatePanel(x,y,width,height,group)
  44.                 d.hwnd = QueryGadget(d.p,QUERY_HWND)
  45.                 Local wstyle:Int = WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP
  46.                 d.edit_hwnd = CreateWindowEx(0,DATETIMEPICK_CLASSW,"Date",wstyle,..
  47.                                                         0,0,width,height,d.hwnd,Null,GetModuleHandle(Null),Null)
  48.                 If format<>""
  49.                         d.format = format
  50.                         Local hformat:Byte Ptr = format.ToCString()
  51.                         SendMessageW(d.edit_hwnd, DTM_SETFORMAT, 0, Int(hformat))
  52.                         MemFree hformat
  53.                 EndIf
  54.                
  55.                 Return d
  56.         End Function
  57.        
  58.         Method activate()
  59.                 SetFocus(edit_hwnd)
  60.         EndMethod
  61.        
  62.         Method GetDate:String()
  63.                 Local buffer:Byte[20]
  64.                 Local st:_SYSTEMTIME = New _SYSTEMTIME
  65.                 SendMessageW(edit_hwnd, DTM_GETSYSTEMTIME, 0, Int(Byte Ptr st))
  66.                 If format<>""
  67.                         Local hformat:Byte Ptr = format.ToCString()
  68.                         GetDateFormatA(0,Null,Int(Byte Ptr st),hformat,buffer,20)
  69.                         MemFree hformat
  70.                 Else
  71.                         GetDateFormatA(0,Null,Int(Byte Ptr st),Null,buffer,20)
  72.                 EndIf
  73.                 Local s:String
  74.                 For Local bb:Byte = EachIn buffer
  75.                         If bb>0 Then s:+ Chr(bb)
  76.                 Next
  77.                 Return s
  78.         EndMethod
  79. EndType
  80.  
  81. Type  _SYSTEMTIME
  82.     Field wYear:Int
  83.     Field wMonth:Int
  84.     Field wDayOfWeek:Int
  85.     Field wDay:Int
  86.     Field wHour:Int
  87.     Field wMinute:Int
  88.     Field wSecond:Int
  89.     Field wMilliseconds:Int
  90. EndType


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal