Babygrid coded with FB

Windows specific questions.
Post Reply
aloberoger
Posts: 507
Joined: Jan 13, 2009 19:23

Babygrid coded with FB

Post by aloberoger »

Since I Know there is not Grid completly coded with FreeBasic unless the Jonk QSTRINGGRID with RQ
Here Is my first try of this
Babigrid.bi

Code: Select all

#IFNDEF _BABYGR_bi_
#DEFINE _BABYGR_bi_

#INCLUDE ONCE "windows.bi"
#INCLUDE Once "crt.bi"

#DEFINE BABYGRID_CORE

#define CR chr(13)
#define DQ chr(34)
#define CRLF chr(13,10)
#Define FBTAB  Chr(9)
#Define LF   Chr(10)
#define BAND And
#define BOR Or
#Define _RGB(r,g,b) ((cint(r) shl 16) or (cint(g) shl 8) or cint(b))


#define MAX_GRIDS 20
#define MAX_ROWS 32000
#define MAX_COLS 256

Dim Shared As HFONT hfontbody,hfontheader,hfonttitle 

Dim Shared As HFONT holdfont 

type _gridhandlestruct
	gridmenu as UINT
	hlist1 as HWND
	protect as zstring * 2
	title as zstring * 305
	editstring as zstring * 305
	editstringdisplay as zstring * 305
	rows as integer
	cols as integer
	gridwidth as integer
	gridheight as integer
	homerow as integer
	homecol as integer
	rowheight as integer
	leftvisiblecol as integer
	rightvisiblecol as integer
	topvisiblerow as integer
	bottomvisiblerow as integer
	headerrowheight as integer
	cursorrow as integer
	cursorcol as integer
	ownerdrawitem as integer
	visiblecolumns as integer
	titleheight as integer
	fontascentheight as integer
	cursorcolor as COLORREF
	protectcolor as COLORREF
	unprotectcolor as COLORREF
	textcolor as COLORREF
	highlightcolor as COLORREF
	gridlinecolor as COLORREF
	highlighttextcolor as COLORREF
	DRAWHIGHLIGHT as BOOL
	ADVANCEROW as BOOL
	CURRENTCELLPROTECTED as BOOL
	GRIDHASFOCUS as BOOL
	AUTOROW as BOOL
	activecellrect as RECT
	hfont as HFONT
	hcolumnheadingfont as HFONT
	htitlefont as HFONT
	ROWSNUMBERED as BOOL
	COLUMNSNUMBERED as BOOL
	EDITABLE as BOOL
	EDITING as BOOL
	EXTENDLASTCOLUMN as BOOL
	HSCROLL as BOOL
	VSCROLL as BOOL
	SHOWINTEGRALROWS as BOOL
	SIZING as BOOL
	ELLIPSIS as BOOL
	COLAUTOWIDTH as BOOL
	COLUMNSIZING as BOOL
	ALLOWCOLUMNRESIZING as BOOL
	columntoresize as integer
	columntoresizeinitsize as integer
	columntoresizeinitx as integer
	cursortype as integer
	columnwidths(0 to MAX_COLS+1-1) as integer
	REMEMBERINTEGRALROWS as BOOL
	wannabeheight as integer
	wannabewidth as integer
end Type

Dim Shared As Integer BG_GridIndex 
Dim Shared As Integer FindResult 
'Dim Shared As data_ As ZString*1000 

Dim Shared As CREATESTRUCT cs
Dim Shared As CREATESTRUCT Ptr lpcs 

'
'01file: BabyGrid.h

' ''BABYGRID code originally by David Hillard translated to FreeBasic by ALOBER
' 
''
' 
''This code must retain this copyright message
' 
 




#DEFINE BGN_LBUTTONDOWN &h0001
#DEFINE BGN_MOUSEMOVE   &h0002
#Define BGN_OUTOFRANGE  &h0003
#DEFINE BGN_OWNERDRAW   &h0004
#DEFINE BGN_SELCHANGE   &h0005
#DEFINE BGN_ROWCHANGED  &h0006
#DEFINE BGN_COLCHANGED  &h0007
#DEFINE BGN_EDITBEGIN   &h0008
#DEFINE BGN_DELETECELL  &h0009
#DEFINE BGN_EDITEND     &h000A
#DEFINE BGN_F1          &h000B
#DEFINE BGN_F2          &h000C
#DEFINE BGN_F3          &h000D
#DEFINE BGN_F4          &h000E
#DEFINE BGN_F5          &h000F
#DEFINE BGN_F6          &h0010
#DEFINE BGN_F7          &h0011
#DEFINE BGN_F8          &h0012
#DEFINE BGN_F9          &h0013
#DEFINE BGN_F10         &h0014
#DEFINE BGN_F11         &h0015
#DEFINE BGN_F12         &h0016
#DEFINE BGN_GOTFOCUS    &h0017
#DEFINE BGN_LOSTFOCUS   &h0018
#DEFINE BGN_CELLCLICKED &h0019
#DEFINE BGM_PROTECTCELL WM_USER + 1
#DEFINE BGM_SETPROTECT  WM_USER + 2
#DEFINE BGM_SETCELLDATA WM_USER + 3
#DEFINE BGM_GETCELLDATA WM_USER + 4
#DEFINE BGM_CLEARGRID   WM_USER + 5
#DEFINE BGM_SETGRIDDIM  WM_USER + 6
#DEFINE BGM_DELETECELL  WM_USER + 7
#DEFINE BGM_SETCURSORPOS WM_USER + 8
#DEFINE BGM_AUTOROW     WM_USER + 9
#DEFINE BGM_GETOWNERDRAWITEM WM_USER + 10
#DEFINE BGM_SETCOLWIDTH WM_USER + 11
#DEFINE BGM_SETHEADERROWHEIGHT WM_USER + 12
#DEFINE BGM_GETTYPE     WM_USER + 13
#DEFINE BGM_GETPROTECTION WM_USER + 14
#DEFINE BGM_DRAWCURSOR  WM_USER + 15
#DEFINE BGM_SETROWHEIGHT WM_USER + 16
#DEFINE BGM_SETCURSORCOLOR WM_USER + 17
#DEFINE BGM_SETPROTECTCOLOR WM_USER + 18
#DEFINE BGM_SETUNPROTECTCOLOR WM_USER + 19
#DEFINE BGM_SETROWSNUMBERED WM_USER + 20
#DEFINE BGM_SETCOLSNUMBERED WM_USER + 21
#DEFINE BGM_SHOWHILIGHT WM_USER + 22
#DEFINE BGM_GETROWS WM_USER + 23
#DEFINE BGM_GETCOLS WM_USER + 24
#DEFINE BGM_NOTIFYROWCHANGED WM_USER + 25
#DEFINE BGM_NOTIFYCOLCHANGED WM_USER + 26
#DEFINE BGM_GETROW WM_USER + 27
#DEFINE BGM_GETCOL WM_USER + 28
#DEFINE BGM_PAINTGRID WM_USER + 29
#DEFINE BGM_GETCOLWIDTH WM_USER + 30
#DEFINE BGM_GETROWHEIGHT WM_USER + 31
#DEFINE BGM_GETHEADERROWHEIGHT WM_USER + 32
#DEFINE BGM_SETTITLEHEIGHT WM_USER + 33
#DEFINE BGM_SETHILIGHTCOLOR WM_USER + 34
#DEFINE BGM_SETHILIGHTTEXTCOLOR WM_USER + 35
#DEFINE BGM_SETEDITABLE WM_USER + 36
#DEFINE BGM_SETGRIDLINECOLOR WM_USER + 37
#DEFINE BGM_EXTENDLASTCOLUMN WM_USER + 38
#DEFINE BGM_SHOWINTEGRALROWS WM_USER + 39
#DEFINE BGM_SETELLIPSIS WM_USER + 40
#DEFINE BGM_SETCOLAUTOWIDTH WM_USER + 41
#DEFINE BGM_SETALLOWCOLRESIZE WM_USER + 42
#DEFINE BGM_SETTITLEFONT WM_USER + 43
#DEFINE BGM_SETHEADINGFONT WM_USER + 44


TYPE _BGCELL Field=1
  row AS INTEGER
  col AS INTEGER
END Type

Type LPBGCELL As _BGCELL Ptr
Dim Shared  BGcell AS _BGCELL 
Dim Shared LPBGcell AS LPBGCELL

Dim Shared BGHS(MAX_GRIDS) As _gridhandlestruct
Dim Shared As _BGCELL  cell 


''function forward declarations
' 
declare function RegisterGridClass (byval hInstance as Const HINSTANCE) as ATOM

 Declare  Function  GridProc(As HWND, As UINT,As  WPARAM, As LPARAM) As LRESULT
 Declare sub SetCell(cell As LPBGCELL ,row As integer ,col as Integer ) 
' 
' ''macro defs
 #define BabyGrid_AutoRow(hGrid,fSet) cast(Integer,SendMessage((hGrid),BGM_AUTOROW,fSet,0))
 #define BabyGrid_ClearGrid(hGrid) cast(Integer,SendMessage((hGrid),BGM_CLEARGRID,0,0))
 #define BabyGrid_DeleteCell(hGrid,pCell) cast(Integer,SendMessage((hGrid),BGM_DELETECELL,cast(UINT,pCell),0))
 
 #define BabyGrid_ExtendLastColumn(hGrid,fSet) cast(Integer,SendMessage((hGrid),BGM_EXTENDLASTCOLUMN,fSet,0))
 #define BabyGrid_GetCellData(hGrid,pCell,lpzText) cast(Integer,SendMessage(hGrid,BGM_GETCELLDATA,cast(WPARAM,pCell),CInt(StrPtr(lpzText))))
 
 #define BabyGrid_GetCol(hGrid) cast(Integer,SendMessage((hGrid),BGM_GETCOL,0,0)))
 #define BabyGrid_GetColWidth(hGrid,iCol) cast(Integer,SendMessage((hGrid),BGM_GETCOLWIDTH,iCol,0))
 #define BabyGrid_GetCols(hGrid) cast(Integer,SendMessage((hGrid),BGM_GETCOLS,0,0))
 
 #define BabyGrid_GetOwnerDrawItem(hGrid) cast(Integer,SendMessage((hGrid),BGM_GETOWNERDRAWITEM,0,0))
 #define BabyGrid_GetHeaderRowHeight(hGrid) cast(Integer,SendMessage((hGrid),BGM_GETHEADERROWHEIGHT,0,0))
 #define BabyGrid_GetProtection(hGrid,pCell) (BOOL)SendMessage((hGrid),BGM_GETPROTECTION,cast(UINT,pCell),0)) 
 
 #define BabyGrid_GetRow(hGrid) cast(Integer,SendMessage((hGrid),BGM_GETROW,0,0))
 #define BabyGrid_GetRowHeight(hGrid) cast(Integer,SendMessage((hGrid),BGM_GETROWHEIGHT,0,0)) 
 #define BabyGrid_GetRows(hGrid) cast(Integer,SendMessage((hGrid),BGM_GETROWS,0,0))
 #define BabyGrid_GetType(hGrid,pCell) cast(Integer,SendMessage((hGrid),BGM_GETTYPE,cast(UINT,pCell),0))
 
 #define BabyGrid_NotifyColChanged(hGrid) cast(Integer,SendMessage((hGrid),BGM_NOTIFYCOLCHANGED,0,0))
 #define BabyGrid_NotifyRowChanged(hGrid) cast(Integer,SendMessage((hGrid),BGM_NOTIFYROWCHANGED,0,0))
 
 #define BabyGrid_PaintGrid(hGrid) cast(Integer,SendMessage((hGrid),BGM_PAINTGRID,0,0))
 #define BabyGrid_ProtectCell(hGrid,pCell,fSet) cast(Integer,SendMessage((hGrid),BGM_PROTECTCELL,cast(UINT,(pCell),fSet))
 
 #define BabyGrid_SetAllowColResize(hGrid,fSet) cast(Integer,SendMessage((hGrid),BGM_SETALLOWCOLRESIZE,fSet,0))
 #define BabyGrid_SetCellData(hGrid,pCell,lpzText) cast(Integer,SendMessage((hGrid),BGM_SETCELLDATA,Cast(WPARAM,Cast(UINT,pCell)),CInt(StrPtr(lpzText))))
 
 #define BabyGrid_SetColAutoWidth(hGrid,fSet) cast(Integer,SendMessage((hGrid),BGM_SETCOLAUTOWIDTH,fSet,0))
 #define BabyGrid_SetColWidth(hGrid,iCol,nWidth) cast(Integer,SendMessage((hGrid),BGM_SETCOLWIDTH,iCol,nWidth))
 #define BabyGrid_SetColsNumbered(hGrid,fSet) cast(Integer,SendMessage((hGrid),BGM_SETCOLSNUMBERED,fSet,0))
 
 #define BabyGrid_SetCursorColor(hGrid, clrCrsr) cast(Integer,SendMessage((hGrid),BGM_SETCURSORCOLOR,cast(UINT,clrCrsr),0))
 #define BabyGrid_SetCursorPos(hGrid,iRow,iCol) cast(Integer,SendMessage((hGrid),BGM_SETCURSORPOS,iRow,iCol)
 
 #define BabyGrid_SetEditTable(hGrid,fSet) cast(Integer,SendMessage((hGrid),BGM_SETEDITABLE,fSet,0))
 #define BabyGrid_SetEllipsis(hGrid,fSet) cast(Integer,SendMessage((hGrid),BGM_SETELLIPSIS,fSet,0))
 
 #define BabyGrid_SetGridDim(hGrid,nRows,nCols) cast(Integer,SendMessage((hGrid),BGM_SETGRIDDIM,nRows,nCols))
 #define BabyGrid_SetGridLineColor(hGrid,clrGrdLine)  cast(Integer,SendMessage((hGrid),BGM_SETGRIDLINECOLOR,cast(UINT,clrGrdLine),0))
 
 #define BabyGrid_SetHeaderRowHeight(hGrid,nHeight) cast(Integer,SendMessage((hGrid),BGM_SETHEADERROWHEIGHT,nHeight,0))
 #define BabyGrid_SetHeadingFont(hGrid,hFont) cast(Integer,SendMessage((hGrid),BGM_SETHEADINGFONT,cast(UINT,hFont),0))
 
 #define BabyGrid_SetHilightColor(hGrid, clrHilt) cast(Integer,SendMessage((hGrid),BGM_SETHILIGHTCOLOR,cast(UINT,clrHilt),0))
 #define BabyGrid_SetHilightTextColor(hGrid, clrHlText) cast(Integer,SendMessage((hGrid),BGM_SETHILIGHTTEXTCOLOR,cast(UINT,clrHlText),0))
 
 #define BabyGrid_SetProtect(hGrid,fSet) cast(Integer,SendMessage(hGrid,BGM_SETPROTECT,fSet,0))
 #define BabyGrid_SetProtectColor(hGrid, clrProtect) cast(Integer,SendMessage((hGrid),BGM_SETPROTECTCOLOR,cast(UINT, clrProtect),0))
 
 #define BabyGrid_SetRowHeight(hGrid,iHeight) cast(Integer,SendMessage((hGrid),BGM_SETROWHEIGHT,iHeight,0))
 #define BabyGrid_SetRowsNumbered(hGrid,fSet) cast(Integer,SendMessage((hGrid),BGM_SETROWSNUMBERED,fSet,0))
 
 #define BabyGrid_SetTitleFont(hGrid,hFont) cast(Integer,SendMessage((hGrid),BGM_SETTITLEFONT,cast(UINT,hFont),0))
 #define BabyGrid_SetTitleHeight(hGrid,iHeight) cast(Integer,SendMessage((hGrid),BGM_SETTITLEHEIGHT,iHeight,0))
 #define BabyGrid_SetUnprotectColor(hGrid, clrUProtect) cast(Integer,SendMessage((hGrid),BGM_SETUNPROTECTCOLOR,cast(UINT, clrUProtect),0))
 
 #define BabyGrid_ShowHilight(hGrid,fShow) cast(Integer,SendMessage((hGrid),BGM_SHOWHILIGHT,fShow,0))
 #define BabyGrid_ShowIntegralRows(hGrid,fShow) cast(Integer,SendMessage((hGrid),BGM_SHOWINTEGRALROWS,fShow,0))
 
 ''worker macro to simplify the main program code for loading data
 #define BabyGrid_PutCell(hGrid,iRow,iCol,lpzText) _
            	BGcell.row = iRow: BGcell.col = iCol          : _
 	            BabyGrid_SetCellData(hGrid,@BGcell,lpzText)
 

 


''worker macro to simplify the main program code for retrieving data
 #DEFINE BabyGrid_ReadCell(hGrid,iRow,iCol,lpzText)  _
 	BGcell.row = iRow: BGcell.col = iCol: BabyGrid_GetCellData(hGrid,@BGcell,lpzText) 

 

''worker macro to simplify the main program code for deleting cells
 #DEFINE BabyGrid_PopCell(hGrid,iRow,iCol)  _
  	BGcell.row = iRow: BGcell.col = iCol: BabyGrid_DeleteCell(hGrid,@BGcell) 
 

''worker macros to simplify the main program code for cell attributes
  #DEFINE BabyGrid_CellIsProtected(hGrid,iRow,iCol,fProtect)  _
    	           BGcell.row = iRow: BGcell.col = iCol: _
 	              fProtect = BabyGrid_GetProtection(hGrid,@BGcell)
		
  #DEFINE BabyGrid_SetCellProtection(hGrid,iRow,iCol,fSet)  _
   	     BGcell.row = iRow: BGcell.col = iCol: BabyGrid_ProtectCell(hGrid,@BGcell,fSet)
	                                               
 #Define BabyGrid_GetCellDataType(hGrid,iRow,iCol,iType)  _
   	           BGcell.row = iRow: BGcell.col = iCol: _
 	              iType = BabyGrid_GetType(hGrid,@BGcell)


''To reduce flicker use the following instead of MoveWindow(...,bRepaint TRUE)

#DEFINE BabyGrid_Refresh(hWnd) RedrawWindow(hWnd,NULL,NULL,RDW_NOERASE Or RDW_INVALIDATE Or RDW_ALLCHILDREN Or RDW_UPDATENOW) 

' 

''Standard Window macro's for BabyGrid

#DEFINE BabyGrid_Enable(hwndCtl,fEnable) EnableWindow((hwndCtl),(fEnable))
#DEFINE BabyGrid_GetText(hwndCtl,lpch,cchMax) GetWindowText((hwndCtl),(lpch),(cchMax))
#DEFINE BabyGrid_GetTextLength(hwndCtl) GetWindowTextLength(hwndCtl)
#DEFINE BabyGrid_SetText(hwndCtl,lpsz) SetWindowText((hwndCtl),(lpsz))




declare function BinarySearchListBox  alias "BinarySearchListBox" (byval lbhWnd as HWND, byval searchtext as zstring ptr) as integer
declare function FindGrid  alias "FindGrid" (byval menuid as UINT) as integer
declare function AddGrid  alias "AddGrid" (byval menuid as UINT) as integer
declare function CountGrids  alias "CountGrids" () as integer
declare function FindLongestLine  alias "FindLongestLine" (byval hdc as HDC, byval text as zstring ptr, byval size as SIZE ptr) as integer
declare sub SizeGrid  alias "SizeGrid" (byval hWnd as HWND, byval SI as integer)
'declare function RegisterGridClass  alias "RegisterGridClass" (byval hInstance as HINSTANCE) as ATOM
declare sub DisplayEditString  alias "DisplayEditString" (byval hWnd as HWND, byval SI as integer, byval tstring as zstring ptr)
declare sub CloseEdit  alias "CloseEdit" (byval hWnd as HWND, byval SI as integer)
declare function GetNthVisibleColumn  alias "GetNthVisibleColumn" (byval hWnd as HWND, byval SI as integer, byval n as integer) as integer
declare sub GetVisibleColumns  alias "GetVisibleColumns" (byval hWnd as HWND, byval SI as integer)
declare sub NotifyCellClicked  alias "NotifyCellClicked" (byval hWnd as HWND, byval SI as integer)
declare sub NotifyF12  alias "NotifyF12" (byval hWnd as HWND, byval SI as integer)
declare sub NotifyF11  alias "NotifyF11" (byval hWnd as HWND, byval SI as integer)
declare sub NotifyF10  alias "NotifyF10" (byval hWnd as HWND, byval SI as integer)
declare sub ShowHscroll  alias "ShowHscroll" (byval hWnd as HWND, byval SI as integer)
declare sub ShowVscroll  alias "ShowVscroll" (byval hWnd as HWND, byval SI as integer)
declare sub SetHomeCol  alias "SetHomeCol" (byval hWnd as HWND, byval SI as integer, byval row as integer, byval col as integer)
declare sub SetHomeRow  alias "SetHomeRow" (byval hWnd as HWND, byval SI as integer, byval row as integer, byval col as integer)
declare function GetASCII  alias "GetASCII" (byval wParam as WPARAM, byval lParam as LPARAM) as byte
declare sub SetCurrentCellStatus  alias "SetCurrentCellStatus" (byval hWnd as HWND, byval SelfIndex as integer)
declare sub DrawCursor  alias "DrawCursor" (byval hWnd as HWND, byval SI as integer)
declare sub DisplayColumn  alias "DisplayColumn" (byval hWnd as HWND, byval SI as integer, byval c as integer, byval offset as integer, byval hfont as HFONT, byval hcolumnheadingfont as HFONT)
declare sub DisplayTitle  alias "DisplayTitle" (byval hWnd as HWND, byval SI as integer, byval hfont as HFONT)
declare function GetCellRect  alias "GetCellRect" (byval hWnd as HWND, byval SI as integer, byval r as integer, byval c as integer) as RECT
declare sub CalcVisibleCellBoundaries  alias "CalcVisibleCellBoundaries" (byval SelfIndex as integer)
declare function DetermineDataType  alias "DetermineDataType" (byval data as String ) as integer
'declare sub SetCell  alias "SetCell" (byval cell as LPBGCELL, byval row as integer, byval col as integer)
declare function OutOfRange  alias "OutOfRange" (byval cell as LPBGCELL) as BOOL
declare function GetColOfMouse  alias "GetColOfMouse" (byval SI as integer, byval x as integer) as integer
declare function GetRowOfMouse  alias "GetRowOfMouse" (byval SI as integer, byval y as integer) as integer
declare function GetNextColWithWidth  alias "GetNextColWithWidth" (byval SI as integer, byval startcol as integer, byval direction as integer) as integer
declare sub RefreshGrid  alias "RefreshGrid" (byval hWnd as HWND)
declare function HomeColumnNthVisible  alias "HomeColumnNthVisible" (byval SI as integer) as integer

'Dans le cas ou on n'a pas de dialog
Function Create_BG_Grid(Text As String ,hParent AS HWND,IDGRID as integer,x as Integer=10,y as Integer=10,w as Integer=350,h as Integer=300) AS HWND

Dim _hgrid AS HWND 

  RegisterGridClass(GetModuleHandle(0))
  
  If Text="" Then text= " "
  _hgrid=CreateWindowEx(WS_EX_CLIENTEDGE,"BABYGRID", _
               StrPtr(Text), WS_VISIBLE Or WS_CHILD,x,y,w,h,hParent,Cast(HMENU,IDGRID),GetModuleHandle(0),NULL)
  
  SendMessage(_hgrid,WM_SETFONT,Cast(WPARAM,GetStockObject(DEFAULT_GUI_FONT)),Cast(LPARAM,MAKELPARAM(FALSE,0)))

FUNCTION = _hgrid
END FUNCTION


#EndIf
   
aloberoger
Posts: 507
Joined: Jan 13, 2009 19:23

Re: Babygrid coded with FB

Post by aloberoger »


BabyGrid.bas

Code: Select all


#Include Once "babygrid.bi"

	'function forward declarations

'BABYGRID code originaly by David Hillard translated to FreeBasic by ALOBER

'This code must retain this copyright message
 


 
Function ShowLastError()As DWORD
 
 Dim As DWORD nLastError             ' Numéro de l'erreur 
 Dim As LPTSTR lpMessageBuffer       ' Récupération du message 

  nLastError = GetLastError() 

  /' Formatage du message '/
  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER Or FORMAT_MESSAGE_FROM_SYSTEM, _
                NULL, nLastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), _
                Cast(PVOID Ptr,@lpMessageBuffer), 0, NULL) 

  /' Affichage du message '/
  MessageBox(NULL, lpMessageBuffer, "ERROR", MB_OK Or MB_ICONERROR) 

  LocalFree(lpMessageBuffer) 
  return nLastError 
End Function

 

	
 Function HomeColumnNthVisible(ByVal SI As Integer) As Integer
		Dim j As Integer
		Dim hc As Integer
		Dim count As Integer
		count = 0
		hc = BGHS(SI).homecol
		For j = 1 To hc
			If BGHS(SI).columnwidths(j)>0 Then
				count += 1
			End If
		Next j
		Return count
	End Function

Sub RefreshGrid(ByVal hWnd As HWND)
		Dim rect As RECT
		Dim SI As Integer
		GetClientRect(hWnd, @rect)
		InvalidateRect(hWnd, @rect, 0)
		SI = FindGrid(CUInt(GetMenu(hWnd)))
		If BGHS(SI).EDITING <> 0 Then
			DisplayEditString(hWnd, SI, "")
		End If

	End Sub

Function GetNextColWithWidth(ByVal SI As Integer, ByVal startcol As Integer, ByVal direction As Integer) As Integer
		'calls with direction == 1 for right, direction == -1 for left
		'returns 0 if no more cols in that direction, else column number
		Dim j As Integer
		Dim ReturnValue As Integer
		j = startcol
		If direction = 1 Then
			j += 1
		End If
		If direction <> 1 Then
			j -= 1
		End If

		Do While (BGHS(SI).columnwidths(j) = 0) And (j<=BGHS(SI).cols) And (j>0)
			If direction = 1 Then
				j += 1
			End If
			If direction <> 1 Then
				j -= 1
			End If
		Loop
		If (BGHS(SI).columnwidths(j) > 0) And (j<=BGHS(SI).cols) Then
			ReturnValue = j
		Else
			ReturnValue = 0
		End If
		Return ReturnValue
	End Function

 Function GetRowOfMouse(ByVal SI As Integer, ByVal y As Integer) As Integer
		Dim ReturnValue As Integer
		If y<=(BGHS(SI).titleheight) Then
			Return -1
		End If
		If (y>=BGHS(SI).titleheight) And (y<=BGHS(SI).headerrowheight + BGHS(SI).titleheight) Then
			Return 0
		End If


		y = y-(BGHS(SI).headerrowheight + BGHS(SI).titleheight)
		y = y\BGHS(SI).rowheight
		ReturnValue = BGHS(SI).homerow + y
		If ReturnValue > BGHS(SI).rows Then
			ReturnValue = -1
		End If
		Return ReturnValue
	End Function

 Function GetColOfMouse(ByVal SI As Integer, ByVal x As Integer) As Integer
		Dim ReturnValue As Integer
		Dim j As Integer
		If x<=BGHS(SI).columnwidths(0) Then
			Return 0
		End If

		x-=BGHS(SI).columnwidths(0)

		j = BGHS(SI).homecol
		Do While x>0
			x-=BGHS(SI).columnwidths(j)
			j += 1
		Loop
		j -= 1

		ReturnValue = j
		If BGHS(SI).EXTENDLASTCOLUMN <> 0 Then
			If j>BGHS(SI).cols Then
				ReturnValue = BGHS(SI).cols
			End If
		Else
			If j>BGHS(SI).cols Then
				ReturnValue = -1
			End If
		End If
		Return ReturnValue
	End Function

 Function OutOfRange(ByVal cell As LPBGCELL) As BOOL
		If (cell->row >MAX_ROWS) Or (cell->col > MAX_COLS) Then
			Return TRUE
		Else
			Return FALSE
		End If
 End Function
 
Sub SetCell(cell As LPBGCELL ,  row As Integer,  col As Integer)
	cell->row = row
	cell->col = col
End Sub

 Function DetermineDataType(ByVal data_ As String ) As Integer
		'return values:
		'       1 = Text or Alpha
		'       2 = Numeric
		'       3 = Boolean TRUE
		'       4 = Boolean FALSE
		'       5 = Graphic - user drawn (cell text begins with ~)
		Dim j As Integer
		Dim k As Integer
		Dim numberofperiods As Integer
		Dim tbuffer As  ZSTRING*1000
		Dim DIGIT As Integer
		Dim ALPHA_ As Integer
		Dim WHITESPACE As Integer
		
		strcpy(tbuffer,data_) 'tbuffer = *data_
		tbuffer=Trim(tbuffer)
		k = Len(tbuffer)
		tbuffer=Ucase(tbuffer)
		'is it boolean?
		If 0=StrCmp(tbuffer,"TRUE") Then
			Return 3
		End If
		If 0=StrCmp(tbuffer,"FALSE") Then
			Return 4
		End If
		'is it graphic (~)
		If tbuffer[0]=Asc("~") Then
			Return 5
		End If
		DIGIT = 0
		ALPHA_ = 0
		WHITESPACE = 0

		numberofperiods = 0
		For j = 0 To k - 1
			If isalpha(tbuffer[j]) Then
				ALPHA_ = 1
			End If
			If IsDigit(tbuffer[j]) Then
				DIGIT = 1
			End If
			If iswspace(tbuffer[j]) Then
				WHITESPACE = 1
			End If
			If tbuffer[j]=Asc(".") Then
				numberofperiods += 1
			End If
			If tbuffer[j]=Asc("+") Then
				If j>0 Then
					ALPHA_ = 1
				End If
			End If
			If tbuffer[j]=Asc("-") Then
				If j>0 Then
					ALPHA_ = 1
				End If
			End If
		Next j
		If (ALPHA_) Or (WHITESPACE) Then
			Return 1
		End If
		If (DIGIT) And ((0=ALPHA_)) And ((0=WHITESPACE)) Then
			If numberofperiods>1 Then
				Return 1
			Else
				Return 2
			End If
		End If
		Return 1
	End Function

 Sub CalcVisibleCellBoundaries(ByVal SelfIndex As Integer)
		Dim gridx As Integer
		Dim gridy As Integer
		Dim j As Integer
		gridx = BGHS(SelfIndex).gridwidth
		gridy = BGHS(SelfIndex).gridheight

		j = BGHS(SelfIndex).homecol
		BGHS(SelfIndex).leftvisiblecol = BGHS(SelfIndex).homecol
		BGHS(SelfIndex).topvisiblerow = BGHS(SelfIndex).homerow
		'calc columns visible
		'first subtract the width of col 0;
		gridx = gridx - BGHS(SelfIndex).columnwidths(0)
		Do
			gridx = gridx - BGHS(SelfIndex).columnwidths(j)
			j += 1
		Loop While (gridx >= 0) And (j<BGHS(SelfIndex).cols)

		If j>BGHS(SelfIndex).cols Then
			j = BGHS(SelfIndex).cols
		End If
		BGHS(SelfIndex).rightvisiblecol = j

		'calc rows visible;
		gridy = gridy - BGHS(SelfIndex).headerrowheight
		j = BGHS(SelfIndex).homerow
		Do
			gridy = gridy - BGHS(SelfIndex).rowheight
			j += 1
		Loop While (gridy > 0) And (j<BGHS(SelfIndex).rows)

		If j>BGHS(SelfIndex).rows Then
			j = BGHS(SelfIndex).rows
		End If
		BGHS(SelfIndex).bottomvisiblerow = j
	End Sub


 Function GetCellRect(ByVal hWnd As HWND, ByVal SI As Integer, ByVal r As Integer, ByVal c As Integer) As RECT
		Dim rect As RECT
		Dim offset As Integer
		Dim j As Integer
		'c and r must be greater than zero

		'get column offset
		'first get col 0 width
		offset = BGHS(SI).columnwidths(0)
		For j = BGHS(SI).homecol To c - 1
			offset += BGHS(SI).columnwidths(j)
		Next j
		rect.left = offset
		rect.right = offset + BGHS(SI).columnwidths(c)

		If BGHS(SI).EXTENDLASTCOLUMN <> 0 Then
			'see if this is the last column
			If 0=GetNextColWithWidth(SI, c, 1) Then
				'extend this column
				Dim trect As RECT
				Dim temp As Integer
				GetClientRect(hWnd, @trect)
				temp = (offset +(trect.right - rect.left))-rect.left
				If temp > BGHS(SI).columnwidths(c) Then
					rect.right = offset + (trect.right - rect.left)
				End If
			End If
		End If

		'now get the top and bottom of the rect
		offset = BGHS(SI).headerrowheight+BGHS(SI).titleheight
		For j = BGHS(SI).homerow To r - 1
			offset += BGHS(SI).rowheight
		Next j
		rect.top = offset
		rect.bottom = offset + BGHS(SI).rowheight
		Return rect
	End Function


 Sub DisplayTitle(ByVal hWnd As HWND, ByVal SI As Integer, ByVal hfont As HFONT)
		Dim rect As RECT
		Dim gdc As HDC
		Dim holdfont As HFONT

		GetClientRect(hWnd, @rect)

		gdc = GetDC(hWnd)
		SetBkMode(gdc,TRANSPARENT)
		holdfont = Cast(HFONT,(SelectObject(gdc,hfont)))
		rect.bottom = BGHS(SI).titleheight
		DrawEdge(gdc, @rect, EDGE_ETCHED, BF_MIDDLE Or BF_RECT Or BF_ADJUST)
		DrawTextEx(gdc, BGHS(SI).title, -1, @rect, DT_END_ELLIPSIS Or DT_CENTER Or DT_WORDBREAK Or DT_NOPREFIX, NULL)
		SelectObject(gdc,holdfont)
		ReleaseDC(hWnd,gdc)
 End Sub
 
  
  
 
