I'm having problem with setting the picture property of a dynamically created
commandbutton control. The steps I go through are as follows.
1) Adding the command button control using the form's Controls collection
Add method
2) Set the commandbutton's Style property to ICON using the GetWindowLong
and SetWindowLong API's
3) setting the commandbuttons Picture property

When I execute these steps, the button is added to the form and the Style
Bit is changed successfully, and I receive no errors when setting the command
button's picture property. However, when I refresh the command button the
icon does not appear on the command button.

What am I doing wrong?

For reference, below is my test code.


'*********************
'* frmButtonTest.frm *
'*********************

' This form contains a text box for inputing the icon full path name and
' two command buttons, cmdAddButton and cmdExit. The cmdAddButton calls
' the bButtonTest:AddCommandButton procedure, passing to it the icon file
' name and path.

Private Sub cmdExit_Click()
Unload frmButtonTest
End Sub

Private Sub cmdAddButton_Click()
AddCommandButton (txtIconPath.Text)
End Sub


'*******************
'* bButtonTest.Bas *
'*******************
Option Explicit

Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA"
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Const GWL_STYLE& = (-16)
Public Const BS_ICON& = &H40&
Public Const BS_BITMAP& = &H80&


Public Sub AddCommandButton(ByVal strIconPath As String)

Static intCount As Integer

Dim objCmdButton As VB.CommandButton
Dim lngStyle As Long
Dim lngRet As Long

'Increment Count to make unique button name
intCount = intCount + 1

'Create button
Set objCmdButton = frmButtonTest.Controls.Add("VB.CommandButton", "Test"
+ LTrim$(Str(intCount)))

'Set Style to Icon
lngStyle = GetWindowLong(objCmdButton.hwnd, GWL_STYLE)
lngRet = SetWindowLong(objCmdButton.hwnd, GWL_STYLE, lngStyle Or BS_ICON
Or BS_BITMAP)

'Adjust buttons top and left positions to cascade multiple creates
objCmdButton.Top = objCmdButton.Top + ((intCount - 1) * 50)
objCmdButton.Left = objCmdButton.Left + ((intCount - 1) * 50)

'Set properties
objCmdButton.Enabled = True
objCmdButton.Visible = True
objCmdButton.ZOrder 0

'Load icon into picture property
objCmdButton.Picture = LoadPicture(strIconPath)

'refresh button
objCmdButton.Refresh

End Sub