Post by wexhammer on Jan 11, 2020 13:26:21 GMT -5
Hello, after a couple of hours of reading some books and looking at MDSN, i have finally found a solution to my problem. As everyone has been so kind in helping me out the past few days, i thought i would give a little bit back. To those who are advanced this probably is a no brainer for you but to those who are a little more amateur like myself the code below would help many out.
Finally got the date control to hide, show, enable and disable....
Finally got the date control to hide, show, enable and disable....
[Initialize]
DTS.UPDOWN = 1
DTS.RIGHTALIGN = 32
DTS.SHORTDATEFORMAT = 0
DTS.LONGDATEFORMAT = 4
DTS.SHORTDATECENTURYFORMAT = 12
DTS.APPCANPARSE = 16
DTM.GETSYSTEMTIME = 4097
DTM.FIRST = 4096
DTM.SETMCCOLOR=4102
DTM.SETMCCOLOR=DTM.FIRST+6
DTM.SETSYSTEMTIME = 4098
MCSC.BACKGROUND = 0
MCSC.TEXT = 1
MCSC.TITLEBK = 2
MCSC.TITLETEXT = 3
MCSC.MONTHBK=4
MCSC.TRAILINGTEXT = 5
Struct SYSTEMTIME, _
wYear As word, _
wMonth As word, _
wDayOfWeek As word, _
wDay As word, _
wHour As word, _
wMinute As word, _
wSecond As word, _
wMilliseconds As word
Global hMain, hFind
Nomainwin
[GUI]
struct icex, _
dwSize As ulong, _
dwICC As ulong
icex.dwSize.struct = Len(icex.struct)
icex.dwICC.struct = Hexdec("100") 'ICC_DATE_CLASSES
CallDLL #comctl32, "InitCommonControlsEx", _
icex As struct, r As long
Stylebits #main, 0,_WS_MAXIMIZEBOX,0,0
WindowWidth = 295 '595 695 795
WindowHeight = 260
UpperLeftX=Int((DisplayWidth-WindowWidth)/2)
UpperLeftY=Int((DisplayHeight-WindowHeight)/2)
Button #main.adddate, "Show", [show], UL, 10, 45, 90, 30
Button #main.adddate, "Hide", [hide], UL, 10, 85, 90, 30
Button #main.adddate, "Enable", [disable], UL, 10, 125, 90, 30
Button #main.adddate, "Disable", [enable], UL, 10, 165, 90, 30
Open "Test" For Window As #main
Print #main, "Trapclose endProgram"
hMain=hwnd(#main)
h1 = hWnd(#main)
hInst=InstanceHandle(h1)
hwndDTP=CreateDateControl(h1,hInst,10,10,140,20)
[Code]
[inputLoop]
Wait
[calculate]
wait
[endProgram]
Call endProgram handle$
Wait
Sub endProgram handle$
close #main
end
End Sub
Function InstanceHandle(hW)
CallDLL #user32, "GetWindowLongA", _
hW As ulong, _GWL_HINSTANCE As long, _
InstanceHandle As long
End Function
Function CreateDateControl(hW,hInstance,x,y,w,h)
DTS.SHORTDATECENTURYFORMAT = 12
style = _WS_VISIBLE Or _WS_CHILD Or DTS.SHORTDATECENTURYFORMAT
CallDLL #user32, "CreateWindowExA", _
0 As long,_ 'extended style
"SysDateTimePick32" As ptr, _ 'class
"DateTime" As ptr, _ 'name
style As long,_ 'window style flags
x As long, y As long,_ 'upper left x,y
w As long, h As long,_ 'width and height
hW As ulong,_ 'parent window handle
0 As long,_ 'menu handle
hInstance As long,_ 'instance handle of parent
0 As long, _ 'not used here - extra data
CreateDateControl As ulong 'handle of created control
End Function
Function GetWindowText$(hW)
a=GetWindowTextLength(hW)
Title$=Space$(a)+Chr$(0)
l=Len(Title$)
CallDLL #user32, "GetWindowTextA", hW As ulong,_
Title$ As ptr, l As long, result As long
GetWindowText$=Trim$(Title$)
End Function
Function GetWindowTextLength(hW)
CallDLL #user32, "GetWindowTextLengthA",_
hW As ulong, GetWindowTextLength As long
End Function
Sub SetBGColor hW, col
DTM.SETMCCOLOR=4102 'message flag to set calendar color
MCSC.MONTHBK=4 'color to change=month background
CallDLL #user32, "SendMessageA",_
hW As ulong, _ 'handle of control
DTM.SETMCCOLOR As long,_ 'set color message
MCSC.MONTHBK As long,_ 'part of control to set color on
col As long,_ 'color desired
re As long
End Sub
Function GetDate$(hW)
DTM.GETSYSTEMTIME = 4097
CallDLL #user32, "SendMessageA", _
hW As ulong, _ 'handle of control
DTM.GETSYSTEMTIME As long,_ 'flag to get chosen date/time
0 As long, _ 'wparam=0
SYSTEMTIME As struct,_ 'name of struct
ret As long
GetDate$=SYSTEMTIME.wMonth.struct;"/";_
SYSTEMTIME.wDay.struct;"/";_
SYSTEMTIME.wYear.struct
End Function
Function GetMonth$(hW)
DTM.GETSYSTEMTIME = 4097
CallDLL #user32, "SendMessageA", _
hW As ulong, _ 'handle of control
DTM.GETSYSTEMTIME As long,_ 'flag to get chosen date/time
0 As long, _ 'wparam=0
SYSTEMTIME As struct,_ 'name of struct
ret As long
mon=SYSTEMTIME.wMonth.struct
m$="JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC"
GetMonth$=word$(m$,mon)
End Function
Function SetDate(hW,year,month,day)
DTM.SETSYSTEMTIME = 4098
SYSTEMTIME.wDay.struct=day
SYSTEMTIME.wMonth.struct=month
SYSTEMTIME.wYear.struct=year
CallDLL #user32, "SendMessageA", _
hW As ulong, _ 'handle of control
DTM.SETSYSTEMTIME As long,_ 'flag to set chosen date/time
0 As long, _ 'wparam=0
SYSTEMTIME As struct,_ 'name of struct
SetDate As long
End Function
Sub hideorshowWindow hwndDTP, flag
'Enable=1 Disable=0
CallDLL #user32, "ShowWindow", hwndDTP As uLong, flag As Boolean, result As Boolean
End Sub
Sub enableordisableWindow hWnd, flag
'Enable=1 Disable=0
CallDLL #user32, "EnableWindow", hWnd As uLong, flag As Boolean, result As Boolean
End Sub
[show]
call hideorshowWindow hwndDTP,1
calldll #user32, "SetFocus",hwndDTP as ulong, re as long
wait
[hide]
call hideorshowWindow hwndDTP,0
calldll #user32, "SetFocus",hwndDTP as ulong, re as long
wait
[enable]
call enableordisableWindow hwndDTP,0
calldll #user32, "SetFocus",hwndDTP as ulong, re as long
wait
[disable]
call enableordisableWindow hwndDTP,1
calldll #user32, "SetFocus",hwndDTP as ulong, re as long
wait