Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get and Set style of button (BS_ICON)
#1
I had a sample (snippet) script of this but I can not find it anymore.
It is (seems) very simple,

I have 3 buttons:
- One button [B1] toggles BS_ICON style on the RIGHT button
- One button [B2] outputs if BS_ICON style has been set on the RIGHT button
- The third button (which is displayed on the right), is the button on which the style BS_ICON will be set

Below I have the dialog ready but I can't get it to work (tried different flags in SetWinStyle).

Initially you see both icon and text on [TEST BUTTON].
- But when clicking on button [B1] I want to toggle the style BS_ICON on the button [TEST BUTTON] (add/remove style).
- Button [B2] outputs if style BS_ICON on [TEST BUTTON] has been set or not set.

[B2] seems to work because it outputs correctly when  setting/unsetting BS_ICON through dialog editor.


Function set_style_exampel
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 241 159 "Dialog"
;3 Button 0x54032000 0x0 5 11 80 28 "[B1] toggle button style of ''test button''"
;4 Button 0x54032000 0x0 95 34 80 28 "[TEST BUTTON]"
;6 Button 0x54032000 0x4 6 44 80 29 "[B2] Output if[]BS_ICON has been set[]"
;5 Static 0x54000000 0x0 5 92 216 26 "Clicking [B1]:[]Should either display text ''TEST BUTTON'' or display ONLY icon on the button [TEST BUTTON]. (It should remove OR add style BS_ICON)"
;7 Static 0x54000000 0x4 5 122 216 26 "Clicking [B2]:[]Should output  if BS_ICON is set or not set on the button [TEST BUTTON]"
;END DIALOG
;DIALOG EDITOR: "" 0x2040601 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,,SendMessage(id(4 hDlg) BM_SETIMAGE IMAGE_ICON GetFileIcon("$qm$\mouse.ico"))
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3
,,SetWinStyle (id(4 hDlg)) BS_ICON 1|4|8|16
,case 6
,,int st=GetWinStyle(id(4 hDlg))
,,if(st&BS_ICON)
,,,out "BS_ICON style has been set!"
,,else
,,,out "BS_ICON style has NOT been set."
ret 1
#2
Try this:
Macro Macro62
Code:
Copy      Help
,case 3
,,SetWinStyle (id(4 hDlg)) BS_ICON 1|8|16
#3
YES!!!
THANK YOU!!!
#4
to toggle it back and forth do this ron
also need to make sure to remove icon when dialog closes

Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 241 159 "Dialog"
;3 Button 0x54032000 0x0 5 11 80 28 "[B1] toggle button style of ''test button''"
;4 Button 0x54032000 0x0 95 34 80 28 "[TEST BUTTON]"
;6 Button 0x54032000 0x4 6 44 80 29 "[B2] Output if[]BS_ICON has been set[]"
;5 Static 0x54000000 0x0 5 92 216 26 "Clicking [B1]:[]Should either display text ''TEST BUTTON'' or display ONLY icon on the button [TEST BUTTON]. (It should remove OR add style BS_ICON)"
;7 Static 0x54000000 0x4 5 122 216 26 "Clicking [B2]:[]Should output  if BS_ICON is set or not set on the button [TEST BUTTON]"
;END DIALOG
;DIALOG EDITOR: "" 0x2040601 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam
,int-- t_style
sel message
,case WM_INITDIALOG
,int hi=GetFileIcon("$qm$\mouse.ico")
,SendMessage(id(4 hDlg) BM_SETIMAGE IMAGE_ICON hi)
,case WM_DESTROY
,DestroyIcon hi

,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3
,t_style=!t_style
,if t_style
,,SetWinStyle (id(4 hDlg)) BS_ICON 1|16
,else
,,SetWinStyle (id(4 hDlg)) BS_ICON 2|16        
,case 6
,int st=GetWinStyle(id(4 hDlg))
,if(st&BS_ICON)
,,out "BS_ICON style has been set!"
,else
,,out "BS_ICON style has NOT been set."
ret 1
#5
or can get the icon this way then don't need to remember to destroy icon

Code:
Copy      Help
,case WM_INITDIALOG
,__Hicon- t_hi=GetFileIcon("$qm$\mouse.ico")
,SendMessage(id(4 hDlg) BM_SETIMAGE IMAGE_ICON t_hi)
memory leak if icons are not destroyed
#6
Thanks for that!
(I always wondered why to destroy icon, I often skipped it.)


Forum Jump:


Users browsing this thread: 1 Guest(s)