12-05-2017, 06:30 PM
Function StaticControlSetImage
example
See also: change image in bitmap static control
;/
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
,case 7
,out "Change to img\2"
,StaticControlSetImage id(3 hDlg) "$desktop$\img\2.png"
See also: change image in bitmap static control