Sign in to follow this  
Followers 0
AndyK

GUI "Image Map"

6 posts in this topic

#1 ·  Posted (edited)

Im trying to create something similar to an image map. Green or red boxes (representing computers) will be displayed on top of an image, and when you click on them, information on that computer will come . I can get it to work with a Pic control and Graphic control, but I would like to have the ability to use PNG files... My attempt at using GDI does not work... Any advice on how to fix it would be awesome...

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <WinAPI.au3>

_GDIPlus_StartUp()
$hImage   = _GDIPlus_ImageLoadFromFile("C:\Users\user\Pictures\untitled.png")
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetWidth($hImage)

; Window handle
$hWnd = GUICreate("Image Map", $iX, $iY)

GUISetState(@SW_SHOW, $hWnd)

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iX, $iY)

; Define brush colors
$bGreen = 0x33FFAA
$bRed = 0xFF3300

; Clickable control 1
$gph = GUICtrlCreateGraphic(0, 0, 15, 15)
GUICtrlSetState(-1, $GUI_ONTOP)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $bGreen, $bGreen)
GUICtrlSetGraphic($gph, $GUI_GR_RECT, 0, 0, 15, 15)

; Clickable control 2
$gph2 = GUICtrlCreateGraphic(200, 60, 15, 15)
GUICtrlSetState(-1, $GUI_ONTOP)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $bRed, $bRed)
GUICtrlSetGraphic($gph2, $GUI_GR_RECT, 0, 0, 15, 15)


; Background picture - Uncomment this to make it work properly.
;$Pic1 = GUICtrlCreatePic("C:\Users\user\Pictures\untitled.gif", 0, 0, 0, 0, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
;GUICtrlSetState(-1, @SW_DISABLE)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $gph
            _My_Func1()
        Case $gph2
            _My_Func2()
    EndSwitch
WEnd

; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()

Func _My_Func1()
    ; Place holder currently.
    MsgBox(0, "Graphic 1", "You have clicked graphic #1.")
EndFunc

Func _My_Func2()
    ; Place holder currently.
    MsgBox(0, "Graphic 2", "You have clicked graphic #2.")
EndFunc
Edited by AndyK

Share this post


Link to post
Share on other sites



Does this work?

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <WinAPI.au3>

_GDIPlus_StartUp()
$hImage   = _GDIPlus_ImageLoadFromFile("C:\Users\StudioLaptop\Desktop\Desktop\Au3DB\Data\Misc\RecentMenu\Example 1.png")
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetWidth($hImage)

; Window handle
$hWnd = GUICreate("Image Map", $iX, $iY)

GUISetState(@SW_SHOW, $hWnd)

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iX, $iY)

; Define brush colors
$bGreen = 0x33FFAA
$bRed = 0xFF3300

; Clickable control 1
$gph = GUICtrlCreateLabel("",0, 0, 15, 15)
GUICtrlSetBkColor(-1, $bRed)

; Clickable control 2
$gph2 = GUICtrlCreateLabel("", 200, 60, 15, 15)
GUICtrlSetBkColor(-1, $bGreen)


; Background picture - Uncomment this to make it work properly.
;$Pic1 = GUICtrlCreatePic("C:\Users\user\Pictures\untitled.gif", 0, 0, 0, 0, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
;GUICtrlSetState(-1, @SW_DISABLE)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $gph
            _My_Func1()
        Case $gph2
            _My_Func2()
    EndSwitch
WEnd

; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()

Func _My_Func1()
    ; Place holder currently.
    MsgBox(0, "Graphic 1", "You have clicked graphic #1.")
EndFunc

Func _My_Func2()
    ; Place holder currently.
    MsgBox(0, "Graphic 2", "You have clicked graphic #2.")
EndFunc

I would highly recommend looking at Zedna's Resources UDF and the Function _SetBitmapToCtrl() to set an Image to a Control, because at present when you minimise the GUI and restore the GUI is "re-painted." You could also look at these Example too >>


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

I would highly recommend looking at Zedna's Resources UDF and the Function _SetBitmapToCtrl() to set an Image to a Control, because at present when you minimise the GUI and restore the GUI is "re-painted." You could also look at these Example too >>

Hadn't seen those functions as of yet but they look very helpful. Theoretically, using the resource functions I could load a PNG as a bitmap, then use the _SetBitmapToCtrl() to set the picture control as the loaded image? This would then allow the pic control to be repainted properly after it's been minimized?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

If you use Resources.au3 for _SetBitmapToCtrl() then I would do it like this >> You can see I have a custom Function called _GUICtrlSetImage().

Example:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#include "Resources.au3" ; http://www.autoitscript.com/forum/topic/51103-resources-udf/

_Main()

Func _Main()
    Local $hGUI, $iLabel
    $hGUI = GUICreate("_GUICtrlSetImage()", 300, 300)
    $iLabel = GUICtrlCreateLabel("", 0, 0, 64, 64)
    GUISetState(@SW_SHOW, $hGUI)

    _GDIPlus_Startup()
    _GUICtrlSetImage($iLabel, "Example.png")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                _GDIPlus_Shutdown()
                Exit

        EndSwitch
    WEnd
EndFunc   ;==>_Main

Func _GUICtrlSetImage($iControlID, $sImageFile)
    Local $hBitmap, $hImage, $hDC
    $hImage = _GDIPlus_ImageLoadFromFile($sImageFile)
    $hDC = _WinAPI_GetDC(0)
    _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    GUICtrlSetImage($iControlID, "")
    Return _SetBitmapToCtrl($iControlID, $hBitmap)
EndFunc   ;==>_GUICtrlSetImage

This would then allow the pic control to be repainted properly after it's been minimized?

It wouldn't disappear correct! :huh2: Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites
Edit: You might also want to use this >>

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

You can load PNGs using GDI+ and sending it to a pic control.

Something like that:

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
Opt("GuiOnEventMode", 1)

Local Const $STM_SETIMAGE = 0x0172
Local $hGUI, $Pic, $hImage, $hBmp, $iW, $iH

_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile("..\..\Images\Folder Full Tranparent.png")
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)
$hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

;~ _GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

$hGUI = GUICreate("Test", $iW * 2, $iH * 2)
GUISetBkColor(0xFFFFFF)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")


$Pic = GUICtrlCreatePic("", $iW / 2, $iH / 2, $iW, $iH)
;~ GUICtrlSetState(-1, $GUI_DISABLE)
_WinAPI_DeleteObject(GUICtrlSendMsg($Pic, $STM_SETIMAGE, 0, $hBmp))
GUICtrlSetOnEvent($Pic, "_Pic_Clicked")

_WinAPI_DeleteObject($hBmp)

GUISetState()

Do
Until Not Sleep(1000)

Func _Pic_Clicked()
    MsgBox(0, "Test", "You clicked on the pic!")
EndFunc

Func _Quit()
    GUIDelete($hGUI)
    Exit
EndFunc

Just change the path to the PNG image.

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

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