Skip to content

Instantly share code, notes, and snippets.

View CarlTBarnes's full-sized avatar

Carl T. Barnes CarlTBarnes

View GitHub Profile
@CarlTBarnes
CarlTBarnes / DebugOutput.clw
Last active October 7, 2024 20:21
OutputDebugString wrapper for Clarion String
DB PROCEDURE(STRING xMsg)
Prfx EQUATE('Prefix: ')
sz CSTRING(SIZE(Prfx)+SIZE(xMsg)+3),AUTO
CODE
sz=Prfx & CLIP(xMsg) & '<13,10>'
OutputDebugString(sz)
!----------------------------------------
DB PROCEDURE(STRING xMessage)
Prfx EQUATE('PrefixText: ') !All output gets this
sz CSTRING(SIZE(Prfx)+SIZE(xMessage)+3),AUTO
@CarlTBarnes
CarlTBarnes / Resize_Window_RewsCode.clw
Last active August 15, 2024 22:10
Resize Window using the LibSrc Legacy WindowResizeType class in ResCode.clw
!!! 1. In Global Data / Program add thse 2 lines
PRAGMA('compile(ResCode.CLW)')
INCLUDE('ResDef.CLW'),ONCE
!!! 2. For each Window to Resize
!!! 2a. Add to Procedure DATA
WinResize WindowResizeType
@CarlTBarnes
CarlTBarnes / Scratch.clw
Last active July 20, 2024 03:26
Scratch source I use when I want to write a quick test of some code
PROGRAM !Scratch program by Carl Barnes - Version 8/1/2020 - Download https://git.io/JtPKE
INCLUDE('TplEqu.CLW')
INCLUDE('KeyCodes.CLW')
MAP
main PROCEDURE()
DB PROCEDURE(STRING DebugMessage)
DBClear PROCEDURE() !Clear DebugView Buffer
Hex8 PROCEDURE(LONG LongInt),STRING
@CarlTBarnes
CarlTBarnes / TimeSplitAndJoin.clw
Last active July 5, 2024 20:02
TimeHMSh (Hour,Min,Sec) like DATE(). Also TimeSplit() Faster than using Hoiur() Minute() Second()
TimeSplit PROCEDURE(LONG Time2Split, <*? OutHour>, <*? OutMinute>, <*? OutSecond>, <*? OutHundred>)
TimeHMS PROCEDURE(LONG Hours=0, LONG Mins=0, LONG Secs=0, LONG Hundredths=0),LONG !Time Join H:M:S.D
TimeHMS2 PROCEDURE(BYTE Hours=0, BYTE Mins=0, BYTE Secs=0, BYTE Hundredths=0),LONG !Must have valid H,M,S
DateSplit PROCEDURE(LONG Date2Split, <*? OutMonth>, <*? OutDay>, <*? OutYear>)
!==========================================================================================================
TimeHMS PROCEDURE(LONG H=0, LONG M=0, LONG S=0, LONG Hundredths=0)!,LONG
!This allows out of range HMS values, e.g. you can pass 90 minutes
CODE
RETURN (H * 60*60*100) + | !3600 Seconds in 1 Hour *100=360,000
(M * 60*100) + | ! 60 Seconds in 1 Minute *100= 6,000
@CarlTBarnes
CarlTBarnes / DateSplit.clw
Last active June 28, 2024 20:11
DateSplit(Date, Month, Day, Year) much faster than calling MONTH() DAY() YEAR() separately
DateSplit PROCEDURE(LONG Date2Split, <*? OutMonth>, <*? OutDay>, <*? OutYear>)
!==========================================================================================================
DateSplit PROCEDURE(LONG Date2Split, <*? OutMonth>, <*? OutDay>, <*? OutYear>)
!Use DateSplit(Today,M,D,Y) instead of M=MONTH(Today) ; D=DAY(Today) ; Y=YEAR(Today)
D1 DATE,AUTO
DG GROUP, OVER(D1)
D BYTE
M BYTE
Y USHORT
END
@CarlTBarnes
CarlTBarnes / Get_SetWindowLong.CLW
Last active April 14, 2024 21:42
GetWindowLong() then SetWindowLong() applying an OFF and ON Bitmask
MAP
GetSetWindowLongFEQ_GWL_Style Procedure(LONG ControlFEQ, LONG BitsOFF, LONG BitsON) ,LONG,PROC
GetSetWindowLongFEQ_GWL_ExStyle Procedure(LONG ControlFEQ, LONG BitsOFF, LONG BitsON) ,LONG,PROC
GetSetWindowLongFEQ Procedure(LONG ControlFEQ, LONG WLnIndex, LONG BitsOFF, LONG BitsON) ,LONG,PROC
GetSetWindowLongHnd Procedure(LONG WndHandle, LONG WLnIndex, LONG BitsOFF, LONG BitsON) ,LONG,PROC
module('win32')
GetWindowLong(SIGNED hWnd, SIGNED nIndex ),PASCAL,RAW,LONG,PROC,NAME('GetWindowLongA'),DLL(1)
SetWindowLong(SIGNED hWnd, SIGNED nIndex, LONG dwNewLong ),PASCAL,RAW,LONG,PROC,NAME('SetWindowLongA'),DLL(1)
end
@CarlTBarnes
CarlTBarnes / RemoveFileWithAPI.clw
Last active March 21, 2024 17:43
REMOVE() in RTL has bugs and is very slow using ShFileOperation(). My replacement uses API DeleteFile() and sets Clarion ErrorCode() so can replace REMOVE().
!There are a few Remove() things here, what you want is FileApiRemove FUNCTION(STRING Fn2Delete),LONG,PROC
!
!In C8 Clarion REMOVE() was enhanced a second parameter with flags to allow wildcards, recursion, etc
!It was changed from calling API DeleteFile() to use the much more complicated ShFileOperation()
!This makes it much slower and more bug prone
!
!My replacement FileApiRemove() uses API DeleteFile() then sets the Claion Error so it can replace
!an existing REMOVE() in Clarion code. If you are using Remove(FILE) you'll need REMOVE(Name(File))
!or you can create a FileApi2Remove(FILE FileRef) that calls FileApiRemove(FileRef{PROP:Name}) or NAME()
!I named it "FileApiRemove(" so if you are searching "REMOVE(" you'll file it, versus RemoveUsingAPI() would not.
@CarlTBarnes
CarlTBarnes / 00_Index_GIST_.txt
Last active September 22, 2022 14:47
00 Index of my GIST because there does not seem to be options to list them by file name or description
Backup_CW_Project.BAT https://gist.github.com/CarlTBarnes/bbb936e418226d55ff8651bb1bfbf7e4 Backup Clarion Project BAT files
CBAltWin7Fix.tpl https://gist.github.com/CarlTBarnes/5e0e7d5a3e3f0b5c991e8f0601e69004 Fix Alt key lockup problem with the latest version of Windows 10 that I wrote and published in ClarionMag
CascadeMdiChildren.clw https://gist.github.com/CarlTBarnes/ed29557b7142ec4695f7d460cabef3fd Cascade open MDI Child windows like Clarion RTL STD:CascadeWindow using Windows API
Clarion_Hub_Interesting.txt https://gist.github.com/CarlTBarnes/aabb812d5a34fcfe69d2421702799aef Clarion Hub links of interest
CloseWindowHook.clw https://gist.github.com/CarlTBarnes/f86f6b695276b2b3327f5959e5c57682 Prop:CloseWindowHook Example Clarion
DateSplit.clw
@CarlTBarnes
CarlTBarnes / GroupMoveChildren.clw
Last active September 22, 2022 14:45
GROUP Move and also All Child Controls X,Y Position
!When a GROUP X/Y Position is changed it does NOT move the Child Controls
!This loops through the child controls and moves each one
!
!The XAdjust / YAdjust parameters allow some extra move from the TO Control X/Y
!------------------------------------------------------------------------------------
MAP
GroupMoveChildren(LONG FromGroup, LONG ToControl, LONG XAdjust=0, LONG YAdjust=0)
END
@CarlTBarnes
CarlTBarnes / RemoveMinButton.clw
Last active July 17, 2022 23:42
Remove Minimize button so window can have ICON() but user cannot minimize. Also CloseButtonDisable()
! This way your Window can have a pretty Icon() but not a Minimize button that causes end users to lose the form
MAP
RemoveMinButton() !Remove Minimize button on the Current Window so can have Icon() but no Minimize
MinButtonHide(BOOL HideMinimize=True),BOOL,PROC !Hide Minimize button (False Unhide) on the Current Window. Returns True if state changed.
MODULE('Win32')
GetWindowLong(LONG HndWindow, LONG nIndex),LONG,PASCAL,DLL(1),NAME('GetWindowLongA')
SetWindowLong(LONG HndWindow, LONG nIndex, LONG dwNewLong),LONG,PROC,PASCAL,DLL(1),NAME('SetWindowLongA')
END