Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dialog: Bitmap or Icon on Button
#1
How do i display a bitmap on a button (without text) ?
pi
#2
In Dialog Editor, set BS_BITMAP or BS_ICON style.
In dialog procedure, load bitmap file and send BM_SETIMAGE.

Function Dialog7:
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

if(!ShowDialog("Dialog7" &Dialog7)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Form"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Button 0x54030080 0x0 8 4 48 14 "no text"
;4 Button 0x54030040 0x0 62 4 48 14 "no text"
;END DIALOG
;DIALOG EDITOR: "" 0x2010804 "" ""


ret
;messages
sel message
,case WM_INITDIALOG
,DT_Init(hDlg lParam)
,int bm=qm.LoadPictureFile("$qm$\de_ctrl.bmp" 0) ;;loads bmp, gif or jpg. With QM < 2.1.8.4, use int bm=LoadImage(0 _s.expandpath("$qm$\de_ctrl.bmp") IMAGE_BITMAP 0 0 LR_LOADFROMFILE)
,SendMessage(id(3 hDlg) BM_SETIMAGE IMAGE_BITMAP bm)
,int ic=GetIcon("mouse.ico")
,SendMessage(id(4 hDlg) BM_SETIMAGE IMAGE_ICON ic)
,ret 1
,case WM_DESTROY
,DT_DeleteData(hDlg)
,DeleteObject(SendMessage(id(3 hDlg) BM_GETIMAGE IMAGE_BITMAP 0))
,DestroyIcon(SendMessage(id(4 hDlg) BM_GETIMAGE IMAGE_ICON 0))
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1
#3
thanks !
pi
#4
Error (now fixed): for icons, use DestroyIcon, not DeleteObject.
#5
i work on a simple dhtml editor, do you think i should use
something like DEX_InitToolbar or use GetIcon with a .icl file ?
pi
#6
Function DEX_Main (this version loads icons)
Code:
Copy      Help
;Sample dialog with toolbar, tree view, list view and status bar controls, with images.
;Run this function.


;For images, here is used de_ctrl.bmp, the same that is used by the Dialog Editor.
;Change de_ctrl.bmp (below) to the name of your bitmap file. The file must contain
;;any number of 16x16 images arranged horizontally. Use magenta color (0xff00ff)
;;for transparent areas.


;Tested with QM 2.1.5, 6, 7, 8.


#if (QMVER<0x02010700)
#compile "DEX_CC_API"
#endif

type DEX_DATA il1 il2 il3 ;;you can add more members to store various data
DEX_DATA d ;;to access this variable from dialog procedure, use DEX_DATA& d; &d=+DT_GetParam(hDlg)

;add bitmap containing all icons
;d.il1=ImageList_LoadImage(0 _s.expandpath("$qm$\de_ctrl.bmp") 16 0 0xFF00FF IMAGE_BITMAP LR_LOADFROMFILE)
;or load multiple files (slower)

d.il1=ImageList_Create(16 16 WINAPI.ILC_MASK|WINAPI.ILC_COLOR32 0 15)
rep(15) ImageList_ReplaceIcon(d.il1 -1 GetIcon("mouse.ico"))

d.il2=d.il1; d.il3=d.il1 ;;in real world, you can use ImageList_LoadImage/ImageList_Destroy to use different bitmaps for each control

if(!ShowDialog("DEX_Dialog" &DEX_Dialog 0 0 0 0 0 &d)) ret

ImageList_Destroy(d.il1);; ImageList_Destroy(d.il2); ImageList_Destroy(d.il3)
#7
what is the style for showing the first icon(item) unselected ?

for some reason there is a border around the button.
it doesn't look like as the buttons on DEX_InitToolbar


Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

if(!ShowDialog("Dialog7" &Dialog7)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Form"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;4 Button 0x54038040 0x0 62 4 16 16 "icon"
;END DIALOG
;DIALOG EDITOR: "" 0x2010804 "" ""


ret
;messages
sel message
,case WM_INITDIALOG
,DT_Init(hDlg lParam)
,int ic=GetIcon("mouse.ico")
,SendMessage(id(4 hDlg) BM_SETIMAGE IMAGE_ICON ic)
,ret 1
,case WM_DESTROY
,DT_DeleteData(hDlg)
,DestroyIcon(SendMessage(id(4 hDlg) BM_GETIMAGE IMAGE_ICON 0))
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1
pi
#8
Button controls always have border, even with BS_FLAT style. Unless you use BS_OWNERDRAW style and draw it (I never tested). Static icon or bitmap controls with SS_NOTIFY style also can be used as buttons, but are not visually pushed.
#9
sorry to bother again. :oops:

it seems that ToolbarWindow32 doesn't show borders around icons, which look better then using buttons with ico|bmp.

is it right that a ToolbarWindow32 is ever on top in a dialog ?

i need to show two DHTMLEDLib.DHTMLEdit in my dialog,
each should have a toolbar with formating options.

can you give me another example on how to use ToolbarWindow32 in a dialog ?
pi
#10
Add CCS_NOPARENTALIGN and CCS_NORESIZE styles.

Code:
Copy      Help
;3 ToolbarWindow32 0x5400000D 0x0 26 18 162 18 ""
#11
thanks !

... and is there a style for removing vertical scrollbars for DHTMLEDLib.DHTMLEdit ?
pi
#12
I think it is not usual window style. Maybe can be removed like in web browser control in Resources\Misc sample code.
#13
scrollbar is controlled by the html content.

<body SCROLL=NO>

***
but how do i fill my toolbar ?
i understand that it is using a horizontal bitmap with icons ?
pi
#14
I afraid you'll have to go to the MSDN Library and learn about toolbar control, image lists, etc. Generally I don't recommend to use QM to create such applications. Working with common controls is easier in programming languages, such as Visual Basic, than in QM.
#15
???
my only problem is that i don't completely understand your 'dialog
explorer example'.

maybe i asked in the wrong way, but 'DEX_InitToolbar' seems to be exactly what i need.
pi
#16
Function DT_TbAddButtons
Code:
Copy      Help
;/
function hwndTb firstBtnId $stringList $bitmapFile [styles] [flags] [maskColor] [ARRAY(int)&iconHandles] [defaultIcon] ;;flags: 1 icons

;Adds buttons to ToolbarWindow32 control.
;Call this function from dialog procedure, on WM_INITDIALOG. On WM_DESTROY, call DT_TbOnDestroy.


;hwndTb - toolbar control handle.
;firstBtnId - id of first button. Used for notifications in the same way as id of Button control.
;stringList - list of button label strings.
;;;Empty lines also add buttons.
;;;- adds separator. Separator size can be specified after -. Separators don't have id and image.
;bitmapFile - bmp file containing horizontally aligned 16x16 images. Color maskColor will be transparent.
;styles - toolbar styles to add.
;flags - 1 - bitmapFile is list of icon files.
;maskColor - color in bmp file that will be transparent. Default or 0 - magenta (0xff00ff).
;iconHandles - array that contains icon handles. If used and not 0, bitmapFile and maskColor are ignored. You can destroy icons immediately after calling this function.



if(styles) SetWinStyle hwndTb styles 1

int nBtn=numlines(stringList)

;create image list

int il hi j
str s
if(!defaultIcon) defaultIcon=_dialogicon
if(&iconHandles)
,il=ImageList_Create(16 16 WINAPI.ILC_MASK|WINAPI.ILC_COLOR32 0 iconHandles.len)
,for j 0 iconHandles.len
,,hi=iconHandles[j]
,,if(!hi) hi=defaultIcon
,,ImageList_ReplaceIcon(il -1 hi)
else if(flags&1)
,il=ImageList_Create(16 16 WINAPI.ILC_MASK|WINAPI.ILC_COLOR32 0 nBtn)
,foreach s bitmapFile
,,hi=GetIcon(s)
,,if(!hi) hi=defaultIcon
,,ImageList_ReplaceIcon(il -1 hi)
,,if(hi!=defaultIcon) DestroyIcon hi
else
,if(!maskColor) maskColor=0xFF00FF
,il=ImageList_LoadImage(0 _s.expandpath(bitmapFile) 16 0 maskColor IMAGE_BITMAP LR_LOADFROMFILE)
SendMessage hwndTb WINAPI.TB_SETIMAGELIST 0 il

;create array of TBBUTTON structures

type TBBUTTON iBitmap idCommand !fsState !fsStyle !bReserved[2] dwData iString

ARRAY(TBBUTTON) a.create(nBtn)
int i ii
foreach s stringList
,TBBUTTON& t=a[i]
,if(s.beg("-"))
,,t.fsStyle=WINAPI.TBSTYLE_SEP ;;separator
,,t.iBitmap=val(s+1)
,else
,,t.idCommand=firstBtnId+ii
,,t.iBitmap=ii
,,if(s.len) t.iString=SendMessage(hwndTb WINAPI.TB_ADDSTRINGA 0 s)
,,else t.iString=-1
,,t.fsState=WINAPI.TBSTATE_ENABLED
,,ii+1
,i+1

SendMessage(hwndTb WINAPI.TB_BUTTONSTRUCTSIZE sizeof(TBBUTTON) 0)
SendMessage(hwndTb WINAPI.TB_ADDBUTTONS a.len &a[0])

Function DT_TbOnDestroy
Code:
Copy      Help
;/
function hwndtb

ImageList_Destroy SendMessage(hwndtb WINAPI.TB_GETIMAGELIST 0 0)

Sample dialog, function dialog_toolbar
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

if(!ShowDialog("dialog_toolbar" &dialog_toolbar)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 319 197 "Form"
;1 Button 0x54030001 0x4 120 166 48 14 "OK"
;2 Button 0x54030000 0x4 170 166 48 14 "Cancel"
;3 ToolbarWindow32 0x5400000C 0x0 0 0 294 30 ""
;4 ToolbarWindow32 0x5400000C 0x0 0 30 294 18 ""
;5 ToolbarWindow32 0x5400000C 0x0 0 48 294 18 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010805 "" ""


ret
;messages
sel message
,case WM_INITDIALOG
,DT_Init(hDlg lParam)
,int styles=WINAPI.TBSTYLE_FLAT
,DT_TbAddButtons id(3 hDlg) 1001 "one[]two[]-[]three[]four" "$qm$\de_ctrl.bmp" styles|WINAPI.CCS_NODIVIDER
,DT_TbAddButtons id(4 hDlg) 1101 "[][]-60[][][]" "$qm$\de_ctrl.bmp" styles
,DT_TbAddButtons id(5 hDlg) 1201 "one[]two[]three" "shell32.dll,1[]shell32.dll,2[]shell32.dll,3" styles|WINAPI.TBSTYLE_LIST 1
,ret 1
,
,case WM_DESTROY
,DT_DeleteData(hDlg)
,DT_TbOnDestroy id(3 hDlg)
,DT_TbOnDestroy id(4 hDlg)
,DT_TbOnDestroy id(5 hDlg)
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 1001 mes "button 1"
,case 1002 mes "button 2"
,case 1003 mes "button 3"
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1
#17
how to use GetWindowIcon instead of bmp/file in DT_TbAddButtons ?

code snippet (rep)
Code:
Copy      Help
,,,,labels.formata("%s[]" exe.title(15))
,,,,int icon=GetWindowIcon(exe.m_hwnd)
,,,,icons.formata("%i[]" icon)
,,,,count1+1
,,,,DestroyIcon(icon)

Code:
Copy      Help
,DT_TbAddButtons htb 1001 labels icons WINAPI.TBSTYLE_LIST 2 ;;flag2 for GetWindowIcon
pi
#18
Updated. Use iconHandles instead of bitmapFile.


Forum Jump:


Users browsing this thread: 1 Guest(s)