Hi,
I'm trying to use a strip bitmap to provide a graphics knob on a form that can be turned e.g. (like a volume control). I have the a test bitmap and have put together a test program to use it and it works perfectly (ish).
The only problem is that the strip bitmap is clearly grayscale (others could be colour) when I start; whereas when I use it within the program the graphics knob loses resolution (i.e I assume it goes to monochrome [b&w]). I have searched the web and the forum but can find no advice on what might be wrong.
Below is the test program and I have attached it as a zip:-
Its bound to be something obvious on my part - but I cannot see it - so any advice would be greatly appreciated.
Many thanks
Barry
-------
Global gindex As Integer
Global gHandle As Dword
'--------------------------------------------------------------------------------
Function FORM1_COMMAND1_BN_CLICKED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idButtonControl As Long _ ' identifier of button
) As Long
gIndex = gIndex + 1
FF_Control_Redraw( HWND_FORM1_PICTURE1 )
End Function
'--------------------------------------------------------------------------------
Function FORM1_WM_CREATE ( _
hWndForm As Dword, _ ' handle of Form
ByVal UserData As Long _ ' optional user defined Long value
) As Long
gHandle = ImageList_LoadImage( App.hInstance, "barrytest.bmp",0 , 1, %CLR_NONE ,%IMAGE_BITMAP ,%LR_LOADFROMFILE Or %LR_DEFAULTCOLOR )
gIndex = 0
End Function
'--------------------------------------------------------------------------------
Function FORM1_PICTURE1_WM_PAINT ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword _ ' handle of Control
) As Long
Local hdc As Dword
Local nSavedDC As Dword
Local hBitMap As Dword
Local hDCBitMap As Dword
Local ps As paintstruct
If ( gIndex = 0 ) Then Exit Function 'Lets see what the original looks like by missing the first pass
hDC = BeginPaint( hWndControl, ps )
nSavedDC = SaveDC( hDC )
hDCBitMap = CreateCompatibleDC(hDC)
hBitMap = CreateCompatibleBitmap(hDC, ps.rcpaint.nRight, ps.rcpaint.nBottom )
SelectObject ( hDCBitMap, hBitMap )
ImageList_DrawEx( gHandle, gIndex, hDCBitMap, 0, 0, 0, 0,%CLR_NONE,%CLR_NONE,%ILD_NORMAL )
BitBlt ( hDC, 0, 0, 67, 67, hDCBitMap, 0, 0, %srccopy )
RestoreDC ( hDC, nSavedDC )
If hBitMap Then DeleteObject hBitMap
If hDCBitMap Then DeleteObject hDCBitMap
If hDC Then DeleteObject hDC
End Function
Hi,
I think I have found the answer to my problem myself - see below - as it now works.
I've also included/attached the modfiied FireFly project in case it helps anyone in the future.
Obviously if anyone knows a better way then I would always be pleased to be told.
Cheers
Barry
---
Global gindex As Integer
Global gHandle As Dword
'--------------------------------------------------------------------------------
Function FORM1_COMMAND1_BN_CLICKED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idButtonControl As Long _ ' identifier of button
) As Long
gIndex = gIndex + 1
FF_Control_Redraw( HWND_FORM1_PICTURE1 )
End Function
'--------------------------------------------------------------------------------
Function FORM1_WM_CREATE ( _
hWndForm As Dword, _ ' handle of Form
ByVal UserData As Long _ ' optional user defined Long value
) As Long
'------------------------------
' REPLACE THIS .....
'gHandle = ImageList_LoadImage( App.hInstance, "barrytest.bmp",0 , 1, %CLR_NONE ,%IMAGE_BITMAP ,%LR_LOADFROMFILE Or %LR_DEFAULTCOLOR )
' WITH THIS ....
'
'=====
Local hScrBM As Dword
gHandle = ImageList_Create(67, 67, %ILC_COLOR24, 0, 1)
hScrBM = LoadImage(App.hInstance, "barrytest.bmp", %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE )
ImageList_Add(gHandle, hScrBM, %Null)
DeleteObject(hScrBM)
'======
gIndex = 0
End Function
'--------------------------------------------------------------------------------
Function FORM1_PICTURE1_WM_PAINT ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword _ ' handle of Control
) As Long
Local hdc As Dword
Local nSavedDC As Dword
Local hBitMap As Dword
Local hDCBitMap As Dword
Local ps As paintstruct
If ( gIndex = 0 ) Then Exit Function 'Lets see what the original looks like by missing the first pass
hDC = BeginPaint( hWndControl, ps )
nSavedDC = SaveDC( hDC )
hDCBitMap = CreateCompatibleDC(%Null)
hBitMap = CreateCompatibleBitmap(hDC, ps.rcpaint.nRight, ps.rcpaint.nBottom )
SelectObject ( hDCBitMap, hBitMap )
ImageList_Draw ( gHandle, gIndex, hDCBitMap,0,0,%ILD_NORMAL)
BitBlt ( hDC, 0, 0, 67, 67, hDCBitMap, 0, 0, %srccopy )
RestoreDC ( hDC, nSavedDC )
If hBitMap Then DeleteObject hBitMap
If hDCBitMap Then DeleteObject hDCBitMap
If hDC Then DeleteObject hDC
End Function
I looked at your sample and was a little puzzled myself. It looked like the palette was getting changed to 4-bit (16 color). After you posted your solution I looked up ImageList_Create in the WinAPI help and see this for the ILC_COLOR flag:
"Use the default behavior if none of the other ILC_COLOR* flags is specified. Typically, the default is ILC_COLOR4"
So it sounds like if you don't use ImageList_Create you will likely get 4-bit color?
Hi Robert,
Thanks - yes that explains it. I had read the help on LoadImage - but had missed that vital line.
I like to know why solutions work - rather than they just do - as thats how you learn. And now I know....
Cheers
Barry