Date: 02-16-2022
Return to Index
created by gbSnippets
'In this example a 6x6 icon is used. The .hbmMask and .hbmColor
'bitmasks are examined.
'Compilable Example: (Jose Includes)
'The first button pops up the image dimensions
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource "gbsnippets.pbr"
Global hDlg As DWord, hLst As DWord, hIcon As DWord
%ID_Data = 500 : %ID_Graphic = 501
Function PBMain() As Long
Local Style&
style& = %WS_Child Or %WS_Visible Or %ES_MultiLine Or %WS_VScroll Or %ES_AutoHScroll _
Or %WS_HScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %WS_TabStop
Dialog New Pixels, 0, "Test Code",300,300,350,350, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Get AND bitmap", 20,10,160,20
Control Add Graphic, hDlg, %ID_Graphic,"", 50,50,6,6 ', %ws_border
Control Add TextBox, hDlg, %ID_Data,"<bitmap data>", 20,65,300,250, Style&
ImageList New Icon 6,6,24,1 To hLst 'create icon imagelist
ImageList Add Icon hLst, "test"
Graphic Attach hDlg, %ID_Graphic
Graphic Color %rgb_PowderBlue, %rgb_PowderBlue
Graphic Clear
Graphic ImageList (0,0), hLst, 1,0,%ILD_Normal 'copy the icon to the Graphic control
ImageList Kill hLst 'remove the imagelist
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
CreateDATAStatements
End If
End Function
Sub CreateDATAStatements 'Graphic Attach
Local temp$, i As Long, xsize&, ysize&, bmp$, PP As IconInfo, P As Long Ptr
'load a resource icon called "test" (a 6x6 test icon)
hIcon = LoadImage(GetModuleHandle(""), "test", %IMAGE_ICON, 0, 0, %LR_DEFAULTCOLOR)
GetIconInfo hIcon, PP
MsgBox Str$(PP.xhotspot*2) + Str$(PP.yhotspot*2) 'dimensions from IconInfo structure
'use Graphic Attach on the PP.hbmColor member of the IconInfo variable
Graphic Attach PP.hbmColor, 0
Graphic Get Bits To bmp$
MsgBox Str$(Len(bmp$)) 'length of bitmap bitstring
'use pointer variable P to read bitmap dimensions from the bitstring bmp$
xsize& = CVL(bmp$,1) : ysize& = CVL(bmp$,5)
temp$ = Str$(xsize&) + "x" + LTrim$(Str$(ysize&)) + $CrLf
MsgBox temp$ 'dimensions from within the bitmap bitstring
'create a string to display the color values from the bitstring bmp$
P = StrPTR(bmp$) + 8
For i = 2 To (xsize& * ysize& + 1)
If (i-2) Mod 6 = 0 Then temp$ = temp$ + $CrLf + "Data "
temp$ = temp$ + Hex$(@P,6) + " "
Incr P
Next i
Control Set Text hDlg, %ID_Data, temp$ 'temp$ is empty is imgCurrent=0
DestroyIcon hIcon '
End Sub
Sub Result
Data ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8
Data ECE9D8, FF0000, FF0000, FF0000, FF0000, ECE9D8
Data ECE9D8, FF0000, ECE9D8, ECE9D8, FF0000, ECE9D8
Data ECE9D8, FF0000, ECE9D8, ECE9D8, FF0000, ECE9D8
Data ECE9D8, FF0000, FF0000, FF0000, FF0000, ECE9D8
Data ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8
End Sub
'gbs_00506
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm