Jump to content

How to put Picture "jpg" on background of form?


Recommended Posts

Hi it's me again with another foolish question

I read about GUI but I can't make it.

I looking for a way without use a pic control. only with the form.

sorry for my bad english.

Link to comment
Share on other sites

  • Moderators

Danyfirex,

Why do you not want to use a Pic control? That is why the control exists! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

because when I put a Pic control I can´t press my buttons, any of my controls work. so for that I want to put it into the form.

Link to comment
Share on other sites

  • Moderators

Danyfirex,

Read the Help file page fro GuiCtrlCreatePic: ;)

"If a picture is set as a background picture, as the other controls will overlap, it is important to disable the pic control: GuiCtrlSetState(-1, $GUI_DISABLE)."

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Link to comment
Share on other sites

Also, since you seem new and such, if you're gonna compile the script, you don't need to extract the image to anywhere.

Here's a snippet I use to place png and jpg images to a pic control with code by UEZ and trancexx.

#include <GDIPlus.au3>
#include <Memory.au3>

GUICreate("",300,200,-1,-1)
Local $idPic = GUICtrlCreatePic("", 0, 0, 300, 200)
GUICtrlSetState($idPic, 128)
Local $hBmp = Load_BMP_From_Mem(Binary(_ResourceGetAsRaw("[Path to file resource here]", "[Resource name]", "[Resource Type]")), True)
_WinAPI_DeleteObject(GUICtrlSendMsg($idPic, 0x0172, 0, $hBmp))
_WinAPI_DeleteObject($hBmp)
;======================================================================================
; Function Name:        Load_BMP_From_Mem
; Description:        Loads an image which is saved as a binary string and converts it to a bitmap or hbitmap
;
; Parameters:          $bImage:     the binary string which contains any valid image which is supported by GDI+
; Optional:              $hHBITMAP:   if false a bitmap will be created, if true a hbitmap will be created
;
; Remark:                  hbitmap format is used generally for GUI internal images, $bitmap is more a GDI+ image format
;
; Requirement(s):      GDIPlus.au3, Memory.au3 and _GDIPlus_BitmapCreateDIBFromBitmap() from WinAPIEx.au3
; Return Value(s):  Success: handle to bitmap or hbitmap, Error: 0
; Error codes:        1: $bImage is not a binary string
;                              2: unable to create stream on HGlobal
;                              3: unable to create bitmap from stream
;
; Author(s):                UEZ
; Additional Code:  thanks to progandy for the MemGlobalAlloc and tVARIANT lines
; Version:                v0.97 Build 2012-01-04 Beta
;=======================================================================================
Func Load_BMP_From_Mem($bImage, $hHBITMAP = False)
    If Not IsBinary($bImage) Then Return SetError(1, 0, 0)
    Local $aResult
    Local Const $memBitmap = Binary($bImage) ;load image  saved in variable (memory) and convert it to binary
    Local Const $len = BinaryLen($memBitmap) ;get length of image
    Local Const $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory  ($GMEM_MOVEABLE = 0x0002)
    Local Const $pData = _MemGlobalLock($hData) ;translate the handle into a pointer
    Local $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct
    DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data
    _MemGlobalUnlock($hData) ;decrements the lock count  associated with a memory object that was allocated with GMEM_MOVEABLE
    $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0) ;Creates a stream object that uses an HGLOBAL memory handle to store the stream contents
    If @error Then SetError(2, 0, 0)
    Local Const $hStream = $aResult[3]
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $hStream, "int*", 0) ;Creates a Bitmap object based on an IStream COM interface
    If @error Then SetError(3, 0, 0)
    Local Const $hBitmap = $aResult[2]
    Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr")
    DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, _
                                           "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;release memory from $hStream to avoid memory leak
    $tMem = 0
    $tVARIANT = 0
    If $hHBITMAP Then
        Local Const $hHBmp = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
        _GDIPlus_BitmapDispose($hBitmap)
        Return $hHBmp
    EndIf
    Return $hBitmap
