'######################################### 
 ' awinh include file - by  Aurel 2013 
'#########################################

uses corewin
def GetCurrentDir GetCurrentDirectory
typedef POINTL POINTAPI

#autodim off

/*
type WNDCLASS
 Style         as int
 lpfnwndproc   as sys
 cbClsextra    as int
 cbWndExtra    as int
 hInstance     as sys
 hIcon         as sys
 hCursor       as sys
 hbrBackground as sys
 lpszMenuName  as sys
 lpszClassName as sys
end type
*/

type LARGE_INTEGER
lowpart  as int
highpart as int
end type

/*
type POINTAPI
 x as int
 y as int
end type
*/

/*
type MSG
 hwnd    as sys
 message as sys
 wParam  as sys
 lParam  as sys
 time    as sys
 pt      as POINTAPI
end type
*/

/*
type RECT
 Left   as int
 Top    as int
 Right  as int
 Bottom as int
end type
*/

/*
type PAINTSTRUCT
  sys hDC
  bool fErase
  RECT rcPaint
  bool fRestore
  bool fIncUpdate
  byte rgbReserved[32]
end type
*/

type OPENFILENAME
  lStructSize as long
  hwndOwner as long
  hInstance as long
  lpstrFilter as sys
  lpstrCustomFilter as sys
  nMaxCustFilter as long
  nFilterIndex as long
  lpstrFile as sys
  nMaxFile as long
  lpstrFileTitle as sys
  nMaxFileTitle as long
  lpstrInitialDir as sys
  lpstrTitle as sys
  flags as long
  nFileOffset as word
  nFileExtension as word
  lpstrDefExt as sys
  lCustData as long
  lpfnHook as long
  lpTemplateName as sys
end type

% OFN_EXPLORER        = 0x00080000
% OFN_PATHMUSTEXIST   = 0x00000800
% OFN_FILEMUSTEXIST   = 0x00001000
% OFN_OVERWRITEPROMPT = 0x00000002
% OFN_HIDEREADONLY    = 0x00000004

% BCM_FIRST        = 0x1600
% BCM_SETIMAGELIST = (BCM_FIRST + 0x0002)

% SW_NORMAL       = 1
% SW_SHOWDEFAULT  = 10
% SW_SHOW         = 5
% CS_VREDRAW      = 1
% CS_HREDRAW      = 2
% CS_DBLCLKS      = 0x8
% CS_OWNDC        = 32
% SM_CXSCREEN     = 0
% SM_CYSCREEN     = 1
% IDI_HAND        = 32513
% IDI_QUESTION    = 32514
% IDI_EXCLAMATION = 32515
% IDI_ASTERISK    = 32516
% IDI_WINLOGO     = 32517
% IDI_APPLICATION = 32512
% IDC_ARROW       = 32512
% IDC_WAIT        = 32514
% IDC_HAND        = 32649
% IDC_ICON        = 32641
% IDC_IBEAM       = 32513
% IDC_NO          = 32648

% WM_SETICON      = 0X80
% WM_KILLFOCUS    = 0x8  
% WM_CREATE       = 1
% WM_DESTROY      = 2
% WM_CLOSE        = 0x10
% WM_PAINT        = 15
% WM_QUIT         = 18
% WM_SIZE         = 5
% WM_MOVE         = 3
% WM_CHAR         = 258
% WM_KEYLAST      = 0X108
% WM_KEYFIRST     = 0X100
% WM_KEYDOWN      = 256
% WM_MOUSEMOVE    = 512
% WM_MBUTTONDOWN  = 519
% WM_LBUTTONDOWN  = 513
% WM_RBUTTONDOWN  = 516
% WM_LBUTTONUP    = 514
% WM_RBUTTONUP    = 517
% WM_MBUTTONUP    = 520
% WM_TIMER        = 275
% WM_WINDOWPOSCHANGED = 0X47
% WM_NOTIFY       = 0x004E
% WM_SETFONT      = 0X30
% WM_COMMAND      = 0x111
% BN_CLICKED      = 0
% WM_PARENTNOTIFY = 0x210
% WM_SETTEXT      = 0XC
% WM_GETTEXT      = 0xD
% WM_USER         = 0x400
% WM_HSCROLL      = 276

' Edit Control Messages
% EM_GETSEL       = 0xB0
% EM_SETSEL       = 0xB1
% EM_GETRECT      = 0xB2
% EM_SETRECT      = 0xB3
% EM_SETRECTNP    = 0xB4
% EM_SCROLL       = 0xB5
% EM_LINESCROLL   = 0xB6
% EM_SCROLLCARET  = 0xB7
% EM_GETMODIFY    = 0xB8
% EM_SETMODIFY    = 0xB9
% EM_GETLINECOUNT = 0xBA
% EM_LINEINDEX    = 0xBB
% EM_SETHANDLE    = 0xBC
% EM_GETHANDLE    = 0xBD
% EM_GETTHUMB     = 0xBE
% EM_LINELENGTH   = 0xC1
% EM_REPLACESEL   = 0xC2
% EM_GETLINE      = 0xC4
% EM_LIMITTEXT    = 0xC5
% EM_CANUNDO      = 0xC6
% EM_UNDO         = 0xC7
% EM_FMTLINES     = 0xC8
% EM_LINEFROMCHAR = 0xC9
% EM_SETTABSTOPS  = 0xCB
% EM_SETPASSWORDCHAR     = 0xCC
% EM_EMPTYUNDOBUFFER     = 0xCD
% EM_GETFIRSTVISIBLELINE = 0xCE
% EM_SETREADONLY         = 0xCF
% EM_SETWORDBREAKPROC    = 0xD0
% EM_GETWORDBREAKPROC    = 0xD1
% EM_GETPASSWORDCHAR     = 0xD2


'bm bitmaps
% BM_SETIMAGE   = 247
% IMAGE_BITMAP  = 0
% COLOR_BTNFACE = 15
% ILC_MASK      = 1
% ILC_COLOR8    = 8
% ILC_COLOR16   = 16
% PS_SOLID      = 0
% SRCCOPY       = 0xCC0020

'progress constants
% PBM_SETPOS      = 0x402
% PBM_SETRANGE32  = 0x406

'trackbar constants
% TB_TUMBTRACK    = 5

% WS_CLIPSIBLINGS = 0x4000000
% WS_CLIPCHILDREN = 0x2000000
% WS_SYSMENU      = 524288 
% WS_THICKFRAME   = 0x40000
% WS_CAPTION      = 0xC00000 
% WS_OVERLAPPED   = 0x0  
% WS_HIDDEN       = 2048
% WS_SIZED        = 262144
% WS_POPUP        = 0x80000000
% WS_DLGFRAME     = 0x400000
% WS_MAXIMIZE     = 0X1000000
% WS_MINIMIZEBOX  = 0X20000
% WS_MAXIMIZEBOX  = 0x10000
% WS_BORDER       = 0X800000
% WS_CHILD        = 0x40000000
% WS_VISIBLE      = 0x10000000
% WS_VSCROLL      = 0x200000
% WS_HSCROLL      = 0x100000

