china Posted March 30, 2009 Share Posted March 30, 2009 I do some operation, but can not find AU3 code, found the C code, I try to convert AU3, but wrong, so please help me! Thank you everyone! ! C code: expandcollapse popupvoidTransparentBitmap (HDChdc, HBITMAPhBitmap, intxStart, intyStart, intxadd, intyadd, COLORREFcTransparentColor) ( BITMAPm_bm; COLORREFcColor; / / Create a temporary DC HDChMem, hBack, hObject, hTemp, hSave; HBack = CreateCompatibleDC (hdc); HObject = CreateCompatibleDC (hdc); HMem = CreateCompatibleDC (hdc); HSave = CreateCompatibleDC (hdc); HTemp = CreateCompatibleDC (hdc); / / Selected bitmap SelectObject (hTemp, hBitmap); GetObject (hBitmap, sizeof (BITMAP), (LPSTR) & m_bm); / / Show bitmap wide high POINTptSize; / / Get the width of the bitmap PtSize.x = m_bm.bmWidth; / / Get the bitmap of the degree of PtSize.y = m_bm.bmHeight; / / Convert the point value of logic DPtoLP (hTemp, & ptSize, 1); / / Create a temporary bitmap HBITMAPbmBack, bmObject, bmMem, bmSave; / / Monochrome bitmap BmBack = CreateBitmap (ptSize.x, ptSize.y, 1,1, NULL); bmObject = CreateBitmap (ptSize.x, ptSize.y, 1,1, NULL); / / Bitmap compatible with the equipment bmMem = CreateCompatibleBitmap (hdc, ptSize.x, ptSize.y); bmSave = CreateCompatibleBitmap (hdc, ptSize.x, ptSize.y); / / Will create a temporary bitmap selected in the provisional DC HBITMAPOldbmBack, OldbmObject, OldbmMem, OldbmSave; OldbmBack = (HBITMAP) SelectObject (hBack, bmBack); OldbmObject = (HBITMAP) SelectObject (hObject, bmObject); OldbmMem = (HBITMAP) SelectObject (hMem, bmMem); OldbmSave = (HBITMAP) SelectObject (hSave, bmSave); / / Set mapping mode SetMapMode (hTemp, GetMapMode (hdc)); / / Original bitmap to retain BitBlt (hSave, 0,0, ptSize.x, ptSize.y, hTemp, 0,0, SRCCOPY); / / Set the background color for the color to be transparent CColor = SetBkColor (hTemp, cTransparentColor); / / Create a goal shielding code BitBlt (hObject, 0,0, ptSize.x, ptSize.y, hTemp, 0,0, SRCCOPY); / / Restore the original source of DC background color SetBkColor (hTemp, cColor); / / Create a reversal of goal shielding code BitBlt (hBack, 0,0, ptSize.x, ptSize.y, hObject, 0,0, NOTSRCCOPY); / / Copy the background of the main DC to the target DC BitBlt (hMem, 0,0, ptSize.x, ptSize.y, hdc, xStart, yStart, SRCCOPY); / / Mask bitmap display area BitBlt (hMem, 0,0, ptSize.x, ptSize.y, hObject, 0,0, SRCAND); / / Mask of the transparent bitmap color BitBlt (hTemp, 0,0, ptSize.x, ptSize.y, hBack, 0,0, SRCAND); / / To a bitmap with the background of the left goal DC XOR operation BitBlt (hMem, 0,0, ptSize.x, ptSize.y, hTemp, 0,0, SRCPAINT); / / Copy the screen on goal StretchBlt (hdc, xStart, yStart, ptSize.x + xadd, ptSize.y + yadd, hMem, 0,0, ptSize.x, ptSize.y, SRCCOPY); / / Restore original bitmap BitBlt (hTemp, 0,0, ptSize.x, ptSize.y, hSave, 0,0, SRCCOPY); / / Delete temporary memory bitmap DeleteObject (SelectObject (hBack, OldbmBack)); DeleteObject (SelectObject (hObject, OldbmObject)); DeleteObject (SelectObject (hMem, OldbmMem)); DeleteObject (SelectObject (hSave, OldbmSave)); / / Delete temporary memory DC DeleteDC (hMem); DeleteDC (hBack); DeleteDC (hObject); DeleteDC (hSave); DeleteDC (hTemp); )oÝ÷ ØÌ¢{ޮȨ7r^jëh×6#include <WinAPI.au3> $opendll = DllOpen ( "gdi32.dll") $dll = DllOpen ( "user32.dll") $ghGDIPDll = DllOpen ( "GDIPlus.dll") $Bitmap = "main-bg.bmp" $hWin = GUICreate ("test") $nID = GUICtrlCreatePic ("", 10,10,0,0) GUISetState () TransBMP ($hWin, $nID, $Bitmap, 0,0,250,300,0xffffff) Do Sleep (1000) Until GUIGetMsg () = -3 DllClose ($opendll) DllClose ($dll) DllClose ($ghGDIPDll) Func TransBMP ($hWin, $nID, $Bitmap, $xStart, $yStart, $xadd, $yadd, $cTransparentColor) Global Const $SRCCOPY = 0x00CC0020 Global Const $SRCAND = 0x008800C6 Global Const $SRCPAINT = 0x00EE0086 Global Const $IMAGE_BITMAP = 0 Global Const $GWL_HINSTANCE = -6 Global Const $LR_LOADFROMFILE = 0x0010 Global Const $GDIP_PXF32ARGB = 0x0026200A Dim $m_bm ; Create a temporary DC $Hwnd = WinGetHandle ($hWin) $phWnd = DLLCall ($dll, "hwnd", "GetDlgItem", "hwnd", $hWin, "int", $nID) $dc = DllCall ($dll, "int", "GetDC", "hwnd", $phWnd[0]) Dim $HDChMem, $hBack, $hObject, $hTemp, $hSave $HBack = _WinAPI_CreateCompatibleDC ($dc[0]) $HObject = _WinAPI_CreateCompatibleDC ($dc[0]) $HMem = _WinAPI_CreateCompatibleDC ($dc[0]) $HSave = _WinAPI_CreateCompatibleDC ($dc[0]) $HTemp = _WinAPI_CreateCompatibleDC ($dc[0]) $HBmp = BitmapCreateFromFile ($Bitmap) $hBitmap = BitmapCloneArea ($hBmp, 0,0, $xadd, $yadd, $GDIP_PXF32ARGB) ; Selected bitmap _WinAPI_SelectObject ($HTemp, $hBitmap) ; _WinAPI_GetObject ($HBitmap, _WinAPI_GetFileSizeEx ($hBitmap), $hBmp) ; Show wide bitmap high Dim $POINTptSize ; Access to the width of the bitmap $PtSizex = $m_bm.bmWidth ; Made of the degree of bitmap $PtSizey = $m_bm.bmHeight ; Point value is converted to logic $Str = "ptr var1; ptr var2" $Ptsize = DllStructCreate ($str) DllStructSetData ($ptsize, "var1", $ptSizex) DllStructSetData ($ptsize, "var2", $ptSizey) DPtoLP ($hTemp, $ptsize, 1) ; Create a temporary bitmap Dim $HBITMAPbmBack, $bmObject, $bmMem, $bmSave ; Monochrome bitmap $bmBack = _WinAPI_CreateBitmap ($ptSizex, $ptSizey, 1,1) $bmObject = _WinAPI_CreateBitmap ($ptSizex, $ptSizey, 1,1) ; Bitmap compatible with the equipment $bmMem = _WinAPI_CreateCompatibleBitmap ($dc [0], $ptSizex, $ptSizey) $bmSave = _WinAPI_CreateCompatibleBitmap ($dc [0], $ptSizex, $ptSizey) ; Will create a temporary bitmap selected in the provisional DC Dim $HBITMAPOldbmBack, $OldbmObject, $OldbmMem, $OldbmSave $OldbmBack = _WinAPI_SelectObject ($hBack, $bmBack) $OldbmObject = _WinAPI_SelectObject ($hObject, $bmObject) $OldbmMem = _WinAPI_SelectObject ($hMem, $bmMem) $OldbmSave = _WinAPI_SelectObject ($hSave, $bmSave) ; Set mapping mode SetMapMode ($hTemp, GetMapMode ($dc [0])) ; To retain the original bitmap _WinAPI_BitBlt ($HSave, 0,0, $ptSizex, $ptSizey, $hTemp, 0,0, $SRCCOPY) ; The background color set to color to be transparent $cColor = _WinAPI_SetBkColor ($hTemp, $cTransparentColor) ; The creation of goal shielding code _WinAPI_BitBlt ($HObject, 0,0, $ptSizex, $ptSizey, $hTemp, 0,0, $SRCCOPY) ; DC restore the original source of the background color _WinAPI_SetBkColor ($HTemp, $cColor) ; The aim to create shield inversion code _WinAPI_BitBlt ($HBack, 0,0, $ptSizex, $ptSizey, $hObject, 0,0, NOT $SRCCOPY) ; Copies of the background of the main DC to the target DC _WinAPI_BitBlt ($HMem, 0,0, $ptSizex, $ptSizey, $dc [0], $xStart, $yStart, $SRCCOPY) ; Shielding the display bitmap _WinAPI_BitBlt ($HMem, 0,0, $ptSizex, $ptSizey, $hObject, 0,0, $SRCAND) ; Shielding of transparent bitmap color _WinAPI_BitBlt ($HTemp, 0,0, $ptSizex, $ptSizey, $hBack, 0,0, $SRCAND) ; Will aim bitmap with the background of the left DC XOR operation _WinAPI_BitBlt ($HMem, 0,0, $ptSizex, $ptSizey, $hTemp, 0,0, $SRCPAINT) ; Copies to screen on goal StretchBlt ($dc [0], $xStart, $yStart, $ptSizex + $xadd, $ptSizey + $yadd, $hMem, 0,0, $ptSizex, $ptSizey, $SRCCOPY) ; Restore original bitmap _WinAPI_BitBlt ($HTemp, 0,0, $ptSizex, $ptSizey, $hSave, 0,0, $SRCCOPY) ; Delete temporary memory bitmap _WinAPI_DeleteObject (_WinAPI_SelectObject ($HBack, $OldbmBack)) _WinAPI_DeleteObject (_WinAPI_SelectObject ($HObject, $OldbmObject)) _WinAPI_DeleteObject (_WinAPI_SelectObject ($HMem, $OldbmMem)) _WinAPI_DeleteObject (_WinAPI_SelectObject ($HSave, $OldbmSave)) ; Delete temporary memory DC _WinAPI_DeleteDC ($HMem) _WinAPI_DeleteDC ($HBack) _WinAPI_DeleteDC ($HObject) _WinAPI_DeleteDC ($HSave) _WinAPI_DeleteDC ($HTemp) _WinAPI_DeleteObject ($HBitmap) EndFunc Func StretchBlt ($dc, $x, $y, $nWidth, $nHeight, $hSrcDC, $xSrc, $ySrc, $nSrcWidth, $nSrcHeight, $dwrop) $blt = DllCall ($opendll, "int", "StretchBlt", "int", $dc, "int", $x, "int", $y, "int", $nWidth, "int", $nHeight , _ "int", $hSrcDC, "int", $xSrc, "int", $ySrc, "int", $nSrcWidth, "int", $nSrcHeight, "int", $dwrop) Return $blt [0] EndFunc Func DPtoLP ($dc, $lppoint, $ncount) $lp = DllCall ($opendll, "int", "DPtoLP", "ptr", $lppoint, "int", $ncount) Return $lp [0] EndFunc Func SetMapMode ($dc, $nmapmode) $mode = DllCall ($opendll, "int", "SetMapMode", "int", $dc, "int", $nmapmode) Return $mode [0] EndFunc Func GetMapMode ($dc) $mode = DllCall ($opendll, "int", "GetMapMode", "int", $dc) Return $mode [0] EndFunc Func BitmapCreateFromFile ($sFileName) Local $aResult $aResult = DllCall ($ghGDIPDll, "int", "GdipCreateBitmapFromFile", "wstr", $sFileName, "int *", 0) If @ error Then Return SetError (@error, @extended, 0) DllClose ($ghGDIPDll) Return SetError ($aResult [0], 0, $aResult [2]) EndFunc ;==>_ GDIPlus_BitmapCreateFromFile Func BitmapCloneArea ($hBmp, $iLeft, $iTop, $iWidth, $iHeight, $iFormat = 0x00021808) Local $aResult $aResult = DllCall ($ghGDIPDll, "int", "GdipCloneBitmapAreaI", "int", $iLeft, "int", $iTop, "int", $iWidth, "int", $iHeight, _ "Int", $iFormat, "ptr", $hBmp, "int *", 0) If @ error Then Return SetError (@error, @extended, 0) Return SetError ($aResult [0], 0, $aResult [7]) EndFunc ;==>_ GDIPlus_BitmapCloneArea Only a little bit of my English, please forgive me! I hope you understand what I said!thank you! Link to comment Share on other sites More sharing options...
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