EndFunc   ;==>Load_BMP_From_Mem
Func _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
    Local $tBIHDR, $Ret, $tData, $pBits, $hResult = 0
    $Ret = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($Ret[0]) Then Return 0
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $Ret[2], $Ret[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, 'Scan0')
    If Not $pBits Then Return 0
    $tBIHDR = DllStructCreate('dword;long;long;ushort;ushort;dword;dword;long;long;dword;dword')
    DllStructSetData($tBIHDR, 1, DllStructGetSize($tBIHDR))
    DllStructSetData($tBIHDR, 2, $Ret[2])
    DllStructSetData($tBIHDR, 3, $Ret[3])
    DllStructSetData($tBIHDR, 4, 1)
    DllStructSetData($tBIHDR, 5, 32)
    DllStructSetData($tBIHDR, 6, 0)
    $hResult = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBIHDR), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'dword', 0)
    If (Not @error) And ($hResult[0]) Then
        DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hResult[0], 'dword', $Ret[2] * $Ret[3] * 4, 'ptr', DllStructGetData($tData, 'Scan0'))
        $hResult = $hResult[0]
    Else
        $hResult = 0
    EndIf
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    Return $hResult
EndFunc   ;==>_GDIPlus_BitmapCreateDIBFromBitmap
Func _ResourceGetAsRaw($sModule, $iResName, $iResType, $iResLang = 0)
Local $iLoaded
Local $a_hCall = DllCall("kernel32.dll", "hwnd", "GetModuleHandleW", "wstr", $sModule)
If @error Then
  Return SetError(1, 0, "")
EndIf
If Not $a_hCall[0] Then
  $a_hCall = DllCall("kernel32.dll", "hwnd", "LoadLibraryExW", "wstr", $sModule, "hwnd", 0, "int", 34)
  If @error Or Not $a_hCall[0] Then
   Return SetError(2, 0, "")
  EndIf
  $iLoaded = 1
EndIf
Local $hModule = $a_hCall[0]
Switch IsNumber($iResType) + 2 * IsNumber($iResName)
  Case 0
   $a_hCall = DllCall("kernel32.dll", "hwnd", "FindResourceExW", _
     "hwnd", $hModule, _
     "wstr", $iResType, _
     "wstr", $iResName, _
     "int", $iResLang)
  Case 1
   $a_hCall = DllCall("kernel32.dll", "hwnd", "FindResourceExW", _
     "hwnd", $hModule, _
     "int", $iResType, _
     "wstr", $iResName, _
     "int", $iResLang)
  Case 2
   $a_hCall = DllCall("kernel32.dll", "hwnd", "FindResourceExW", _
     "hwnd", $hModule, _
     "wstr", $iResType, _
     "int", $iResName, _
     "int", $iResLang)
  Case 3
   $a_hCall = DllCall("kernel32.dll", "hwnd", "FindResourceExW", _
     "hwnd", $hModule, _
     "int", $iResType, _
     "int", $iResName, _
     "int", $iResLang)
EndSwitch
If @error Or Not $a_hCall[0] Then
  If $iLoaded Then
   Local $a_iCall = DllCall("kernel32.dll", "int", "FreeLibrary", "hwnd", $hModule)
   If @error Or Not $a_iCall[0] Then
    Return SetError(7, 0, "")
   EndIf
  EndIf
  Return SetError(3, 0, "")
EndIf
Local $hResource = $a_hCall[0]
$a_iCall = DllCall("kernel32.dll", "int", "SizeofResource", "hwnd", $hModule, "hwnd", $hResource)
If @error Or Not $a_iCall[0] Then
  If $iLoaded Then
   $a_iCall = DllCall("kernel32.dll", "int", "FreeLibrary", "hwnd", $hModule)
   If @error Or Not $a_iCall[0] Then
    Return SetError(7, 0, "")
   EndIf
  EndIf
  Return SetError(4, 0, "")
EndIf
Local $iSizeOfResource = $a_iCall[0]
$a_hCall = DllCall("kernel32.dll", "hwnd", "LoadResource", "hwnd", $hModule, "hwnd", $hResource)
If @error Or Not $a_hCall[0] Then
  If $iLoaded Then
   $a_iCall = DllCall("kernel32.dll", "int", "FreeLibrary", "hwnd", $hModule)
   If @error Or Not $a_iCall[0] Then
    Return SetError(7, 0, "")
   EndIf
  EndIf
  Return SetError(5, 0, "")
EndIf
Local $a_pCall = DllCall("kernel32.dll", "ptr", "LockResource", "hwnd", $a_hCall[0])
If @error Or Not $a_pCall[0] Then
  If $iLoaded Then
   $a_iCall = DllCall("kernel32.dll", "int", "FreeLibrary", "hwnd", $hModule)
   If @error Or Not $a_iCall[0] Then
    Return SetError(7, 0, "")
   EndIf
  EndIf
  Return SetError(6, 0, "")
EndIf
Local $tOut = DllStructCreate("byte[" & $iSizeOfResource & "]", $a_pCall[0])
Local $sReturnData = DllStructGetData($tOut, 1)
If $iLoaded Then
  $a_iCall = DllCall("kernel32.dll", "int", "FreeLibrary", "hwnd", $hModule)
  If @error Or Not $a_iCall[0] Then
   Return SetError(7, 0, "")
  EndIf
EndIf
Return SetError(0, 0, $sReturnData)
EndFunc   ;==>_ResourceGetAsRaw
Link to comment
Share on other sites

  • 3 weeks later...
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...