'minmaxsize-> overlappedwindow
% WS_MINMAXSIZE   = (WS_OVERLAPPED Or WS_VISIBLE Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)

% TRANSPARENT    = 1
% OPAQUE         = 2
% PM_REMOVE      = 1
% PM_NOREMOVE    = 0
% PM_NOYIELD     = 2
% NULL_BRUSH     = 5

% ES_SUNKEN      = 0x4000
% ES_MULTILINE   = 0x4 
% ES_WANTRETURN  = 0x1000 
% ES_AUTOVSCROLL = 0x40 
% ES_AUTOHSCROLL = 0x80 

' Listbox messages
% LB_ADDSTRING       = 0x180
% LB_INSERTSTRING    = 0x181
% LB_DELETESTRING    = 0x182
% LB_SELITEMRANGEEX  = 0x183
% LB_RESETCONTENT    = 0x184
% LB_SETSEL          = 0x185
% LB_SETCURSEL       = 0x186
% LB_GETSEL          = 0x187
% LB_GETCURSEL       = 0x188
% LB_GETTEXT         = 0x189
% LB_GETTEXTLEN      = 0x18A
% LB_GETCOUNT        = 0x18B
% LB_SELECTSTRING    = 0x18C
% LB_DIR             = 0x18D
% LB_GETTOPINDEX     = 0x18E
% LB_FINDSTRING      = 0x18F
% LB_GETSELCOUNT     = 0x190
% LB_GETSELITEMS     = 0x191
% LB_SETTABSTOPS     = 0x192
% LB_GETHORIZONTALEXTENT = 0x193
% LB_SETHORIZONTALEXTENT = 0x194
% LB_SETCOLUMNWIDTH  = 0x195
% LB_ADDFILE         = 0x196
% LB_SETTOPINDEX     = 0x197
% LB_GETITEMRECT     = 0x198
% LB_GETITEMDATA     = 0x199
% LB_SETITEMDATA     = 0x19A
% LB_SELITEMRANGE    = 0x19B
% LB_SETANCHORINDEX  = 0x19C
% LB_GETANCHORINDEX  = 0x19D
% LB_SETCARETINDEX   = 0x19E
% LB_GETCARETINDEX   = 0x19F
% LB_SETITEMHEIGHT   = 0x1A0
% LB_GETITEMHEIGHT   = 0x1A1
% LB_FINDSTRINGEXACT = 0x1A2
% LB_SETLOCALE       = 0x1A5
% LB_GETLOCALE       = 0x1A6
% LB_SETCOUNT        = 0x1A7
% LB_MSGMAX          = 0x1A8
% LBN_DBLCLICK       = 2
% CTLISTNOTIFY       = 1

'combo constants
% CB_INSERTSTRING  = 0x14A
% CB_RESETCONTENT  = 0x14B
% CB_FINDSTRING    = 0x14C
% CB_SELECTSTRING  = 0x14D
% CB_SETCURSEL     = 0x14E
% CB_SHOWDROPDOWN  = 0x14F
% CB_GETITEMDATA   = 0x150
% CB_SETITEMDATA   = 0x151

'treeview constants
% TVS_LINESATROOT   = 0x0004
% TVS_HASLINES      = 2
% TVS_HASBUTTONS    = 0x0001
% TV_FIRST          = 0x1100
% TVS_CHECKBOXES    = 0x100
% TVM_SETBKCOLOR    = (TV_FIRST + 29)
% TVM_SETLINECOLOR  = (TV_FIRST + 40)
% TVM_SETTEXTCOLOR  = (TV_FIRST + 30)
% TVM_SETITEMA = (TV_FIRST + 13)
% TVM_INSERTITEMW   = (TV_FIRST + 50)
% TVM_INSERTITEM    = 4352
% TVI_ROOT          = 0xFFFF0000
% TVI_LAST          = 0xFFFF0002
'
% TVIF_TEXT       = 1
% TVIF_HANDLE     = 16 
% TVIF_IMAGE      = 2 
% TVIF_PARAM      = 4
% TVIF_DI_SETITEM = 128
% TVSELECTEDIMAGE = 36
'
TYPE TVINSERTSTRUCT 
 hParent as int 
 hInsertAfter as int 
 mask as int  ' tvitemex  
 hitem as int 
 state as int 
 statemask as int 
 pszText as sys 
 cchTextMax as int 
 iImage as int 
 iSelectedImage as int 
 cChildren as int 
 lparam as int 
 IIntegral as int 
end TYPE 
'
type NMTREEVIEW 
  hwnd as sys 
  idfrom as int 
  code as int 
  action as int 
  omask as int 
  ohitem as int 
  ostate as int 
  ostatemask as int 
  opszText as sys
  occhTextMax as int 
  oiImage as int 
  oiSelectedImage as int 
  ocChildren as int 
  olparam as int 
  oIIntegral as int 
  nmask as int 
  nhitem as int 
  nstate as int 
  nstatemask as int 
  npszText as sys
  ncchTextMax as int 
  niImage as int 
  niSelectedImage as int 
  ncChildren as int 
  nlparam as int 
  nIIntegral as int 
end type 

dim tvi as TVINSERTSTRUCT 
dim MyNmTV as NMTREEVIEW 

'tabControl constants

% TCM_FIRST        = 0x1300
% TCM_SETITEM      = (TCM_FIRST + 6)
% TCM_GETITEM      = 4869
% TCM_GETITEMCOUNT = 4868
% TCM_DELETEITEM   = (TCM_FIRST + 8)
% TCM_INSERTITEM   = 0x1307
% TCM_SETCURFOCUS  = 0x1330 
% TCN_FIRST        = -550
% TCN_SELCHANGE    = -551
% TCN_SELCHANGING  = -552
% TCM_GETCURSEL    = 4875
% TCM_SETCURSEL    = 0x130C 
% TCIF_TEXT        = 1
% TCS_HOTTRACK     = 0x40
 
type TC_ITEM 
 mask as int 
 res1 as int 
 res2 as int 
 pszText as sys 
 cchTextMax as int 
 iImage as int 
 lParam as int 
end type

'toolbar constants

'typedef INITCOMMONCONTROLSEX *LPINITCOMMONCONTROLSEX
typedef struct tagINITCOMMONCONTROLSEX {
  DWORD dwSize;
  DWORD dwICC;
} INITCOMMONCONTROLSEXtype, *LPINITCOMMONCONTROLSEX;

'tooltips constants ''''''''''''''''''''''''''''''''''''''''''''''''''
% TB_SETTOOLTIPS   = 1060
% EBTOOLTIPS       = 256
% TBSTYLE_TOOLTIPS = 0X100
% TBSETTIP         = 9
% TTS_ALWAYSTIP    = 0X1
% TTS_NOPREFIX     = 0X2
% TTS_BALLOON      = 0X40 ' comctl32.dll v5.8 require
% TTM_ACTIVATE     = WM_USER+1

% TTM_ADDTOOL         = (WM_USER + 4)
% TTM_DELTOOL         = (WM_USER + 5)
% TTM_NEWTOOLRECT     = (WM_USER + 6)
% TTM_GETTOOLINFO     = (WM_USER + 8)
% TTM_SETTIPBKCOLOR   = (WM_USER + 19)
% TTM_SETTIPTEXTCOLOR = (WM_USER + 20)
% TTM_SETMAXTIPWIDTH  = (WM_USER + 24)
% TTM_UPDATETIPTEXT   = 1036
% TTDT_AUTOPOP        = 2
% TTDT_INITIAL        = 3

% TTF_IDISHWND  = 0X1
% TTF_CENTERTIP = 0X2
% TTF_SUBCLASS  = 0X10

type TOOLINFO
  cbSize      as int
  uFlags      as int
  hWnd        as int
  uId         as int
  cRect       as RECT
  hinst       as sys
  lpszText    as sys
end type

'trackbar constants
% TBM_SETPAGESIZE = 1045
% TBM_SETRANGEMIN = 1031
% TBM_SETRANGEMAX = 1032
% TBM_SETPOS      = 1029
% TRACKBARNORMAL  = 1409351681

'
% CCS_ADJUSTABLE  = 32
% CCS_NODIVIDER   = 64
% TBSTYLE_FLAT    = 0X800
% tb_addbuttons   = wm_user+21
% TB_SETIMAGELIST = 1072
% TB_ADDBITMAP    = 1043
% TB_AUTOSIZE     = 1057


type TBBUTTON
  iBitmap      as long
  idCommand    as long
  fsState      as byte
  fsStyle      as byte
  bReserved[2] as byte '6 for 64bit
  dwData      as sys 'pointer
  iString      as sys
end type

'statusbar constants
% SBARS_SIZEGRIP = 0x100

% FW_BOLD       = 700
% FW_LIGHT      = 300
% FW_HEAVY      = 900
% FW_NORMAL     = 400
% FW_DONTCARE   = 0
% FW_EXTRABOLD  = 800
% FW_EXTRALIGHT = 200
% FW_HEAVY      = 900
% FW_LIGHT      = 300
% FW_MEDIUM     = 500
% FW_SEMIBOLD   = 600
% FW_THIN       = 100

% WHITE_BRUSH  = 0
% BLACK_BRUSH  = 4
% LTGRAY_BRUSH = 0xC0C0C0
% LTGRBL_BRUSH = 0xDCDCCE

/*
% vk_LBUTTON  = 0X1	
% vk_RBUTTON  = 0X2 
% vk_MBUTTON  = 0X4
% vk_BACK     = 0X8
% vk_TAB      = 0X9 
% vk_CLEAR    = 0XC 
% vk_RETURN   = 0XD 
% vk_SHIFT    = 0X10 
% vk_CONTROL  = 0X11 
% vk_MENU     = 0X12 
% vk_PAUSE    = 0X13 
% vk_CAPITAL  = 0X14 
% vk_ESCAPE   = 0X1B 
% vk_SPACE    = 0X20 
% vk_PRIOR    = 0X21 
% vk_NEXT     = 0X22 
% vk_end      = 0X23 
% vk_HOME     = 0X24 
% vk_LEFT     = 0X25 
% vk_UP       = 0X26 
% vk_RIGHT    = 0X27 
% vk_DOWN     = 0X28 
% vk_PRINT    = 0X2A 
% vk_SNAPSHOT = 0X2C	 
% vk_INSERT   = 0X2D 
% vk_DELETE   = 0X2E 
% vk_HELP     = 0X2F 
% vk_0        = 0X30 
% vk_1        = 0X31 
% vk_2        = 0X32 
% vk_3        = 0X33 
% vk_4        = 0X34 
% vk_5        = 0X35
% vk_6        = 0X36 
% vk_7        = 0X37 
% vk_8        = 0X38 
% vk_9        = 0X39 
% vk_@        = 0X40
% vk_A        = 0X41 
% vk_B        = 0X42 
% vk_C        = 0X43 
% vk_D        = 0X44 
% vk_E        = 0X45 
% vk_F        = 0X46 
% vk_G        = 0X47 
% vk_H        = 0X48 
% vk_I        = 0X49 
% vk_J        = 0X4A 
% vk_K        = 0X4B
% vk_L        = 0X4C 
% vk_M        = 0X4D 
% vk_N        = 0X4E 
% vk_O        = 0X4F 
% vk_P        = 0X50 
% vk_Q        = 0X51 
% vk_R        = 0X52 
% vk_S        = 0X53 
% vk_T        = 0X54 
% vk_U        = 0X55 
% vk_V        = 0X56 
% vk_W        = 0X57 
% vk_X        = 0X58 
% vk_Y        = 0X59 
% vk_Z        = 0X5A 
% vk_F1       = 0X70 
% vk_F2       = 0X71 
% vk_F3       = 0X72 
% vk_F4       = 0X73 
% vk_F5       = 0X74 
% vk_F6       = 0X75 
% vk_F7       = 0X76 
% vk_F8       = 0X77 
% vk_F9       = 0X78 
% vk_F10      = 0X79 
% vk_F11      = 0X7A 
% vk_F12      = 0X7B 
% vk_NUMLOCK    = 0X90 
% vk_OEM_SCROLL = 0X91	 
% vk_LSHIFT     = 0XA0 
% vk_RSHIFT     = 0XA1 
% vk_LCONTR     = 0XA2	 
% vk_RCONTROL   = 0XA3
*/
	
#lookahead

dim sys kernel32,user32,gdi32,riched32,comdialog32,comctl32
'kernel32     = LoadLibrary "kernel32.dll"
'user32       = LoadLibrary "user32.dll"
'gdi32        = LoadLibrary "gdi32.dll"
riched32     = LoadLibrary "riched20.dll"
comctl32     = LoadLibrary "comctl32.dll"
'comdialog32 = LoadLibrary "comdlg32.dll"
'Bind kernel32
'(
'    
'  GetModuleHandle  GetModuleHandleA
'  GetCurrentDir    GetCurrentDirectoryA '"kernel32",GetCurrentDirectoryA(nBufferLength:int,lpBuffer:String),int  
'  ExitProcess      ExitProcess
'  'GetTickCount    GetTickCount
'  sleep            Sleep
'  Beep             Beep    
')  

'Bind user32
'(
'  LoadIcon         LoadIconA        
'  LoadCursor       LoadCursorA       
'  RegisterClass    RegisterClassA
'  RegisterClassEx  RegisterClassExA   
'  MessageBox       MessageBoxA       
'  SendMessage      SendMessageA 
'  GetMessage       GetMessageA 
'  PeekMessage      PeekMessageA
'  TranslateMessage TranslateMessage 
'  DispatchMessage  DispatchMessageA 
'  PostQuitMessage  PostQuitMessage  
'  PostMessage      PostMessageA
'  CreateWindowEx   CreateWindowExA   
'  ShowWindow       ShowWindow        
'  UpdateWindow     UpdateWindow      
'  DefWindowProc    DefWindowProcA
'  InvalidateRect   InvalidateRect
'  ValidateRect     ValidateRect
'  GetSystemMetrics GetSystemMetrics 
'  ReleaseDC        ReleaseDC
'  GetDC            GetDC
'  BeginPaint       BeginPaint 
'  EndPaint         EndPaint   
'  ShowCursor       ShowCursor
'  GetAsyncKeyState GetAsyncKeyState
')
 
