Sign in to follow this  
Followers 0
Flisker

Adding picture as background to GUI

7 posts in this topic

Hello,

I would like to ask if anybody knows simple solution for adding background to _GUICtrlEdit_Create().

All I want now is add background picture to this GUI while text would be visible over the picture.

Thanks in advance guys.

ps: Attached picture of finished script.

#include <GuiEdit.au3>
#include <File.au3>

Global $GUI
Global $MAIN
Global $guiData = @CRLF&@CRLF

Func GUIInit()
    $MAIN = GUICreate("Aktualizace",@DesktopWidth,@DesktopHeight,0,0)
    $GUI = _GUICtrlEdit_Create($MAIN,"",1,1,@DesktopWidth,@DesktopHeight,BitOR(0x0004,0x00200000))
;~  GUICtrlCreatePic("C:\win7_bg.jpg",0,0)
    GUISetState(@SW_SHOW,$MAIN)
EndFunc

Func GUIMessage($message,$type)    ; Show Message
    If $type == 1 Then
        $message = $message&@CRLF
        _GUICtrlEdit_AppendText($GUI,$message)
    EndIf
    If $type == 2 Then
        $message = $message&@CRLF&@CRLF
        _GUICtrlEdit_AppendText($GUI,$message)
    EndIf
    If $type == 3 Then
        $message = @CRLF&$message&@CRLF&@CRLF
        _GUICtrlEdit_AppendText($GUI,$message)
    EndIf
    Return $message
EndFunc

GUIInit()

$guiData &= GUIMessage("» Mapovani disku","2")

$guiData &= GUIMessage("Disk I:","1")
DriveMapDel("I:")
DriveMapAdd("I:","\\S-doa-25\data")

$guiData &= GUIMessage("Disk P:","1")
DriveMapDel("P:")
DriveMapAdd("P:","\\S-doa-25\okprace")

$guiData &= GUIMessage("Disk R:","1")
DriveMapDel("R:")
DriveMapAdd("R:","\\10.186.66.50\intranet\aplikace\dopisy")

......... and so on

Share this post


Link to post
Share on other sites



Have a look here: '?do=embed' frameborder='0' data-embedContent>>

 

Br,

UEZ

1 person likes this

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Ok, thanks. Guess there is no "easy" one/two line solution for this right ?

Share this post


Link to post
Share on other sites

Flisker,

Save the difficult code in a file - then using it becomes a 2-line matter: one to #include the file and one to call the function within it. ;)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

You're right M23. Thank you both guys.

I was thinking I want to understand completely my whole script... but I just realised that I already use functions so why not make one for this too :)