Sub DisplayColumn(ByVal hWnd As HWND, ByVal SI As Integer, ByVal c As Integer, ByVal offset As Integer, ByVal hfont As HFONT, ByVal hcolumnheadingfont As HFONT)
		Dim gdc As HDC
		Dim rect As RECT
		Dim rectsave As RECT
		Dim holdfont As HFONT
		Dim r As Integer
		Dim buffer As  ZSTRING*1000
		Dim iDataType As Integer
		Dim iProtection As Integer
		If BGHS(SI).columnwidths(c)=0 Then
			Return
		End If

		gdc = GetDC(hWnd)
		SetBkMode(gdc,TRANSPARENT)
		ShowHscroll(hWnd,SI)
		ShowVscroll(hWnd, SI)

		holdfont = Cast(HFONT,SelectObject(gdc,hcolumnheadingfont))
		SetTextColor(gdc,BGHS(SI).textcolor)
		'display header row
		r = 0

		rect.left = offset + 0
		rect.top = BGHS(SI).titleheight '0
		rect.right = BGHS(SI).columnwidths(c) + offset
		rect.bottom = BGHS(SI).headerrowheight + BGHS(SI).titleheight

		If BGHS(SI).EXTENDLASTCOLUMN Then
			'see if this is the last column
			If 0=GetNextColWithWidth(SI,c,1) Then
				'extend this column
				Dim trect As RECT
				GetClientRect(hWnd, @trect)

				rect.right = offset + (trect.right - rect.left)
			End If
		Else
			If 0=GetNextColWithWidth(SI,c,1) Then
				'repaint right side of grid
				Dim trect As RECT
				Dim holdbrush As HBRUSH
				Dim holdpen As HPEN
				GetClientRect(hWnd, @trect)
				trect.left=offset+(rect.right-rect.left)
				holdbrush = Cast(HBRUSH,SelectObject(gdc,GetStockObject(GRAY_BRUSH)))
				holdpen = Cast(HPEN,SelectObject(gdc,GetStockObject(NULL_PEN)))
				Rectangle(gdc,trect.left,trect.top+BGHS(SI).titleheight,trect.right+1,trect.bottom+1)
				SelectObject(gdc,holdbrush)
				SelectObject(gdc,holdpen)

			End If
		End If

		SetCell(@BGcell, r, c)
		strcpy(buffer,"")
		SendMessage(hWnd, BGM_GETCELLDATA, CUInt(@BGcell), CInt(StrPtr(buffer)))
		 
		If BGHS(SI).COLUMNSNUMBERED Then
			If c>0 Then
				Dim high As Integer
				Dim low As Integer
				high = ((c-1)/26)
				low = c Mod 26
				If high = 0 Then
					high = 32
				Else
					high +=64
				End If
				If low = 0 Then
					low = 26
				End If
				low += 64
				 wsprintf(buffer,!"%c%c",high,low)
			End If
		End If
		rectsave = rect
		DrawEdge(gdc, @rect, EDGE_ETCHED, BF_MIDDLE Or BF_RECT Or BF_ADJUST)
		DrawTextEx(gdc, buffer, -1, @rect, DT_END_ELLIPSIS Or DT_CENTER Or DT_WORDBREAK Or DT_NOPREFIX, NULL)
		rect = rectsave

		r = BGHS(SI).topvisiblerow
		'set font for grid body
		SelectObject(gdc,hfont)
		Do While r<=BGHS(SI).bottomvisiblerow

			'try to set cursor row to different display color
			If (r = BGHS(SI).cursorrow) And (c>0) And (BGHS(SI).DRAWHIGHLIGHT) Then
				If BGHS(SI).GRIDHASFOCUS Then
					SetTextColor(gdc,BGHS(SI).highlighttextcolor)
				Else
					SetTextColor(gdc,_RGB(0,0,0)) 'set black text for nonfocus grid hilight
				End If
			Else
				SetTextColor(gdc,_RGB(0,0,0))
			End If

			rect.top = rect.bottom
			rect.bottom = rect.top + BGHS(SI).rowheight
			rectsave = rect
			SetCell(@BGcell, r, c)
			strcpy(buffer,"")
			SendMessage(hWnd, BGM_GETCELLDATA, cUInt(@BGcell), CInt(StrPtr(buffer)))
			If (c = 0) And (BGHS(SI).ROWSNUMBERED) Then
				wsprintf(buffer,!"%d",r)
			End If
			If c = 0 Then
				DrawEdge(gdc, @rect, EDGE_ETCHED, BF_MIDDLE Or BF_RECT Or BF_ADJUST)

			Else
				Dim hbrush As HBRUSH
				Dim holdbrush As HBRUSH
				Dim hpen As HPEN
				Dim holdpen As HPEN
				iProtection = SendMessage(hWnd, BGM_GETPROTECTION, CUInt(@BGcell), 0)
				If BGHS(SI).DRAWHIGHLIGHT Then 'highlight on
					If r = BGHS(SI).cursorrow Then
						If BGHS(SI).GRIDHASFOCUS Then
							hbrush = CreateSolidBrush(BGHS(SI).highlightcolor)
						Else
							hbrush = CreateSolidBrush(_RGB(200,200,200))
						End If

					Else
						If iProtection = 1 Then
							hbrush = CreateSolidBrush(BGHS(SI).protectcolor)
						Else
							hbrush = CreateSolidBrush(BGHS(SI).unprotectcolor)
						End If
					End If
				Else
					If iProtection = 1 Then
						hbrush = CreateSolidBrush(BGHS(SI).protectcolor)
					Else
						hbrush = CreateSolidBrush(BGHS(SI).unprotectcolor)
					End If

				End If
				hpen = CreatePen(PS_SOLID,1,BGHS(SI).gridlinecolor)
				holdbrush = Cast(HBRUSH,SelectObject(gdc,hbrush))
				holdpen = Cast(HPEN,SelectObject(gdc,hpen))
				Rectangle(gdc,rect.left,rect.top,rect.right,rect.bottom)
				SelectObject(gdc,holdbrush)
				SelectObject(gdc,holdpen)
				DeleteObject(hbrush)
				DeleteObject(hpen)
			End If
			rect.right -= 2
			rect.left += 2

			iDataType = SendMessage(hWnd, BGM_GETTYPE, CUInt(@BGcell), 0)
			If (iDataType < 1) or  (iDataType > 5) Then
				iDataType = 1 'default to alphanumeric data type.. can't happen
			End If
			If c = 0 Then
				iDataType = 2
			End If

			If iDataType = 1 Then 'ALPHA
				If BGHS(SI).ELLIPSIS Then
					DrawTextEx(gdc, buffer , -1, @rect, DT_END_ELLIPSIS Or DT_LEFT Or DT_VCENTER Or DT_SINGLELINE Or DT_NOPREFIX, NULL)
				Else
					DrawTextEx(gdc,  buffer , -1, @rect, DT_LEFT Or DT_WORDBREAK Or DT_EDITCONTROL Or DT_NOPREFIX, NULL)
				End If
			End If

			If iDataType = 2 Then 'NUMERIC
				DrawTextEx(gdc,  buffer , -1, @rect, DT_END_ELLIPSIS Or DT_RIGHT Or DT_VCENTER Or DT_SINGLELINE Or DT_NOPREFIX, NULL)
			End If

			If iDataType = 3 Then 'BOOLEAN TRUE
				Dim k As Integer
				Dim excess As Integer
				k = 2
				rect.top +=k
				rect.bottom -=k
				rect.left +=0
				rect.right -=0
				If (rect.bottom - rect.top)>24 Then
					excess = (rect.bottom - rect.top)-16
					rect.top += CInt((excess\2))
					rect.bottom -= CInt((excess\2))
				End If
				DrawFrameControl(gdc, @rect, DFC_BUTTON, DFCS_BUTTONCHECK Or DFCS_CHECKED)
			End If

			If iDataType = 4 Then 'BOOLEAN FALSE
				Dim k As Integer
				Dim excess As Integer
				k = 2
				rect.top +=k
				rect.bottom -=k
				rect.left +=0
				rect.right -=0
				If (rect.bottom - rect.top)>24 Then
					excess = (rect.bottom - rect.top)-16
					rect.top += CInt((excess\2))
					rect.bottom -= CInt((excess\2))
				End If

				DrawFrameControl(gdc, @rect, DFC_BUTTON, DFCS_BUTTONCHECK)
			End If

			If iDataType = 5 Then 'user drawn graphic
				Dim wParam As WPARAM
				buffer[0]=&H20
				BGHS(SI).ownerdrawitem = CInt(buffer)
				wParam = MAKEWPARAM(CUInt(GetMenu(hWnd)),BGN_OWNERDRAW)
				SendMessage(GetParent(hWnd), WM_COMMAND, wParam, CLng(@rect))
			End If

			If BGHS(SI).EDITING Then
				DisplayEditString(hWnd,SI,"")
			End If

			rect = rectsave
			r += 1
		Loop 'end while r<=bottomvisiblerow

		'repaint bottom of grid
		Dim trect As RECT
		Dim holdbrush As HBRUSH
		Dim holdpen As HPEN
		GetClientRect(hWnd, @trect)
		trect.top = rect.bottom
		trect.left = rect.left
		trect.right = rect.right

		holdbrush = Cast(HBRUSH,SelectObject(gdc,GetStockObject(GRAY_BRUSH)))
		holdpen   = Cast(HPEN,SelectObject(gdc,GetStockObject(NULL_PEN)))

		Rectangle(gdc,trect.left,trect.top,trect.right+1,trect.bottom+1)

		SelectObject(gdc,holdbrush)
		SelectObject(gdc,holdpen)

		SelectObject(gdc,holdfont)
		DeleteObject(holdfont)
		ReleaseDC(hWnd,gdc)
	End Sub

 Sub DrawCursor(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim rect As RECT
		Dim rectwhole As RECT
		Dim gdc As HDC
		Dim hpen As HPEN
		Dim holdpen As HPEN
		Dim rop As Integer
		If BGHS(SI).rows = 0 Then
			Return
		End If
		GetClientRect(hWnd, @rect)
		'if active cell has scrolled off the top, don't draw a focus rectangle
		If BGHS(SI).cursorrow < BGHS(SI).homerow Then Return
		 
		'if active cell has scrolled off to the left, don't draw a focus rectangle
		If BGHS(SI).cursorcol < BGHS(SI).homecol Then Return
		 

		rect = GetCellRect(hWnd,SI,BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		rectwhole = rect
		gdc = GetDC(hWnd)
		BGHS(SI).activecellrect = rect
		rop = GetROP2(gdc)
		SetROP2(gdc,R2_XORPEN)
		SelectObject(gdc,Cast(HBRUSH,GetStockObject(NULL_BRUSH)))
		hpen = CreatePen(PS_SOLID,3,BGHS(SI).cursorcolor) 'width of 3
		holdpen = Cast(HPEN,SelectObject(gdc,hpen))
		Rectangle(gdc,rect.left,rect.top,rect.right,rect.bottom)
		SelectObject(gdc,holdpen)
		DeleteObject(hpen)
		SetROP2(gdc,rop)
		ReleaseDC(hWnd,gdc)
	End Sub

 Sub SetCurrentCellStatus(ByVal hWnd As HWND, ByVal SelfIndex As Integer)
		SetCell(@BGcell, BGHS(SelfIndex).cursorrow, BGHS(SelfIndex).cursorcol)
		If SendMessage(hWnd, BGM_GETPROTECTION, CUInt(@BGcell), 0) Then
			BGHS(SelfIndex).CURRENTCELLPROTECTED = 1
		Else
			BGHS(SelfIndex).CURRENTCELLPROTECTED = 0
		End If

	End Sub

 Function GetASCII(ByVal wParam As WPARAM, ByVal lParam As LPARAM) As BYTE
		Dim returnvalue As Integer
		Dim mbuffer As ZString*100
		Dim result As Integer
		Dim keys(255) As Byte
		Dim dwReturnedValue As WORD
		GetKeyboardState(@keys(0))
		result = ToAscii_(CUInt(wParam), CUInt((lParam Shr 16) And &Hff), @keys(0), @dwReturnedValue, 0)
		returnvalue = CByte(dwReturnedValue)
		If returnvalue < 0 Then
			returnvalue = 0
		End If
		wsprintf(mbuffer,!"return value = %d",returnvalue)
		If result<>1 Then
			returnvalue = 0
		End If
		Return CByte(returnvalue)

	End Function

 Sub SetHomeRow(ByVal hWnd As HWND, ByVal SI As Integer, ByVal row As Integer, ByVal col As Integer)
		Dim gridrect As RECT
		Dim cellrect As RECT
		'get rect of grid window
		GetClientRect(hWnd, @gridrect)
		'get rect of current cell
		cellrect = GetCellRect(hWnd,SI,row,col)
		If (cellrect.bottom > gridrect.bottom) And ((cellrect.bottom - cellrect.top)<(gridrect.bottom-(BGHS(SI).headerrowheight+BGHS(SI).titleheight))) Then
			Do While cellrect.bottom > gridrect.bottom
				BGHS(SI).homerow += 1
				If row = BGHS(SI).rows Then
					gridrect.top = gridrect.bottom - (BGHS(SI).rowheight)
					InvalidateRect(hWnd, @gridrect, 1)
				Else
					InvalidateRect(hWnd, @gridrect, 0)
				End If
				cellrect = GetCellRect(hWnd,SI,row,col)
			Loop
		Else
			If (cellrect.bottom - cellrect.top)>=(gridrect.bottom - (BGHS(SI).headerrowheight+BGHS(SI).titleheight)) Then
				BGHS(SI).homerow += 1
			End If
		End If
		cellrect = GetCellRect(hWnd,SI,row,col)
			Do While (row < BGHS(SI).homerow)
				BGHS(SI).homerow -= 1
				InvalidateRect(hWnd, @gridrect, 0)
				cellrect = GetCellRect(hWnd,SI,row,col)
			Loop
		'set the vertical scrollbar position
		SetScrollPos(hWnd,SB_VERT,BGHS(SI).homerow,1)
	End Sub

 Sub SetHomeCol(ByVal hWnd As HWND, ByVal SI As Integer, ByVal row As Integer, ByVal col As Integer)
		Dim gridrect As RECT
		Dim cellrect As RECT

		'get rect of grid window
		GetClientRect(hWnd, @gridrect)
		'get rect of current cell
		cellrect = GetCellRect(hWnd,SI,row,col)
		'determine if scroll left or right is needed
		Do While (cellrect.right > gridrect.right) And (cellrect.left <> BGHS(SI).columnwidths(0))
			'scroll right is needed
			BGHS(SI).homecol += 1

			cellrect = GetCellRect(hWnd,SI,row,col)
			InvalidateRect(hWnd, @gridrect, 0)
		Loop
		cellrect = GetCellRect(hWnd,SI,row,col)
		Do While (BGHS(SI).cursorcol < BGHS(SI).homecol) And (BGHS(SI).homecol > 1)

			'scroll left is needed
			BGHS(SI).homecol -= 1

			cellrect = GetCellRect(hWnd,SI,row,col)
			InvalidateRect(hWnd, @gridrect, 0)

			Dim k As Integer
			k = HomeColumnNthVisible(SI)
			SetScrollPos(hWnd,SB_HORZ,k,1)
		Loop
	End Sub

 Sub ShowVscroll(ByVal hWnd As HWND, ByVal SI As Integer)
		'if more rows than can be visible on grid, display vertical scrollbar
		'otherwise, hide it.
		Dim gridrect As RECT
		Dim totalpixels As Integer
		Dim rowsvisibleonscreen As Integer
		GetClientRect(hWnd, @gridrect)
		totalpixels = gridrect.bottom
		totalpixels -= BGHS(SI).titleheight
		totalpixels -= BGHS(SI).headerrowheight
		totalpixels -= (BGHS(SI).rowheight * BGHS(SI).rows)
		rowsvisibleonscreen = (gridrect.bottom - (BGHS(SI).headerrowheight+BGHS(SI).titleheight)) / BGHS(SI).rowheight
		If totalpixels < 0 Then
			'show vscrollbar
			ShowScrollBar(hWnd,SB_VERT,1)
			SetScrollRange(hWnd,SB_VERT,1,(BGHS(SI).rows-rowsvisibleonscreen)+1,1)
			BGHS(SI).VSCROLL = 1
		Else
			'hide vscrollbar
			ShowScrollBar(hWnd,SB_VERT,0)
			BGHS(SI).VSCROLL = 0
		End If

	End Sub



 Sub ShowHscroll(ByVal hWnd As HWND, ByVal SI As Integer)
		'if more rows than can be visible on grid, display vertical scrollbar
		'otherwise, hide it.
		Dim gridrect As RECT
		Dim totalpixels As Integer
		Dim colswithwidth As Integer
		Dim j As Integer
		GetClientRect(hWnd, @gridrect)
		totalpixels = gridrect.right
		totalpixels -= BGHS(SI).columnwidths(0)
		colswithwidth = 0
		For j = 1 To BGHS(SI).cols
			totalpixels -= BGHS(SI).columnwidths(j)
			If BGHS(SI).columnwidths(j)>0 Then
				colswithwidth += 1
			End If
		Next j
		If totalpixels < 0 Then
			'show hscrollbar
			ShowScrollBar(hWnd,SB_HORZ,1)
			SetScrollRange(hWnd,SB_HORZ,1,colswithwidth,1)
			BGHS(SI).HSCROLL = 1
		Else
			'hide hscrollbar
			ShowScrollBar(hWnd,SB_HORZ,0)
			BGHS(SI).HSCROLL = 0
		End If

 End Sub
 
 Sub NotifyRowChanged(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_ROWCHANGED)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_SELCHANGE)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
End Sub

 Sub NotifyColChanged(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_COLCHANGED)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_SELCHANGE)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)

	End Sub
 Sub NotifyEndEdit(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_EDITEND)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)

	End Sub

 Sub NotifyDelete(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_DELETECELL)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)

	End Sub

 Sub NotifyEditBegin(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_EDITBEGIN)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)

	End Sub

 Sub NotifyEditEnd(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_EDITEND)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)

	End Sub

 Sub NotifyF1(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_F1)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)

	End Sub

 Sub NotifyF2(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_F2)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
	End Sub

 Sub NotifyF3(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_F3)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
	End Sub

 Sub NotifyF4(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_F4)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)

	End Sub

 Sub NotifyF5(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_F5)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)

	End Sub

 Sub NotifyF6(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_F6)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)

	End Sub

 Sub NotifyF7(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_F7)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)

	End Sub

 Sub NotifyF8(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_F8)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)

	End Sub

 Sub NotifyF9(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_F9)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
	End Sub

 Sub NotifyF10(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_F10)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)

	End Sub

 Sub NotifyF11(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_F11)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
	End Sub

 Sub NotifyF12(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_F12)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
	End Sub

 Sub NotifyCellClicked(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim wParam As WPARAM
		Dim lParam As LPARAM
		lParam = MAKELPARAM(BGHS(SI).cursorrow,BGHS(SI).cursorcol)
		wParam = MAKEWPARAM(CUInt(BGHS(SI).gridmenu),BGN_CELLCLICKED)
		SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
	End Sub

 Sub GetVisibleColumns(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim j As Integer
		Dim value As Integer
		value = 0
		For j = 1 To BGHS(SI).cols
			If BGHS(SI).columnwidths(j) > 0 Then
				value += 1
			End If
		Next j
		BGHS(SI).visiblecolumns = value
		SetScrollRange(hWnd,SB_HORZ,1,value,1)
	End Sub

 Function GetNthVisibleColumn(ByVal hWnd As HWND, ByVal SI As Integer, ByVal n As Integer) As Integer
		Dim j As Integer
		Dim count As Integer
		Dim value As Integer
		j = 1
		count = 0
		value = n-1
		Do While j<=BGHS(SI).cols
			If BGHS(SI).columnwidths(j)>0 Then
				count += 1
				If count = n Then
					value = j
				End If
			End If
			j += 1
		Loop
		Return value
	End Function

 Sub CloseEdit(ByVal hWnd As HWND, ByVal SI As Integer)
		Dim r As Integer
		Dim c As Integer
		Dim cell As  _BGCELL
		r = BGHS(SI).cursorrow
		c = BGHS(SI).cursorcol
		cell.row = r
		cell.col = c
		SendMessage(hWnd, BGM_SETCELLDATA, CUInt(@cell), Clng(StrPtr(BGHS(SI).editstring)))
		BGHS(SI).editstring = ""
		RefreshGrid(hWnd)
		BGHS(SI).EDITING = 0
		HideCaret(hWnd)
		NotifyEditEnd(hWnd, SI)
	End Sub

 Sub DisplayEditString(ByVal hWnd As HWND, ByVal SI As Integer, ByVal tstring As ZString Ptr)
		Dim r As Integer
		Dim c As Integer
		Dim holdfont As HFONT
		Dim rt As RECT
		Dim cdc As HDC
		r = BGHS(SI).cursorrow
		c = BGHS(SI).cursorcol
		ShowCaret(hWnd)
		If (r<BGHS(SI).homerow) Or (c<BGHS(SI).homecol) Then
			HideCaret(hWnd)
			Return
		End If
		rt = GetCellRect(hWnd,SI,r,c)
		rt.top += 2
		rt.bottom -= 2
		rt.right -=2
		rt.left += 2

		cdc = GetDC(hWnd)
		Rectangle(cdc,rt.left,rt.top,rt.right,rt.bottom)
		rt.top    += 2
		rt.bottom -= 2
		rt.right  -= 2
		rt.left   += 2

		If Len(BGHS(SI).editstring)<=300 Then
			BGHS(SI).editstring &= *tstring
			BGHS(SI).editstringdisplay = BGHS(SI).editstring
		Else
			MessageBeep(0)
		End If

		holdfont = Cast(HFONT,SelectObject(cdc,BGHS(SI).hfont))
		rt.right -= 5
		DrawText(cdc, BGHS(SI).editstringdisplay, -1, @rt, DT_RIGHT Or DT_VCENTER Or DT_SINGLELINE)
		rt.right +=5
		ShowCaret(hWnd)

		Dim rh As Integer
		Dim ah As Integer
		rh = BGHS(SI).rowheight
		ah = BGHS(SI).fontascentheight

		SetCaretPos(rt.right-4,rt.top+CInt((rh\2))-ah+2)

		SelectObject(cdc,holdfont)
		ReleaseDC(hWnd,cdc)
	End Sub

'//////////////////////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////


 Function RegisterGridClass(ByVal hInstance As Const HINSTANCE) As ATOM
		'initialize BGHS structure
		Dim j As Integer
		Dim k As Integer

		For j = 0 To MAX_GRIDS - 1
			BGHS(j).gridmenu = 0
			BGHS(j).hlist1 = NULL
			BGHS(j).protect = "U"
			BGHS(j).rows = 100
			BGHS(j).cols = 255
			BGHS(j).homerow = 1
			BGHS(j).homecol = 1
			BGHS(j).rowheight = 21
			BGHS(j).headerrowheight = 21
			BGHS(j).ROWSNUMBERED = 1
			BGHS(j).COLUMNSNUMBERED = 1
			BGHS(j).EDITABLE = 0
			BGHS(j).EDITING = 0
			BGHS(j).AUTOROW = 1
			BGHS(j).cursorcol = 1
			BGHS(j).cursorrow = 1
			BGHS(j).columnwidths(0)=50
			BGHS(j).ADVANCEROW = 1
			BGHS(j).DRAWHIGHLIGHT = 1
			BGHS(j).cursorcolor = _RGB(255,255,255)
			BGHS(j).protectcolor = _RGB(255,255,255)
			BGHS(j).unprotectcolor = _RGB(255,255,255)
			BGHS(j).highlightcolor = _RGB(0,0,128)
			BGHS(j).gridlinecolor = _RGB(220,220,220)
			BGHS(j).highlighttextcolor = _RGB(255,255,255)
			BGHS(j).textcolor = _RGB(0,0,0)
			BGHS(j).titleheight = 0
			BGHS(j).EXTENDLASTCOLUMN = 1
			BGHS(j).SHOWINTEGRALROWS = 1
			BGHS(j).SIZING = 0
			BGHS(j).ELLIPSIS = 1
			BGHS(j).COLAUTOWIDTH = 0
			BGHS(j).COLUMNSIZING = 0
			BGHS(j).ALLOWCOLUMNRESIZING = 0
			BGHS(j).cursortype = 0
			BGHS(j).hcolumnheadingfont = NULL
			BGHS(j).htitlefont = NULL
			BGHS(j).editstring = ""
			For k = 1 To MAX_COLS - 1
				BGHS(j).columnwidths(k)=50
			Next k
		Next j

		Dim wcx As WNDCLASSEX
		wcx.cbClsExtra=0
		wcx.cbSize=sizeof(WNDCLASSEX)
		wcx.cbWndExtra=0
		wcx.hCursor=NULL
		wcx.hIcon=NULL
		wcx.hIconSm=NULL
		wcx.hInstance = hInstance
		wcx.hbrBackground=Cast(HBRUSH,GetStockObject(GRAY_BRUSH))
		wcx.lpfnWndProc=@GridProc
		wcx.lpszClassName=StrPtr("BABYGRID")
		wcx.lpszMenuName=NULL
		wcx.style=CS_BYTEALIGNCLIENT

		Return RegisterClassEx(@wcx)
	End Function

 Sub SizeGrid(ByVal hWnd As HWND, ByVal SI As Integer)
		SendMessage(hWnd,WM_SIZE,SIZE_MAXIMIZED,MAKELPARAM(BGHS(SI).wannabewidth,BGHS(SI).wannabeheight))
		SendMessage(hWnd,WM_SIZE,SIZE_MAXIMIZED,MAKELPARAM(BGHS(SI).wannabewidth,BGHS(SI).wannabeheight))
	End Sub

 Function FindLongestLine(ByVal hdc As HDC, ByVal text As zstring Ptr, ByVal size As SIZE Ptr) As Integer
		Dim longest As Integer
		Dim lines As Integer
		Dim j As Integer
		Dim temptext As  ZSTRING*1000
		Dim p As String
		longest = 0
		lines = 1
		For j = 0 To CInt(strLen(text))- 1
			If text[j] = Asc(Lf) Then
				lines += 1
			End If
		Next j
		temptext = *text
		p=*strtok(temptext,!"\n")
		Do While (p <> "")
			GetTextExtentPoint32(hdc,p,Len(p),size)
			If size->cx > longest Then
				longest = size->cx
			End If
			p = *strtok(!"\0",!"\n")
		Loop

		'MessageBox(NULL,text,"FindLongestLine",MB_OK) 
		Return longest
	End Function


 Function GridProc(ByVal hWnd As HWND, ByVal message As UINT, ByVal wParam As WPARAM, ByVal lParam As LPARAM) As Integer
		Dim wmId As Integer
		Dim ps As PAINTSTRUCT
		Dim hdc As HDC
		Dim buffer As  ZSTRING*1000
		Dim SelfIndex As Integer
		Dim ReturnValue As Integer
		Dim hInst As HINSTANCE
		Dim iDataType As Integer

		SelfIndex = FindGrid(CUInt(GetMenu(hWnd)))

		'update the grid width and height variable
			Static rect As RECT

			GetClientRect(hWnd, @rect)
			BGHS(SelfIndex).gridwidth = rect.right - rect.left
			BGHS(SelfIndex).gridheight = rect.bottom - rect.top


		ReturnValue = 0

		Select Case message
			Case WM_COMMAND
				wmId = LOWORD(wParam)
				' Parse the menu selections:
				Select Case wmId
					Case Else
						Return DefWindowProc(hWnd, message, wParam, lParam)
				End Select

			Case WM_PAINT
				hdc = BeginPaint(hWnd, @ps)
				Dim rt As RECT
				GetClientRect(hWnd, @rt)
				CalcVisibleCellBoundaries(SelfIndex)
				'display title
				DisplayTitle(hWnd,SelfIndex,BGHS(SelfIndex).htitlefont)
				'display column 0;

				DisplayColumn(hWnd,SelfIndex,0,0,BGHS(SelfIndex).hfont,BGHS(SelfIndex).hcolumnheadingfont)
					Dim c As Integer
					Dim j As Integer
					Dim k As Integer
					Dim offset As Integer
					offset = BGHS(SelfIndex).columnwidths(0)
					j = BGHS(SelfIndex).leftvisiblecol
					k = BGHS(SelfIndex).rightvisiblecol
					For c = j To k
						DisplayColumn(hWnd,SelfIndex,c,offset,BGHS(SelfIndex).hfont,BGHS(SelfIndex).hcolumnheadingfont)
						offset+=BGHS(SelfIndex).columnwidths(c)
					Next c

				DeleteDC(hdc)
				EndPaint(hWnd, @ps)
				'
				If GetFocus()=hWnd Then
					PostMessage(hWnd,BGM_DRAWCURSOR,CUInt(SelfIndex),0)
				End If

         


			Case BGM_PAINTGRID
				Dim rect As RECT
				GetClientRect(hWnd, @rect)
				InvalidateRect(hWnd, @rect, 1)
				UpdateWindow(hWnd)
				MessageBeep(0)
			Case WM_SETTEXT
				Dim j As Integer
				Dim linecount As Integer
				Dim size As SIZE
				Dim gdc As HDC
				Dim holdfont As HFONT
				If Len(*Cast(ZString Ptr,lParam))>300 Then
					BGHS(SelfIndex).title = "Title too long (300 chars max)"
				Else
					BGHS(SelfIndex).title =*Cast(ZString Ptr,lParam)
				End If

				gdc = GetDC(hWnd)
				'get linecount of title;
				If Len(BGHS(SelfIndex).title) > 0 Then
					linecount = 1
					For j = 0 To CInt(Len((BGHS(SelfIndex).title)))- 1
						If BGHS(SelfIndex).title[j]=Asc(Lf) Then
							linecount += 1
						End If

					Next j
					holdfont = Cast(HFONT,SelectObject(gdc,BGHS(SelfIndex).htitlefont))
					GetTextExtentPoint32(gdc, BGHS(SelfIndex).title, Len(BGHS(SelfIndex).title), @size)
					SelectObject(gdc,holdfont)
					BGHS(SelfIndex).titleheight = CInt(((size.cy *1.2) * linecount))
				Else
					'no title
					BGHS(SelfIndex).titleheight = 0
				End If
				ReleaseDC(hWnd,gdc)


				RefreshGrid(hWnd)
				SizeGrid(hWnd,SelfIndex)

			Case BGM_GETROWS
				ReturnValue = BGHS(SelfIndex).rows

			Case BGM_GETCOLS
				ReturnValue = BGHS(SelfIndex).cols

			Case BGM_GETCOLWIDTH
				ReturnValue = BGHS(SelfIndex).columnwidths(wParam)

			Case BGM_GETROWHEIGHT
				ReturnValue = BGHS(SelfIndex).rowheight

			Case BGM_GETHEADERROWHEIGHT
				ReturnValue = BGHS(SelfIndex).headerrowheight

			Case BGM_GETOWNERDRAWITEM
				ReturnValue = BGHS(SelfIndex).ownerdrawitem

			Case BGM_DRAWCURSOR
				DrawCursor(hWnd,wParam)
			Case BGM_SETCURSORPOS
				DrawCursor(hWnd,SelfIndex)
				If ((CInt(wParam) <= BGHS(SelfIndex).rows) And (CInt(wParam) > 0)) And ((CInt(lParam) <= BGHS(SelfIndex).cols) And (CInt(lParam) > 0)) Then
					BGHS(SelfIndex).cursorrow=wParam
					BGHS(SelfIndex).cursorcol=lParam
				Else
					DrawCursor(hWnd,SelfIndex)
					Exit Select
				End If
				SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
				SetHomeCol(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
				DrawCursor(hWnd,SelfIndex)
				RefreshGrid(hWnd)

			Case BGM_SHOWHILIGHT
				BGHS(SelfIndex).DRAWHIGHLIGHT = CInt(wParam)
				RefreshGrid(hWnd)
			Case BGM_EXTENDLASTCOLUMN
				BGHS(SelfIndex).EXTENDLASTCOLUMN = CInt(wParam)
				RefreshGrid(hWnd)

			Case BGM_SHOWINTEGRALROWS
				BGHS(SelfIndex).SHOWINTEGRALROWS = CInt(wParam)
				SizeGrid(hWnd,SelfIndex)
				RefreshGrid(hWnd)

			Case BGM_SETCOLAUTOWIDTH
				BGHS(SelfIndex).COLAUTOWIDTH = CInt(wParam)

			Case BGM_SETALLOWCOLRESIZE
				BGHS(SelfIndex).ALLOWCOLUMNRESIZING = CInt(wParam)

			Case BGM_PROTECTCELL
				LPBGcell=Cast(_BGCELL Ptr,wParam)
				If OutOfRange(LPBGcell) Then
					wParam = MAKEWPARAM(CUInt(GetMenu(hWnd)),BGN_OUTOFRANGE)
					lParam = 0
					SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
					ReturnValue = -1
					Exit Select
				End If
				wsprintf(buffer,!"%05d-%03d",LPBGcell->row,LPBGcell->col)
				'see if that cell is already loaded
				FindResult = BinarySearchListBox(BGHS(SelfIndex).hlist1,buffer)
				If FindResult <> LB_ERR Then
					'it was found, get the text, modify text delete it from list, add modified to list
					SendMessage(BGHS(SelfIndex).hlist1,LB_GETTEXT,FindResult,CInt(StrPtr(buffer)))
					If CInt(lParam) Then
						buffer[10] = asc("P")
					Else
						buffer[10] = Asc("U")
					End If
					SendMessage(BGHS(SelfIndex).hlist1,LB_DELETESTRING,FindResult,0)
					SendMessage(BGHS(SelfIndex).hlist1,LB_ADDSTRING,FindResult,CInt(StrPtr(buffer)))
				Else
					'protecting or unprotecting a cell that isn't in the list
					'add it as blank;
					buffer &= "|"
					If CInt(lParam) Then
						buffer &= "PA"
					Else
						buffer &= "UA"
					End If
					buffer &= "|"
					SendMessage(BGHS(SelfIndex).hlist1,LB_ADDSTRING,FindResult,CInt(StrPtr(buffer)))
				End If

			Case BGM_NOTIFYROWCHANGED
				NotifyRowChanged(hWnd,SelfIndex)
			Case BGM_NOTIFYCOLCHANGED
				NotifyColChanged(hWnd,SelfIndex)
			Case BGM_SETPROTECT
				If CInt(wParam) Then
					BGHS(SelfIndex).protect = "P"
				Else
					BGHS(SelfIndex).protect = "U"
				End If

			Case BGM_AUTOROW
				If CInt(wParam) Then
					BGHS(SelfIndex).AUTOROW = 1
				Else
					BGHS(SelfIndex).AUTOROW = 0
				End If
			Case BGM_SETEDITABLE
				If CInt(wParam) Then
					BGHS(SelfIndex).EDITABLE = 1
				Else
					BGHS(SelfIndex).EDITABLE = 0
				End If

			Case BGM_SETCELLDATA
				LPBGcell=Cast(_BGCELL Ptr,wParam)
				If OutOfRange(LPBGcell) Then
					wParam = MAKEWPARAM(CUInt(GetMenu(hWnd)),BGN_OUTOFRANGE)
					lParam = 0
					SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
					ReturnValue = -1
					Exit Select
				End If
				wsprintf(buffer,!"%05d-%03d",LPBGcell->row,LPBGcell->col)
				'see if that cell is already loaded
				FindResult = BinarySearchListBox(BGHS(SelfIndex).hlist1,buffer)
				If FindResult <> LB_ERR Then
					'it was found, delete it
					SendMessage(BGHS(SelfIndex).hlist1,LB_DELETESTRING,FindResult,0)
				End If
				'now add it
				buffer &= "|"
				buffer &= BGHS(SelfIndex).protect
				'determine data type (text,numeric, or boolean)(1,2,3)
				iDataType = DetermineDataType( *Cast(ZString ptr,lParam))
				If iDataType = 1 Then
					buffer &= "A"
				End If
				If iDataType = 2 Then
					buffer &= "N"
				End If
				If iDataType = 3 Then
					buffer &= "T"
				End If
				If iDataType = 4 Then
					buffer &= "F"
				End If
				If iDataType = 5 Then
					buffer &= "G"
				End If

				buffer &= "|"
				buffer &= *Cast(ZString ptr,lParam)
				FindResult=SendMessage(BGHS(SelfIndex).hlist1,LB_ADDSTRING,0,CInt(StrPtr(buffer)))
				 
            'ShowLastError
				If FindResult=LB_ERR Then
					MessageBeep(0)
				End If
				Dim rect As RECT
				rect = GetCellRect(hWnd,SelfIndex,LPBGcell->row,LPBGcell->col)
				InvalidateRect(hWnd, @rect, 0)

				'get the last line and adjust grid dimmensions
				If BGHS(SelfIndex).AUTOROW Then
					Dim j As Integer
					j = SendMessage(BGHS(SelfIndex).hlist1,LB_GETCOUNT,0,0)
					If j>0 Then
						SendMessage(BGHS(SelfIndex).hlist1,LB_GETTEXT,j-1,CInt(StrPtr(buffer)))
						buffer[5]= &H00   ' les 5 premiers lettres de buffer 00001-
						j = atoi(buffer) 
						' messagebox NULL,Trim(buffer),"ok2",0
						If j>SendMessage(hWnd,BGM_GETROWS,0,0) Then
							SendMessage(hWnd,BGM_SETGRIDDIM,j,BGHS(SelfIndex).cols)
						End If
					Else
						'no items in the list
						SendMessage(hWnd,BGM_SETGRIDDIM,j,BGHS(SelfIndex).cols)
					End If
				End If

				'adjust the column width if COLAUTOWIDTH==TRUE
				If (BGHS(SelfIndex).COLAUTOWIDTH) Or (LPBGcell->row = 0) Then
					Dim hdc As HDC
					Dim size As SIZE
					Dim required_width As Integer
					Dim current_width As Integer
					Dim required_height As Integer
					Dim current_height As Integer
					Dim longestline As Integer
					Dim holdfont As HFONT
					hdc = GetDC(hWnd)
					If LPBGcell->row = 0 Then
						holdfont = Cast(HFONT,SelectObject(hdc,BGHS(SelfIndex).hcolumnheadingfont) )
					Else
						holdfont = Cast(HFONT,SelectObject(hdc,BGHS(SelfIndex).hfont))
					End If
					'if there are \n codes in the string, find the longest line
					longestline = FindLongestLine(hdc, cast(ZString Ptr,lParam), @size)
					'GetTextExtentPoint32(hdc,(char*)lParam,strlen((char*)lParam),&size);
					required_width = longestline+5
					required_height = size.cy
					'count lines
						Dim count As Integer = 1
						Dim tbuffer As zString*254 
						tbuffer = *Cast(ZString ptr,lParam)
						For j As Integer = 0 To CInt(Len(tbuffer))- 1
							If tbuffer[j]=Asc(!"\n") Then
								count += 1
							End If
						Next j
						If ((0= BGHS(SelfIndex).ELLIPSIS)) or  (LPBGcell->row = 0) Then
							required_height *= count
						End If
						required_height +=5
					SelectObject(hdc,holdfont)
					ReleaseDC(hWnd,hdc)
					current_width = BGHS(SelfIndex).columnwidths(LPBGcell->col)
					If LPBGcell->row = 0 Then
						current_height = BGHS(SelfIndex).headerrowheight
						If required_height > current_height Then
							SendMessage(hWnd,BGM_SETHEADERROWHEIGHT,required_height,0)
						End If
					Else
						current_height = BGHS(SelfIndex).rowheight
						If required_height > current_height Then
							SendMessage(hWnd,BGM_SETROWHEIGHT,required_height,0)
						End If

					End If
					If required_width > current_width Then
						SendMessage(hWnd,BGM_SETCOLWIDTH,LPBGcell->col,required_width)
					End If
					ReleaseDC(hWnd,hdc)
				End If


			Case BGM_GETCELLDATA
				LPBGcell=Cast(LPBGCELL,wParam)
				If OutOfRange(LPBGcell) Then
					wParam = MAKEWPARAM(CUInt(GetMenu(hWnd)),BGN_OUTOFRANGE)
					lParam = 0
					SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
					ReturnValue = -1
					Exit Select
				End If
				wsprintf(buffer,!"%05d-%03d",LPBGcell->row,LPBGcell->col)
				'see if that cell is already loaded
				FindResult = BinarySearchListBox(BGHS(SelfIndex).hlist1,buffer)
				If FindResult <> LB_ERR Then
					Dim j As Integer
					Dim k As Integer
					Dim c As Integer
					Dim tbuffer As  ZSTRING*1000
					'it was found, get it
					SendMessage(BGHS(SelfIndex).hlist1,LB_GETTEXT,FindResult,CInt(lParam))
					tbuffer = *Cast(ZString Ptr,lParam)
					'messagebox NULL,Trim(tbuffer),"ok1",0
					k = Len(tbuffer)
					c = 0
					For j = 13 To k - 1
						buffer[c]=tbuffer[j]
						c += 1
					Next j
					buffer[c]= &H0 
					 	strcpy(cast(ZString Ptr,lParam),buffer) 
					' lParam = Cast(LPARAM,@buffer)
				Else
					 strcpy(cast(ZString Ptr,lParam),"")
					 'lParam = Cast(LPARAM,NULL)
				End If

			Case BGM_CLEARGRID
				SendMessage(BGHS(SelfIndex).hlist1,LB_RESETCONTENT,0,0)
				BGHS(SelfIndex).rows = 0
				BGHS(SelfIndex).cursorrow = 1
				BGHS(SelfIndex).homerow = 1
				BGHS(SelfIndex).homecol = 1
					Dim rect As RECT
					GetClientRect(hWnd, @rect)
					InvalidateRect(hWnd, @rect, 1)

			Case BGM_DELETECELL
				LPBGcell=Cast(LPBGCELL,wParam)
				If OutOfRange(LPBGcell) Then
					wParam = MAKEWPARAM(CUInt(GetMenu(hWnd)),BGN_OUTOFRANGE)
					lParam = 0
					SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
					ReturnValue = -1
					Exit Select
				End If
				wsprintf(buffer,!"%05d-%03d",LPBGcell->row,LPBGcell->col)
				'see if that cell is already loaded
				FindResult = BinarySearchListBox(BGHS(SelfIndex).hlist1,buffer)
				If FindResult <> LB_ERR Then
					'it was found, delete it
					SendMessage(BGHS(SelfIndex).hlist1,LB_DELETESTRING,FindResult,0)
					NotifyEndEdit(hWnd,SelfIndex)
				End If
	     Case BGM_SETGRIDDIM
				If (CInt(wParam)>=0) And (CInt(wParam)<=MAX_ROWS) Then
					BGHS(SelfIndex).rows = wParam
				Else
					If CInt(wParam)<0 Then
						BGHS(SelfIndex).rows = 0
					Else
						BGHS(SelfIndex).rows = MAX_ROWS
					End If
				End If

				If (lParam>0) And (lParam<=MAX_COLS) Then
					BGHS(SelfIndex).cols = lParam
				Else
					If lParam <= 0 Then
						BGHS(SelfIndex).cols = 1
					Else
						BGHS(SelfIndex).cols = MAX_COLS
					End If
				End If
				GetClientRect(hWnd, @rect)
				InvalidateRect(hWnd, @rect, 1)
				GetVisibleColumns(hWnd,SelfIndex)
				


			Case BGM_SETCOLWIDTH
				If (CInt(wParam) <= MAX_COLS) And (CInt(wParam) >= 0) And (CInt(lParam) >= 0) Then
					Dim rect As RECT
					BGHS(SelfIndex).columnwidths(wParam) = lParam
					GetClientRect(hWnd, @rect)
					InvalidateRect(hWnd, @rect, 0)
					GetVisibleColumns(hWnd,SelfIndex)
				End If
				
			Case BGM_SETHEADERROWHEIGHT
				If CInt(wParam) >= 0 Then
					Dim rect As RECT
					BGHS(SelfIndex).headerrowheight = wParam
					SizeGrid(hWnd,SelfIndex)
					GetClientRect(hWnd, @rect)
					InvalidateRect(hWnd, @rect, 0)
				End If
				

			Case BGM_GETROW
				ReturnValue = BGHS(SelfIndex).cursorrow
				
			Case BGM_GETCOL
				ReturnValue = BGHS(SelfIndex).cursorcol
				

			Case BGM_GETTYPE
				LPBGcell=Cast(_BGCELL Ptr,wParam)
				If OutOfRange(LPBGcell) Then
					wParam = MAKEWPARAM(CUInt(GetMenu(hWnd)),BGN_OUTOFRANGE)
					lParam = 0
					SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
					ReturnValue = -1
					
				End If
				wsprintf(buffer,!"%05d-%03d",LPBGcell->row,LPBGcell->col)
				'see if that cell is already loaded
				FindResult = BinarySearchListBox(BGHS(SelfIndex).hlist1,buffer)
				If FindResult <> LB_ERR Then
					'it was found, get it
					SendMessage(BGHS(SelfIndex).hlist1,LB_GETTEXT,FindResult,CInt(StrPtr(buffer)))
					Select Case buffer[11]
						Case Asc("A")
							ReturnValue=1
						Case Asc("N")
							ReturnValue=2
						Case Asc("T")
							ReturnValue=3
						Case Asc("F")
							ReturnValue=4
						Case Asc("G")
							ReturnValue=5
						Case Else
							ReturnValue =1
					End Select
				End If
				
			Case BGM_GETPROTECTION
				LPBGcell=Cast(LPBGCELL,wParam)
				If OutOfRange(LPBGcell) Then
					wParam = MAKEWPARAM(CUInt(GetMenu(hWnd)),BGN_OUTOFRANGE)
					lParam = 0
					SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
					ReturnValue = -1
					
				End If
				wsprintf(buffer,!"%05d-%03d",LPBGcell->row,LPBGcell->col)
				'see if that cell is already loaded
				ReturnValue = 0
				FindResult = BinarySearchListBox(BGHS(SelfIndex).hlist1,buffer)
				If FindResult <> LB_ERR Then
					'it was found, get it
					SendMessage(BGHS(SelfIndex).hlist1,LB_GETTEXT,FindResult,CInt(StrPtr(buffer)))
					Select Case buffer[10]
						Case Asc("U")
							ReturnValue=0
						Case Asc("P")
							ReturnValue=1
						Case Else
							ReturnValue =0
					End Select
				End If

				
			Case BGM_SETROWHEIGHT
				If wParam <1 Then
					wParam = 1
				End If
				BGHS(SelfIndex).rowheight = wParam
				SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
				SetHomeCol(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
				SizeGrid(hWnd,SelfIndex)

					Dim rect As RECT
					GetClientRect(hWnd, @rect)
					InvalidateRect(hWnd, @rect, 0)
				

			Case BGM_SETTITLEHEIGHT
				If CInt(wParam)<0 Then
					wParam = 0
				End If
				BGHS(SelfIndex).titleheight = wParam
				SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
				SetHomeCol(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					Dim rect As RECT
					GetClientRect(hWnd, @rect)
					InvalidateRect(hWnd, @rect, 0)
				
			Case BGM_SETGRIDLINECOLOR
				DrawCursor(hWnd,SelfIndex)
				BGHS(SelfIndex).gridlinecolor = CUInt(wParam)
				DrawCursor(hWnd,SelfIndex)
				RefreshGrid(hWnd)
				

			Case BGM_SETCURSORCOLOR
				DrawCursor(hWnd,SelfIndex)
				BGHS(SelfIndex).cursorcolor = CUInt(wParam)
				DrawCursor(hWnd,SelfIndex)
				RefreshGrid(hWnd)
				

			Case BGM_SETHILIGHTTEXTCOLOR
				BGHS(SelfIndex).highlighttextcolor = CUInt(wParam)
					Dim rect As RECT
					GetClientRect(hWnd, @rect)
					InvalidateRect(hWnd, @rect, 0)
				
			Case BGM_SETHILIGHTCOLOR
				BGHS(SelfIndex).highlightcolor = CUInt(wParam)
					Dim rect As RECT
					GetClientRect(hWnd, @rect)
					InvalidateRect(hWnd, @rect, 0)
				

			Case BGM_SETPROTECTCOLOR
				BGHS(SelfIndex).protectcolor = CUInt(wParam)
					Dim rect As RECT
					GetClientRect(hWnd, @rect)
					InvalidateRect(hWnd, @rect, 0)
				

			Case BGM_SETUNPROTECTCOLOR
				BGHS(SelfIndex).unprotectcolor = CUInt(wParam)
					Dim rect As RECT
					GetClientRect(hWnd, @rect)
					InvalidateRect(hWnd, @rect, 0)
				

			Case BGM_SETELLIPSIS
				BGHS(SelfIndex).ELLIPSIS = CInt(wParam)
					Dim rect As RECT
					GetClientRect(hWnd, @rect)
					InvalidateRect(hWnd, @rect, 0)

				

			Case BGM_SETTITLEFONT
				BGHS(SelfIndex).htitlefont = Cast(HFONT,wParam )
					Dim rect As RECT
					GetClientRect(hWnd, @rect)
					InvalidateRect(hWnd, @rect, 0)

				

			Case BGM_SETHEADINGFONT
				BGHS(SelfIndex).hcolumnheadingfont = Cast(HFONT,wParam )
					Dim rect As RECT
					GetClientRect(hWnd, @rect)
					InvalidateRect(hWnd, @rect, 0)

				

			Case BGM_SETROWSNUMBERED
				BGHS(SelfIndex).ROWSNUMBERED = CInt(wParam)
					Dim rect As RECT
					GetClientRect(hWnd, @rect)
					InvalidateRect(hWnd, @rect, 0)

				

			Case BGM_SETCOLSNUMBERED
				BGHS(SelfIndex).COLUMNSNUMBERED = CInt(wParam)
					Dim rect As RECT
					GetClientRect(hWnd, @rect)
					InvalidateRect(hWnd, @rect, 0)

				

			Case WM_ENABLE
				If wParam = 0 Then
					BGHS(SelfIndex).textcolor = _RGB(120,120,120)
				Else
					BGHS(SelfIndex).textcolor = _RGB(0,0,0)
				End If

			Case WM_MOUSEMOVE
				Dim x As Integer
				Dim y As Integer
				Dim r As Integer
				Dim c As Integer
				Dim t As Integer
				Dim z As Integer
				x = LOWORD(lParam)
				y = HIWORD(lParam)
				r = GetRowOfMouse(SelfIndex,y)
				c = GetColOfMouse(SelfIndex,x)
				t = GetColOfMouse(SelfIndex,x+10)
				z = GetColOfMouse(SelfIndex,x-10)

				If BGHS(SelfIndex).COLUMNSIZING Then
					Dim dx As Integer
					Dim nx As Integer
					Dim cr_ As Integer
					dx = x-BGHS(SelfIndex).columntoresizeinitx
					nx = BGHS(SelfIndex).columntoresizeinitsize + dx
					If nx<=0 Then
						nx = 0
					End If
					cr_ = BGHS(SelfIndex).columntoresize
					SendMessage(hWnd,BGM_SETCOLWIDTH,cr_,nx)

				End If
				If (r = 0) And (c>=-1) And ((t<>c) or  (z<>c)) And ((0= BGHS(SelfIndex).COLUMNSIZING)) Then
					If (BGHS(SelfIndex).cursortype <> 2) And (BGHS(SelfIndex).ALLOWCOLUMNRESIZING) Then
						BGHS(SelfIndex).cursortype = 2
						SetCursor(LoadCursor(NULL, IDC_SIZEWE))
					End If

				Else
					If (BGHS(SelfIndex).cursortype <> 1) And ((0= BGHS(SelfIndex).COLUMNSIZING)) Then
						BGHS(SelfIndex).cursortype = 1
						SetCursor(LoadCursor(NULL, IDC_ARROW))
					End If
				End If
			

			Case WM_LBUTTONUP
				If BGHS(SelfIndex).COLUMNSIZING Then
					BGHS(SelfIndex).COLUMNSIZING = 0
					SetCursor(LoadCursor(NULL, IDC_ARROW))
					BGHS(SelfIndex).cursortype = 1
					BGHS(SelfIndex).SHOWINTEGRALROWS=BGHS(SelfIndex).REMEMBERINTEGRALROWS
					SizeGrid(hWnd,SelfIndex)
				End If
				

		
   
aloberoger
Posts: 507
Joined: Jan 13, 2009 19:23

Re: Babygrid coded with FB

Post by aloberoger »

babygrid.bas (partII)

Code: Select all

	Case WM_LBUTTONDOWN
				Dim x As Integer
				Dim y As Integer
				Dim r As Integer
				Dim c As Integer

				'check for column sizing
				If BGHS(SelfIndex).cursortype = 2 Then
					Dim c As Integer
					Dim x As Integer
					Dim t As Integer
					Dim z As Integer
					'start column sizing
					If 0= BGHS(SelfIndex).COLUMNSIZING Then
						BGHS(SelfIndex).REMEMBERINTEGRALROWS = BGHS(SelfIndex).SHOWINTEGRALROWS
					End If
					BGHS(SelfIndex).COLUMNSIZING = 1
					BGHS(SelfIndex).SHOWINTEGRALROWS = 0
					x = LOWORD(lParam)
					BGHS(SelfIndex).columntoresizeinitx=x
					t = GetColOfMouse(SelfIndex,x+10)
					z = GetColOfMouse(SelfIndex,x-10)
					c = GetColOfMouse(SelfIndex,x)
					If t<>c Then
						'resizing column c
						BGHS(SelfIndex).columntoresize = c
					End If
					If z<>c Then
						'resizing hidden column to the left of cursor
						If c = -1 Then
							c = SendMessage(hWnd,BGM_GETCOLS,0,0)
						Else
							c-=1
						End If
						BGHS(SelfIndex).columntoresize = c
					End If

					BGHS(SelfIndex).columntoresizeinitsize = BGHS(SelfIndex).columnwidths(c)
				End If

				If BGHS(SelfIndex).EDITING Then
					CloseEdit(hWnd,SelfIndex)
				Else
					SetFocus(hWnd)
				End If
				Dim NRC As Integer
				Dim NCC As Integer
				NRC = 0
				NCC = 0

				If GetFocus()=hWnd Then

					x = LOWORD(lParam)
					y = HIWORD(lParam)
					r = GetRowOfMouse(SelfIndex,y)
					c = GetColOfMouse(SelfIndex,x)
					DrawCursor(hWnd,SelfIndex)
					If (r>0) And (c>0) Then
						If r <> BGHS(SelfIndex).cursorrow Then
							BGHS(SelfIndex).cursorrow = r
							NRC = 1
						Else
							BGHS(SelfIndex).cursorrow = r
						End If
						If c <> BGHS(SelfIndex).cursorcol Then
							BGHS(SelfIndex).cursorcol = c
							NCC = 1
						Else
							BGHS(SelfIndex).cursorcol = c
						End If
						NotifyCellClicked(hWnd,SelfIndex)
					End If
					If NRC <> 0 Then
						NotifyRowChanged(hWnd,SelfIndex)
					End If
					If NCC <> 0 Then
						NotifyColChanged(hWnd,SelfIndex)
					End If

					DrawCursor(hWnd,SelfIndex)
					SetCurrentCellStatus(hWnd,SelfIndex)
					SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					SetHomeCol(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					RefreshGrid(hWnd)

				Else
					SetFocus(hWnd)
				End If
			

			Case WM_ERASEBKGND
				Return 1
		Case WM_GETDLGCODE

				'old: ReturnValue = DLGC_WANTARROWS|DLGC_WANTCHARS|DLGC_DEFPUSHBUTTON;

				'Note: David Hillard replied to my Email concerning BabyGrid
				'  in a dialog on windows 9x machines as follows:
				'  "As I remember, the problem with BabyGrid
				'  was in the WM_GETDLGCODE message handler.
				'  It fails because it's coded wrong.
				'  I didn't completely understand it when
				'  I was programming it.
				ReturnValue = DLGC_WANTARROWS Or DLGC_WANTCHARS
				' 	find and compare.
				If wParam = 13 Then
					'same as arrow down
					If BGHS(SelfIndex).EDITING Then
						CloseEdit(hWnd,SelfIndex)
					End If
					DrawCursor(hWnd,SelfIndex)
					BGHS(SelfIndex).cursorrow += 1
					If BGHS(SelfIndex).cursorrow > BGHS(SelfIndex).rows Then
						BGHS(SelfIndex).cursorrow = BGHS(SelfIndex).rows
					Else
						NotifyRowChanged(hWnd,SelfIndex)
					End If
					DrawCursor(hWnd,SelfIndex)
					SetCurrentCellStatus(hWnd,SelfIndex)
					SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					RefreshGrid(hWnd)
					BGHS(SelfIndex).EDITING = 0
					 
				End If

				If wParam = VK_ESCAPE Then
					If BGHS(SelfIndex).EDITING Then
						BGHS(SelfIndex).EDITING = 0
						BGHS(SelfIndex).editstring = ""
						HideCaret(hWnd)
						RefreshGrid(hWnd)
						NotifyEditEnd(hWnd,SelfIndex)
					Else
						ReturnValue = 0
					End If
					 
				End If
				 
			Case WM_KEYDOWN

				If wParam = VK_ESCAPE Then
					If BGHS(SelfIndex).EDITING Then
						BGHS(SelfIndex).EDITING = 0
						BGHS(SelfIndex).editstring = ""
						HideCaret(hWnd)
						RefreshGrid(hWnd)
						NotifyEditEnd(hWnd,SelfIndex)
					End If
					 
				End If
				If wParam = VK_F1 Then
					NotifyF1(hWnd,SelfIndex)
					 
				End If

				If wParam = VK_F2 Then
					NotifyF2(hWnd,SelfIndex)
					 
				End If
				If wParam = VK_F3 Then
					NotifyF3(hWnd,SelfIndex)
					 
				End If
				If wParam = VK_F4 Then
					NotifyF4(hWnd,SelfIndex)
					 
				End If
				If wParam = VK_F5 Then
					NotifyF5(hWnd,SelfIndex)
					 
				End If
				If wParam = VK_F6 Then
					NotifyF6(hWnd,SelfIndex)
					 
				End If
				If wParam = VK_F7 Then
					NotifyF7(hWnd,SelfIndex)
					 
				End If
				If wParam = VK_F8 Then
					NotifyF8(hWnd,SelfIndex)
					 
				End If
				If wParam = VK_F9 Then
					NotifyF9(hWnd,SelfIndex)
					 
				End If
				If wParam = VK_F10 Then
					NotifyF10(hWnd,SelfIndex)
					 
				End If
				If wParam = VK_F11 Then
					NotifyF11(hWnd,SelfIndex)
					 
				End If
				If wParam = VK_F12 Then
					NotifyF12(hWnd,SelfIndex)
					 
				End If

				If wParam = VK_DELETE Then
					NotifyDelete(hWnd,SelfIndex)
					 
				End If
				If wParam = VK_TAB Then
					SetFocus(GetParent(hWnd))
					 
				End If
				If wParam = VK_NEXT Then
					Dim gridrect As RECT
					Dim rpp As Integer
					If BGHS(SelfIndex).EDITING Then
						CloseEdit(hWnd,SelfIndex)
					End If

					If BGHS(SelfIndex).rows = 0 Then
						 
					End If
					If BGHS(SelfIndex).cursorrow = BGHS(SelfIndex).rows Then
						 
					End If
					'get rows per page
					GetClientRect(hWnd, @gridrect)
					rpp = (gridrect.bottom - (BGHS(SelfIndex).headerrowheight+BGHS(SelfIndex).titleheight))/BGHS(SelfIndex).rowheight
					DrawCursor(hWnd,SelfIndex)
					BGHS(SelfIndex).cursorrow += rpp

					If BGHS(SelfIndex).cursorrow > BGHS(SelfIndex).rows Then
						BGHS(SelfIndex).cursorrow = BGHS(SelfIndex).rows
					End If
					NotifyRowChanged(hWnd,SelfIndex)
					DrawCursor(hWnd,SelfIndex)
					SetCurrentCellStatus(hWnd,SelfIndex)
					SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					SetHomeCol(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					RefreshGrid(hWnd)
					
				End If
				If wParam = VK_PRIOR Then
					Dim gridrect As RECT
					Dim rpp As Integer
					If BGHS(SelfIndex).EDITING Then
						CloseEdit(hWnd,SelfIndex)
					End If

					If BGHS(SelfIndex).rows = 0 Then
						
					End If
					If BGHS(SelfIndex).cursorrow = 1 Then
						
					End If
					'get rows per page
					GetClientRect(hWnd, @gridrect)
					rpp = (gridrect.bottom - (BGHS(SelfIndex).headerrowheight+BGHS(SelfIndex).titleheight))/BGHS(SelfIndex).rowheight
					DrawCursor(hWnd,SelfIndex)
					BGHS(SelfIndex).cursorrow -= rpp
					If BGHS(SelfIndex).cursorrow < 1 Then
						BGHS(SelfIndex).cursorrow = 1
					End If
					NotifyRowChanged(hWnd,SelfIndex)
					DrawCursor(hWnd,SelfIndex)
					SetCurrentCellStatus(hWnd,SelfIndex)
					SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					SetHomeCol(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					RefreshGrid(hWnd)
					 
				End If
				If wParam = VK_DOWN Then
					If BGHS(SelfIndex).EDITING Then
						CloseEdit(hWnd,SelfIndex)
					End If

					If BGHS(SelfIndex).rows = 0 Then
						 
					End If
					If BGHS(SelfIndex).cursorrow = BGHS(SelfIndex).rows Then
						 
					End If
					DrawCursor(hWnd,SelfIndex)
					BGHS(SelfIndex).cursorrow += 1
					If BGHS(SelfIndex).cursorrow > BGHS(SelfIndex).rows Then
						BGHS(SelfIndex).cursorrow = BGHS(SelfIndex).rows
					Else
						NotifyRowChanged(hWnd,SelfIndex)
					End If
					DrawCursor(hWnd,SelfIndex)
					SetCurrentCellStatus(hWnd,SelfIndex)
					SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					SetHomeCol(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					RefreshGrid(hWnd)
					 
				End If
				If wParam = VK_UP Then
					If BGHS(SelfIndex).EDITING Then
						CloseEdit(hWnd,SelfIndex)
					End If

					If BGHS(SelfIndex).rows = 0 Then
						 
					End If
					If BGHS(SelfIndex).cursorrow = 1 Then
						 
					End If

					DrawCursor(hWnd,SelfIndex)
					BGHS(SelfIndex).cursorrow -= 1
					If BGHS(SelfIndex).cursorrow < 1 Then
						BGHS(SelfIndex).cursorrow = 1
					Else
						NotifyRowChanged(hWnd,SelfIndex)
					End If
					DrawCursor(hWnd,SelfIndex)
					SetCurrentCellStatus(hWnd,SelfIndex)
					SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					SetHomeCol(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					RefreshGrid(hWnd)
					 
				End If

				If wParam = VK_LEFT Then
					Dim k As Integer
					If BGHS(SelfIndex).EDITING Then
						CloseEdit(hWnd,SelfIndex)
					End If

					If 0= GetNextColWithWidth(SelfIndex,BGHS(SelfIndex).cursorcol,-1) Then
						 
					End If
					DrawCursor(hWnd,SelfIndex)
					k = GetNextColWithWidth(SelfIndex,BGHS(SelfIndex).cursorcol,-1)
					If k <> 0 Then
						BGHS(SelfIndex).cursorcol = k
						NotifyColChanged(hWnd,SelfIndex)
					End If
					DrawCursor(hWnd,SelfIndex)
					SetCurrentCellStatus(hWnd,SelfIndex)
					SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					SetHomeCol(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					 
				End If

				If wParam = VK_RIGHT Then
					Dim k As Integer
					If BGHS(SelfIndex).EDITING Then
						CloseEdit(hWnd,SelfIndex)
					End If
					DrawCursor(hWnd,SelfIndex)
					k = GetNextColWithWidth(SelfIndex,BGHS(SelfIndex).cursorcol,1)
					If k <> 0 Then
						BGHS(SelfIndex).cursorcol = k
						NotifyColChanged(hWnd,SelfIndex)
					End If
					DrawCursor(hWnd,SelfIndex)
					SetCurrentCellStatus(hWnd,SelfIndex)
					SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					SetHomeCol(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					RefreshGrid(hWnd)
					 
				End If

				SetCurrentCellStatus(hWnd,SelfIndex)

				If (BGHS(SelfIndex).CURRENTCELLPROTECTED) And (wParam = 13) Then

					DrawCursor(hWnd,SelfIndex)
					BGHS(SelfIndex).cursorrow += 1
					If BGHS(SelfIndex).cursorrow > BGHS(SelfIndex).rows Then
						BGHS(SelfIndex).cursorrow = BGHS(SelfIndex).rows
					Else
						NotifyRowChanged(hWnd,SelfIndex)
					End If
					DrawCursor(hWnd,SelfIndex)
					SetCurrentCellStatus(hWnd,SelfIndex)
					SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					RefreshGrid(hWnd)
					 
				End If

				If BGHS(SelfIndex).CURRENTCELLPROTECTED Then
					 
				End If

				If 0= BGHS(SelfIndex).EDITABLE Then
					Dim ascii As Integer
					ascii = GetASCII(wParam,lParam)
					If ascii = 13 Then 'enter pressed, treat as arrow down
						'same as arrow down
						DrawCursor(hWnd,SelfIndex)
						BGHS(SelfIndex).cursorrow += 1
						If BGHS(SelfIndex).cursorrow > BGHS(SelfIndex).rows Then
							BGHS(SelfIndex).cursorrow = BGHS(SelfIndex).rows
						Else
							NotifyRowChanged(hWnd,SelfIndex)
						End If
						DrawCursor(hWnd,SelfIndex)
						SetCurrentCellStatus(hWnd,SelfIndex)
						SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
						RefreshGrid(hWnd)
						 

					End If

				End If

				'if it's not an arrow key, make an edit box in the active cell rectangle
				If (BGHS(SelfIndex).EDITABLE) And (BGHS(SelfIndex).rows > 0) Then

					SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
					DrawCursor(hWnd,SelfIndex)
					DrawCursor(hWnd,SelfIndex)

						Dim ascii As Integer
						ascii = GetASCII(wParam,lParam)
						wParam = ascii
						If (wParam >= 32) And (wParam <= 125) Then
							Dim tstring As zString*2 
							If 0= BGHS(SelfIndex).EDITING Then
								NotifyEditBegin(hWnd,SelfIndex)
							End If
							BGHS(SelfIndex).EDITING = 1
							tstring[0]=wParam
							tstring[1]= &H0 
							DisplayEditString(hWnd,SelfIndex,tstring)
							 
						End If
						If wParam = 8 Then 'backspace
							If 0= BGHS(SelfIndex).EDITING Then
								NotifyEditBegin(hWnd,SelfIndex)
							End If

							BGHS(SelfIndex).EDITING = 1
							If len(BGHS(SelfIndex).editstring)=0 Then
								DisplayEditString(hWnd,SelfIndex,"")
								 
							Else
								Dim j As Integer
								j = len(BGHS(SelfIndex).editstring) 
								BGHS(SelfIndex).editstring[j-1]= &H0 
								DisplayEditString(hWnd,SelfIndex,"")
							End If
							 
						End If
						If wParam = 13 Then
							'same as arrow down
							If BGHS(SelfIndex).EDITING Then
								CloseEdit(hWnd,SelfIndex)
							End If
							DrawCursor(hWnd,SelfIndex)
							BGHS(SelfIndex).cursorrow += 1
							If BGHS(SelfIndex).cursorrow > BGHS(SelfIndex).rows Then
								BGHS(SelfIndex).cursorrow = BGHS(SelfIndex).rows
							Else
								NotifyRowChanged(hWnd,SelfIndex)
							End If
							DrawCursor(hWnd,SelfIndex)
							SetCurrentCellStatus(hWnd,SelfIndex)
							SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
							RefreshGrid(hWnd)
							BGHS(SelfIndex).EDITING = 0
							 
						End If
				End If
				 
			Case WM_HSCROLL
				SetFocus(hWnd)
				If (LOWORD(wParam = SB_LINERIGHT)) or  (LOWORD(wParam)=SB_PAGERIGHT) Then
					Dim cp As Integer
					Dim np As Integer
					cp = GetScrollPos(hWnd,SB_HORZ)
					SetScrollPos(hWnd,SB_HORZ,cp+1,1)
					cp = GetScrollPos(hWnd,SB_HORZ)
					np = GetNthVisibleColumn(hWnd,SelfIndex,cp)
					BGHS(SelfIndex).homecol = np
					SetScrollPos(hWnd,SB_HORZ,cp,1)
					RefreshGrid(hWnd)
				End If
				If (LOWORD(wParam = SB_LINELEFT)) or  (LOWORD(wParam)=SB_PAGELEFT) Then
					Dim cp As Integer
					Dim np As Integer
					cp = GetScrollPos(hWnd,SB_HORZ)
					SetScrollPos(hWnd,SB_HORZ,cp-1,1)
					cp = GetScrollPos(hWnd,SB_HORZ)
					np = GetNthVisibleColumn(hWnd,SelfIndex,cp)
					BGHS(SelfIndex).homecol = np
					SetScrollPos(hWnd,SB_HORZ,cp,1)
					RefreshGrid(hWnd)
				End If
				If LOWORD(wParam)=SB_THUMBTRACK Then
					Dim cp As Integer
					Dim np As Integer
					cp = HIWORD(wParam)
					np = GetNthVisibleColumn(hWnd,SelfIndex,cp)
					SetScrollPos(hWnd,SB_HORZ,np,1)
					BGHS(SelfIndex).homecol = np
					SetScrollPos(hWnd,SB_HORZ,cp,1)
					RefreshGrid(hWnd)
				End If
		Case WM_VSCROLL
				SetFocus(hWnd)
				If LOWORD(wParam)=SB_THUMBTRACK Then
					Dim gridrect As RECT
					Dim min_ As Integer
					Dim max_ As Integer
					BGHS(SelfIndex).homerow = HIWORD(wParam)
					SetScrollPos(hWnd,SB_VERT,HIWORD(wParam),1)
					GetClientRect(hWnd, @gridrect)
					GetScrollRange(hWnd, SB_VERT, @min_, @max_)
					If HIWORD(wParam)=max_ Then
						gridrect.top = gridrect.bottom - (BGHS(SelfIndex).rowheight)
						InvalidateRect(hWnd, @gridrect, 1)
					Else
						InvalidateRect(hWnd, @gridrect, 0)
					End If
				End If

				If LOWORD(wParam)=SB_PAGEDOWN Then
					Dim gridrect As RECT
					Dim min_ As Integer
					Dim max_ As Integer
					Dim sp As Integer
					Dim rpp As Integer
					'get rows per page
					GetClientRect(hWnd, @gridrect)
					rpp = (gridrect.bottom - (BGHS(SelfIndex).headerrowheight+BGHS(SelfIndex).titleheight))/BGHS(SelfIndex).rowheight
					GetScrollRange(hWnd, SB_VERT, @min_, @max_)
					sp = GetScrollPos(hWnd,SB_VERT)
					sp += rpp
					If sp > max_ Then
						sp = max_
					End If
					BGHS(SelfIndex).homerow = sp
					SetScrollPos(hWnd,SB_VERT,sp,1)
					SetHomeRow(hWnd,SelfIndex,sp,BGHS(SelfIndex).homecol)
					If sp = max_ Then
						gridrect.top = gridrect.bottom - (BGHS(SelfIndex).rowheight)
						InvalidateRect(hWnd, @gridrect, 1)
					Else
						InvalidateRect(hWnd, @gridrect, 0)
					End If

				End If
				If LOWORD(wParam)=SB_LINEDOWN Then
					Dim gridrect As RECT
					Dim min_ As Integer
					Dim max_ As Integer
					Dim sp As Integer
					'get rows per page
					GetClientRect(hWnd, @gridrect)
					GetScrollRange(hWnd, SB_VERT, @min_, @max_)
					sp = GetScrollPos(hWnd,SB_VERT)
					sp += 1
					If sp > max_ Then
						sp = max_
					End If
					BGHS(SelfIndex).homerow = sp
					SetScrollPos(hWnd,SB_VERT,sp,1)
					SetHomeRow(hWnd,SelfIndex,sp,BGHS(SelfIndex).homecol)
					If sp = max_ Then
						gridrect.top = gridrect.bottom - (BGHS(SelfIndex).rowheight)
						InvalidateRect(hWnd, @gridrect, 1)
					Else
						InvalidateRect(hWnd, @gridrect, 0)
					End If

				End If

				If LOWORD(wParam)=SB_PAGEUP Then
					Dim gridrect As RECT
					Dim min_ As Integer
					Dim max_ As Integer
					Dim sp As Integer
					Dim rpp As Integer
					'get rows per page
					GetClientRect(hWnd, @gridrect)
					rpp = (gridrect.bottom - (BGHS(SelfIndex).headerrowheight+BGHS(SelfIndex).titleheight))/BGHS(SelfIndex).rowheight
					GetScrollRange(hWnd, SB_VERT, @min_, @max_)
					sp = GetScrollPos(hWnd,SB_VERT)
					sp -= rpp
					If sp < 1 Then
						sp = 1
					End If
					BGHS(SelfIndex).homerow = sp
					SetScrollPos(hWnd,SB_VERT,sp,1)
					SetHomeRow(hWnd,SelfIndex,sp,BGHS(SelfIndex).homecol)
					If sp = max_ Then
						gridrect.top = gridrect.bottom - (BGHS(SelfIndex).rowheight)
						InvalidateRect(hWnd, @gridrect, 1)
					Else
						InvalidateRect(hWnd, @gridrect, 0)
					End If

				End If
				If LOWORD(wParam)=SB_LINEUP Then
					Dim gridrect As RECT
					Dim min_ As Integer
					Dim max_ As Integer
					Dim sp As Integer
					'get rows per page
					GetClientRect(hWnd, @gridrect)
					sp = GetScrollPos(hWnd,SB_VERT)
					GetScrollRange(hWnd, SB_VERT, @min_, @max_)
					sp -= 1
					If sp < 1 Then
						sp = 1
					End If
					BGHS(SelfIndex).homerow = sp
					SetScrollPos(hWnd,SB_VERT,sp,1)
					SetHomeRow(hWnd,SelfIndex,sp,BGHS(SelfIndex).homecol)
					If sp = max_ Then
						gridrect.top = gridrect.bottom - (BGHS(SelfIndex).rowheight)
						InvalidateRect(hWnd, @gridrect, 1)
					Else
						InvalidateRect(hWnd, @gridrect, 0)
					End If

				End If
				RefreshGrid(hWnd)

				 
			Case WM_DESTROY
				Dim k As Integer
				If CountGrids = 0 Then
					DeleteObject(hfontbody)
					DeleteObject(hfontheader)
					DeleteObject(hfonttitle)
				End If
				SendMessage(BGHS(SelfIndex).hlist1,LB_RESETCONTENT,0,0)
				DestroyWindow(BGHS(SelfIndex).hlist1)
				BGHS(SelfIndex).gridmenu = 0
				BGHS(SelfIndex).hlist1 = NULL
				BGHS(SelfIndex).hfont = NULL
				BGHS(SelfIndex).protect = "U"
				BGHS(SelfIndex).rows = 100
				BGHS(SelfIndex).cols = 255
				BGHS(SelfIndex).homerow = 1
				BGHS(SelfIndex).homecol = 1
				BGHS(SelfIndex).rowheight = 20
				BGHS(SelfIndex).headerrowheight = 20
				BGHS(SelfIndex).ROWSNUMBERED = 1
				BGHS(SelfIndex).COLUMNSNUMBERED = 1
				BGHS(SelfIndex).DRAWHIGHLIGHT = 1

				BGHS(SelfIndex).cursorcol = 1
				BGHS(SelfIndex).cursorrow = 1
				BGHS(SelfIndex).columnwidths(0)=40
				BGHS(SelfIndex).ADVANCEROW = 1
				BGHS(SelfIndex).cursorcolor = _RGB(255,255,255)
				BGHS(SelfIndex).protectcolor = _RGB(128,128,128)
				BGHS(SelfIndex).unprotectcolor = _RGB(255,255,255)
				For k = 1 To MAX_COLS - 1
					BGHS(SelfIndex).columnwidths(k)=50
				Next k
			 
			Case WM_SETFOCUS
				DrawCursor(hWnd,SelfIndex)
				BGHS(SelfIndex).GRIDHASFOCUS = 1
				DrawCursor(hWnd,SelfIndex)
				SetCurrentCellStatus(hWnd,SelfIndex)
				SetHomeRow(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)
				SetHomeCol(hWnd,SelfIndex,BGHS(SelfIndex).cursorrow,BGHS(SelfIndex).cursorcol)

				wParam=MAKEWPARAM(CUInt(GetMenu(hWnd)),BGN_GOTFOCUS)
				lParam = 0
				SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
					Dim tm As  TEXTMETRIC
					Dim hdc As HDC
					hdc = GetDC(hWnd)
					GetTextMetrics(hdc, @tm)
					ReleaseDC(hWnd,hdc)
					BGHS(SelfIndex).fontascentheight = CInt(Fix(tm.tmAscent))
					CreateCaret(hWnd,NULL,3,tm.tmAscent)
				RefreshGrid(hWnd)
				 
			Case WM_KILLFOCUS
				DestroyCaret()
				DrawCursor(hWnd,SelfIndex)
				BGHS(SelfIndex).GRIDHASFOCUS = 0

				wParam=MAKEWPARAM(CUInt(GetMenu(hWnd)),BGN_LOSTFOCUS)
				lParam = 0
				SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam)
				RefreshGrid(hWnd)

				 
			Case WM_SETFONT
				BGHS(SelfIndex).hfont = Cast(HFONT,wParam)
				If 0= BGHS(SelfIndex).hcolumnheadingfont Then
					BGHS(SelfIndex).hcolumnheadingfont = Cast(HFONT,wParam)
				End If
				If 0= BGHS(SelfIndex).htitlefont Then
					BGHS(SelfIndex).htitlefont = Cast(HFONT,wParam)
				End If
				RefreshGrid(hWnd)
				 
			Case WM_SIZE
				Static SI As Integer
				Static cheight As Integer
				Static savewidth As Integer
				Static saveheight As Integer
				Dim intout As Integer
				SI = SelfIndex

				' char tbuffer[100];
				' wsprintf(tbuffer,"W=%d H=%d",BGHS[SI].wannabewidth,BGHS[SI].wannabeheight);
				' SetWindowText(GetParent(hWnd),tbuffer);


				If BGHS(SI).SIZING Then
					BGHS(SI).SIZING = 0
					 
				End If
				ShowHscroll(hWnd,SI)
				ShowVscroll(hWnd,SI)

				If (BGHS(SI).SHOWINTEGRALROWS) And (BGHS(SI).VSCROLL) Then
					saveheight = HIWORD(lParam)
					savewidth = LOWORD(lParam)
					cheight = HIWORD(lParam)
					cheight-=BGHS(SI).titleheight
					cheight-=BGHS(SI).headerrowheight

						Dim sbheight As Integer
						sbheight = GetSystemMetrics(SM_CYHSCROLL)
						If BGHS(SI).HSCROLL Then
							cheight-=sbheight
						End If
						If BGHS(SI).VSCROLL Then
							Dim grect As RECT
							Dim prect As RECT
							GetClientRect(hWnd, @grect)
							GetClientRect(GetParent(hWnd), @prect)
							If (grect.right+sbheight) < prect.right Then
								savewidth+=sbheight
							End If
						End If




					If cheight <= BGHS(SI).rowheight Then
						 
					Else
						'calculate fractional part of cheight/rowheight
						Dim remainder_ As Integer
						Dim nrows As Integer
						nrows = CInt(Fix(cheight/BGHS(SI).rowheight))
						remainder_ = cheight-(nrows * BGHS(SI).rowheight)
						'make the window remainder pixels shorter
						saveheight -= remainder_
						saveheight +=4 '+=4
						intout = saveheight
						Dim wp As  WINDOWPLACEMENT
						Dim crect As RECT
 
						wp.length = sizeof(WINDOWPLACEMENT)
						GetWindowPlacement(hWnd, @wp)
						crect = wp.rcNormalPosition
						crect.bottom=intout
						crect.right=savewidth
						BGHS(SI).SIZING = 1

						BGHS(SI).wannabeheight = HIWORD(lParam)
						BGHS(SI).wannabewidth  = LOWORD(lParam)

						MoveWindow(hWnd,crect.left,crect.top,crect.right,crect.bottom,1)
					End If
				End If
               
			 
			Case WM_CREATE
				lpcs = @cs
				lpcs = Cast(LPCREATESTRUCT,lparam)

				hInst = lpcs->hInstance

				BG_GridIndex = AddGrid(CUInt(GetMenu(hWnd)))

				If CountGrids = 1 Then
					hfontbody=CreateFont(16,0,0, 0,100,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,PROOF_QUALITY,VARIABLE_PITCH Or FF_MODERN,NULL)
					hfontheader=CreateFont(18,0,0, 0,FW_HEAVY,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,PROOF_QUALITY,VARIABLE_PITCH Or FF_MODERN,NULL)
					hfonttitle=CreateFont(20,0,0, 0,FW_HEAVY,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,PROOF_QUALITY,VARIABLE_PITCH Or FF_MODERN,NULL)
				End If


				If (BG_GridIndex >= 0) And (BG_GridIndex < MAX_GRIDS) Then 'if you aren't over the MAX_GRIDS limit, add a grid

					BGHS(BG_GridIndex).gridmenu = CUInt(GetMenu(hWnd))

					BGHS(BG_GridIndex).hlist1=CreateWindowEx(WS_EX_CLIENTEDGE,"LISTBOX","", WS_CHILD Or LBS_STANDARD,50,150,200,100,hWnd,NULL,hInst,NULL)

					BGHS(BG_GridIndex).hfont = hfontbody
					BGHS(BG_GridIndex).htitlefont = hfonttitle
					BGHS(BG_GridIndex).hcolumnheadingfont = hfontheader
					BGHS(BG_GridIndex).title = *lpcs->lpszName
					SendMessage(hWnd,WM_SETTEXT,0,CInt(lpcs->lpszName))
				End If
				If BG_GridIndex = -1 Then
					DestroyWindow(hWnd)
				End If
				 
			Case Else
				Return DefWindowProc(hWnd, message, wParam, lParam)
		END Select	
		return ReturnValue
 End Function


 Function CountGrids() As Integer
		Dim j As Integer
		Dim count As Integer
		count = 0
		For j = 0 To MAX_GRIDS - 1
			If BGHS(j).gridmenu <> 0 Then
				count += 1
			End If
		Next j
		Return count
	End Function


 Function AddGrid(ByVal menuid As UInteger) As Integer
		'if grid doesn't exist, add it.  otherwise return existing index + MAX_GRIDS
		'if trying to add more than MAX_GRIDS, return -1;
		Dim empty_space As Integer
		Dim returnvalue As Integer
		Dim j As Integer
		Dim MATCH As Integer
		MATCH = 0
		empty_space = -1
		For j = 0 To MAX_GRIDS - 1
			If BGHS(j).gridmenu = menuid Then
				MATCH = 1
				returnvalue = j
			End If
			If BGHS(j).gridmenu = 0 Then
				empty_space = j
			End If
		Next j

		If ((0=MATCH)) And (empty_space >= 0) Then
			BGHS(empty_space).gridmenu = menuid
			returnvalue = empty_space
		End If
		If MATCH <> 0 Then
			Return returnvalue+MAX_GRIDS
		End If
		If ((0= MATCH)) And (empty_space = -1) Then
			Return -1
		End If
		Return returnvalue

	End Function

 Function FindGrid(ByVal menuid As UInteger) As Integer
		'if grid doesn't exist, return -1, else return gridindex
		Dim returnvalue As Integer
		Dim j As Integer
		returnvalue = -1
		For j = 0 To MAX_GRIDS - 1
			If BGHS(j).gridmenu = menuid Then
				returnvalue = j
			End If
		Next j


		Return returnvalue
	End Function



 Function BinarySearchListBox(ByVal lbhWnd As HWND, ByVal searchtext As ZString Ptr) As Integer
		Dim ReturnValue As Integer
		Dim lbcount As Integer
		Dim head As Integer
		Dim tail As Integer
		Dim finger As Integer
		Dim FindResult As Integer
		Dim tbuffer As  ZSTRING*1000
		Dim headtext As  ZSTRING*1000
		Dim tailtext As  ZSTRING*1000
		Dim p As Integer
		Dim FOUND As Integer
		FOUND = 0
		'get count of items in listbox
		lbcount = SendMessage(lbhWnd,LB_GETCOUNT,0,0)
		If lbcount = 0 Then
			ReturnValue = LB_ERR
			Return ReturnValue
		End If
		If lbcount < 12 Then
			'not worth doing binary search, do regular search
			FindResult = SendMessage(lbhWnd,LB_FINDSTRING,-1,CInt(searchtext))
			ReturnValue = FindResult
			Return ReturnValue
		End If
		' do a binary search
		head = 0
		tail = lbcount - 1

		'is it the head?
		SendMessage(lbhWnd,LB_GETTEXT,head,CInt(StrPtr(headtext)))
		headtext[9] = &H0 
      *searchtext=Trim(*searchtext)
      headtext=Trim(headtext)
		p = StrCmp(searchtext,headtext)
		If p = 0 Then
			'it was the head
			ReturnValue = head
			Return ReturnValue
		End If
		If p<0 Then
			'it was less than the head... not found
			ReturnValue = LB_ERR
			Return ReturnValue
		End If

		'is it the tail?
		SendMessage(lbhWnd,LB_GETTEXT,tail,CInt(StrPtr(tailtext)))
		tailtext[9] =&H0 
		*searchtext=Trim(*searchtext)
      tailtext=Trim(tailtext)
		p = StrCmp(searchtext,tailtext)
		If p = 0 Then
			'it was the tail
			ReturnValue = tail
			Return ReturnValue
		End If
		If p>0 Then
			'it was greater than the tail... not found
			ReturnValue = LB_ERR
			Return ReturnValue
		End If

		'is it the finger?
		ReturnValue = LB_ERR
		FOUND = 0


		Do While ((0=FOUND)) And ((tail-head)>1)
			finger = head + ((tail - head) / 2)

			SendMessage(lbhWnd,LB_GETTEXT,finger,CInt(StrPtr(tbuffer)))
			tbuffer[9] =&H0
			tbuffer=Trim(tbuffer)
			p = StrCmp(tbuffer,searchtext)
			If p = 0 Then
				FOUND = 1
				ReturnValue = finger
			End If

			If p<0 Then
				'change  tail to finger
				head = finger
			End If
			If p>0 Then
				'change head to finger
				tail = finger
			End If
		Loop
		Return ReturnValue
	End Function


aloberoger
Posts: 507
Joined: Jan 13, 2009 19:23

Re: Babygrid coded with FB

Post by aloberoger »

test.bas
You can compile Babygrid.bas as a library or use directly In the project
this example use a library

Code: Select all

                                               
 

#define WIN32_LEAN_AND_MEAN
 

#include "windows.bi"
 
#include "win/commctrl.bi"
 #include "windowsx.bi"
#include "resource.bi"

#Inclib "babygrid"
#include "babygrid.bi"  ' <------- You must include the babygrid.bi header file




/'* Global variables *******************************************************'/

static Shared As HANDLE ghInstance 

Dim Shared As HWND hgrid1,hgrid2    ' <------------ Window handles of the grids you'll create

/'* Functions **************************************************************'/

function  About_DlgProc (hDlg As HWND , message As UINT,wParam As WPARAM ,lParam As LPARAM )As BOOL

	Select Case (message)
	
		case WM_INITDIALOG:
				return TRUE

		case WM_COMMAND:
			if (LOWORD(wParam) = IDOK Or LOWORD(wParam) = IDCANCEL) Then
			
				EndDialog(hDlg, LOWORD(wParam))
				return TRUE
			End If
			
	End select
    return FALSE
End Function

Sub LoadGrid2(hgrid As HWND )

	'load grid 2 with initial demo data
	BabyGrid_PutCell(hgrid,0,1,!"Multi-line\nHeadings\nSupported")
	BabyGrid_PutCell(hgrid,0,2,!"\n\nName")
	BabyGrid_PutCell(hgrid,0,3,!"\n\nAge")

	BabyGrid_SetProtect(hgrid,TRUE)
	'every cell entered after a BGM_SETPROTECT TRUE will set the 
	'protected attribute of that cell.  This keeps an editable grid
	'from allowing the user to overwrite whatever is in the protected cell

	BabyGrid_SetProtectColor(hgrid, BGR(210,210,210))
	'the setprotectcolor is optional, but it gives a visual indication
	'of which cells are protected.

	'now put some data in the cells in grid2
	BabyGrid_PutCell(hgrid,1,2,"David")
	BabyGrid_PutCell(hgrid,2,2,"Maggie")
	BabyGrid_PutCell(hgrid,3,2,"Chester")
	BabyGrid_PutCell(hgrid,4,2,"Molly")
	BabyGrid_PutCell(hgrid,5,2,"Bailey")
	                     
	BabyGrid_PutCell(hgrid,1,3,"43")
	BabyGrid_PutCell(hgrid,2,3,"41")
	BabyGrid_PutCell(hgrid,3,3,"3")
	BabyGrid_PutCell(hgrid,4,3,"3")
	BabyGrid_PutCell(hgrid,5,3,"1")

	BabyGrid_PutCell(hgrid,10,5,"Shaded cells are write-protected.")
  
   ' Pour permettre la saisie dans le grid
   BabyGrid_SetEditTable(hgrid,TRUE)
   
	BabyGrid_SetProtect(hgrid,FALSE)
	'turn off automatic cell protection
	'if you don't turn off automatic cell protection, if the 
	'grid is editable, the user can enter data into empty cells
	'but cannot change what he entered... not good.

	BabyGrid_PutCell(hgrid,1,0,"Row Headers customizable")
End sub

Sub LoadGrid1(hgrid As HWND )

	'load data into the properties grid

	BabyGrid_PutCell(hgrid,1,1,"User Column Resizing")
	BabyGrid_PutCell(hgrid,1,2,"FALSE")
	BabyGrid_PutCell(hgrid,2,1,"User Editable")
	BabyGrid_PutCell(hgrid,2,2,"FALSE")
	BabyGrid_PutCell(hgrid,3,1,"Show Ellipsis")
	BabyGrid_PutCell(hgrid,3,2,"TRUE")
	BabyGrid_PutCell(hgrid,4,1,"Auto Column Size")
	BabyGrid_PutCell(hgrid,4,2,"FALSE")
	BabyGrid_PutCell(hgrid,5,1,"Extend Last Column")
	BabyGrid_PutCell(hgrid,5,2,"TRUE")
	BabyGrid_PutCell(hgrid,6,1,"Numbered Columns")
	BabyGrid_PutCell(hgrid,6,2,"TRUE")
	BabyGrid_PutCell(hgrid,7,1,"Numbered Rows")
	BabyGrid_PutCell(hgrid,7,2,"TRUE")
	BabyGrid_PutCell(hgrid,8,1,"Highlight Row")
	BabyGrid_PutCell(hgrid,8,2,"TRUE")
	BabyGrid_PutCell(hgrid,9,1,"Show Cursor")
	BabyGrid_PutCell(hgrid,9,2,"TRUE")
	BabyGrid_PutCell(hgrid,10,1,"Show Gridlines")
	BabyGrid_PutCell(hgrid,10,2,"TRUE")

	'make the grid notify the program that the row in the 
	'grid has changed.  Usually this is done by the user clicking
	'a cell, or moving thru the grid with the keyboard.  But we
	'want the grid to initially send this message to get things going.
	'If we didn't call BGM_NOTIFYROWCHANGED, the first row would be 
	'hilighted, but the ACTION wouldn't be performed.

	BabyGrid_NotifyRowChanged(hgrid)

	'make the properties grid have the focus when the application starts
	SetFocus(hgrid)
End Sub

Sub Main_OnClose(hwnd As HWND )
	EndDialog(hwnd, 0)
End Sub

Sub Main_OnCommand(hwnd As HWND , id As Integer,hwndCtl As HWND ,codeNotify As UINT )
 
	Select case (id)
	 
		case IDM_ABOUT:
		   DialogBox(ghInstance, MAKEINTRESOURCE(DLG_ABOUT), hwnd, cast(DLGPROC,@About_DlgProc)) 
		   
		case IDM_EXIT:
		   Main_OnClose(hwnd) 
		   
		case IDC_BABYGRID1: 'properties grid notification that something happened
	     
			if(codeNotify=BGN_CELLCLICKED) Then'a cell was clicked in the properties grid
			 
				Dim As Integer row,col,dtype 

				'get the row and column of the clicked cell
				row=LOWORD(hwndCtl) 
				col=HIWORD(hwndCtl) 

				'get the data type that is in the cell
				'in this instance, we're looking for BOOLEAN data (types 3 [TRUE] or 4 [FALSE])
				'datatype 1 is alphanumeric data
				'datatype 2 is numeric data
				'datatype 3 is BOOLEAN TRUE data
				'datatype 4 is BOOLEAN FALSE data
				BabyGrid_GetCellDataType(hgrid1,row,col,dtype) 
				if(dtype = 3) Then 'bool true
				 
					'if the grid cell was true (checked checkbox), toggle it false
					BabyGrid_PutCell(hgrid1,row,col,"FALSE") 
					'send appropriate control message to the grid based
					'on the row of the cell that was toggled
					if(row=1) Then   BabyGrid_SetAllowColResize (hgrid2,FALSE) 
					if(row=2) Then   BabyGrid_SetEditTable(hgrid2,FALSE) 
					if(row=3)Then    BabyGrid_SetEllipsis(hgrid2,FALSE) 
					if(row=4)Then    BabyGrid_SetColAutoWidth(hgrid2,FALSE) 
					if(row=5)Then    BabyGrid_ExtendLastColumn(hgrid2,FALSE) 
					if(row=6)Then
					
					    BabyGrid_SetColsNumbered(hgrid2,FALSE) 
					    LoadGrid2(hgrid2) 
				   End If
					if(row=7) Then  BabyGrid_SetRowsNumbered(hgrid2,FALSE) 
					if(row=8) Then  BabyGrid_ShowHilight(hgrid2,FALSE) 
					if(row=9) Then   BabyGrid_SetCursorColor(hgrid2, BGR(0,0,0)) 
					if(row=10)Then  BabyGrid_SetGridLineColor(hgrid2, BGR(255,255,255)) 
				End If
				if(dtype = 4) Then'bool false
				 
					'if the grid cell was false (unchecked checkbox), toggle it true
					BabyGrid_PutCell(hgrid1,row,col,"TRUE")
					'send appropriate control message to the grid based
					'on the row of the cell that was toggled
					if(row=1)Then  BabyGrid_SetAllowColResize (hgrid2,TRUE) 
					if(row=2)Then  BabyGrid_SetEditTable(hgrid2,TRUE) 
					if(row=3)Then  BabyGrid_SetEllipsis(hgrid2,TRUE) 
					if(row=4)Then  BabyGrid_SetColAutoWidth(hgrid2,TRUE) 
					if(row=5)Then  BabyGrid_ExtendLastColumn(hgrid2,TRUE) 
					if(row=6)Then
					   BabyGrid_SetColsNumbered(hgrid2,TRUE) 
						BabyGrid_SetHeaderRowHeight(hgrid2,21) 
					End If
					if(row=7)Then  BabyGrid_SetRowsNumbered(hgrid2,TRUE) 
					if(row=8)Then  BabyGrid_ShowHilight(hgrid2,TRUE) 
					if(row=9) Then BabyGrid_SetCursorColor(hgrid2, BGR(255,255,255)) 
					if(row=10) Then BabyGrid_SetGridLineColor(hgrid2, BGR(220,220,220)) 
				End If
			End If'if(codeNotify=BGN_CELLCLICKED)
		Case Else 'case IDC_BABYGRID1:
			
	End select
End Sub

 Function Main_OnInitDialog(hwnd As HWND ,hwndFocus As HWND , lParam As LPARAM )As BOOL 

	'Get window handles
	hgrid1=GetDlgItem(hwnd,IDC_BABYGRID1) 
	hgrid2=GetDlgItem(hwnd,IDC_BABYGRID2) 


   
	'Set the heading font
Dim As HFONT hFont1=CreateFont(20,0,0, 0,FW_EXTRABOLD,FALSE,FALSE,FALSE, _
			                      ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, _
			                     PROOF_QUALITY,VARIABLE_PITCH Or FF_MODERN ,"ARIEL") 
	BabyGrid_SetHeadingFont(hgrid1,hFont1) 
	
Dim As HFONT hFont2=CreateFont(12,0,0, 0,FW_BOLD,FALSE,FALSE,FALSE, _
			                      ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, _
			                      PROOF_QUALITY,VARIABLE_PITCH Or FF_MODERN ,"ARIEL") 	
	BabyGrid_SetHeadingFont(hgrid2,hFont2) 
   
   
	'Set grid2 (the working demonstration grid) to be 100 rows by 5 columns
	BabyGrid_SetGridDim(hgrid2,100,5) 

	'set grid1 (the properties grid) to automatically size columns 
	'based on the length of the text entered into the cells
	BabyGrid_SetColAutoWidth(hgrid1,TRUE) 
	'only want 2 columns, rows will be added as data is entered programmatically
	BabyGrid_SetGridDim(hgrid1,0,2) 
	'I don't want a row header, so make it 0 pixels wide
	BabyGrid_SetColWidth(hgrid1,0,0) 
	'this grid won't use column headings, set header row height = 0
	BabyGrid_SetHeaderRowHeight(hgrid1,0) 
	'populate grid1 with data
	LoadGrid1(hgrid1) 
	
	BabyGrid_SetColsNumbered(hGrid2,FALSE) ' Pour accepter les entrées entetede de colonnes ligne 0
	BabyGrid_SetGridLineColor(hGrid2,BGR(0,255,0))
	'populate grid2 with initial demo data
	LoadGrid2(hgrid2) 
	'make grid2 header row to initial height of 21 pixels
	BabyGrid_SetHeaderRowHeight(hgrid2,40) 
	return TRUE 
End function

Sub Main_OnSize(hwnd As HWND ,state As UINT , cx  As Integer, cy As integer)
Dim As RECT rect 
	'GetClientRect(hwnd,@rect) 
	MoveWindow(hgrid1,0,0,cx/3,cy,FALSE) 
	MoveWindow(hgrid2,cx/3,0,cx-cx/3,cy,FALSE) 
	BabyGrid_Refresh(hwnd) 
End Sub

/'***************************************************************************
 *                                                                          *
 * Function: MainDlgProc                                                    *
 *                                                                          *
 * Purpose : Process messages for the Main dialog.                          *
 *                                                                          *
 * History : Date      Reason                                               *
 *           00/00/10  Created                                              *
 *                                                                          *
 ***************************************************************************'/

function   Main_DlgProc (hwndDlg As HWND ,msg As UINT ,wParam As WPARAM ,lParam As LPARAM )As BOOL
 
 
	Select case(msg)
		
		Case WM_CLOSE
		  Main_OnClose(hwndDlg)
	          'HANDLE_MSG (hwndDlg, WM_CLOSE, Main_OnClose) 
		Case WM_COMMAND
			
			   Main_OnCommand(hwndDlg , LoWord(wparam), Cast(HWND,lparam) ,HiWord(wparam) )
	        'HANDLE_MSG (hwndDlg, WM_COMMAND, Main_OnCommand) 
	 
		Case WM_INITDIALOG
			Main_OnInitDialog(hwndDlg ,Cast(HWND,wparam) , lParam )
	     ' HANDLE_MSG (hwndDlg, WM_INITDIALOG, Main_OnInitDialog) 
		Case WM_SIZE
			Main_OnSize(hwndDlg,0,LoWord(lparam),HiWord(lparam))
	'HANDLE_MSG (hwndDlg, WM_SIZE, Main_OnSize) 

	Case Else : return FALSE 
	End Select
End function

/'***************************************************************************
 *                                                                          *
 * Function: WinMain                                                        *
 *                                                                          *
 * Purpose : Initialize the application.  Register a window class,          *
 *           create and display the main window and enter the               *
 *           message loop.                                                  *
                                           *
 *                                                                          *
 ***************************************************************************'/

Function  WinMain (hInstance As HINSTANCE ,hPrevInstance As HINSTANCE ,lpszCmdLine As  LPSTR , nCmdShow As Integer)As Integer

   Dim As  WNDCLASSEX wcx 
    
    ghInstance = hInstance 

    ' Initialize common controls. Also needed for MANIFEST's.
    InitCommonControls() 

    
	' Initialize Baby Grid
    RegisterGridClass(hInstance)  'initializes BABYGRID control
                                  'only call this function once in your program 

    ' Get system dialog information.
    wcx.cbSize = sizeof(WNDCLASSEX)
    if (0=GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), @wcx)) Then    return 0

    ' Add our own stuff.
    wcx.hInstance = hInstance
    wcx.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN))
	 wcx.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_SMALL))
	 wcx.hbrBackground	= Cast(HBRUSH,COLOR_WINDOW+1)
    wcx.lpszClassName =StrPtr("BbyGrdDlgDmo")
    if (0=RegisterClassEx(@wcx)) Then   return 0 


    ' The user interface is a modal dialog box.
    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, Cast(DLGPROC,@Main_DlgProc))
End Function


 End  WinMain (GetModuleHandle(NULL),null ,command , SW_SHOWNORMAL)




test.rc
you need one icon

Code: Select all

 

#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"

#define DLG_MAIN						1001

#define DLG_ABOUT	                    1002

#define IDM_BABYGRID_DEMO               2001
#define IDM_ABOUT                       2002
#define IDM_EXIT                        2003

#define BMP_BABYGRID_DEMO               4001
#define IDC_STATIC                      4002
#define IDC_BABYGRID1					4003
#define IDC_BABYGRID2					4004

#define IDR_ICO_MAIN					8001
#define IDR_ICO_SMALL					8002
LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_US

DLG_MAIN DIALOGEX DISCARDABLE 6, 18, 334, 222
STYLE DS_MODALFRAME|DS_3DLOOK|WS_THICKFRAME|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_VISIBLE
CAPTION "Baby Grid Dialog Demo"
MENU IDM_BABYGRID_DEMO
CLASS "BbyGrdDlgDmo"
FONT 8, "MS Sans Serif", 0, 0, 1
BEGIN
  CONTROL "Grid Properties", IDC_BABYGRID1, "BABYGRID", 0x00000000, 0, 0, 96, 220, 0x00000200
  CONTROL "BABYGRID -- A simple grid forWin32 API Programmers", IDC_BABYGRID2, "BABYGRID", 0x00000000, 100, 0, 232, 220, 0x00000200
END

DLG_ABOUT DIALOG DISCARDABLE 22, 17, 235, 71
STYLE DS_MODALFRAME|WS_CAPTION|WS_SYSMENU
CAPTION "About"
FONT 8, "System"
BEGIN
  CONTROL BMP_BABYGRID_DEMO, IDR_ICO_MAIN, "Static", SS_ICON, 14, 9, 20, 20
  CONTROL "BABYGRID_DEMO Version 1.0", IDC_STATIC, "Static", SS_NOPREFIX|WS_GROUP, 49, 10, 119, 8
  CONTROL "Copyright (C) 2002", IDC_STATIC, "Static", WS_GROUP, 49, 20, 119, 8
  CONTROL "OK", IDOK, "Button", BS_DEFPUSHBUTTON|WS_GROUP|WS_TABSTOP, 195, 6, 30, 11
  CONTROL "David Hillard", IDC_STATIC, "Static", WS_GROUP, 49, 30, 153, 8
  CONTROL "email:  mudcat@mis.net", IDC_STATIC, "Static", WS_GROUP, 64, 39, 103, 8
  CONTROL "Dialog Demo: Ported to FB by ALOBER - 2010", 4005, "Static", WS_GROUP, 48, 52, 156, 16
END

IDM_BABYGRID_DEMO MENU
BEGIN
  POPUP "&File"
  BEGIN
    MENUITEM "E&xit", IDM_EXIT
  END
  POPUP "&Help"
  BEGIN
    MENUITEM "&About ...", IDM_ABOUT
  END
END

IDR_ICO_MAIN ICON "small.ico"
IDR_ICO_SMALL ICON "MAIN.ico"

nobozoz
Posts: 238
Joined: Nov 17, 2005 6:24
Location: Chino Hills, CA, USA

Re: Babygrid coded with FB

Post by nobozoz »

aloberoger,

"windowsx.bi" is nowhere to be found?

Jim
aloberoger
Posts: 507
Joined: Jan 13, 2009 19:23

Re: Babygrid coded with FB

Post by aloberoger »

Please simply remove this include file. I thing things are going fine.
aloberoger
Posts: 507
Joined: Jan 13, 2009 19:23

Re: Babygrid coded with FB

Post by aloberoger »

Please simply remove this include file. I thing things are going fine.
nobozoz
Posts: 238
Joined: Nov 17, 2005 6:24
Location: Chino Hills, CA, USA

Re: Babygrid coded with FB

Post by nobozoz »

aloberoger,

I commented out: "windowsx.bi".

Now, 'resource.bi' cannot be found. It looks to be a required file.

Jim
aloberoger
Posts: 507
Joined: Jan 13, 2009 19:23

Re: Babygrid coded with FB

Post by aloberoger »

ok heare is Resource.bi

Code: Select all

#define DLG_MAIN						1001

#define DLG_ABOUT	                    1002

#define IDM_BABYGRID_DEMO               2001
#define IDM_ABOUT                       2002
#define IDM_EXIT                        2003

#define BMP_BABYGRID_DEMO               4001
#define IDC_STATIC                      4002
#define IDC_BABYGRID1					4003
#define IDC_BABYGRID2					4004

#define IDR_ICO_MAIN					8001
#define IDR_ICO_SMALL					8002
heare is a clean Main.rc

Code: Select all

#define DLG_MAIN						1001

#define DLG_ABOUT	                    1002

#define IDM_BABYGRID_DEMO               2001
#define IDM_ABOUT                       2002
#define IDM_EXIT                        2003

#define BMP_BABYGRID_DEMO               4001
#define IDC_STATIC                      4002
#define IDC_BABYGRID1					4003
#define IDC_BABYGRID2					4004

#define IDR_ICO_MAIN					8001
#define IDR_ICO_SMALL					8002
LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_US

DLG_MAIN DIALOGEX DISCARDABLE 6, 18, 334, 222
STYLE DS_MODALFRAME|DS_3DLOOK|WS_THICKFRAME|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_VISIBLE
CAPTION "Baby Grid Dialog Demo"
MENU IDM_BABYGRID_DEMO
CLASS "BbyGrdDlgDmo"
FONT 8, "MS Sans Serif", 0, 0, 1
BEGIN
  CONTROL "Grid Properties", IDC_BABYGRID1, "BABYGRID", 0x00000000, 0, 0, 96, 220, 0x00000200
  CONTROL "BABYGRID -- A simple grid forWin32 API Programmers", IDC_BABYGRID2, "BABYGRID", 0x00000000, 100, 0, 232, 220, 0x00000200
END

DLG_ABOUT DIALOG DISCARDABLE 22, 17, 235, 71
STYLE DS_MODALFRAME|WS_CAPTION|WS_SYSMENU
CAPTION "About"
FONT 8, "System"
BEGIN
  CONTROL BMP_BABYGRID_DEMO, IDR_ICO_MAIN, "Static", SS_ICON, 14, 9, 20, 20
  CONTROL "BABYGRID_DEMO Version 1.0", IDC_STATIC, "Static", SS_NOPREFIX|WS_GROUP, 49, 10, 119, 8
  CONTROL "Copyright (C) 2002", IDC_STATIC, "Static", WS_GROUP, 49, 20, 119, 8
  CONTROL "OK", IDOK, "Button", BS_DEFPUSHBUTTON|WS_GROUP|WS_TABSTOP, 195, 6, 30, 11
  CONTROL "David Hillard", IDC_STATIC, "Static", WS_GROUP, 49, 30, 153, 8
  CONTROL "email:  mudcat@mis.net", IDC_STATIC, "Static", WS_GROUP, 64, 39, 103, 8
  CONTROL "Dialog Demo: Ported to FB by ALOBER - 2010", 4005, "Static", WS_GROUP, 48, 52, 156, 16
END

IDM_BABYGRID_DEMO MENU
BEGIN
  POPUP "&File"
  BEGIN
    MENUITEM "E&xit", IDM_EXIT
  END
  POPUP "&Help"
  BEGIN
    MENUITEM "&About ...", IDM_ABOUT
  END
END

IDR_ICO_MAIN ICON "small.ico"
IDR_ICO_SMALL ICON "MAIN.ico"
marpon
Posts: 342
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Babygrid coded with FB

Post by marpon »

Hy

I tried to compile the test but it is not linking with the static lib I have done according your code.

the static lib, compiled without error with fb 0.24
https://dl.dropboxusercontent.com/u/104 ... BabyGrid.a

but the test program does not link : error 1
FreeBASIC Compiler - Version 0.24.0 (08-19-2012) for win32
Copyright (C) 2004-2012 The FreeBASIC development team.
standalone, objinfo (libbfd 217)
compiling: test_grid.bas -o test_grid.asm (main module)
assembling: E:\Free Basic\FreeBASIC\bin\win32\as.exe --32 --strip-local-absolute "test_grid.asm" -o "test_grid.o"

compiling rc: E:\Free Basic\FreeBASIC\bin\win32\GoRC.exe /ni /nw /o /fo "main.obj" "main.rc"

linking: E:\Free Basic\FreeBASIC\bin\win32\ld.exe -o "C:\Documents and Settings\Perso\Mes documents\grid_fb\test_grid.exe" -subsystem windows "E:\Free Basic\FreeBASIC\lib\win32\fbextra.x" --stack 1048576,1048576 -s -L "E:\Free Basic\FreeBASIC\lib\win32" -L "." "E:\Free Basic\FreeBASIC\lib\win32\crt2.o" "E:\Free Basic\FreeBASIC\lib\win32\crtbegin.o" "E:\Free Basic\FreeBASIC\lib\win32\fbrt0.o" "test_grid.o" "main.obj" "-(" -lkernel32 -lgdi32 -luser32 -lversion -ladvapi32 -lmsvcrt -lcomctl32 -lbabygrid -lfb -lgcc -lmingw32 -lmingwex -lmoldname -lsupc++ "-)" "E:\Free Basic\FreeBASIC\lib\win32\crtend.o"

linking failed: 'E:\Free Basic\FreeBASIC\bin\win32\ld.exe' terminated with exit code 1
is it a problem with static lib ?
marpon
Posts: 342
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Babygrid coded with FB

Post by marpon »

I tried also without static lib, just including the babygrid.bas .

It compiled and linked without error with both Fb 0.24 and Fb 0.90.1

But in execution time , it blocked immediatly with error message from windows for both versions

miss something ?
marpon
Posts: 342
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Babygrid coded with FB

Post by marpon »

Hy , i've done it.

Just don't need the "Function Create_BG_Grid" in babygrid.bi , if you create the lib with it , use a modified babygrid.bi to avoid to get it compiled a second time with your test code.

In fact I tested , static lib without and test without and it compiles and works fine.

Thanks for that version in FB , I will see if it is better than using the Static lib from C or C++
aloberoger
Posts: 507
Joined: Jan 13, 2009 19:23

Re: Babygrid coded with FB

Post by aloberoger »

I thing FB version is not better than C version, but it cqn shoz the way of creating huge grid control zith FB, like TGRID in guitk
Post Reply