'Bind gdi32
'(
'  GetStockObject   GetStockObject
'  CreateSolidBrush CreateSolidBrush
'  SetBkMode        SetBkMode
'  SetBkColor       SetBkColor
')  

! lstrcmpi       lib "kernel32.dll" Alias "lstrcmpiA" (ByVal lpString1 as String, ByVal lpString2 as String) as long
! GetCommandLine lib "kernel32.dll" Alias "GetCommandLineA" () as String
! GetParent      lib "user32.dll" (ByVal hWnd as long) as long
! GetSysColor    lib "user32.dll" (ByVal nIndex as long) as long
! GetWindowRect  lib "user32.dll" (ByVal hwnd as long, lpRect as RECT) as long
! SetWindowPos   lib "user32.dll"(hwnd as int,hWndInsertAfter as int,x as int,y as int,cx as int,cy as int,wFlags as int) as int
! MoveWindow     lib "user32.dll" (ByVal hwnd as long, ByVal x as long, ByVal y as long, ByVal nWidth as long, ByVal nHeight as long, ByVal bRepaint as long) as long

! GetFocus       lib "user32.dll" () as long

! SetFocus       lib "user32.dll" (ByVal hwnd as int) as int
! LoadImage      lib "user32.dll" Alias "LoadImageA" (ByVal hInst as long,ByVal lpsz as String,ByVal un1 as long,ByVal n1 as long, ByVal n2 as long, ByVal un2 as long) as long
! GetPixel       lib "gdi32.dll" (ByVal hdc as long, ByVal x as long, ByVal y as long) as long
! CreateHatchBrush lib "gdi32.dll" (ByVal nIndex as long, ByVal crColor as long) as long
! CreatePen      lib "gdi32.dll" Alias "CreatePen" (ByVal nPenStyle as long, ByVal nWidth as long, ByVal crColor as long) as long
! FillRect       lib "user32.dll" (ByVal hdc as long, lpRect as RECT, ByVal hBrush as long) as long
! MoveToEx       lib "gdi32.dll" (ByVal hdc as sys, ByVal x as long, ByVal y as long, ByRef lpPoint as POINTAPI) as long
! LineTo         lib "gdi32.dll" (ByVal hdc as sys, ByVal x as long, ByVal y as long) as long
! Ellipse        lib "gdi32.dll" (ByVal hdc as long, ByVal X1 as long, ByVal Y1 as long, ByVal X2 as long, ByVal Y2 as long) as long
! GetClientRect  lib "user32.dll" (ByVal hwnd as sys, ByRef lpRect as RECT) as long
! SetPixel       lib "gdi32.dll" (ByVal hdc as long, ByVal x as long, ByVal y as long, ByVal crColor as long) as long
! SetPixelV      lib "gdi32.dll" (ByVal hdc as sys, ByVal x as long, ByVal y as long, ByVal crColor as long) as long
! Rectangle      lib "gdi32.dll" (ByVal hdc as long, ByVal x1 as long, ByVal y1 as long, ByVal x2 as long, ByVal y2 as long) as long

! TextOut        lib "gdi32.dll" Alias "TextOutA" (ByVal hdc as long, ByVal x as long, ByVal y as long, ByVal lpString as String, ByVal nCount as long) as long
! DeleteDC       lib "gdi32.dll" (ByVal hdc as long) as long
! PlaySound      lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName as String, ByVal hModule as long, ByVal dwFlags as long) as long
! PatBlt         lib "gdi32.dll" (ByVal hdc as long, ByVal x as long, ByVal y as long, ByVal nWidth as long, ByVal nHeight as long, ByVal dwRop as long) as long
! SetBkColor     lib "gdi32.dll" (ByVal hdc as long, ByVal crColor as long) as long
! BitBlt         lib "gdi32.dll" (ByVal hDestDC as long, ByVal x as long, ByVal y as long, ByVal nWidth as long, ByVal nHeight as long, ByVal hSrcDC as long, ByVal xSrc as long, ByVal ySrc as long, ByVal dwRop as long) as long
! CreateFont     lib "gdi32.dll" Alias "CreateFontA" (ByVal H as long, ByVal W as long, ByVal E as long, ByVal O as long, ByVal W as long, ByVal I as long, ByVal u as long, ByVal S as long, ByVal C as long, ByVal OP as long, ByVal CP as long, ByVal Q as long, ByVal PAF as long, ByVal F as String) as long
! GetObject      lib "gdi32.dll" Alias "GetObjectA" (ByVal hObject as long, ByVal nCount as long, ByRef lpObject as Any) as long

! SetWindowText  lib "user32.dll" Alias "SetWindowTextA" (ByVal hwnd as long, ByVal lpString as String) as long
! DestroyWindow  lib "user32.dll" (ByVal hwnd as long) as long
'! UpdateWindow  lib "user32.dll" (ByVal hwnd as long),As Long
! timeGetTime    lib "winmm.dll" () as long
! SelectObject   lib "gdi32.dll" (ByVal hdc as long, ByVal hObject as long) as long
! DeleteObject   lib "gdi32.dll" (ByVal hObject as long) as long
! SetTextColor   lib "gdi32.dll" (ByVal hdc as long, ByVal crColor as long) as long
! FloodFill      lib "gdi32.dll" Alias "FloodFill" (ByVal hdc as int, ByVal x as int, ByVal y as int, ByVal crColor as int) as int
! ExtFloodFill   lib "gdi32.dll" Alias "ExtFloodFill" (ByVal hdc as int, ByVal x as int, ByVal y as int, ByVal crColor as int, ByVal wFillType as int) as int

! CreatePopupMenu lib "user32.dll" () as long 
! CreateMenu      lib "user32.dll" () as long 
! GetMenu         lib "user32.dll" (ByVal hwnd as long) as long 
! SetMenu         lib "user32.dll" (ByVal hwnd as long, ByVal hMenu as long) as long 
! AppendMenu      lib "user32.dll" Alias "AppendMenuA" (ByVal hMenu as long, ByVal wFlags as long, ByVal wIDNewItem as long, ByVal lpNewItem as Any) as long 
! DrawMenuBar     lib "user32.dll" (ByVal hwnd as long) as long 
! DeleteMenu      lib "user32.dll" (ByVal hMenu as long, ByVal nPosition as long, ByVal wFlags as long) as long 
! DestroyMenu     lib "user32.dll" (ByVal hMenu as long) as long 
! TrackPopupMenu  lib "user32.dll" (ByVal hMenu as long, ByVal wFlags as long, ByVal x as long, ByVal y as long, ByVal nReserved as long, ByVal hwnd as long, lprc as RECT) as long 



