Jump to content
Sign in to follow this  
Kyan

set input background image (if possible)

Recommended Posts

Kyan

Hi

its possible to set a image like this: Posted Image

as background of a input? i tried GUICtrlSetImage() without success, maybe I need to convert it to .ico :s

thanks in advance :)


Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites
stormbreaker

A dumb example:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Example()

Func Example()
Local $msg

GUICreate("My GUI") ; will create a dialog box that when displayed is centered

GUICtrlCreateInput("", 10, 20, 140, 40, $BS_ICON)
GUICtrlCreatePic("background-input.bmp",9, 19, 141, 41)

GUISetState()

; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
EndFunc ;==>Example

Convert your img to bmp first. Doesn't work once you start typing

Edited by MKISH

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Share this post


Link to post
Share on other sites
UEZ

Here 2 snippets I've found:

1)

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>


Global $hGUI = GUICreate("Background pic in input control", 615, 438)

Global $iW = 255, $iH = 40 ;size child GUI
Global $iX = 56, $iY = 64 ;position of child gui  and background pic within main GUI

Global $pic = GUICtrlCreatePic(StringReplace(@AutoItExe, "autoit3.exe", "ExamplesGUImslogo.jpg"), $iX, $iY, $iW, $iH)
GUICtrlSetState(-1, $GUI_DISABLE)

Global $hGUI_Child = GUICreate("Test", $iW, $iH, $iX, $iY, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_MDICHILD + $WS_EX_LAYERED, $hGUI)
GUICtrlSetBkColor($hGUI_Child, 0xABCDEF)
Global $Input = GUICtrlCreateInput("", 0, 0, $iW, $iH, $WS_BORDER)
GUICtrlSetFont($Input, 18, 800, 0, "MS Sans Serif", 5)
GUICtrlSetBkColor($Input, 0xABCDEF)
GUICtrlSetColor($Input, 0xFFFFFF)

GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI_Child)
_WinAPI_SetLayeredWindowAttributes($hGUI_Child, 0xABCDEF)

WinActivate($hGUI_Child)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
    EndSwitch
WEnd

2)

#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
HotKeySet("{ESC}", "_Exit")

$hGUI = GUICreate("Test", 82, 34, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
GUISetBkColor(0xFEDCBA, $hGUI)

$pic1 = GUICtrlCreatePic("back1.jpg", 0, 0, 78, 14)
GUICtrlSetState(-1, $GUI_DISABLE)
$pic2 = GUICtrlCreatePic("back2.jpg", 0, 18, 78, 14)
GUICtrlSetState(-1, $GUI_DISABLE)

$hGUI_Child = GUICreate("",  82, 32, 0, 0,  $WS_POPUP, $WS_EX_MDICHILD +$WS_EX_LAYERED, $hGUI)
GUICtrlSetBkColor($hGUI_Child, 0xABCDEF)
$Input1 = GUICtrlCreateInput("", 0, 0, 82, 16)
GUICtrlSetOnEvent(-1, "_1")
GUICtrlSetFont($Input1, 8, 800, 0, "Tahoma")
GUICtrlSetBkColor($Input1, 0xABCDEF)
$Input2 = GUICtrlCreateInput("", 0, 18, 82, 16)
GUICtrlSetOnEvent(-1, "_2")
GUICtrlSetFont($Input2, 8, 800, 0, "Tahoma")
GUICtrlSetBkColor($Input2, 0xABCDEF)

_WinAPI_SetLayeredWindowAttributes($hGUI, 0xFEDCBA)
_WinAPI_SetLayeredWindowAttributes($hGUI_Child, 0xABCDEF)
GUISetState(@SW_SHOW, $hGUI_Child)
GUISetState(@SW_SHOW, $hGUI)

WinActivate($hGUI_Child)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

While Sleep(10000)
WEnd

Func _1()
    Local $Input_1_Text = GUICtrlRead($Input1)
    GUICtrlSetData($Input1, "")
    MsgBox(0, "", "1: " & "''" & $Input_1_Text & "''")
EndFunc

Func _2()
    Local $Input_2_Text = GUICtrlRead($Input2)
    GUICtrlSetData($Input2, "")
    MsgBox(0, "", "2: " & "''" & $Input_2_Text & "''")
EndFunc

Func _Exit()
    GUIDelete($hGUI)
    Exit
EndFunc

Change the path to the images appropriately.

Br,

UEZ

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

Share this post


Link to post
Share on other sites
Kyan

A dumb example:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Example()

Func Example()
Local $msg

GUICreate("My GUI") ; will create a dialog box that when displayed is centered

GUICtrlCreateInput("", 10, 20, 140, 40, $BS_ICON)
GUICtrlCreatePic("background-input.bmp",9, 19, 141, 41)

GUISetState()

; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
EndFunc ;==>Example

Convert your img to bmp first. Doesn't work once you start typing

ya, it disappears once I start typing :( would be a easy way to do it :))

