continued...
Function fnGridProc_OnCreate(Wea As WndEventArgs) As Long
Local iFlds,iHdlCount,iCols,iCtr,iSize As Long
Local strParseData(),strFieldData() As BStr
Local pGridData1,pGridData2 As GridData Ptr
Local dwStyle,hButton,hCell,hDC As Dword
Local pCreateStruct As CREATESTRUCT Ptr
Local uCC As INIT_COMMON_CONTROLSEX
Local szText As ZStr*64
Local hdrItem As HDITEM
Local strSetup As BStr
Local iPos() As Long
Register i As Long
Register j As Long
Local rc As RECT
#If %Def(%DEBUG)
Print #fp, " Entering %WM_CREATE Case"
#EndIf
pCreateStruct=Wea.lParam
Wea.hInst=@pCreateStruct.hInstance
pGridData1=@pCreateStruct.lpCreateParams
strSetup=@pCreateStruct.@lpszName
Call GetClientRect(Wea.hWnd,rc)
#If %Def(%DEBUG)
Print #fp, " %WM_USER = " %WM_USER
Print #fp, " %WM_APP = " %WM_APP
Print #fp, " hGrid = " Wea.hWnd
Print #fp, " pGridData1 = " pGridData1
Print #fp, " Wea.hInstance = " Wea.hInst
Print #fp, " @pCreateStruct.cx = " @pCreateStruct.cx
Print #fp, " @pCreateStruct.cy = " @pCreateStruct.cy
Print #fp, " rc.Right = " rc.Right
Print #fp, " rc.Bottom = " rc.Bottom
Print #fp, " @pGridData1.iFontSize = " @pGridData1.iFontSize
Print #fp, " @pGridData1.iFontWeight = " @pGridData1.iFontWeight
Print #fp, " @pGridData1.szFontName = " @pGridData1.szFontName
Print #fp, " strSetup = " strSetup
#EndIf
uCC.dwSize = SizeOf(uCC)
uCC.dwICC = %ICC_LISTVIEW_CLASSES
Call InitCommonControlsEx(uCC)
iCols=ParseCount(strSetup,",")
#If %Def(%DEBUG)
Print #fp, " iCols = " iCols
Print #fp, " @pGridData1.iRows = " @pGridData1.iRows
Print #fp, " @pGridData1.iCols = " @pGridData1.iCols
Print #fp, " @pGridData1.iRowHeight = " @pGridData1.iRowHeight
#EndIf
If iCols<>@pGridData1.iCols Then
Function=-1 : Exit Function
End If
pGridData2=GlobalAlloc(%GPTR,sizeof(GridData))
If pGridData2=0 Then
Function=-1 : Exit Function
End If
Call SetWindowLong(Wea.hWnd,0,pGridData2)
@pGridData2.iCtrlID=@pCreateStruct.hMenu
@pGridData2.cx=@pCreateStruct.cx
@pGridData2.cy=@pCreateStruct.cy
@pGridData2.iCols=iCols
@pGridData2.iRows=@pGridData1.iRows
@pGridData2.iRowHeight=@pGridData1.iRowHeight
@pGridData2.iVisibleRows=Fix((rc.Bottom-@pGridData1.iRowHeight)/@pGridData1.iRowHeight)
@pGridData2.iPaneHeight=(@pGridData2.iVisibleRows+1)*@pGridData1.iRowHeight
@pGridData2.hGrid=Wea.hWnd
@pGridData2.hParent=GetParent(Wea.hWnd)
@pGridData1.iVisibleRows=@pGridData2.iVisibleRows
#If %Def(%DEBUG)
Print #fp, " pGridData2 = " pGridData2
Print #fp, " @pGridData2.hParent = " @pGridData2.hParent
Print #fp, " @pGridData2.iCtrlID = " @pGridData2.iCtrlID
Print #fp, " @pGridData2.iPaneHeight = " @pGridData2.iPaneHeight
Print #fp, " @pCreateStruct.cy = " @pCreateStruct.cy
Print #fp, " @pGridData1.iRowHeight = " @pGridData1.iRowHeight
Print #fp, " @pGridData2.iVisibleRows = " @pGridData2.iVisibleRows
Print #fp, " @pGridData2.iRows = " @pGridData2.iRows
#EndIf
Redim strParseData(iCols) As BStr
Parse strSetup,strParseData(),","
@pGridData2.pColWidths=GlobalAlloc(%GPTR,(iCols+1)*%SIZEOF_PTR)
If @pGridData2.pColWidths=0 Then
Call GlobalFree(pGridData2)
Function=-1 : Exit Function
End If
#If %Def(%DEBUG)
Print #fp, " @pGridData2.pColWidths = " @pGridData2.pColWidths
Print #fp,
Print #fp, " i strParseData(i) "
Print #fp, " ============================="
For i=0 To iCols-1
Print #fp, " " i, strParseData(i)
Next i
Print #fp,
#EndIf
@pGridData2.hBase=CreateWindowEx(0,"Base","",%WS_CHILD Or %WS_VISIBLE,0,0,0,0,Wea.hWnd,1499,Wea.hInst,Byval 0)
dwStyle=%WS_CHILD Or %WS_BORDER Or %WS_VISIBLE Or %HDS_HOTTRACK Or %HDS_HORZ
@pGridData2.hPane=CreateWindowEx(0,"Pane","",%WS_CHILD Or %WS_VISIBLE,0,0,0,0,@pGridData2.hBase,%ID_PANE,Wea.hInst,Byval 0) 'Create Pane
@pGridData2.hHeader=CreateWindowEx(0,WC_HEADER,"",dwStyle,0,0,0,0,@pGridData2.hPane,%ID_HEADER,Wea.hInst,Byval 0) 'Create Header Control
Call SetWindowLong(@pGridData2.hPane,0,pGridData2)
#If %Def(%DEBUG)
Print #fp, " @pGridData2.hBase = " @pGridData2.hBase
Print #fp, " @pGridData2.hPane = " @pGridData2.hPane
Print #fp, " @pGridData2.hHeader = " @pGridData2.hHeader
Print #fp,
Print #fp, " i @pColWidths[i] iPos(i) szText"
Print #fp, " =================================================="
#EndIf
hdrItem.mask=%HDI_FORMAT Or %HDI_WIDTH Or %HDI_TEXT
Redim iPos(iCols) As Long
For i=0 To iCols-1
iFlds=ParseCount(strParseData(i),":")
Redim strFieldData(iFlds-1)
Parse strParseData(i), strFieldData(), ":"
@pGridData2.@pColWidths[i]=Val(strFieldData(0))
@pGridData2.@pColWidths[iCols]=@pGridData2.@pColWidths[iCols]+@pGridData2.@pColWidths[i]
hdrItem.cxy=@pGridData2.@pColWidths[i]
szText=strFieldData(1)
hdrItem.pszText=Varptr(szText) : hdrItem.cchTextMax=Len(szText)
hdrItem.fmt=%HDF_STRING Or %HDF_CENTER
'Call Header_InsertItem(@pGridData2.hHeader,i,Varptr(hdrItem))
Call Header_InsertItem(@pGridData2.hHeader,i,hdrItem)
If i Then
iPos(i)=iPos(i-1)+@pGridData2.@pColWidths[i-1]
End If
#If %Def(%DEBUG)
Print #fp, " " i, @pGridData2.@pColWidths[i], iPos(i), szText
#EndIf
Erase strFieldData()
Next i
#If %Def(%DEBUG)
Print #fp,
Print #fp, " @pGridData2.@pColWidths[iCols] = " @pGridData2.@pColWidths[iCols]
Print #fp,
#EndIf
Call MoveWindow(@pGridData2.hBase,12,0,rc.right-12,@pGridData2.iPaneHeight,%FALSE)
Call MoveWindow(@pGridData2.hPane,0,0,@pGridData2.@pColWidths[iCols],@pGridData2.iPaneHeight,%FALSE) 'Size Pane
Call MoveWindow(@pGridData2.hHeader,0,0,@pGridData2.@pColWidths[iCols],@pGridData2.iRowHeight,%TRUE) 'Size Header
'Make Verticle Buttons
@pGridData2.pVButtons=GlobalAlloc(%GPTR,(@pGridData2.iVisibleRows+1)*%SIZEOF_PTR)
#If %Def(%DEBUG)
Print #fp, " @pGridData2.pVButtons = " @pGridData2.pVButtons
Print #fp,
Print #fp, " i @pGridData2.@pVButtons[i] "
Print #fp, " ====================================="
#EndIf
If @pGridData2.pVButtons Then
For i=0 To @pGridData2.iVisibleRows
@pGridData2.@pVButtons[i]=CreateWindow("button","",%WS_CHILD Or %WS_VISIBLE Or %BS_FLAT,0,@pGridData2.iRowHeight*i,12,@pGridData2.iRowHeight,Wea.hWnd,20000+i,Wea.hInst,Byval 0)
#If %Def(%DEBUG)
Print #fp, " " i, @pGridData2.@pVButtons[i]
#EndIf
Next i
Else
Call GlobalFree(@pGridData2.pColWidths)
Call GlobalFree(pGridData2)
Function=-1 : Exit Function
End If
'Try To Create Font ' ANSI_CHARSET '%OEM_CHARSET
#If %Def(%DEBUG)
Print #fp,
Print #fp, " Now Gonna Try To Create Font..."
Print #fp, " @pGridData1.szFontName = " @pGridData1.szFontName
#EndIf
If @pGridData1.szFontName<>"" Then
hDC=GetDC(Wea.hWnd)
@pGridData2.hFont=CreateFont _
( _
-1*(@pGridData1.iFontSize*GetDeviceCaps(hDC,%LOGPIXELSY))/72, _
0, _
0, _
0, _
@pGridData1.iFontWeight, _
0, _
0, _
0, _
%ANSI_CHARSET, _
0, _
0, _
%DEFAULT_QUALITY, _
0, _
@pGridData1.szFontName _
)
Call ReleaseDC(Wea.hWnd,hDC)
End If
#If %Def(%DEBUG)
Print #fp, " @pGridData2.hFont = " @pGridData2.hFont
#EndIf
'Try To Make Cells
iHdlCount=@pGridData2.iCols*@pGridData2.iVisibleRows
@pGridData2.pCellHandles=GlobalAlloc(%GPTR, iHdlCount * %SIZEOF_HANDLE)
If @pGridData2.pCellHandles Then
dwStyle=%WS_CHILD Or %WS_VISIBLE Or %WS_BORDER
#If %Def(%DEBUG)
Print #fp,
Print #fp, " i j iPos(j) yLoc hCell"
Print #fp, " ============================================================="
#EndIf
For i=0 To @pGridData2.iVisibleRows-1
For j=0 To @pGridData2.iCols-1
hCell=CreateWindowEx _
( _
0, _
"Cell", _
"", _
dwStyle, _
iPos(j), _
@pGridData2.iRowHeight+(i*@pGridData2.iRowHeight), _
@pGridData2.@pColWidths[j], _
@pGridData2.iRowHeight, _
@pGridData2.hPane, _
%ID_CELL+iCtr, _
Wea.hInst, _
Byval 0 _
)
@pGridData2.@pCellHandles[iCtr]=hCell
Call SetWindowLong(hCell,4,@pGridData2.hFont)
#If %Def(%DEBUG)
Print #fp, " " i, j, iPos(j), @pGridData2.iRowHeight+(i*@pGridData2.iRowHeight), hCell
#EndIf
Incr iCtr
Next j
Next i
'Create Grid Memory
iSize=@pGridData2.iCols * @pGridData2.iRows
#If %Def(%DEBUG)
Print #fp,
Print #fp, " Now Will Try To Create Grid Row Memory!"
Print #fp,
Print #fp, " iSize = " iSize
#EndIf
@pGridData2.pGridMemory=GlobalAlloc(%GPTR,iSize*%SIZEOF_PTR)
#If %Def(%DEBUG)
Print #fp, " @pGridData2.pGridMemory = " @pGridData2.pGridMemory
#EndIf
Else
Erase strParseData()
Erase iPos()
Call GlobalFree(@pGridData2.pColWidths)
Call GlobalFree(pGridData2)
Function=-1 : Exit Function
End If
Erase strParseData()
Erase iPos()
#If %Def(%DEBUG)
Print #fp,
Print #fp, " Leaving %WM_CREATE Case" : Print #fp,
#EndIf
Function=0
End Function
Function fnGridProc_OnSize(Wea As WndEventArgs) As Long
Local pGridData As GridData Ptr
Local si As SCROLLINFO
Local iCols As Long
#If %Def(%DEBUG)
Print #fp,
Print #fp, " Entering %WM_SIZE Case"
#EndIf
pGridData=GetWindowLong(Wea.hWnd,0)
iCols=@pGridData.iCols
'Set Up Horizontal Scrollbar
si.cbSize=Sizeof(SCROLLINFO)
si.fMask=%SIF_RANGE Or %SIF_PAGE Or %SIF_POS
si.nMin=0
si.nMax=@pGridData.@pColWidths[iCols]
si.nPage=@pGridData.cx-33 '33 is the width of vert
si.nPos=0 'btns + width scroll bar + window edge
Call SetScrollInfo(Wea.hWnd,%SB_HORZ,si,%TRUE)
#If %Def(%DEBUG)
Print #fp, " Horizontal Scrollbar...."
Print #fp, " si.nMin = " si.nMin
Print #fp, " si.nMax = " si.nMax
Print #fp, " si.nPos = " si.nPos
Print #fp,
#EndIf
'Set Up Verticle Scrollbar
si.cbSize=Sizeof(SCROLLINFO)
si.fMask=%SIF_RANGE Or %SIF_PAGE Or %SIF_POS
si.nMin=1
si.nMax=@pGridData.iRows
si.nPage=@pGridData.iVisibleRows
si.nPos=1
Call SetScrollInfo(Wea.hWnd,%SB_VERT,si,%TRUE)
#If %Def(%DEBUG)
Print #fp,
Print #fp, " Verticle Scrollbar...."
Print #fp, " si.nMin = " si.nMin
Print #fp, " si.nMax = " si.nMax
Print #fp, " si.nPos = " si.nPos
Print #fp, " Leaving %WM_SIZE Case" : Print #fp,
#EndIf
fnGridProc_OnSize=0
End Function
Function fnGridProc_OnHScroll(Wea As WndEventArgs) As Long
Local pGridData As GridData Ptr
Local iCols,iScrollPos As Long
Local si As SCROLLINFO
#If %Def(%DEBUG)
Print #fp,
Print #fp, " Entering %WM_HSCROLL Case"
#EndIf
pGridData=GetWindowLong(Wea.hWnd,0)
iCols=@pGridData.iCols
si.cbSize = sizeof(SCROLLINFO) : si.fMask=%SIF_ALL
Call GetScrollInfo(@pGridData.hGrid,%SB_HORZ,si)
iScrollPos=si.nPos
#If %Def(%DEBUG)
Print #fp, " Before Adjustments"
Print #fp, " si.nMin = " si.nMin
Print #fp, " si.nMax = " si.nMax
Print #fp, " si.nPos = " si.nPos
Print #fp,
#EndIf
Select Case As Long Lowrd(Wea.wParam)
Case %SB_LINELEFT
#If %Def(%DEBUG)
Print #fp, " Got In %SB_LINELEFT"
#EndIf
If si.nPos > si.nMin Then
si.nPos=si.nPos-50
End If
Case %SB_PAGELEFT
si.nPos = si.nPos - si.nPage
Case %SB_LINERIGHT
#If %Def(%DEBUG)
Print #fp, " Got In %SB_LINERIGHT"
#EndIf
If si.nPos<si.nMax Then
si.nPos=si.nPos+50
End If
Case %SB_PAGERIGHT
si.nPos = si.nPos + si.nPage
Case %SB_THUMBTRACK
si.nPos=si.nTrackPos
End Select
si.fMask=%SIF_POS
Call SetScrollInfo(@pGridData.hGrid,%SB_HORZ,si,%TRUE)
Call GetScrollInfo(@pGridData.hGrid,%SB_HORZ,si)
If iScrollPos<>si.nPos Then 'Original
If si.nPos=0 Then
Call SetWindowPos(@pGridData.hPane,%HWND_TOP,0,0,@pGridData.@pColWidths[iCols],@pGridData.iPaneHeight,%SWP_SHOWWINDOW)
Else
Call SetWindowPos(@pGridData.hPane,%HWND_TOP,-si.nPos,0,@pGridData.@pColWidths[iCols],@pGridData.iPaneHeight,%SWP_SHOWWINDOW)
End If
End If
#If %Def(%DEBUG)
Print #fp, " After All Adjustments"
Print #fp, " si.nMin = " si.nMin
Print #fp, " si.nMax = " si.nMax
Print #fp, " si.nPos = " si.nPos
Print #fp, " Leaving %WM_HSCROLL Case"
#EndIf
fnGridProc_OnHScroll=0
End Function
Function fnGridProc_OnVScroll(Wea As WndEventArgs) As Long
Local pGridData As GridData Ptr
Local iScrollPos As Long
Local si As SCROLLINFO
Local hCell As Dword
Register i As Long
#If %Def(%DEBUG)
Print #fp,
Print #fp, " Entering %WM_VSCROLL Case"
#EndIf
pGridData=GetWindowLong(Wea.hWnd,0)
Call blnFlushEditControl(@pGridData.hGrid)
si.cbSize = sizeof(SCROLLINFO) : si.fMask=%SIF_ALL
Call GetScrollInfo(@pGridData.hGrid,%SB_VERT,si)
iScrollPos=si.nPos
#If %Def(%DEBUG)
Print #fp, " Before Adjustments"
Print #fp, " si.nMin = " si.nMin
Print #fp, " si.nMax = " si.nMax
Print #fp, " si.nPos = " si.nPos
Print #fp,
#EndIf
Select Case As Long Lowrd(Wea.wParam)
Case %SB_LINEUP
#If %Def(%DEBUG)
Print #fp, " Got In %SB_LINEUP"
#EndIf
If si.nPos > si.nMin Then
si.nPos=si.nPos-1
End If
Case %SB_PAGEUP
si.nPos = si.nPos - si.nPage
Case %SB_LINEDOWN
#If %Def(%DEBUG)
Print #fp, " Got In %SB_LINEDOWN"
#EndIf
If si.nPos<si.nMax Then
si.nPos=si.nPos+1
End If
Case %SB_PAGEDOWN
si.nPos = si.nPos + si.nPage
Case %SB_THUMBTRACK
si.nPos=si.nTrackPos
End Select
si.fMask=%SIF_POS
Call SetScrollInfo(@pGridData.hGrid,%SB_VERT,si,%TRUE)
Call GetScrollInfo(@pGridData.hGrid,%SB_VERT,si)
If iScrollPos<>si.nPos Then
Local iNum,iLast,iRange As Long
iNum=@pGridData.iCols*(si.nPos-1)
iRange=@pGridData.iCols
iLast=(iRange * @pGridData.iVisibleRows) - 1
For i=0 To iLast
hCell=@pGridData.@pCellHandles[i]
Call SetWindowLong(hCell,0,@pGridData.@pGridMemory[iNum])
Incr iNum
Next i
End If
Call InvalidateRect(@pGridData.hGrid,Byval %NULL,%TRUE)
#If %Def(%DEBUG)
Print #fp, " After All Adjustments"
Print #fp, " si.nMin = " si.nMin
Print #fp, " si.nMax = " si.nMax
Print #fp, " si.nPos = " si.nPos
Print #fp, " Leaving %WM_VSCROLL Case"
#EndIf
fnGridProc_OnVScroll=0
End Function
Function fnGridProc_OnCommand(Wea As WndEventArgs) As Long
Local iCellRow,iGridRow,hr As Long
Local pGridData As GridData Ptr
Local Vtbl As Dword Ptr
Local si As SCROLLINFO
#If %Def(%DEBUG)
Print #fp,
Print #fp, " Entering fnGridProc_OnCommand()"
Print #fp, " Lowrd(Wea.wParam) = " Lowrd(Wea.wParam)
#EndIf
If Lowrd(Wea.wParam)>20000 Then
pGridData=GetWindowLong(Wea.hWnd,0)
Call blnFlushEditControl(@pGridData.hGrid)
si.cbSize = sizeof(SCROLLINFO)
si.fMask=%SIF_POS
Call GetScrollInfo(@pGridData.hGrid,%SB_VERT,si)
iCellRow=Lowrd(Wea.wParam)-20000 : iGridRow=si.nPos+iCellRow-1
Vtbl=@g_ptrOutGoing
Call Dword @Vtbl[8] Using ptrVButtonClick(g_ptrOutGoing, iCellRow, iGridRow) To hr
#If %Def(%DEBUG)
If SUCCEEDED(hr) Then
Print #fp, " Call Dword @Vtbl[8] Using ptrVButtonClick() Succeeded!"
End If
#EndIf
End If
#If %Def(%DEBUG)
Print #fp, " Leaving fnGridProc_OnCommand()"
Print #fp,
#EndIf
Function=0
End Function
Function fnGridProc_OnDestroy(Wea As WndEventArgs) As Long
Local pGridData As GridData Ptr
Local blnFree,iCtr As Long
Local pMem As ZStr Ptr
Register i As Long
Register j As Long
#If %Def(%DEBUG)
Print #fp,
Print #fp, " Entering fnGridProc_OnDestroy()"
#EndIf
pGridData=GetWindowLong(Wea.hWnd,0)
If pGridData Then
#If %Def(%DEBUG)
Print #fp, " @pGridData.iCols = " @pGridData.iCols
Print #fp, " @pGridData.iRows = " @pGridData.iRows
Print #fp, " @pGridData.pColWidths = " @pGridData.pColWidths
#EndIf
blnFree=GlobalFree(@pGridData.pColWidths)
#If %Def(%DEBUG)
Print #fp, " blnFree(pColWidths) = " blnFree
#EndIf
If @pGridData.hFont Then
blnFree=DeleteObject(@pGridData.hFont)
#If %Def(%DEBUG)
Print #fp, " blnFree(hFont) = " blnFree
#EndIf
End If
'Grid Row Memory
#If %Def(%DEBUG)
Print #fp,
Print #fp, " i j iCtr strCoordinate pMem"
Print #fp, " ============================================================================"
#EndIf
iCtr=0
For i=1 To @pGridData.iRows
For j=1 To @pGridData.iCols
pMem=@pGridData.@pGridMemory[iCtr]
#If %Def(%DEBUG)
Print #fp, " " i,j,iCtr,@pMem Tab(72) pMem
#EndIf
Incr iCtr
Next j
Next i
#If %Def(%DEBUG)
Print #fp,
Print #fp,
Print #fp, " i j iCtr blnFree"
Print #fp, " ==========================================="
#EndIf
iCtr=0
For i=1 To @pGridData.iRows
For j=1 To @pGridData.iCols
pMem=@pGridData.@pGridMemory[iCtr]
If pMem Then
blnFree=GlobalFree(pMem)
#If %Def(%DEBUG)
Print #fp, " " i,j,iCtr,blnFree
#EndIf
End If
Incr iCtr
Next j
Next i
blnFree=GlobalFree(@pGridData.pGridMemory)
#If %Def(%DEBUG)
Print #fp,
Print #fp, " blnFree(@pGridData.pGridMemory) = " blnFree
#EndIf
blnFree = GlobalFree(pGridData)
#If %Def(%DEBUG)
Print #fp, " blnFree = " blnFree
#EndIf
End If
#If %Def(%DEBUG)
Print #fp, " Leaving fnGridProc_OnDestroy()"
#EndIf
Function=0
End Function
Function fnGridProc(ByVal hWnd As Long,ByVal wMsg As Long,ByVal wParam As Long,ByVal lParam As Long) As Long
Local wea As WndEventArgs
Register iReturn As Long
Register i As Long
For i=0 To 5
If wMsg=MsgHdlr(i).wMessage Then
wea.hWnd=hWnd: wea.wParam=wParam: wea.lParam=lParam
Call Dword MsgHdlr(i).dwFnPtr Using FnPtr(wea) To iReturn
fnGridProc=iReturn
Exit Function
End If
Next i
fnGridProc=DefWindowProc(hWnd,wMsg,wParam,lParam)
End Function
Sub AttachMessageHandlers()
ReDim MsgHdlr(5) As MessageHandler 'Associate Windows Message With Message Handlers
MsgHdlr(3).wMessage=%WM_CREATE : MsgHdlr(3).dwFnPtr=CodePtr(fnGridProc_OnCreate)
MsgHdlr(2).wMessage=%WM_SIZE : MsgHdlr(2).dwFnPtr=CodePtr(fnGridProc_OnSize)
MsgHdlr(1).wMessage=%WM_HSCROLL : MsgHdlr(1).dwFnPtr=CodePtr(fnGridProc_OnHScroll)
MsgHdlr(0).wMessage=%WM_VSCROLL : MsgHdlr(0).dwFnPtr=CodePtr(fnGridProc_OnVScroll)
MsgHdlr(5).wMessage=%WM_COMMAND : MsgHdlr(5).dwFnPtr=CodePtr(fnGridProc_OnCommand)
MsgHdlr(4).wMessage=%WM_DESTROY : MsgHdlr(4).dwFnPtr=CodePtr(fnGridProc_OnDestroy)
End Sub
Function IGrid_Initialize(Byval this As IGrid Ptr) As Long
Local szClassName As ZStr*16
Local wc As WNDCLASSEX
#If %Def(%DEBUG)
Prnt ""
Prnt " Entering Initialize() -- IGrid_Initialize()"
#EndIf
szClassName="Cell"
wc.lpszClassName=VarPtr(szClassName) : wc.lpfnWndProc=CodePtr(fnCellProc)
wc.cbSize=SizeOf(wc) : wc.style=0
wc.cbClsExtra=0 : wc.cbWndExtra=8
wc.hInstance=g_hModule : wc.hIcon=LoadIcon(%NULL, ByVal %IDI_APPLICATION)
wc.hCursor=LoadCursor(%NULL, ByVal %IDC_ARROW) : wc.hbrBackground=GetStockObject(%WHITE_BRUSH)
wc.lpszMenuName=%NULL
If RegisterClassEx(wc)=%FALSE Then
Function=%E_FAIL
Exit Function
End If
szClassName="Pane"
wc.lpszClassName=VarPtr(szClassName) : wc.lpfnWndProc=CodePtr(fnPaneProc)
wc.cbSize=SizeOf(wc) : wc.style=0
wc.cbClsExtra=0 : wc.cbWndExtra=4
wc.hInstance=g_hModule : wc.hIcon=LoadIcon(%NULL, ByVal %IDI_APPLICATION)
wc.hCursor=LoadCursor(%NULL, ByVal %IDC_ARROW) : wc.hbrBackground=GetStockObject(%WHITE_BRUSH)
wc.lpszMenuName=%NULL
If RegisterClassEx(wc)=%FALSE Then
Function=%E_FAIL
Exit Function
End If
szClassName="Base"
wc.lpszClassName=VarPtr(szClassName) : wc.lpfnWndProc=CodePtr(fnBaseProc)
wc.cbSize=SizeOf(wc) : wc.style=0
wc.cbClsExtra=0 : wc.cbWndExtra=0
wc.hInstance=g_hModule : wc.hIcon=LoadIcon(%NULL, ByVal %IDI_APPLICATION)
wc.hCursor=LoadCursor(%NULL, ByVal %IDC_ARROW) : wc.hbrBackground=GetStockObject(%GRAY_BRUSH)
wc.lpszMenuName=%NULL
If RegisterClassEx(wc)=%FALSE Then
Function=%E_FAIL
Exit Function
End If
szClassName="Grid"
wc.lpszClassName=VarPtr(szClassName) : wc.lpfnWndProc=CodePtr(fnGridProc)
wc.cbSize=SizeOf(wc) : wc.style=0
wc.cbClsExtra=0 : wc.cbWndExtra=4
wc.hInstance=g_hModule : wc.hIcon=LoadIcon(%NULL, ByVal %IDI_APPLICATION)
wc.hCursor=LoadCursor(%NULL, ByVal %IDC_ARROW) : wc.hbrBackground=GetStockObject(%DKGRAY_BRUSH)
wc.lpszMenuName=%NULL
#If %Def(%DEBUG)
Prnt " GetModuleHandle() = " & Str$(wc.hInstance)
#EndIf
If RegisterClassEx(wc)=%FALSE Then
Function=%E_FAIL
Exit Function
End If
Call AttachMessageHandlers()
#If %Def(%DEBUG)
Prnt " Leaving Initialize()"
Prnt ""
#EndIf
Function=%True
End Function
Function IGrid_CreateGrid _
( _
ByVal this As IGrid Ptr, _
Byval hContainer As Long, _
Byval strSetup As BStr, _
Byval x As Long, _
Byval y As Long, _
Byval cx As Long, _
Byval cy As Long, _
Byval iRows As Long, _
Byval iCols As Long, _
Byval iRowHt As Long, _
Byval strFontName As BStr, _
Byval iFontSize As Long, _
Byval iFontWeight As Long _
) As Long
Local hGrid,dwStyle As Dword
Local pGrid As Grid Ptr
Local gd As GridData
Prnt " Entering IGrid_CreateGrid()"
Prnt " this = " & Str$(this)
Prnt " hContainer = " & Str$(hContainer)
Prnt " strSetup = " & strSetup
Prnt " x = " & Str$(x)
Prnt " y = " & Str$(y)
Prnt " cx = " & Str$(cx)
Prnt " cy = " & Str$(cy)
Prnt " iRows = " & Str$(iRows)
Prnt " iCols = " & Str$(iCols)
Prnt " iRowHt = " & Str$(iRowHt)
Prnt " strFontName = " & strFontName
dwStyle = %WS_CHILD Or %WS_VISIBLE Or %WS_HSCROLL Or %WS_VSCROLL
gd.iCols = iCols
gd.iRowHeight = iRowHt
gd.szFontName = strFontName
gd.iFontSize = iFontSize
gd.iFontWeight = iFontWeight
gd.iRows = iRows
'hGrid=CreateWindowEx(%WS_EX_OVERLAPPEDWINDOW,"Grid",Byval Strptr(strSetup),dwStyle,10,10,570,218,Wea.hWnd,%IDC_GRID1,Wea.hInst,ByVal Varptr(grdData))
hGrid=CreateWindowEx _
( _
%WS_EX_OVERLAPPEDWINDOW, _
"Grid", _
Byval Strptr(strSetup), _
dwStyle, _
x, _
y, _
cx, _
cy, _
hContainer, _
g_CtrlId, _
g_hModule, _
ByVal Varptr(gd) _
)
Prnt " GetLastError() = " & Str$(GetLastError())
Prnt " hGrid = " & Str$(hGrid)
Incr g_CtrlId
pGrid=this
@pGrid.hContainer=hContainer
@pGrid.hControl=hGrid
Call SetFocus(hGrid)
Prnt " Leaving IGrid_CreateGrid()" : Prnt ""
Function=%S_OK
End Function
Function IConnectionPointContainer_QueryInterface(ByVal this As IConnectionPointContainer1 Ptr, ByRef iid As Guid, ByVal ppv As Dword Ptr) As Long
#If %Def(%DEBUG)
Prnt " Entering IConnectionPointContainer_QueryInterface()"
#EndIf
@ppv=%NULL
Select Case iid
Case $IID_IUnknown
#If %Def(%DEBUG)
Prnt " Looking For IID_IUnknown"
#EndIf
Decr this : @ppv=this
Call IGrid_AddRef(this)
#If %Def(%DEBUG)
Prnt " Leaving IConnectionPointContainer_QueryInterface()"
#EndIf
Function=%S_OK : Exit Function
Case $IID_IFHGrid
#If %Def(%DEBUG)
Prnt " Looking For IID_IFJHGrid"
#EndIf
Decr this : @ppv=this
Call IGrid_AddRef(this)
#If %Def(%DEBUG)
Prnt " Leaving IConnectionPointContainer_QueryInterface()"
#EndIf
Function=%S_OK : Exit Function
Case $IID_IConnectionPointContainer
#If %Def(%DEBUG)
Prnt " Looking For IID_IConnectionPointContainer"
#EndIf
Call IConnectionPointContainer_AddRef(this)
#If %Def(%DEBUG)
Prnt " Leaving IConnectionPointContainer_QueryInterface()"
#EndIf
@ppv=this : Function=%S_OK : Exit Function
Case $IID_IConnectionPoint
#If %Def(%DEBUG)
Prnt " Looking For IID_IConnectionPoint"
#EndIf
Incr this : @ppv=this
Call IConnectionPoint_AddRef(this)
#If %Def(%DEBUG)
Prnt " Leaving IConnectionPointContainer_QueryInterface()"
#EndIf
Function=%S_OK : Exit Function
Case Else
#If %Def(%DEBUG)
Prnt " Looking For Something I Ain't Got!"
Prnt " Leaving IConnectionPointContainer_QueryInterface()"
#EndIf
End Select
Function=%E_NOINTERFACE
End Function
Function IConnectionPointContainer_AddRef(ByVal this As IConnectionPointContainer1 Ptr) As Long
Local pGrid As Grid Ptr
#If %Def(%DEBUG)
Prnt " Entering IConnectionPointContainer_AddRef()"
#EndIf
Decr this
pGrid=this
#If %Def(%DEBUG)
Prnt " @pGrid.m_cRef = " & Str$(@pGrid.m_cRef) & " << Before"
#EndIf
Incr @pGrid.m_cRef
#If %Def(%DEBUG)
Prnt " @pGrid.m_cRef = " & Str$(@pGrid.m_cRef) & " << After"
Prnt " Leaving IConnectionPointContainer_AddRef()"
#EndIf
Function=@pGrid.m_cRef
End Function
Function IConnectionPointContainer_Release(ByVal this As IConnectionPointContainer1 Ptr) As Long
Local pGrid As Grid Ptr
#If %Def(%DEBUG)
Prnt " Entering IConnectionPointContainer_Release()"
#EndIf
Decr this : pGrid=this
#If %Def(%DEBUG)
Prnt " @pGrid.m_cRef = " & Str$(@pGrid.m_cRef) & " << Before"
#EndIf
Decr @pGrid.m_cRef
If @pGrid.m_cRef=0 Then
Call DestroyWindow(@pGrid.hControl)
#If %Def(%DEBUG)
Prnt " @pGrid.m_cRef = 0 And Will Now Delete pGrid!"
#EndIf
Call CoTaskMemFree(this)
Call InterlockedDecrement(g_lObjs)
Function=0
Else
#If %Def(%DEBUG)
Prnt " @pGrid.m_cRef = " & Str$(@pGrid.m_cRef) & " << After"
#EndIf
Function=@pGrid.m_cRef
End If
#If %Def(%DEBUG)
Prnt " Leaving IConnectionPointContainer_Release()"
#EndIf
End Function
Function IConnectionPointContainer_EnumConnectionPoints(ByVal this As IConnectionPointContainer1 Ptr, Byval ppEnum As IEnumConnectionPoints1 Ptr) As Long
Function=%E_NOTIMPL
End Function
Function IConnectionPointContainer_FindConnectionPoint(ByVal this As IConnectionPointContainer1 Ptr, ByRef iid As Guid, ByVal ppCP As Dword Ptr) As Long
Local hr As Long
#If %Def(%DEBUG)
Prnt " Entering IConnectionPointContainer_FindConnectionPoint()"
#EndIf
If iid=$IID_IFHGrid_Events Then
#If %Def(%DEBUG)
Prnt " this = " & Str$(this)
Prnt " @ppCP = " & Str$(@ppCP)
#EndIf
hr=IConnectionPointContainer_QueryInterface(this, $IID_IConnectionPoint, ppCP)
#If %Def(%DEBUG)
Prnt " @ppCP = " & Str$(@ppCP)
Prnt " Leaving IConnectionPointContainer_FindConnectionPoint()" : Prnt ""
#EndIf
Function=hr : Exit Function
End If
Function=%E_NOINTERFACE
End Function
Function IConnectionPoint_QueryInterface(ByVal this As IConnectionPoint1 Ptr, ByRef iid As Guid, ByVal ppv As Dword Ptr) As Long
#If %Def(%DEBUG)
Prnt " Entering IConnectionPoint_QueryInterface()"
#EndIf
@ppv=%NULL
Select Case iid
Case $IID_IUnknown
Decr this : Decr this
@ppv=this
Call IGrid_AddRef(this)
Function=%S_OK
Exit Function
Case $IID_IFHGrid
Decr this : Decr this
@ppv=this
Call IGrid_AddRef(this)
Function=%S_OK
Exit Function
Case $IID_IConnectionPointContainer
Decr this
@ppv=this
Call IConnectionPointContainer_AddRef(this)
Function=%S_OK
Exit Function
Case $IID_IConnectionPoint
@ppv=this
Call IConnectionPoint_AddRef(this)
Function=%S_OK
Exit Function
Case Else
#If %Def(%DEBUG)
Prnt " Looking For Something I Ain't Got!"
Prnt " Leaving IConnectionPoint_QueryInterface()"
#EndIf
End Select
Function=%E_NOINTERFACE
End Function
Function IConnectionPoint_AddRef(ByVal this As IConnectionPoint1 Ptr) As Long
Local pGrid As Grid Ptr
#If %Def(%DEBUG)
Prnt " Entering IConnectionPoint_AddRef()"
#EndIf
Decr this : Decr this
pGrid=this
#If %Def(%DEBUG)
Prnt " @pGrid.m_cRef = " & Str$(@pGrid.m_cRef) & " << Before"
#EndIf
Incr @pGrid.m_cRef
#If %Def(%DEBUG)
Prnt " @pGrid.m_cRef = " & Str$(@pGrid.m_cRef) & " << After"
Prnt " Leaving IConnectionPoint_AddRef()"
#EndIf
Function=@pGrid.m_cRef
End Function
Function IConnectionPoint_Release(ByVal this As IConnectionPoint1 Ptr) As Long
Local pGrid As Grid Ptr
#If %Def(%DEBUG)
Prnt " Entering IConnectionPoint_Release()"
#EndIf
Decr this : Decr this
pGrid=this
#If %Def(%DEBUG)
Prnt " @pGrid.m_cRef = " & Str$(@pGrid.m_cRef) & " << Before"
#EndIf
Decr @pGrid.m_cRef
If @pGrid.m_cRef=0 Then
Call DestroyWindow(@pGrid.hControl)
#If %Def(%DEBUG)
Prnt " @pGrid.m_cRef = 0 And Will Now Delete pGrid!"
#EndIf
Call CoTaskMemFree(this)
Call InterlockedDecrement(g_lObjs)
#If %Def(%DEBUG)
Prnt " Leaving IConnectionPoint_Release()"
#EndIf
Function=0
Else
#If %Def(%DEBUG)
Prnt " @pGrid.m_cRef = " & Str$(@pGrid.m_cRef) & " << After"
Prnt " Leaving IConnectionPoint_Release()"
#EndIf
Function=@pGrid.m_cRef
End If
End Function
Function IConnectionPoint_GetConnectionInterface(Byval this As IConnectionPoint1 Ptr, Byref iid As Guid) As Long
Function=%E_NOTIMPL
End Function
Function IConnectionPoint_GetConnectionPointContainer(Byval this As IConnectionPoint1 Ptr, Byval ppCPC As IConnectionPointContainer1 Ptr) As Long
Function=%E_NOTIMPL
End Function
Function IConnectionPoint_Advise(Byval this As IConnectionPoint1 Ptr, Byval pUnkSink As Dword Ptr, Byval pdwCookie As Dword Ptr) As Long
Local Vtbl As Dword Ptr
Local hr As Long
#If %Def(%DEBUG)
Prnt " Entering IConnectionPoint_Advise()! Grab Your Hardhat And Hang On Tight!"
Prnt " pUnkSink = " & Str$(pUnkSink)
Prnt " @pUnkSink = " & Str$(@pUnkSink)
#EndIf
Vtbl=@pUnkSink
#If %Def(%DEBUG)
Prnt " Vtbl = " & Str$(Vtbl)
Prnt " @Vtbl[0] = " & Str$(@Vtbl[0])
Prnt " g_ptrOutGoing = " & Str$(g_ptrOutGoing) & " << Before Call Of QueryInterface() On Sink"
#EndIf
Call Dword @Vtbl[0] Using ptrQueryInterface(pUnkSink,$IID_IFHGrid_Events,Varptr(g_ptrOutGoing)) To hr
#If %Def(%DEBUG)
Prnt " g_ptrOutGoing = " & Str$(g_ptrOutGoing) & " << After Call Of QueryInterface() On Sink"
#EndIf
If SUCCEEDED(hr) Then
#If %Def(%DEBUG)
Prnt " Call Dword Succeeded!"
#EndIf
@pdwCookie=1
Else
@pdwCookie=0
End If
#If %Def(%DEBUG)
Prnt " Leaving IConnectionPoint_Advise() And Still In One Piece!" : Prnt ""
#EndIf
Function=hr
End Function
Function IConnectionPoint_Unadvise(Byval this As IConnectionPoint1 Ptr, Byval dwCookie As Dword) As Long
Local Vtbl As Dword Ptr
Local iReturn As Long
#If %Def(%DEBUG)
Prnt " Entering IConnectionPoint_Unadvise()"
#EndIf
VTbl=@g_ptrOutGoing
Call Dword @Vtbl[2] Using ptrRelease(g_ptrOutGoing) To iReturn
#If %Def(%DEBUG)
Prnt " dwCookie = " & Str$(dwCookie)
#EndIf
If SUCCEEDED(iReturn) Then
#If %Def(%DEBUG)
Prnt " IGrid_Events::Release() Succeeded!"
#EndIf
End If
#If %Def(%DEBUG)
Prnt " Release() Returned " & Str$(iReturn)
Prnt " Leaving IConnectionPoint_Unadvise()"
#EndIf
Function=%NOERROR
End Function
Function IConnectionPoint_EnumConnections(Byval this As IConnectionPoint1 Ptr, Byval ppEnum As IEnumConnections1 Ptr) As Long
Function=%E_NOTIMPL
End Function
Function IClassFactory_AddRef(ByVal this As IClassFactory1 Ptr) As Long
#If %Def(%DEBUG)
Prnt " Entering IClassFactory_AddRef()"
#EndIf
Call InterlockedIncrement(g_lObjs)
#If %Def(%DEBUG)
Prnt " g_lObjs = " & Str$(g_lObjs)
Prnt " Leaving IClassFactory_AddRef()"
#EndIf
IClassFactory_AddRef=g_lObjs
End Function
Function IClassFactory_Release(ByVal this As IClassFactory1 Ptr) As Long
#If %Def(%DEBUG)
Prnt " Entering IClassFactory_Release()"
#EndIf
Call InterlockedDecrement(g_lObjs)
#If %Def(%DEBUG)
Prnt " g_lObjs = " & Str$(g_lObjs)
Prnt " Leaving IClassFactory_Release()"
#EndIf
IClassFactory_Release=g_lObjs
End Function
Function IClassFactory_QueryInterface(ByVal this As IClassFactory1 Ptr, ByRef RefIID As Guid, ByVal pCF As Dword Ptr) As Long
#If %Def(%DEBUG)
Prnt " Entering IClassFactory_QueryInterface()"
#EndIf
@pCF=0
If RefIID=$IID_IUnknown Or RefIID=$IID_IClassFactory Then
Call IClassFactory_AddRef(this)
@pCF=this
#If %Def(%DEBUG)
Prnt " this = " & Str$(this)
Prnt " Leaving IClassFactory_QueryInterface()"
#EndIf
Function=%NOERROR : Exit Function
End If
#If %Def(%DEBUG)
Prnt " Leaving IClassFactory_QueryInterface() Empty Handed!"
#EndIf
Function=%E_NoInterface
End Function
Function IClassFactory_CreateInstance(ByVal this As IClassFactory1 Ptr, ByVal pUnknown As Dword, ByRef RefIID As Guid, Byval ppv As Dword Ptr) As Long
Local pIGrid As IGrid Ptr
Local pGrid As Grid Ptr
Local hr As Long
#If %Def(%DEBUG)
Prnt " Entering IClassFactory_CreateInstance()"
#EndIf
@ppv=%NULL
If pUnknown Then
hr=%CLASS_E_NOAGGREGATION
Else
pGrid=CoTaskMemAlloc(SizeOf(Grid))
#If %Def(%DEBUG)
Prnt " pGrid = " & Str$(pGrid)
#EndIf
If pGrid Then
@pGrid.lpIGridVtbl = VarPtr(IGrid_Vtbl)
@pGrid.lpICPCVtbl = VarPtr(IConnPointContainer_Vtbl)
@pGrid.lpICPVtbl = Varptr(IConnPoint_Vtbl)
#If %Def(%DEBUG)
Prnt " Varptr(@pGrid.lpIGridVtbl) = " & Str$(Varptr(@pGrid.lpIGridVtbl))
Prnt " Varptr(@pGrid.lpICPCVtbl) = " & Str$(Varptr(@pGrid.lpICPCVtbl))
Prnt " Varptr(@pGrid.lpICPVtbl) = " & Str$(Varptr(@pGrid.lpICPVtbl))
#EndIf
@pGrid.m_cRef=0
@pGrid.hContainer=0 : @pGrid.hControl=0
pIGrid=pGrid
#If %Def(%DEBUG)
Prnt " @ppv = " & Str$(@ppv) & " << Before QueryInterface() Call"
#EndIf
hr= IGrid_QueryInterface(pIGrid,RefIID,ppv)
#If %Def(%DEBUG)
Prnt " @ppv = " & Str$(@ppv) & " << After QueryInterface() Call"
#EndIf
If SUCCEEDED(hr) Then
Call InterlockedIncrement(g_lObjs)
Else
Call CoTaskMemFree(pGrid)
End If
Else
hr=%E_OutOfMemory
End If
End If
#If %Def(%DEBUG)
Prnt " Leaving IClassFactory_CreateInstance()"
Prnt ""
#EndIf
IClassFactory_CreateInstance=hr
End Function
Function IClassFactory_LockServer(ByVal this As IClassFactory1 Ptr, Byval flock As Long) As Long
If flock Then
Call InterlockedIncrement(g_lLocks)
Else
Call InterlockedDecrement(g_lLocks)
End If
IClassFactory_LockServer=%NOERROR
End Function
Function DllCanUnloadNow Alias "DllCanUnloadNow" () Export As Long
#If %Def(%DEBUG)
Prnt "Entering DllCanUnloadNow()"
#EndIf
If g_lObjs = 0 And g_lLocks = 0 Then
#If %Def(%DEBUG)
Prnt " I'm Outta Here! (dll is unloaded)"
#EndIf
Function=%S_OK
Else
#If %Def(%DEBUG)
Prnt " The System Wants Rid Of Me But I Won't Go!"
#EndIf
Function=%S_FALSE
End If
#If %Def(%DEBUG)
Prnt "Leaving DllCanUnloadNow()"
#EndIf
End Function
continued...