Spinor


How to use in VBA for Excel such API functions like, SetPixel, GetPixel, LineTo, PolyLine or ArcTo acting on the new created standard UserForm or in the special new window opened by appropriate API function. I know that it is trivial within VB applications, whereas VBA makes troubles (handle address of UserForm). I would be grateful for some simple examples (which have been tested and work well).

My second question is: How one can use OpenGL library in VBA (as far as I know it is possible in the case of VB)

Thank you in advance

Spinor




Re: API and OpenGL in VBA for Excel

João Rodrigues


Hi Spinor,

in a Excel module:

Option Explicit
Declare Function SetPixel Lib "gdi32" Alias "SetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long

Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long

Declare Function LineTo Lib "gdi32" Alias "LineTo" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long

Declare Function PolyPolyline Lib "gdi32" Alias "PolyPolyline" (ByVal hdc As Long, lppt As POINTAPI, lpdwPolyPoints As Long, ByVal cCount As Long) As Long

public Type POINTAPI
x As Long
y As Long
End Type

Declare Function ArcTo Lib "gdi32" Alias "ArcTo" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As Long

then you can go to http://msdn2.microsoft.com/en-us/library/aa383749.aspx and see code examples...

the thing is that you must translate from C to VB ... but it can be done...

HTH

Joao Rodrigues






Re: API and OpenGL in VBA for Excel

Spinor

Hi Joao and everybody,

Many thanks for your kindness and your answer.

The crucial problem for me is how to get the value of "hdc As Long"

for given UserForm. Do you know how to do this

Spinor






Re: API and OpenGL in VBA for Excel

João Rodrigues

...well i haven't try but perhaps:

hdc = FindWindow32("ThunderDFrame", userform.Caption) 'UserForm Excel 2000

Excel 97
' hdc= FindWindow32("ThunderXFrame", userform.Caption) 'UserForm

Good luck.

Joao Rodrigues





Re: API and OpenGL in VBA for Excel

Spinor

Hi Joao,

Many thanks again.

Unfortuantely, FindWindow32 function is not present in VBA for Excel.

Maybe you know its equivalent version in API library.

Best wishes

Spinor





Re: API and OpenGL in VBA for Excel

João Rodrigues

Declare Function FindWindow32 Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Until tomorrow..

JR





Re: API and OpenGL in VBA for Excel

@sanya

Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Long, ByVal hdc As Long) As Long

FindWindow obtain a HWND!
hWnd = FindWindow32("ThunderDFrame", userform.Caption) 'UserForm Excel 2000
'This is NOT a hDC!

If you want to obtain an hDC try this:
hDC = GetDC( hWnd )

If no longer needed this hDC, the ReleaseDC function must be called to release the DC
for example:
ReleaseDC( hWnd, hDC )







Re: API and OpenGL in VBA for Excel

@sanya

Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Long, ByVal hdc As Long) As Long

FindWindow obtain a HWND!
hWnd = FindWindow32("ThunderDFrame", userform.Caption) 'UserForm Excel 2000
'This is NOT a hDC!

If you want to obtain an hDC try this:
hDC = GetDC( hWnd )

If no longer needed this hDC, the ReleaseDC function must be called to release the DC
for example:
ReleaseDC( hWnd, hDC )

Use this: http://allapi.mentalis.org/apilist/apilist.php