! QueryPerformanceCounter   lib "kernel32.dll" (ByRef lpPerformanceCount as LARGE_INTEGER) as long
! QueryPerformanceFrequency lib "kernel32.dll" (ByRef lpFrequency as LARGE_INTEGER) as long
! CreateCompatibleBitmap    lib "gdi32.dll" (ByVal hdc as long, ByVal nWidth as long, ByVal nHeight as long) as long
! CreateCompatibleDC        lib "gdi32.dll" (ByVal hdc as long) as long
! SetForegroundWindow       lib "user32.dll" (ByVal hwnd as long) as long
'
'def NULL 0
! GetModuleHandle  lib "kernel32.dll" alias "GetModuleHandleA" (sys lpModuleName) as long
! GetOpenFileName  lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename as OPENFILENAME) as long
! GetSaveFileName  lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename as OPENFILENAME) as long

! ShellExecute          lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd as long, ByVal lpOperation as String, ByVal lpFile as String, ByVal lpParameters as String, ByVal lpDirectory as String, ByVal nShowCmd as long) as long
!  InitCommonControlsEx lib "comctl32.dll" alias "InitCommonControlsEx" (INITCOMMONCONTROLSEXtype*ic) as sys
! ImageList_Create      lib "comctl32.dll" (byval cx as int,byval cy as int,byval flags as int,byval cInitial as int,byval cGrow as int) as sys
! ImageList_Add         lib "comctl32.dll" (ByVal cx as int, ByVal cy as int ByVal flags as uint, ByVal cInitial as int, ByVal cGrow as int) as sys
! ImageList_AddMasked   lib "comctl32.dll" (byval hImageList as sys,byval hBitmap as sys,byval crMask as sys) as sys


% sys_Red   = 1
% sys_Green = 2
% sys_Blue  = 4
% SYS_BLACK = 0X101010
% SYS_WHITE = 0XE0E0E0


type TRGB
 long r
 long g
 long b
end type

type BUTTON
 long w
 long h
 long c
 long a
 long b
 string t
end type

type TBADDBITMAP
     sys hInst
     int nID
end type


dim But(512) as Button
dim cRgb     as TRGB
dim wm       as MSG
dim rc       as RECT
dim wcx      as WNDCLASS


dim ShpHnd (512) as long
dim ShpHdc (512) as long
dim ShpWide(512) as long
dim ShpHigh(512) as long
dim SprHnd (512) as long
dim SprHdc (512) as long
dim SprWide(512) as long
dim SprHigh(512) as long
dim BmpHnd (512) as long
dim BmpHdc (512) as long
dim BmpWide(512) as long
dim BmpHigh(512) as long
dim ImgHdc (512) as long
dim ImgHnd (512) as long
dim ImgWide(512) as long
dim ImgHigh(512) as long


dim BackHdc    as long
dim BackHnd    as long
dim xBack      as long
dim yBack      as long
dim sys_Seed   as long
dim MouseX     as long
dim MouseY     as long
dim controlID  as long
dim notifyCode as long
dim sys_clic   as long
dim sys_Hdc    as sys
dim sys_hwnd   as sys

'---previously undefined
dim width       as long
dim height      as long
dim hstatus     as long
dim font_width  as long
dim font_height as long
dim font_flag   as long
dim font_name   as string

'Controls handler

dim hButton   as long
dim hEdit     as long
dim hRichEdit as long
dim hScrollBar as long
dim hListbox  as long
dim hCombobox as long
dim hStatic   as long
dim hProgress as long

dim hTreeView as long
dim hTabControl as long
dim hTBControl as long
dim hTTControl as long
dim hTrackBar as long

dim sys_Focus as long
dim sys_hFont as long
dim sys_Font  as String
dim sys_xFont as long
dim sys_yFont as long
dim sys_Flag  as long
dim WinExit   as long
dim WinWidth  as long
dim WinHeight as long
dim ImgHdc    as long
dim ImgHnd    as long
dim ImgWidth  as long
dim ImgHeight as long
dim sys_wx    as long
dim sys_wy    as long
dim sys_color as long
dim sys_xPos  as long
dim sys_yPos  as long
sys bHnd,bHdc
sys hbrush
dim AscKey    as sys
'
macro Default
DefWindowProc hwnd,wMsg,wParam,lParam
end macro
'
macro rights(s,i)
mid(s,(-i))
end macro

'
! Main()


function HiWord (byval hi as long) as long
shr hi,16 : function=hi
end function

function LoWord (byval lo as long) as long
And lo,0Xffff : function=lo
end function


function SetBuffer (byval x as long, byval y as long) as long
BackHnd = CreateCompatibleBitmap(sys_hdc, x, y)
BackHdc = CreateCompatibleDC(sys_hdc)
SelectObject BackHdc, BackHnd
xBack = x : yBack = y
function = BackHdc
end function


function ClearBuffer (byval color as long)
sys_color = color
sys sys_Brush = CreateSolidBrush color
SelectObject BackHdc, sys_Brush
Rectangle BackHdc,-1,-1,xBack+1,yBack+1
DeleteObject sys_Brush
end function


function FlipBuffer()
BitBlt Sys_hdc, 0, 0, xBack, yBack, BackHdc, 0, 0, 0XCC0020
end function


sub Events()
if PeekMessage (&wm,0,0,0,Pm_Remove) >0
if wm.message = Wm_Quit Then WinExit=1 
TranslateMessage &wm
DispatchMessage  &wm
end if
end sub

sub DoWait()
While AscKey=0
Events
'if WinExit=1
  ' WinEnd
  ' ExitProcess 0
'end if
FlipBuffer
Wend
AscKey=0
end sub


function ControlFont ( byval hwnd as long,byval height as long, byval width as long, byval flag as long,byval fontname as string)  
int hFont
hFont = CreateFont( height,width,0,0,flag,0,0,0,0,0,0,0,0,fontname)
SendMessage hwnd,WM_SETFONT,hfont,0
end function


sub Delay(byval time as long)
Long Tick, cTime  
cTime = timeGetTime 
Tick = cTime + time
While  Tick > cTime
cTime = timeGetTime
Wend 
end sub


function SetWindow (byval caption as string ,byval Wx as int,byval Wy as int, byval Ww as int, byval Wh as int, byval wparent as int, byval style as int) as int
 sys inst = GetModuleHandle 0
'sys hbrush=RGB(250,250,255)
'wcx.cbSize = sizeof(WNDCLASSEX)
 wcx.style = CS_DBLCLKS | CS_OWNDC 
 wcx.lpfnWndProc = &WndProc
'wcx.cbClsExtra = 0
'wcx.cbWndExtra = 0
 wcx.hInstance  = inst
 wcx.hIcon=LoadIcon 0,IDI_APPLICATION 
'wcx.hIconSm=LoadIcon 0,IDI_APPLICATION         
 wcx.hCursor=LoadCursor 0,IDC_ARROW       
