Posts: 41
Threads: 21
Joined: Apr 2007
Hello Gintaras:
How to get the bitmap using Clipboard Functions and draw it on dialog.
Function fingerDtect
;\Dialog_Editor
function# hDlg message wParam lParam
CAPDRIVERCAPS-- CaptureCaps
BITMAP-- mb
__MemBmp-- m_mb
if(hDlg) goto messages
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 515 317 "Dialog"
;3 Button 0x54032000 0x0 464 208 48 14 "Button"
;4 Static 0x5400000E 0x0 0 0 460 308 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030109 "" "" ""
ret
;messages
sel message
,case WM_INITDIALOG
,case WM_PAINT
,,PAINTSTRUCT p; int dc=BeginPaint(hDlg &p)
,,RECT r; GetClientRect hDlg &r;
,,;FillRect dc &r GetSysColorBrush(COLOR_BTNFACE)
,,BITMAP b; GetObjectW m_mb.bm sizeof(BITMAP) &mb
,,BitBlt dc 100 10 mb.bmWidth mb.bmHeight m_mb.dc 0 0 SRCCOPY
,,EndPaint hDlg &p
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,,int camscreen=GetDlgItem(hDlg,4)
,,int cwn=capCreateCaptureWindow(0,WS_CHILD|WS_VISIBLE,0,0,320,240,camscreen,0)
,,int hCaptureDevice=0
,,SendMessage cwn,WM_CAP_DRIVER_CONNECT,hCaptureDevice,0
,,;out CaptureCaps.fCaptureInitialized
,,SendMessage cwn,WM_CAP_DRIVER_GET_CAPS,sizeof(CAPDRIVERCAPS),&CaptureCaps
,,;out CaptureCaps.fCaptureInitialized
,,SendMessage cwn,WM_CAP_SET_SCALE,TRUE,0
,,SendMessage cwn,WM_CAP_SET_PREVIEWRATE,1,0
,,SendMessage cwn,WM_CAP_SET_PREVIEW,TRUE,0
,,SendMessage cwn,WM_CAP_GRAB_FRAME,0,0
,,wait 2
,,SendMessage cwn,WM_CAP_EDIT_COPY,0,0
,,OpenClipboard(hDlg)
,,;****HOW TO GET THIS BITMAP AND DRAW IT ON DIALOG USING GDI****
,,mb=&GetClipboardData(CF_BITMAP)
,,CloseClipboard
,,
,,
,,SendMessage cwn,WM_CAP_DRIVER_DISCONNECT,hCaptureDevice,0
,,RedrawWindow hDlg 0 0 RDW_INVALIDATE
,case IDOK
,case IDCANCEL
ret 1
Thank you
Regards
Posts: 12,075
Threads: 141
Joined: Dec 2002
Function dlg_display_clipboard_bitmap
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
if(!ShowDialog("dlg_display_clipboard_bitmap" &dlg_display_clipboard_bitmap 0)) ret
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 515 317 "Dialog"
;3 Button 0x54032000 0x0 464 208 48 14 "Button"
;END DIALOG
;DIALOG EDITOR: "" 0x2030109 "" "" ""
ret
;messages
__MemBmp-- t_mb
sel message
,case WM_INITDIALOG
,
,case WM_PAINT
,PAINTSTRUCT p; int dc=BeginPaint(hDlg &p)
,BITMAP b; GetObject t_mb.bm sizeof(BITMAP) &b
,BitBlt dc 10 10 b.bmWidth b.bmHeight t_mb.dc 0 0 SRCCOPY
,EndPaint hDlg &p
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,OpenClipboard(hDlg)
,int h=GetClipboardData(CF_BITMAP)
,if(h) t_mb.Attach(CopyImage(h IMAGE_BITMAP 0 0 0))
,CloseClipboard
,InvalidateRect hDlg 0 1
,
,case IDOK
,case IDCANCEL
ret 1
Posts: 12,075
Threads: 141
Joined: Dec 2002
Can use this function to simply display a bitmap in a dialog when you have bitmap handle.
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
Posts: 41
Threads: 21
Joined: Apr 2007
woww hock: , thank you Gintaras.
Regards.
Posts: 1,000
Threads: 253
Joined: Feb 2008
How do you get bitmap handle from string filename of image?
Posts: 12,075
Threads: 141
Joined: Dec 2002
Macro Macro1468
__GdiHandle hb=LoadPictureFile(filename)
Posts: 858
Threads: 196
Joined: Apr 2005
Is possible to resize the dialog to be equal to the size of the image (like a sticky note)?
Posts: 12,075
Threads: 141
Joined: Dec 2002
Function dlg_display_bitmap
\Dialog_Editor
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 515 317 "Dialog"
;4 Static 0x5400000E 0x0 0 0 460 308 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030200 "" "" ""
str md=
;BEGIN MENU
;>Bitmap
;,Clipboard :501 0x0 0x0 Cq
;,Capture :502 0x0 0x0 Cw
;,<
;END MENU
if(!ShowDialog(dd &sub.DlgProc 0 0 0 0 0 0 0 0 0 md)) 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 501
,OpenClipboard(hDlg)
,int h1=GetClipboardData(CF_BITMAP)
,if(h1)
,,sub.Resize hDlg 4 h1
,,StaticImageControlSetBitmap id(4 hDlg) h1
,CloseClipboard
,;note: don't need to delete bitmap when from clipboard
,
,case 502
,__GdiHandle h2
,if(!CaptureImageOrColor(&h2 2 hDlg)) ret
,sub.Resize hDlg 4 h2
,StaticImageControlSetBitmap id(4 hDlg) h2
,
,case IDOK
,case IDCANCEL
ret 1
#sub Resize
function hDlg cid hBitmap
BITMAP b
if(!GetObjectW(hBitmap sizeof(b) &b)) ret
siz b.bmWidth b.bmHeight id(cid hDlg)
WINDOWINFO k.cbSize=sizeof(k); GetWindowInfo hDlg &k
int dx=(k.rcWindow.right-k.rcWindow.left)-(k.rcClient.right-k.rcClient.left)
int dy=(k.rcWindow.bottom-k.rcWindow.top)-(k.rcClient.bottom-k.rcClient.top)
siz b.bmWidth+dx b.bmHeight+dy hDlg
CenterWindow hDlg
Posts: 858
Threads: 196
Joined: Apr 2005
|