Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Set/Change Dialog Image
#1
I know the basics of displaying an image in a dialog, but Is it possible to make a button in the dialog or an outside macro change the path of the specified image so that the image will change?

Function dialog_image
Trigger F12     Help - how to add the trigger to the macro
Code:
Select All      Help
;\Dialog_Editor

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 248 152 "Set Image"
;3 Static 0x5400000E 0x0 16 16 96 96 ""
;4 Static 0x5400000E 0x4 136 16 96 96 ""
;7 Button 0x54032000 0x0 12 128 48 14 "Set 1"
;8 Button 0x54032000 0x0 68 128 48 14 "Set2"
;9 Button 0x54032000 0x0 132 128 48 14 "Set 1"
;10 Button 0x54032000 0x0 188 128 48 14 "Set2"
;5 Button 0x54020007 0x0 8 4 114 117 ""
;6 Button 0x54020007 0x0 128 4 112 117 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040500 "*" "" "" ""

str controls = "3 4"
str sb3 sb4
sb3 = "$desktop$\img\1.png"
sb4 = "$desktop$\img\2.png"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam

,case 7
,out "Change to img\2"

,case 8
,out "Change to img\1"

,case IDOK
,case IDCANCEL
ret 1
#2
Update:

I found the dlg_button_images function in the archive. Is there a way to make this work with the static bitmap that can be used in the dialog?
#3
Function StaticControlSetImage
Code:
Select All      Help
;/
function hwnd [$imageFile] [hbitmap]

;Displays image in a static control in a dialog.

;hwnd - static control handle.
;imageFile - image file. Can be bmp, png, gif, jpg. The function uses <help>LoadPictureFile</help>. If not used, can be "".
;hbitmap - bitmap handle. Can be used instead of imageFile. The caller can delete it immediately (this function copies it). If omitted or 0, the function uses imageFile.

;REMARKS
;If the control has style SS_REALSIZEIMAGE, resizes it to display whole image.
;Unlike STM_SETIMAGE, correctly displays alpha bitmaps.


if(hbitmap) hbitmap=CopyImage(hbitmap IMAGE_BITMAP 0 0 0)
else hbitmap=LoadPictureFile(imageFile); if(hbitmap=0) end "LoadPictureFile failed"

type __SICSB4249 __MemBmp'mb wid hei

__SICSB4249* p=+GetProp(hwnd "__SICSB4249")
if(!p) SetWindowSubclass(hwnd &sub.SubclassProc 1 p._new)

p.mb.Attach(hbitmap)

BITMAP b; GetObject p.mb.bm sizeof(BITMAP) &b
p.wid=b.bmWidth; p.hei=b.bmHeight

InvalidateRect hwnd 0 1
if(GetWinStyle(hwnd)&SS_REALSIZEIMAGE) siz p.wid p.hei hwnd


#sub SubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData

__SICSB4249* p=+dwRefData

sel message
,case WM_PAINT
,PAINTSTRUCT ps; int dc=BeginPaint(hwnd &ps)
,RECT rc; GetClientRect hwnd &rc; FillRect dc &rc GetSysColorBrush(COLOR_BTNFACE) ;;erase
,BitBlt dc 0 0 p.wid p.hei p.mb.dc 0 0 SRCCOPY ;;memory bitmap -> display
,EndPaint hwnd &ps
,ret
,
,case WM_ERASEBKGND
,ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.SubclassProc uIdSubclass)
,p._delete

ret R

example
Code:
Select All      Help
,case 7
,out "Change to img\2"
,StaticControlSetImage id(3 hDlg) "$desktop$\img\2.png"

See also: change image in bitmap static control
#4
Thank you very much sir! Works like a charm Big Grin


Forum Jump:


Users browsing this thread: 1 Guest(s)