'wcx.hbrBackground = CreateSolidBrush(hbrush)
 wcx.hbrBackground = CreateSolidBrush(GetSysColor(15))
'wcx.lpszMenuName  = 0
 wcx.lpszClassName = strptr "Oxygen"

RegisterClass &wcx

'create window

sys_hwnd = CreateWindowEx 0, wcx.lpszClassName, caption, style, Wx, Wy, Ww, Wh, wparent, 0, inst, 0

if style <> WS_HIDDEN
  ShowWindow sys_hwnd, SW_SHOW
end if
'UpdateWindow sys_hwnd
sys_hdc = GetDC(sys_hwnd)
'static defwndproc as var
'dim MRET as sys
'MRET = DefWindowProc(sys_hwnd,wm,wParamS,lParamS)
'GetClientRect sys_hwnd,rc   
'w = ww-rc.right
'h = wh-rc.bottom
'GetWindowRect sys_hwnd,rc
'MoveWindow sys_hwnd,rc.left-1,rc.top-1,ww+w,wh+h,1
bHnd = CreateCompatibleBitmap(sys_hdc,ww,wh)
bHdc = CreateCompatibleDC(sys_hdc)
SelectObject bHdc, bHnd
Width = ww
Height= wh
'SetBuffer ww,wh
sys_Seed = timeGetTime
'QueryPerformanceFrequency sys_qf
'QueryPerformanceCounter   sys_qc1
function = sys_hwnd
end function


'- Msg Loop

function Wait() as sys
  sys _message
  while GetMessage(@wm,0,0,0) <> 0
     Translatemessage @wm
     DispatchMessage @wm  
  wend
  return @wm
end function


function CloseWindow(wnd as int) as int
DestroyWindow wnd
'PostQuitMessage 0
return 0
end function


sub EndProgram
PostQuitMessage 0
end sub

'GetClientsize

sub GetSize(int hnd,hndx as int,hndy as int,hndw as int,hndh as int)
GetClientRect(hnd,rc)
'hndx=0:hndy=0:hndw=0:hndh=0
hndx = rc.left
hndy = rc.top
hndw = rc.right
hndh = rc.bottom
end sub


'SetSize()

sub SetSize(int hnd,byref hndx as int,byref hndy as int,byref hndw as int,byref hndh as int)
INT sdata[4]
sdata[0]=hndx
sdata[1]=hndy
sdata[2]=hndw
sdata[3]=hndh
'SetWindowPos(hnd,0,sdata[0],sdata[1],sdata[2],sdata[3],0)
MoveWindow(hnd,sdata[0],sdata[1],sdata[2],sdata[3],1)
end sub


'syn : SetButton (hwnd,x,y,w,h,caption,style,ext,controlID)

function SetButton(byval _bhwnd as int,byval _bx as int,byval _by as int,byval _bw as int,byval _bh as int, byval _btext as string,byval _bflag as int,byval _ext as int,byval _cID as int) as int
INT _hfont
if _bflag=0
    _bflag = 0x50000000
EndIf
_ext = 0
hButton = CreateWindowEx(_ext,"BUTTON",_btext,_bflag,_bx,_by,_bw,_bh,_bhwnd,_cID,0,0)
_hfont = GetStockObject(17)
SendMessage hButton,WM_SETFONT,_hfont,0
UpdateWindow _bhwnd
function = hButton
end function


'syn : SetEditBox (hwnd,x,y,w,h,caption,style,ext)
function SetEditBox(byval _ehwnd as int,byval _ex as int,byval _ey as int,byval _ew as int,byval _eh as int, byval _etext as string,byval _eflag as int,byval _ext as int,byval _cID as int) as int
INT _hfont
if _eflag=0
    _eflag = 0x50800000
EndIf
hEdit = CreateWindowEx(_ext,"EDIT",_etext,_eflag,_ex,_ey,_ew,_eh,_ehwnd,_cID,0,0)
_hfont = GetStockObject(17)
SendMessage hEdit,WM_SETFONT,_hfont,0
UpdateWindow _ehwnd
function = hEdit
end function


function SetListBox (byval _ehwnd as int,byval _ex as int,byval _ey as int,byval _ew as int,byval _eh as int, byval _etext as string,byval _eflag as int,byval _ext as int,byval _cID as int) as int
INT _hfont
if _eflag=0
    _eflag = 0x50A00140 or CTLISTNOTIFY
EndIf
hListbox = CreateWindowEx(_ext,"LISTBOX",_etext,_eflag,_ex,_ey,_ew,_eh,_ehwnd,_cID,0,0)
_hfont = GetStockObject(17)
SendMessage hListbox,WM_SETFONT,_hfont,0
UpdateWindow _ehwnd
function = hListbox
end function


function SetStatic (byval _ehwnd as int,byval _ex as int,byval _ey as int,byval _ew as int,byval _eh as int, byval _etext as string,byval _eflag as int,byval _ext as int,byval _cID as int) as int
int _hfont
if _eflag=0
    _eflag = 0x5000010B
EndIf
hStatic = CreateWindowEx(_ext,"STATIC",_etext,_eflag,_ex,_ey,_ew,_eh,_ehwnd,_cID,0,0)
_hfont = GetStockObject(17)
SendMessage hStatic,WM_SETFONT,_hfont,0
UpdateWindow _ehwnd
function = hStatic
end function


function SetRichEdit (byval _ehwnd as int,byval _ex as int,byval _ey as int,byval _ew as int,byval _eh as int, byval _etext as string,byval _eflag as int,byval _ext as int,byval _cID as int) as int
int _hfont
if _eflag=0
'0x50800080 single , 0x50B010C4 multiline
    _eflag = 0x50800080 Or ES_SUNKEN
end if
hRichEdit = CreateWindowEx(_ext,"richedit20a",_etext,_eflag,_ex,_ey,_ew,_eh,_ehwnd,_cID,0,0)
_hfont = GetStockObject(17)
SendMessage hRichEdit,WM_SETFONT,_hfont,0
UpdateWindow _ehwnd
function = hRichEdit
end function


'SetProgressbar(hwnd,x,y,w,h,min,max,pos,flag,ext)
function SetProgressBar (byval _ehwnd as int,byval _ex as int,byval _ey as int,byval _ew as int,byval _eh as int,byval _emin as int,byval _emax as int,byval _epos as int,byval _eflag as int,byval _ext as int,byval cID as int)
  if _eflag = 0 then
    _eflag=WS_CHILD or WS_VISIBLE
  end if
  hprogress = CreateWindowEx(_ext,"msctls_progress32","",_eflag,_ex,_ey,_ew,_eh,_ehwnd,cID,0,0)
  'UpdateWindow hprogress
  SendMessage(hprogress,PBM_SETRANGE32,_emin,_emax)
  SendMessage(hprogress,PBM_SETPOS,_epos,0)
   UpdateWindow hprogress
  return hprogress
end function