Here 2 snippets I've found:

1)

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Background pic in input control", 615, 438)

$pic = GUICtrlCreatePic("..\..\Images\Button1.jpg", 56, 64, 329, 21)
GUICtrlSetState(-1, $GUI_DISABLE)

$hGUI_Child = GUICreate("Test", 329, 21, 56, 64, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_MDICHILD + $WS_EX_LAYERED, $hGUI)
GUICtrlSetBkColor($hGUI_Child, 0xABCDEF)
$Input = GUICtrlCreateInput("", 0, 0, 329, 21, $WS_BORDER)
GUICtrlSetFont($Input, 9, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor($Input, 0xABCDEF)
GUICtrlSetColor($Input, 0xFFFFFF)

GUISetState(@SW_SHOW, $hGUI_Child)
GUISetState(@SW_SHOW, $hGUI)
_WinAPI_SetLayeredWindowAttributes($hGUI_Child, 0xABCDEF)

WinActivate($hGUI_Child)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

2)

#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
HotKeySet("{ESC}", "_Exit")

$hGUI = GUICreate("Test", 82, 34, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
GUISetBkColor(0xFEDCBA, $hGUI)

$pic1 = GUICtrlCreatePic("back1.jpg", 0, 0, 78, 14)
GUICtrlSetState(-1, $GUI_DISABLE)
$pic2 = GUICtrlCreatePic("back2.jpg", 0, 18, 78, 14)
GUICtrlSetState(-1, $GUI_DISABLE)

$hGUI_Child = GUICreate("", 82, 32, 0, 0, $WS_POPUP, $WS_EX_MDICHILD +$WS_EX_LAYERED, $hGUI)
GUICtrlSetBkColor($hGUI_Child, 0xABCDEF)
$Input1 = GUICtrlCreateInput("", 0, 0, 82, 16)
GUICtrlSetOnEvent(-1, "_1")
GUICtrlSetFont($Input1, 8, 800, 0, "Tahoma")
GUICtrlSetBkColor($Input1, 0xABCDEF)
$Input2 = GUICtrlCreateInput("", 0, 18, 82, 16)
GUICtrlSetOnEvent(-1, "_2")
GUICtrlSetFont($Input2, 8, 800, 0, "Tahoma")
GUICtrlSetBkColor($Input2, 0xABCDEF)

_WinAPI_SetLayeredWindowAttributes($hGUI, 0xFEDCBA)
_WinAPI_SetLayeredWindowAttributes($hGUI_Child, 0xABCDEF)
GUISetState(@SW_SHOW, $hGUI_Child)
GUISetState(@SW_SHOW, $hGUI)

WinActivate($hGUI_Child)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

While Sleep(10000)
WEnd

Func _1()
Local $Input_1_Text = GUICtrlRead($Input1)
GUICtrlSetData($Input1, "")
MsgBox(0, "", "1: " & "''" & $Input_1_Text & "''")
EndFunc

Func _2()
Local $Input_2_Text = GUICtrlRead($Input2)
GUICtrlSetData($Input2, "")
MsgBox(0, "", "2: " & "''" & $Input_2_Text & "''")
EndFunc

Func _Exit()
    GUIDelete($hGUI)
    Exit
EndFunc

Change the path to the images appropriately.

Br,

UEZ

wow, I like the first one :D, could you explain the layered window? (I want to change the input position, but turns a bit tricky with all that position differences between the ctrlpic and input position

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites
UEZ

I modified the code above. I hope that it is now more clear to you.

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

Share this post


Link to post
Share on other sites
Kyan

I modified the code above. I hope that it is now more clear to you.

Br,

UEZ

thanks UEZ, really awesome code :D

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

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  

×