CatFelix
2017-07-31T08:29:43Z
I am trying to get to grips with how iGrid functions by working through the Samples.

CellButtons requires a number of WIN API functions to be declared in a VBA environment:

So far I have made the following declarations:

Public Declare Function DrawFrameControl Lib "user32" (ByVal hdc As Long, lpRect As Rect, ByVal uType As Long, ByVal uState As Long) As Long
Public Declare Function InflateRect Lib "user32" (lpRect As Rect, ByVal x As Long, ByVal y As Long) As Long
Public Declare Function OffsetRect Lib "user32" (lpRect As Rect, ByVal x As Long, ByVal y As Long) As Long
Public Declare Function SetTextColor Lib "user32" (ByVal hdc As Long, ByVal crColor As Long) As Long

The first 3 work OK, but when calling SetTextColor I get the following Message:

"Can't find dll entry point for SetTextColor in user32."

I actually called it through the following little test routine:

Sub TestColor()
Dim hdc, crColor As Long
crColor = RGB(150, 0, 0)
SetTextColor hdc, crColor
End Sub

Does the problem occur because of my definition? If so how should it be defined? Also how should TranslateColor and DrawText be declared?


Igor/10Tec
2017-07-31T12:29:53Z
The WinAPI SetTextColor function is defined in gdi32.dll - see MSDN .

Where did you find this declaration of SetTextColor? If you meant the Command Button Cells sample for iGrid from the online Extra Samples  library, it contains the correct definition for the function (see the API.bas file):

Public Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long

You can also find the declaration for the WinAPI DrawText function there:

Public Declare Function DrawText Lib "user32" Alias "DrawTextA" _
   (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long

The helper TranslateColor function is also defined in that module:

Public Declare Function OleTranslateColor Lib "OLEPRO32.DLL" (ByVal OLE_COLOR As Long, ByVal HPALETTE As Long, pccolorref As Long) As Long

Public Function TranslateColor(ByVal oClr As OLE_COLOR, _
                        Optional hPal As Long = 0) As Long
    ' Convert Automation color to Windows color
    Const CLR_INVALID = -1
    If OleTranslateColor(oClr, hPal, TranslateColor) Then
        TranslateColor = CLR_INVALID
    End If
End Function

****************************

And your calling code in TestColor has one problem. Actually you defined the hdc variable as Variant, not as Long. The correct version of your sub could look like this:

Sub TestColor()
    Dim hdc As Long
    Dim crColor As Long
    crColor = RGB(150, 0, 0)
    SetTextColor hdc, crColor
End Sub

Read the Declaring Variables  VBA MSDN topic to know all rules used in VBA to declare variables.
CatFelix
2017-08-01T01:02:14Z
Thanks Igor,

I think I'm now getting the hang of iGrid. Will continue through other Sample code