'Progress SET  POSITION
sub PBSetPos (byval _hpb as int,byval _pbpos as int)
if _hpb <> 0
SendMessage(_hpb,PBM_SETPOS,_pbpos,0)
UpdateWindow _hpb
end if
end sub


'syn : SetRadioButton (hwnd,x,y,w,h,caption,style,ext,controlID)
function SetRadioButton(byval _bhwnd as int,byval _bx as int,byval _by as int,byval _bw as int,byval _bh as int, byval _btext as string,byval _bflag as int,byval _ext as int,byval _cID as int) as int
INT _hfont
if _bflag=0
    _bflag = 0x50000009
end if
_ext = 0
hButton = CreateWindowEx(_ext,"BUTTON",_btext,_bflag,_bx,_by,_bw,_bh,_bhwnd,_cID,0,0)
_hfont = GetStockObject(17)
SendMessage hButton,WM_SETFONT,_hfont,0
UpdateWindow _bhwnd
function = hButton
end function


'syn : SetCheckBox (hwnd,x,y,w,h,caption,style,ext,controlID)
function SetCheckBox (byval _bhwnd as int,byval _bx as int,byval _by as int,byval _bw as int,byval _bh as int, byval _btext as string,byval _bflag as int,byval _ext as int,byval _cID as int) as int
INT _hfont
if _bflag=0
    _bflag = 0x50008003
end if
_ext = 0
hButton = CreateWindowEx(_ext,"BUTTON",_btext,_bflag,_bx,_by,_bw,_bh,_bhwnd,_cID,0,0)
_hfont = GetStockObject(17)
SendMessage hButton,WM_SETFONT,_hfont,0
UpdateWindow _bhwnd
function = hButton
end function


function SetComboBox(byval _cbhwnd as int,byval _cbx as int,byval _cby as int,byval _cbw as int,byval _cbh as int, byval _cbtext as string,byval _cbflag as int,byval _ext as int,byval _cID as int) as int
INT _hfont
  if _cbflag=0
    _cbflag = 0x50A00603
  EndIf
  hComboBox = CreateWindowEx(_ext,"COMBOBOX",_cbText,_cbflag,_cbx,_cby,_cbw,_cbh,_cbhwnd,_cID,0,0)
_hfont = GetStockObject(17)
SendMessage hComboBox,WM_SETFONT,_hfont,0
UpdateWindow _cbhwnd
function = hComboBox
end function


function SetTreeView(byval _tvhwnd as int,byval _tvx as int,byval _tvy as int,byval _tvw as int,_tvh,byval tvflag as int,byval _tvextend as int,byval _cID as int) as int
  'INT hTreeView
  if tvflag=0
    tvflag= tvflag | WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT
  EndIf
  'if _tvinit=0
   ' FirstTreeViewInit()
  'EndIf
 hTreeView  = CreateWindowEx(_tvextend,"SysTreeView32","",tvflag,_tvx,_tvy,_tvw,_tvh,_tvhwnd,_cID,0,0)
UpdateWindow _tvhwnd
  function = hTreeView
end function


'FN -> InsertItem (hwnd ,text ,parent ,insertafter ,img, select)
function TVInsertItem (byval hTree as int ,tvText as string,byval tvParent as int,byval insertAfter as int,byval hImg as int,byval tvselect as int ) as int
INT h
tvi.hparent = tvParent
tvi.hinsertAfter = insertAfter
tvi.mask = TVIF_TEXT | TVIF_IMAGE |TVSELECTEDIMAGE
tvi.state = 0
tvi.statemask = 0
tvi.pszText = strptr(tvText) 
tvi.cchtextmax = sizeOf(tvText)+1 
tvi.iImage = 0
tvi.iSelectedImage = 1
h = SendMessage(hTree,TVM_INSERTITEM,0,&tvi)
'UpdateWindow hTree
Function= h
end function


function SetTabControl (byval _tbhwnd as int,byval _tx as int,byval _ty as int,byval _tw as int,byval _th as int,byval _tbflag as int,byval _ex as int,byval cID as int) as int
INT _hfont
  if _tbflag=0
    _tbflag=WS_CHILD | WS_VISIBLE| TCS_HOTTRACK
  end if
  
  hTabControl = CreateWindowEx(_ex,"SysTabControl32","",_tbflag,_tx,_ty,_tw,_th,_tbhwnd,cID,0,0)
 _hfont = GetStockObject(17)
 SendMessage hTabControl,WM_SETFONT,_hfont,0
  UpdateWindow _tbhwnd
function = hTabControl
end function


'AddTab
function AddTab (byval hwnd as int ,byval tbpos as int,byval tbtext as String ) as int
TC_ITEM tie
tie.mask=1
tie.pszText= strptr(tbtext)
tie.cchTextMax=Len(tbtext)
tie.iImage = -1
SendMessage(hWnd,0x1307,tbpos,&tie)

end function


function SetTabText (cntID as int,tbIndex as int,tabText as String)
TC_ITEM tie
tie.mask=1
tie.pszText= strptr(tabText)
tie.cchTextMax=Len(tabtext)
tie.iImage = -1
SendMessage(cntID,TCM_SETITEM,tbIndex,&tie)
Return
end function


sub SetSelectedTab (cntID as int,index as int)
Sendmessage (cntID,TCM_SETCURSEL,index,0)

'return tbIndex
end sub


function GetSelectedTab (cntID as int) as sys
INT tbIndex
tbIndex = Sendmessage (cntID,TCM_GETCURSEL,0,0)

return tbIndex
end function


function GetTabText (cntID as int,tbIndex as int) as string
string tabText=Space(256)
TC_ITEM tie
tie.mask=1
tie.pszText = strptr tabText
tie.cchTextMax = 256
tie.iImage = -1
Sendmessage (cntID,TCM_GETITEM,tbIndex,&tie)
return tabText
end function


function GetTabCount (cntID as int) as int
INT tbCount
tbCount = Sendmessage (cntID,TCM_GETITEMCOUNT,0,0)

return tbCount
end function


function DeleteTab (cntID as int, index as int ) as int
Sendmessage (cntID,TCM_DELETEITEM,index,0)
return 0
end function


function SetToolbar (byval _tbhwnd as int,byval _tbflag as int,byval _ex as int,byval cID as int) as int
INT _hfont
INT  TBSTYLES = TBSTYLE_FLAT '| CCS_ADJUSTABLE '| CCS_NODIVIDER 
  if _tbflag=0
    _tbflag=1342179328 | TBSTYLES |4 | 0X100
  'ELSE
   '_tbflag=1342179328 | TBSTYLES |4 | _tbflag
  end if
  
  hTBControl = CreateWindowEx(_ex,"ToolbarWindow32","",_tbflag,0,0,0,0,_tbhwnd,0,0,0)
 _hfont = GetStockObject(17)
 SendMessage hTBControl,WM_SETFONT,_hfont,0
  UpdateWindow _tbhwnd
function = hTBControl
end function


'set tooltip control
function SetToolTip (byval _tthwnd as int) as int
INT _hfont


