03-02-2010, 08:57 AM
Can use this function to simply display a bitmap in a dialog when you have bitmap handle.
Function StaticImageControlSetBitmap
Also need this function.
Function __SICSB_WndProc
EXAMPLES
Function dlg_clipboard_bitmap
Macro capture bitmap to clipboard
Function dlg_capture_bitmap
Function StaticImageControlSetBitmap
;/
function hwnd hbitmap
;Displays bitmap in static control.
;Differences from STM_SETIMAGE: 1. Copies the bitmap. 2. Correctly displays alpha bitmaps.
;hwnd - static control handle.
;hbitmap - bitmap handle. The caller can delete it immediately.
type SICSBDATA wndproc __MemBmp'mb
SICSBDATA* p=+GetProp(hwnd "sicsbdata")
if(!p)
,p._new
,p.wndproc=SubclassWindow(hwnd &__SICSB_WndProc)
,SetProp(hwnd "sicsbdata" p)
p.mb.Attach(CopyImage(hbitmap IMAGE_BITMAP 0 0 0))
InvalidateRect hwnd 0 1
if(GetWinStyle(hwnd)&SS_REALSIZEIMAGE)
,BITMAP b; GetObject p.mb.bm sizeof(BITMAP) &b
,siz b.bmWidth b.bmHeight hwnd
Also need this function.
Function __SICSB_WndProc
;/
function# hwnd message wParam lParam
SICSBDATA* p=+GetProp(hwnd "sicsbdata")
sel message
,case WM_PAINT
,PAINTSTRUCT ps; int dc=BeginPaint(hwnd &ps)
,RECT rc; GetClientRect hwnd &rc; FillRect dc &rc GetSysColorBrush(COLOR_BTNFACE) ;;erase
,BITMAP b; GetObject p.mb.bm sizeof(BITMAP) &b ;;get bitmap dimensions
,BitBlt dc 0 0 b.bmWidth b.bmHeight p.mb.dc 0 0 SRCCOPY ;;memory bitmap -> display
,EndPaint hwnd &ps
,ret
,
,case WM_ERASEBKGND
,ret
int r=CallWindowProcW(p.wndproc hwnd message wParam lParam)
sel message
,case WM_NCDESTROY
,SubclassWindow hwnd p.wndproc
,RemoveProp(hwnd "sicsbdata")
,p._delete
ret r
EXAMPLES
Function dlg_clipboard_bitmap
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
if(!ShowDialog("dlg_clipboard_bitmap" &dlg_clipboard_bitmap 0)) ret
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 515 317 "Dialog"
;3 Button 0x54032000 0x0 464 208 46 38 "Display Clipboard Bitmap"
;4 Static 0x5400000E 0x0 0 0 460 308 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030200 "" "" ""
ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,OpenClipboard(hDlg)
,int h=GetClipboardData(CF_BITMAP)
,if(h) StaticImageControlSetBitmap id(4 hDlg) h
,CloseClipboard
,
,case IDOK
,case IDCANCEL
ret 1
Macro capture bitmap to clipboard
__GdiHandle h
if(!CaptureImageOrColor(&h 0)) ret
int r=OpenClipboard(_hwndqm)
if(r) EmptyClipboard; r=SetClipboardData(CF_BITMAP h)!0; CloseClipboard
Function dlg_capture_bitmap
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
if(!ShowDialog("dlg_capture_bitmap" &dlg_capture_bitmap 0)) ret
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 515 317 "Dialog"
;3 Button 0x54032000 0x0 464 208 46 38 "Capture Bitmap"
;4 Static 0x5400000E 0x0 0 0 460 308 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030200 "" "" ""
ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,__GdiHandle h
,if(!CaptureImageOrColor(&h 2 hDlg)) ret
,StaticImageControlSetBitmap id(4 hDlg) h
,
,case IDOK
,case IDCANCEL
ret 1