hat Posted June 21, 2010 Share Posted June 21, 2010 How kind it into au3?? expandcollapse popupBOOL CJPGRES2BMPView::JpgRes2Bmp(UINT ResourceName, LPCSTR ResourceType, HBITMAP *lphBmp) { HGLOBAL hGlobal = NULL; HRSRC hSource = NULL; LPVOID lpVoid = NULL; int nSize = 0; IPicture* p_IPicture = NULL; OLE_HANDLE hJpegBmp = 0; hSource = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(ResourceName), ResourceType); if(hSource == NULL) { return(FALSE); } hGlobal = LoadResource(AfxGetResourceHandle(), hSource); if(hGlobal == NULL) { return(FALSE); } lpVoid = LockResource(hGlobal); if(lpVoid == NULL) { return(FALSE); } nSize = (UINT)SizeofResource(AfxGetResourceHandle(), hSource); HGLOBAL hGlobalMem = GlobalAlloc(GMEM_MOVEABLE, nSize); if(hGlobalMem == NULL) { return(FALSE); } void* pData = GlobalLock(hGlobalMem); memcpy(pData, (BYTE*)hGlobal, nSize); GlobalUnlock(hGlobalMem); IStream* pStream = NULL; if(CreateStreamOnHGlobal(hGlobalMem, TRUE, &pStream) == S_OK) { HRESULT hr; if(E_NOINTERFACE == (hr = OleLoadPicture(pStream, nSize, FALSE, IID_IPicture, (LPVOID *)&p_IPicture))) { return(FALSE); } else // S_OK { pStream->Release(); pStream = NULL; } } // MSDN:not necessary for Win32-based applications UnlockResource(hGlobal); FreeResource(hGlobal); FreeResource(hGlobalMem); if(p_IPicture != NULL) { // Get the handle to the image, and then copy it. if((p_IPicture->get_Handle(&hJpegBmp)) != S_OK) { p_IPicture->Release(); p_IPicture = NULL; *lphBmp = 0; return(FALSE); } if((*lphBmp = (HBITMAP)CopyImage((HANDLE *) hJpegBmp, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)) == NULL) { p_IPicture->Release(); p_IPicture = NULL; *lphBmp = 0; return(FALSE); } p_IPicture->Release(); p_IPicture = NULL; return(TRUE); } else { p_IPicture->Release(); p_IPicture = NULL; return(FALSE); } } Link to comment Share on other sites More sharing options...
hat Posted June 21, 2010 Author Share Posted June 21, 2010 (edited) ////////////////////////////////////////////// ///////////////////////////////// //JpgRes2Bmp: reading resources in the JPG image data, the resulting bitmap image generation handle a pointer //Parameter: //ResourceName: [iN] resource name, such as IDR_JPG_1 //ResourceType: [iN] resource type, depending on your custom resource name, such as "JPG" //LphBmp: [OUT] output bitmap handle pointer //Return value: //Success return TRUE, failed to return FALSE /////////////////////////////////////////////// ///////////////////////////////// Edited June 21, 2010 by hat Link to comment Share on other sites More sharing options...
UEZ Posted June 21, 2010 Share Posted June 21, 2010 (edited) Something like that? expandcollapse popup;Coded by UEZ #include <GDIPlus.au3> #include <ScreenCapture.au3> Opt('MustDeclareVars', 1) Global $iMemo _Main() Func _Main() Local $hBitmap, $hImage, $hGraphic, $hGUI, $hBmp ; Create GUI $hGUI = GUICreate("GDI+", 600, 400) GUISetState() ; Initialize GDI+ library _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ; Capture 32 bit bitmap $hBitmap = _ScreenCapture_Capture("") $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) _WinAPI_DeleteObject($hBitmap) _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0) _GDIPlus_GraphicsDispose($hGraphic) _WinAPI_DeleteObject($hImage) _GDIPlus_Shutdown() ; Loop until user exits Do Until GUIGetMsg() = -3 EndFunc ;==>_Main Or this one? expandcollapse popup;Coded by UEZ #include <GuiConstantsEx.au3> #include <GDIPlus.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Global $hWnd, $hGraphic, $file, $hImage, $scale_factor Global $iX, $iY $file = FileOpenDialog("Select image to load", @ScriptDir, "Images (*.jpg;*.png;*.bmp)") _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile($file) $scale_factor = 0.5 ;1.00 = 100%, 1.25 = 125% $iX = _GDIPlus_ImageGetWidth($hImage) * $scale_factor $iY = _GDIPlus_ImageGetHeight($hImage) * $scale_factor $hWnd = GUICreate("Display Image: " & $file & " (" & $iX & "x" & $iY & " -> " & $scale_factor * 100 & "%)!", $iX, $iY) GUISetState() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iX, $iY) GUIRegisterMsg(0x000F, "WM_PAINT") ;$WM_PAINT = 0x000F GUIRegisterMsg(0x0014 , "WM_ERASEBKGND") ;WM_ERASEBKGND = 0x0014 GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Do Until Not Sleep(10000000) Func _Exit() GUIRegisterMsg(0x000F, "") GUIRegisterMsg(0x0014, "") _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Exit EndFunc Func WM_PAINT() _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iX, $iY) Return "GUI_RUNDEFMSG" EndFunc ;==>WM_PAINT Func WM_ERASEBKGND() _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iX, $iY) Return "GUI_RUNDEFMSG" EndFunc BR, UEZ Edited June 21, 2010 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
hat Posted June 22, 2010 Author Share Posted June 22, 2010 (edited) Thank you. But the effect is not the case I want to I want the following example to support JPG, or PNG image #include <GuiComboBoxEx.au3> #include <GuiImageList.au3> #include <GuiConstantsEx.au3> #include <File.au3> #include <WindowsConstants.au3> $count = _FileListToArray(@ScriptDir, '*') $hGUI = GUICreate("", 300, 300) $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 20, 20, 70, 335, $CBS_DROPDOWNLIST) $hImage = _GUIImageList_Create(48, 48, 5, 1) For $i = 1 To $count[0] _GUIImageList_AddBitmap($hImage, @ScriptDir & "\" & $count[$i]) Next _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage) For $i = 0 To $count[0] - 1 _GUICtrlComboBoxEx_AddString($hCombo, "", $i, $i) Next _GUICtrlComboBoxEx_SetItemHeight($hCombo, 0, 51) _GUICtrlComboBoxEx_SetCurSel($hCombo, 0) $botton = GUICtrlCreateButton("Select", 120, 20, 100, 25) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $gui_event_close ExitLoop Case $msg = $botton MsgBox(0, "", _GUICtrlComboBoxEx_GetCurSel($hCombo)) EndSelect WEnd This is the annex, and examples, you can download to seeExpand.rar Edited June 22, 2010 by hat Link to comment Share on other sites More sharing options...
hat Posted June 22, 2010 Author Share Posted June 22, 2010 (edited) I want the following example to support JPG, or PNG image??? #include <GuiComboBoxEx.au3> #include <GuiImageList.au3> #include <GuiConstantsEx.au3> #include <File.au3> #include <WindowsConstants.au3> $count = _FileListToArray(@ScriptDir, '*');*.bmp,*.jpg,*.png;;;;I want the following example to support JPG, or PNG image??? $hGUI = GUICreate("", 300, 300) $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 20, 20, 70, 335, $CBS_DROPDOWNLIST) $hImage = _GUIImageList_Create(48, 48, 5, 1) For $i = 1 To $count[0] _GUIImageList_AddBitmap($hImage, @ScriptDir & "\" & $count[$i]) Next _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage) For $i = 0 To $count[0] - 1 _GUICtrlComboBoxEx_AddString($hCombo, "", $i, $i) Next _GUICtrlComboBoxEx_SetItemHeight($hCombo, 0, 51) _GUICtrlComboBoxEx_SetCurSel($hCombo, 0) $botton = GUICtrlCreateButton("Select", 120, 20, 100, 25) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $gui_event_close ExitLoop Case $msg = $botton MsgBox(0, "", _GUICtrlComboBoxEx_GetCurSel($hCombo)) EndSelect WEnd //JpgRes2Bmp: reading resources in the JPG image data, the resulting bitmap image generation handle a pointer //Parameter: //ResourceName: [IN] resource name, such as IDR_JPG_1 //ResourceType: [IN] resource type, depending on your custom resource name, such as "JPG" //LphBmp: [OUT] output bitmap handle pointer //Return value: //Success return TRUE, failed to return FALSE expandcollapse popupBOOL CJPGRES2BMPView::JpgRes2Bmp(UINT ResourceName, LPCSTR ResourceType, HBITMAP *lphBmp) { HGLOBAL hGlobal = NULL; HRSRC hSource = NULL; LPVOID lpVoid = NULL; int nSize = 0; IPicture* p_IPicture = NULL; OLE_HANDLE hJpegBmp = 0; hSource = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(ResourceName), ResourceType); if(hSource == NULL) { return(FALSE); } hGlobal = LoadResource(AfxGetResourceHandle(), hSource); if(hGlobal == NULL) { return(FALSE); } lpVoid = LockResource(hGlobal); if(lpVoid == NULL) { return(FALSE); } nSize = (UINT)SizeofResource(AfxGetResourceHandle(), hSource); HGLOBAL hGlobalMem = GlobalAlloc(GMEM_MOVEABLE, nSize); if(hGlobalMem == NULL) { return(FALSE); } void* pData = GlobalLock(hGlobalMem); memcpy(pData, (BYTE*)hGlobal, nSize); GlobalUnlock(hGlobalMem); IStream* pStream = NULL; if(CreateStreamOnHGlobal(hGlobalMem, TRUE, &pStream) == S_OK) { HRESULT hr; if(E_NOINTERFACE == (hr = OleLoadPicture(pStream, nSize, FALSE, IID_IPicture, (LPVOID *)&p_IPicture))) { return(FALSE); } else // S_OK { pStream->Release(); pStream = NULL; } } // MSDN:not necessary for Win32-based applications UnlockResource(hGlobal); FreeResource(hGlobal); FreeResource(hGlobalMem); if(p_IPicture != NULL) { // Get the handle to the image, and then copy it. if((p_IPicture->get_Handle(&hJpegBmp)) != S_OK) { p_IPicture->Release(); p_IPicture = NULL; *lphBmp = 0; return(FALSE); } if((*lphBmp = (HBITMAP)CopyImage((HANDLE *) hJpegBmp, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)) == NULL) { p_IPicture->Release(); p_IPicture = NULL; *lphBmp = 0; return(FALSE); } p_IPicture->Release(); p_IPicture = NULL; return(TRUE); } else { p_IPicture->Release(); p_IPicture = NULL; return(FALSE); } }Expand.rar Edited June 22, 2010 by hat Link to comment Share on other sites More sharing options...
UEZ Posted June 22, 2010 Share Posted June 22, 2010 (edited) Try this: expandcollapse popup#include <Array.au3> #include <GDIPlus.au3> #include <GuiButton.au3> #include <GuiComboBoxEx.au3> #include <GuiImageList.au3> #include <GuiConstantsEx.au3> #include <File.au3> #include <WindowsConstants.au3> Dim $aCount[1], $aExt[5] = ["*.jpg", "*.png", "*.bmp", "*.ico", "*.gif"] $image_path = @ScriptDir & "\Images" For $i = 0 To UBound($aExt) - 1 $aTmp = _FileListToArray($image_path, $aExt[$i] , 1) _ArrayConcatenate($aCount, $aTmp, 1) Next $aCount[0] = UBound($aCount) If Not IsArray($aCount) Then Exit MsgBox(16, "Error", "No images found in " & $image_path, 10) $iX = 800 $iY = 600 $hGUI = GUICreate("Image to _GUIImageList Example by UEZ 2010", $iX, $iY) $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 20, 20, 70, 335, $CBS_DROPDOWNLIST) Dim $bitmap_from_file[$aCount[0]] _GDIPlus_Startup() $iCX = 48 $iCY = 48 $hImage = _GUIImageList_Create($iCX, $iCY, 5) For $i = 1 To $aCount[0] - 1 _GUIImageList_AddBitmapEx($hImage, $image_path & "\" & $aCount[$i], $iCX, $iCY) Next _GUICtrlComboBoxEx_BeginUpdate ($hCombo) _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage) For $i = 0 To $aCount[0] - 2 _GUICtrlComboBoxEx_AddString($hCombo, $image_path & "\" & $aCount[$i + 1], $i + 1, $i + 1) Next _GUICtrlComboBoxEx_EndUpdate ($hCombo) _GUICtrlComboBoxEx_SetItemHeight($hCombo, 0, $iCY) _GUICtrlComboBoxEx_SetCurSel($hCombo, 0) $botton = GUICtrlCreateButton("Display Image", 120, 20, 90, 55, $BS_BITMAP) GUISetState() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $iW = 256 $iH = 256 GUICtrlCreateIcon("", 0, ($iX - $iW) * 0.5, ($iY - $iH) * 0.5) $Icon = GUICtrlGetHandle(-1) While 1 $msg = GUIGetMsg() Select Case $msg = $gui_event_close _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() GUIDelete($hGUI) Exit Case $msg = $botton _WinAPI_RedrawWindow($hGUI) $select = _GUICtrlComboBoxEx_GetCurSel($hCombo) + 1 $aItem = _GUICtrlComboBoxEx_GetItem($hCombo, $select) WinSetTitle($hGUI, "", $aItem[0]) $suffix = StringRight($aItem[0], 3) If $suffix = "ico" Then $iW = 256 $iH = 256 $aRet = DllCall('comctl32.dll ', 'uint', 'LoadIconWithScaleDown', 'ptr', 0, 'wstr', $aItem[0], 'int', $iW, 'int', $iH, 'ptr*', 0) $hIcon = $aRet[5] $hPrev = _SendMessage($Icon, 0x0172, 1, $hIcon) ;$STM_SETIMAGE = 0x0172 If $hPrev Then DllCall('user32.dll', 'int', 'DestroyIcon', 'ptr', $hPrev) EndIf _WinAPI_DestroyIcon($hIcon) Else $hImg = _GDIPlus_BitmapCreateFromFile($aItem[0]) $iW = _GDIPlus_ImageGetWidth($hImg) $iH = _GDIPlus_ImageGetHeight($hImg) If $iW < $iX * 0.8 And $iH < $iY - 100 Then _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImg, ($iX - $iW) * 0.5, ($iY - $iH) * 0.5, $iW, $iH) Else $iW = ($iX / $iW) * $iW * 0.8 $iH = ($iY / $iH) * $iH * 0.8 _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImg, ($iX - $iW) * 0.5, 100, $iW, $iH) EndIf _GDIPlus_BitmapDispose($hImg) EndIf EndSelect WEnd ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUIImageList_AddBitmapEx ; Description ...: Creates a bitmap from an image file (JPG, PNG, BMP, GIF, ICO, etc.) and adds it to the _GUIImageList control ; Syntax.........: _GUIImageList_AddBitmapEx($hWnd, $sFile, $iWidth, $iHeight) ; Parameters ....: $hWnd - file name where the icon should be extracted from (*.dll, *.ico, *.exe) ; $sFile - path to the bitmap that contains the image ; $iWidth - width of the _GUIImageList ; $iHeight - height of the _GUIImageList ; $iIndex = 0 - icon index which should be extracted ; Return values .: Success - Returns 1 ; Failure - @error ; Author ........: UEZ ; Version .......: 0.80 Build 2011-11-05 beta ; Remarks .......: <GDIPlus.au3> must be included and _GDIPlus_Startup() must be started to use GDI+ functions. ; Don't forget the _GDIPlus_Shutdown() when closing! ; =============================================================================================================================== Func _GUIImageList_AddBitmapEx($hWnd, $sFile, $iWidth = 16, $iHeight = 16, $iIndex = 0) If Not IsHWnd($hWnd) = 0 Or $sFile = "" Or Not FileExists($sFile) Or IsDeclared("ghGDIPDll") <> 1 Then Return SetError(1, 0, 0) Local $ext = StringRight($sFile, 3) If $ext = "ico" Or $ext = "exe" Or $ext = "dll" Then Local $aRet = DllCall("Shell32", "long", "ExtractAssociatedIcon", "int", 0, "str", $sFile, "word*", $iIndex) If @error Then Return SetError(1, @extended, 0) Local $hIcon = $aRet[0] Local $hDC = _WinAPI_GetDC(0) ;thanks to Yashied Local $hBackDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBitmap = _WinAPI_CreateSolidBitmap(0, _WinAPI_GetSysColor($COLOR_MENU), $iWidth, $iHeight) Local $hBackSv = _WinAPI_SelectObject($hBackDC, $hBitmap) _WinAPI_DrawIconEx($hBackDC, 0, 0, $hIcon, $iWidth, $iHeight, 0, 0, 3) _WinAPI_SelectObject($hBackDC, $hBackSv) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_DeleteDC($hBackDC) _GUIImageList_Add($hWnd, $hBitmap) _WinAPI_DeleteObject($hBitmap) Else Local $aProcessIcons = _GDIPlus_BitmapCreateFromFile($sFile) If @error Then Return SetError(2, @extended, 0) Local $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0 Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0) If @error Then Return SetError(3, @extended, 0) Local $hClone = $aResult[6] Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hClone) ;~ DllCall($ghGDIPDll, "int", "GdipSetInterpolationMode", "handle", $hGraphics, "int", 5) _GDIPlus_GraphicsDrawImageRect($hGraphics, $aProcessIcons, 0, 0, $iWidth, $iHeight) Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hClone) _GUIImageList_Add($hWnd, $hBmp) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hClone) _WinAPI_DeleteObject($hBmp) _GDIPlus_BitmapDispose($aProcessIcons) EndIf Return 1 EndFunc BR, UEZ Edited November 5, 2011 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
hat Posted June 22, 2010 Author Share Posted June 22, 2010 ICO files currently not supported.BR,UEZThank you for your help. Thanks very much. Link to comment Share on other sites More sharing options...
enaiman Posted June 23, 2010 Share Posted June 23, 2010 What is this supposed to mean??? For me it looks like a support request, no way an "Example Script". I would really advise the one who gave 5 stars to this to "review" his/her criterias of post rating. It is really ridiculous. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 23, 2010 Moderators Share Posted June 23, 2010 What is this supposed to mean???For me it looks like a support request, no way an "Example Script". I would really advise the one who gave 5 stars to this to "review" his/her criterias of post rating. It is really ridiculous.It means he has no idea how to ask a question properly ( or where to even post one ). I wonder if there's a big sign out some where today that says "Post your Questions in the EXAMPLES FORUM ".Moving to support.Wait... thought I'd check his topics, I'm not moving this to support, I'm merging it with his ALREADY ASKED TOPIC.Yes, the bold marks are for you to take as an insult. I don't enjoy having to waste my time moving stupid threads to the correct forums, or reminding people to maintain any type of forum etiquette. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
UEZ Posted June 23, 2010 Share Posted June 23, 2010 May I ask what happened with this thread? Post Rating? This was as far as I can remember always in "General Help and Support". What is enaiman talking about? BR, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
enaiman Posted June 23, 2010 Share Posted June 23, 2010 The same thread was this morning in "Example Scripts" forum and somebody rated it with 5 stars. That's why I decided to post in there. Later Smoke_N merged these two threads. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
UEZ Posted June 23, 2010 Share Posted June 23, 2010 The same thread was this morning in "Example Scripts" forum and somebody rated it with 5 stars. That's why I decided to post in there.Later Smoke_N merged these two threads.Thanks for clarification! I never saw this thread in "Examples Scripts"!BR,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ 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