Started working with MPVs script () but got another issue, when I run few lines in GUI, font gets bold till I click somewhere else :(

Could you help me with this one too please ?

Modded MPVs script :

#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3> ;required for: $GUI_EVENT_CLOSE
#include <Constants.au3>
#include <WinAPIEx.au3> ;url: http://www.autoitscript.com/forum/topic/98712-winapiex-udf/
#include <Color.au3> ;required for: _RGBtoBGR
#include <Debug.au3> ;required for: _Assert

#region Global Vars
Global Const $WM_APP_REDRAWWINDOW = $WM_APP + 1

Global $_hBrushBack = 0, $_hBitmapBack = 0, $_pfnDefEditProc = 0

Global Const $_sBkBitmapFullPath = @ScriptDir & "\win7_bg.bmp"

Local $hNew_WndProc = DllCallbackRegister("_MyEdit_Proc", "int", "hwnd;uint;wparam;lparam")
Global $_pNew_WndProc = DllCallbackGetPtr($hNew_WndProc)
#endregion Global Vars

#region GUI
Local Const $hGUI = GUICreate("Aktualizace Softwaru", 1024, 764, -1, -1, BitOR($DS_MODALFRAME, $WS_POPUP, $WS_CAPTION, $WS_SYSMENU))

Global Const $tbMyEdit = GUICtrlCreateEdit("Welcome", 0, 0, 1024, 764, BitOR($ES_MULTILINE, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL))

;~ GUIRegisterMsg($WM_INITDIALOG, "WM_INITDIALOG")
WM_INITDIALOG($hGUI)
GUIRegisterMsg($WM_CTLCOLOREDIT, "WM_CTLCOLOREDIT")
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")
GUIRegisterMsg($WM_DESTROY, "WM_DESTROY")

GUISetState(@SW_SHOW, $hGUI)
#endregion GUI

;~ MsgBox("","» Aktualizace","» Probihaji aktualizace, prosim vyckejte",1)

GUICtrlSetData($tbMyEdit,"» "&@ComputerName&@CRLF&@CRLF,1)

GUICtrlSetData($tbMyEdit,"» Mapovani disku"&@CRLF&@CRLF,1)

If Ping("10.186.66.25",1000) <> 0 Then
    GUICtrlSetData($tbMyEdit,"Disk I:"&@CRLF,1)
    DriveMapDel("I:")
    DriveMapAdd("I:","\\S-doa-25\data")

    GUICtrlSetData($tbMyEdit,"Disk P:"&@CRLF,1)
    DriveMapDel("P:")
    DriveMapAdd("P:","\\S-doa-25\okprace")

    GUICtrlSetData($tbMyEdit,"Disk S:"&@CRLF,1)
    DriveMapDel("S:")
    DriveMapAdd("S:","\\S-doa-25\ips")

    GUICtrlSetData($tbMyEdit,"Disk T:"&@CRLF,1)
    DriveMapDel("T:")
    DriveMapAdd("T:","\\S-doa-25\texty")

    GUICtrlSetData($tbMyEdit,"Disk H:"&@CRLF,1)
    DriveMapDel("H:")
    DriveMapAdd("H:","\\s-doa-25\user$\UP\"&@UserName&"\dokumenty")
Else
    GUICtrlSetData($tbMyEdit,"» Disky I,P,S,T,H(10.186.66.25) Nejsou dostupne !"&@CRLF,1)
EndIf

GUICtrlSetData($tbMyEdit,"Disk I:"&@CRLF,1)
GUICtrlSetData($tbMyEdit,"Disk I:"&@CRLF,1)
GUICtrlSetData($tbMyEdit,"Disk I:"&@CRLF,1)
GUICtrlSetData($tbMyEdit,"Disk I:"&@CRLF,1)
GUICtrlSetData($tbMyEdit,"Disk I:"&@CRLF,1)
GUICtrlSetData($tbMyEdit,"Disk I:"&@CRLF,1)
GUICtrlSetData($tbMyEdit,"Disk I:"&@CRLF,1)
GUICtrlSetData($tbMyEdit,"Disk I:"&@CRLF,1)



#region Loop
While GUIGetMsg() <> $GUI_EVENT_CLOSE
    Sleep(10)
WEnd

GUIDelete($hGUI)
#endregion Loop

#region WM
Func WM_INITDIALOG($hWnd) ;bool
    $_hBitmapBack = _WinAPI_LoadImage(0, $_sBkBitmapFullPath, $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
    _Assert("$_hBitmapBack <> 0")
    $_hBrushBack = _WinAPI_CreatePatternBrush($_hBitmapBack)
    _Assert("$_hBrushBack <> 0")

    ; Subclass edit control
    Local $hWndEdit = _WinAPI_GetDlgItem($hWnd, $tbMyEdit)
;~     _Assert("$hWndEdit <> 0") ;commented, reason: bug
    $_pfnDefEditProc = _WinAPI_SetWindowLong($hWndEdit, $GWL_WNDPROC, $_pNew_WndProc)

    Return False
EndFunc   ;==>WM_INITDIALOG

Func WM_CTLCOLOREDIT($hWnd, $uMsg, $wParam, $lParam) ;HBRUSH
    Local $hBrush = 0

    Switch $uMsg
        Case $WM_CTLCOLOREDIT
            _WinAPI_SetTextColor($wParam, _RGBtoBGR(0xffffff))
            _WinAPI_SetBkMode($wParam, $TRANSPARENT)
            $hBrush = $_hBrushBack
    EndSwitch

    Return $hBrush
EndFunc   ;==>WM_CTLCOLOREDIT

Func WM_ERASEBKGND($hWnd, $uMsg, $wParam, $lParam) ;bool
    Local $tRect = _WinAPI_GetClientRect($hWnd)
    Local $hOldBrush = _WinAPI_SelectObject($wParam, $_hBrushBack)
    _WinAPI_PatBlt($wParam, 0, 0, DllStructGetData($tRect, "Right") - DllStructGetData($tRect, "Left"), DllStructGetData($tRect, "Bottom") - DllStructGetData($tRect, "Top"), $PATCOPY)
    _WinAPI_SelectObject($wParam, $hOldBrush)

    Return True
EndFunc   ;==>WM_ERASEBKGND

Func WM_DESTROY($hWnd, $uMsg, $wParam, $lParam) ;void
    _WinAPI_DeleteObject($_hBitmapBack)
    _WinAPI_DeleteObject($_hBrushBack)
EndFunc   ;==>WM_DESTROY
#endregion WM

Func _MyEdit_Proc($hWnd, $uMsg, $wParam, $lParam) ;LRESULT CALLBACK
    Switch $uMsg
        Case $WM_VSCROLL, $WM_HSCROLL, $WM_MOUSEWHEEL, $WM_KEYDOWN
            _WinAPI_PostMessage($hWnd, $WM_APP_REDRAWWINDOW, $hWnd, 0)
        Case $WM_APP_REDRAWWINDOW
            Return _MyEdit_OnRedrawWindow($wParam, $lParam)
    EndSwitch

    Return _WinAPI_CallWindowProc($_pfnDefEditProc, $hWnd, $uMsg, $wParam, $lParam)
EndFunc   ;==>_MyEdit_Proc

Func _MyEdit_OnRedrawWindow($wParam, $lParam) ;HRESULT
    Local $uFlags = BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_ERASE)

    _WinAPI_RedrawWindow($wParam, 0, 0, $uFlags)

    Return 0
EndFunc   ;==>_MyEdit_OnRedrawWindow

Func _WinAPI_CreatePatternBrush($hbmp) ;By ProgAndy
    Local $brush = DllCall("gdi32.dll", "long", "CreatePatternBrush", "long", $hbmp)
    If Not @error Then Return $brush[0]

    Return 0
EndFunc   ;==>_WinAPI_CreatePatternBrush

Func _RGBtoBGR($iColor) ;by FireFox
    Return "0x" & Hex(_ColorGetRed($iColor), 2) & Hex(_ColorGetGreen($iColor), 2) & Hex(_ColorGetBlue($iColor), 2)
EndFunc   ;==>_RGBtoBGR

34-71 Lines and changed bg pic and font color.

Got only few lines there to try it out.

post-64059-0-74851300-1386323474_thumb.j

Share this post


Link to post
Share on other sites

Still can't make this "bold" issue right :( anybody has idea what's the problem please ?

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi,

Unfortunately I don't have this issue :(

It should be fixed by the repaint triggered on some WM (VSCROLL, HSCROLL, MOUSEWHEEL, KEYDOWN).

I suggest you to check if one of the above is not triggered or if there is a WM I forgot to add (make a ConsoleWrite of the $uMsg in the _MyEdit_Proc function).

Have you tried the richedit solution in the thread you linked?

Br, FireFox.

Edited by FireFox
1 person likes this

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0