Yashied Posted October 28, 2009 Posted October 28, 2009 (edited) Why is the background disappears when I set HBITMAP to the control?Thanks.#Include <ScreenCapture.au3> #Include <WinAPI.au3> $hBitmap = _ScreenCapture_Capture('' , 0, 0, 400, 400, 0) GUICreate('MyGUI', 400, 400) $Pic = GUICtrlCreatePic('', 0, 0, 400, 400) _SendMessage(GUICtrlGetHandle($Pic), 0x0172, 0, $hBitmap) ; STM_SETIMAGE GUISetState() Do Until GUIGetMsg() = -3If I replaced SRCCOPY to MERGECOPY in _ScreenCapture_Capture() function, it will work but it is incorrectly.Func __ScreenCapture_Capture($sFileName = "", $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $fCursor = True) Local $iH, $iW, $hWnd, $hDDC, $hCDC, $hBMP, $aCursor, $aIcon, $hIcon If $iRight = -1 Then $iRight = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CXSCREEN) If $iBottom = -1 Then $iBottom = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CYSCREEN) If $iRight < $iLeft Then Return SetError(-1, 0, 0) If $iBottom < $iTop Then Return SetError(-2, 0, 0) $iW = $iRight - $iLeft $iH = $iBottom - $iTop $hWnd = _WinAPI_GetDesktopWindow() $hDDC = _WinAPI_GetDC($hWnd) $hCDC = _WinAPI_CreateCompatibleDC($hDDC) $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iW, $iH) _WinAPI_SelectObject($hCDC, $hBMP) _WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $iLeft, $iTop, 0x00C000CA) ; MERGECOPY If $fCursor Then $aCursor = _WinAPI_GetCursorInfo() If $aCursor[1] Then $hIcon = _WinAPI_CopyIcon($aCursor[2]) $aIcon = _WinAPI_GetIconInfo($hIcon) _WinAPI_DrawIcon($hCDC, $aCursor[3] - $aIcon[2] - $iLeft, $aCursor[4] - $aIcon[3] - $iTop, $hIcon) _WinAPI_DestroyIcon($hIcon) EndIf EndIf _WinAPI_ReleaseDC($hWnd, $hDDC) _WinAPI_DeleteDC($hCDC) If $sFileName = "" Then Return $hBMP _ScreenCapture_SaveImage($sFileName, $hBMP) _WinAPI_DeleteObject($hBMP) EndFunc ;==>__ScreenCapture_Capture Edited October 28, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
Malkey Posted October 29, 2009 Posted October 29, 2009 Why is the background disappears when I set HBITMAP to the control? Thanks. #Include <ScreenCapture.au3> #Include <WinAPI.au3> $hBitmap = _ScreenCapture_Capture('' , 0, 0, 400, 400, 0) GUICreate('MyGUI', 400, 400) $Pic = GUICtrlCreatePic('', 0, 0, 400, 400) _SendMessage(GUICtrlGetHandle($Pic), 0x0172, 0, $hBitmap) ; STM_SETIMAGE GUISetState() Do Until GUIGetMsg() = -3 If I replaced SRCCOPY to MERGECOPY in _ScreenCapture_Capture() function, it will work but it is incorrectly. Func __ScreenCapture_Capture($sFileName = "", $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $fCursor = True) Local $iH, $iW, $hWnd, $hDDC, $hCDC, $hBMP, $aCursor, $aIcon, $hIcon If $iRight = -1 Then $iRight = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CXSCREEN) If $iBottom = -1 Then $iBottom = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CYSCREEN) If $iRight < $iLeft Then Return SetError(-1, 0, 0) If $iBottom < $iTop Then Return SetError(-2, 0, 0) $iW = $iRight - $iLeft $iH = $iBottom - $iTop $hWnd = _WinAPI_GetDesktopWindow() $hDDC = _WinAPI_GetDC($hWnd) $hCDC = _WinAPI_CreateCompatibleDC($hDDC) $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iW, $iH) _WinAPI_SelectObject($hCDC, $hBMP) _WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $iLeft, $iTop, 0x00C000CA) ; MERGECOPY If $fCursor Then $aCursor = _WinAPI_GetCursorInfo() If $aCursor[1] Then $hIcon = _WinAPI_CopyIcon($aCursor[2]) $aIcon = _WinAPI_GetIconInfo($hIcon) _WinAPI_DrawIcon($hCDC, $aCursor[3] - $aIcon[2] - $iLeft, $aCursor[4] - $aIcon[3] - $iTop, $hIcon) _WinAPI_DestroyIcon($hIcon) EndIf EndIf _WinAPI_ReleaseDC($hWnd, $hDDC) _WinAPI_DeleteDC($hCDC) If $sFileName = "" Then Return $hBMP _ScreenCapture_SaveImage($sFileName, $hBMP) _WinAPI_DeleteObject($hBMP) EndFunc ;==>__ScreenCapture_Capture This appears to work with or without your __ScreenCapture_Capture function. #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> Local $hBitmap, $Pic, $hImage, $hBMP $hBitmap = _ScreenCapture_Capture('', 0, 0, 360, 360, 0) $hGUI = GUICreate('GUI with Pic control', 400, 400) GUISetBkColor(0xBBBBBB, $hGUI) $Pic = GUICtrlCreatePic('', 20, 20, 360, 360) _GDIPlus_Startup() $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) $hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _SendMessage(GUICtrlGetHandle($Pic), 0x0172, 0, $hBMP) ; STM_SETIMAGE _WinAPI_DeleteObject($hBMP) _WinAPI_DeleteObject($hImage) _WinAPI_DeleteObject($hBitmap) _GDIPlus_Shutdown() GUISetState() Do Until GUIGetMsg() = -3
Yashied Posted October 29, 2009 Author Posted October 29, 2009 (edited) Thanks Malkey, but I know this trick with GDI+ "there-here". I am interested in the cause of such behavior HDC. Edited October 29, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now