hTTControl = CreateWindowEx(0,"tooltips_class32","", -805306368,0,0,0,0,_tthwnd,0,0,0)
SendMessage( _tthwnd, 1060, hTTControl,0)


function = hTTControl
end function

'Statusbar...
function SetStatusBar (byval shwnd as int,byval stext as STRING,byval sflag as int,byval ex as int) as int
  if sflag=0
    sflag= 1409286400 
    'sflag = WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP | WS_CLIPSIBLINGS
  end if
  hStatus =CreateWindowEx(ex,"msctls_statusbar32",stext,sflag,0,0,0,0,shwnd,0,0,0)
'UpdateWindow shwnd  
  return hStatus
end function


'Trackbar...
function SetTrackBar (sys _ehwnd,_ex,_ey,_ew,_eh,_emin,_emax,_epage,_epos,_eflag,_ext,_tID)
  
  if _eflag=0
    _eflag = TRACKBARNORMAL|_eflag
  end if
  hTrackbar=CreateWindowEx(_ext,"msctls_trackbar32","",_eflag,_ex,_ey,_ew,_eh,_ehwnd,_tID,0,0)
  SendMessage(hTrackbar, TBM_SETPAGESIZE,0,_epage)
  SendMessage(hTrackbar, TBM_SETRANGEMIN, 0,_emin)
  SendMessage(hTrackbar, TBM_SETRANGEMAX, 0,_emax)
  SendMessage(hTrackbar, TBM_SETPOS, 1,_epos)
  return hTrackbar
end function

function GetTrackPos (byval wnd as int) as int
INT tpos
  tpos=SendMessage( wnd , 1024,0,0)
return tpos
end function


function Randomize()
sys_Seed = timeGetTime
end function


function RGB(sys red,green,blue) as sys
  sys color
  color = red
  color = color + green*256
  color = color + blue*65536
  return color
end function 


'sub PSet(wnd as int,sys x, y, r, g, b)
'sys pcolor = RGB(r,g,b)
'Setpixel hdc, x, y,pcolor
'ReleaseDC(wnd, hdc)
'end sub


function Rand(byval z1 as long, byval z2 as long) as long
Long rnd 
mov  eax,z2
sub  eax,z1
Inc  eax
imul edx,sys_Seed,0x8088405
Inc  edx
mov  sys_Seed,edx
mul  edx
add  edx,z1
mov  rnd,edx
function = rnd
end function


function LoadBitmap(byval BmpFile as String, byval wBmp as long, byval hBmp as long) as long
Static bNr as long: bNr +=1
if bNr >256 Then bNr =256  
BmpHnd(bNr) = LoadImage(0, BmpFile,0,0,0,16)
BmpHdc(bNr) = CreateCompatibleDC(sys_hdc)
SelectObject BmpHdc(bNr), BmpHnd(bNr)
BmpWide(bNr) = wBmp
BmpHigh(bNr) = hBmp
function     = bNr
end function 


function SetImage(byval iWidth as long, byval iHeight as long) as long
ImgHnd = CreateCompatibleBitmap(sys_hdc, iWidth, iHeight)
ImgHdc = CreateCompatibleDC(sys_hdc)
SelectObject ImgHdc, ImgHnd
ImgWidth = iWidth:ImgHeight = iHeight
function = ImgHdc
end function


function FlipImageRect(byval x1 as long, byval y1 as long, byval iw as long, byval ih as long, byval x0 as long, byval y0 as long)
BitBlt sys_hdc, x1, y1, iw, ih, ImgHdc, x0, y0, 0XCC0020
end function


function ClearImage()
PatBlt ImgHdc, 0, 0, ImgWidth, ImgHeight, 0X42
end function


function FreeGraphics()
DeleteObject BackHnd
DeleteDC     BackHdc
DeleteObject ImgHnd
DeleteDC     ImgHdc 
DeleteObject sys_Font 
end function


function Key(byval cKey as long) as long
function = GetAsyncKeyState(cKey)
end function


function EscKey() as long
function = GetAsyncKeyState(27)
end function


sub Font(long hwnd,sys width, height, flag, string fontname)  
sys hFont
hFont = CreateFont height,width,0,0,flag,0,0,0,0,0,0,0,0,fontname
bHdc=GetDC(hwnd)
SelectObject bHdc, hFont
SetBkMode bHdc,1
DeleteObject hFont
Font_Width = width
Font_Height= height
Font_Flag  = flag
Font_Name  = fontname
end sub


function GetRGB(byval color as long, co as long) as long 
cRGB.r = color & 0XFF0000
cRGB.g = color & 0X00FF00
cRGB.b = color & 0X0000FF
if  co = 1 Then function = cRGB.r
if  co = 2 Then function = cRGB.g
if  co = 4 Then function = cRGB.b
end function


'MsgBox
function MsgBox (lpText as STRING,lpCaption as STRING) as int
if lpCaption = "" then lpCaption="<MsgBox>"
return MessageBox 0,lpText,lpCaption,0
end function


function Replace(string t,w,r) as string
'
sys a,b,lw,lr
string s=t
'
lw=Len(w)
lr=Len(r)
a=1
'  
do
  a=Instr(a,s,w)
  if a=0 then exit do
  s=Left(s,a-1)+r+Mid(s,a+lw)
  a+=lr
end do
return s
end function


'Contributed by James C. Fuller - April 2009.
' LTRIM
' multiple entries in Match are treated individually
function Trim(Main as String) as String
  String res=""
  res = Ltrim(Rtrim(Main)) 
  return res
end function

 
'FileDialog( $ iDir , $ filter ,$ title , % parent ,% flag )
function FileDialog(String Dir, filter , Title , long Hwnd, Flags, string defext) as String
dim ofn as OPENFILENAME
dim filename[255] as zstring 
INT retval	
ofn.lStructSize = 76
ofn.hwndOwner = hWnd
ofn.hInstance = GetModuleHandle(0)
ofn.lpstrFilter = strptr filter
ofn.lpstrCustomFilter= NULL
ofn.nMaxCustFilter = 0
ofn.nFilterIndex = 2
ofn.lpstrFile = @ filename 'zstring buffer
ofn.nMaxFile = 255
ofn.lpstrFileTitle = NULL
ofn.nMaxFileTitle = 0
ofn.lpstrInitialDir = strptr dir
ofn.lpstrTitle = strptr title
if Flags = 0 then ofn.Flags = OFN_EXPLORER Or OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY
if Flags = 1 then ofn.Flags = OFN_EXPLORER Or OFN_OVERWRITEPROMPT Or OFN_HIDEREADONLY
ofn.nFileOffset = 0
ofn.nFileExtension = 0
ofn.lpstrDefExt = strptr defext
ofn.lCustData = 0
ofn.lpfnHook = 0
ofn.lpTemplateName = NULL
' Execute the dialog box
if Flags = 0 then retval = GetOpenFileName(ofn)
if Flags = 1 then retval = GetSaveFileName(ofn)
return filename
end function
 