Jump to content

Button Image - Icon from shell32.dll - rotate


Go to solution Solved by Nine,

Recommended Posts

Hey, 

TLDR; Take Image from dll File, rotate as needed, Put into Button Control 

 

I want to use Icons from shell32 and Put them into Buttons as Images. So far so easy, Buttons are created with Style BS_ICON and the Image ist set via guictrlsetimage with specific identifier.

But the Idea is to use arrows or other Icons from the shell32.dll or different files, but rotating them as needed for the Button controls. Since the Rotation has to be done at runtime, creating the icons in advance wont work.

I got a bit lost, using GDI Plus in this. Every attemp i tried, failed in No Icon displayed. But i am not used to GDI Plus at all, that might be the Problem here.

When i have access to the current source, i will add this to the topic.

 

Any ideas so far how to solve this?

 

Greetings.

Link to comment
Share on other sites

  • Solution

Maybe this ?

#include <Constants.au3>
#include <GUIConstants.au3>
#include <WinAPIRes.au3>
#include <GDIPlus.au3>

Opt("MustDeclareVars", True)

Example()

Func Example()
  GUICreate("Rotate")

  Local $idButton = GUICtrlCreateButton("", 10, 20, 50, 50, $BS_ICON)
  Local $hInstance = _WinAPI_LoadLibraryEx("shell32.dll", $LOAD_LIBRARY_AS_DATAFILE)
  Local $hIcon = _WinAPI_LoadIcon($hInstance, 231)

  _GDIPlus_Startup()
  Local $hImage = _GDIPlus_BitmapCreateFromHICON($hIcon)
  _GDIPlus_ImageRotateFlip($hImage, 1) ; 90 degree
  Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  _GDIPlus_ImageDispose($hImage)
  _GDIPlus_Shutdown()

  GUICtrlSendMsg($idButton, $BM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)

  GUISetState()

  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd

  _WinAPI_DeleteObject($hBitmap)
  _WinAPI_DestroyIcon($hIcon)
  _WinAPI_FreeLibrary($hInstance)

EndFunc   ;==>Example

 

Edited by Nine
Link to comment
Share on other sites

Hey,

 

thank you for the fast answer, it is working as intended now. This Function uses the name of the icon rather then the ordinal number. this has to be kept in mind, when using the Icon Selector from examples in AU3 Installation.

 

Greetings.

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

×
×
  • Create New...