Jump to content

GDI+ Image in a Tab Control


Recommended Posts

I feel like this should have been answered before but I scoured for about 45 minutes with no success, so I was probably using the wrong search params ^^;

 

Example script of what I tried.

 

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>

Opt("GUIOnEventMode", 1)

Global $NavigationBar

_CreateGui()

Func _CreateGUI()
    $MainGUI = GuiCreate("Test GUI", 1000, 500)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GuiSetState()

    $NavigationBar = GuiCtrlCreateTab(20, 10, 960, 480)
    GUICtrlSetOnEvent(-1, "_NavigationCheck")

    $GlossaryTab = GuiCtrlCreateTabItem("Glossary")

    _GDIPlus_Startup()

    $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "/Pics/Logo.png")
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($MainGui)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 80, 200, 800, 200)

    _GDIPlus_Shutdown()

    $Item1Tab = GuiCtrlCreateTabItem("Tab 2")

    GuiCtrlCreateLabel("Test", 200, 200)
EndFunc

Func _NavigationCheck()
    $ReadNavigationBar = GUiCtrlRead($NavigationBar)
    ; Do other stuff if need be later
EndFunc

Func _Exit()
    Exit
EndFunc


While 1
    Sleep(10)
WEnd

 

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

I would do it rather this way:

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>

Opt("GUIOnEventMode", 1)

Global $NavigationBar

_CreateGui()

Func _CreateGUI()

    _GDIPlus_Startup()

    $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\FF.png") ;<-- your image
    $iWidth = _GDIPlus_ImageGetWidth($hImage)
    $iHeight = _GDIPlus_ImageGetHeight($hImage)
    $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_ImageDispose($hImage)

    $MainGUI = GuiCreate("Test GUI", 1000, 500)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    $NavigationBar = GuiCtrlCreateTab(20, 10, 960, 480)
    GUICtrlSetOnEvent(-1, "_NavigationCheck")

    $GlossaryTab = GuiCtrlCreateTabItem("Glossary")
    $iPic = GUICtrlCreatePic("", 80, 200, $iWidth, $iHeight)

    $Item1Tab = GuiCtrlCreateTabItem("Tab 2")
    GuiCtrlCreateLabel("Test", 200, 200)

    _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, $IMAGE_BITMAP, $hGDIBitmap)) ;$STM_SETIMAGE = 0x0172
    _WinAPI_DeleteObject($hGDIBitmap)
    _GDIPlus_Shutdown()
    GuiSetState()

EndFunc

Func _NavigationCheck()
    $ReadNavigationBar = GUiCtrlRead($NavigationBar)
    ; Do other stuff if need be later
EndFunc

Func _Exit()
    Exit
EndFunc


While 1
    Sleep(10)
WEnd

 

Otherwise image will be erased when switching the tabs, GUI is minimized/restored again or GUI will be moved partial outside the screen borders.

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

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...