how can i get this to work under both win95/98 and win2k/nt/me (basically all win platforms =P)?

Public Function getbitmapregion(cPicture As StdPicture, cTransparent As Long)
Dim hRgn As Long, tRgn As Long
Dim X As Integer, Y As Integer, X0 As Integer
Dim hDC As Long, BM As BITMAP

hDC = CreateCompatibleDC(0)

If hDC Then
SelectObject hDC, cPicture
GetObject cPicture, Len(BM), BM
hRgn = CreateRectRgn(0, 0, BM.bmWidth, BM.bmHeight)

For Y = 0 To BM.bmHeight

For X = 0 To BM.bmWidth
While X <= BM.bmWidth And GetPixel(hDC, X, Y) <> cTransparent
X = X + 1
Wend
X0 = X
While X <= BM.bmWidth And GetPixel(hDC, X, Y) = cTransparent
X = X + 1
Wend
If X0 < X Then
tRgn = CreateRectRgn(X0, Y, X, Y + 1)
CombineRgn hRgn, hRgn, tRgn, 4
DeleteObject tRgn
End If
Next X
Next Y

getbitmapregion = hRgn
DeleteObject SelectObject(hDC, cPicture)
End If

DeleteDC hDC
End Function