Jump to content

How to detect click on GDI+ graphic?


E1M1
 Share

Recommended Posts

How detect when user clicks on GDI+ graphic? I am trying to make my own window control. I have read somewhere that GDI+ can be used to create new controls. I am not sure if it's right idea to use GDI+ to make custom window controls. Let me know If GDI+ isn't right method to make new window controls.

I managed to create graphic that reminds input control. But I cant invent code to detect if it's clicked.

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $hGUI, $hGraphic, $hBrush
    Local $hFormat, $hFamily, $hFont, $tLayout
    Local $sString = "Hello world", $aInfo
    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    GUISetState()

    ; Fill a rectangle
    _GDIPlus_Startup ()
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
    _GDIPlus_GraphicsFillRect($hGraphic, 10, 10, 100, 25,$hBrush)
    _GDIPlus_BrushDispose($hBrush)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont = _GDIPlus_FontCreate ($hFamily, 10, 0)
    $tLayout = _GDIPlus_RectFCreate (10, 10, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, $sString, $hFont, $tLayout, $hFormat)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)


    ; Loop until user exits
    Do
    Until GUIGetMsg() = -3

    ; Clean up resources
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()

EndFunc   ;==>_Main

edited

Link to comment
Share on other sites

Try this:

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $hGUI, $hGraphic, $hBrush
    Local $hFormat, $hFamily, $hFont, $tLayout
    Local $sString = "Hello world", $aInfo, $label, $msg
    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    GUISetState()

    ; Fill a rectangle
    _GDIPlus_Startup ()
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
    $label = GUICtrlCreateLabel("", 10, 10, 100,25)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    _GDIPlus_GraphicsFillRect($hGraphic, 10, 10, 100, 25,$hBrush)

    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont = _GDIPlus_FontCreate ($hFamily, 10, 0)
    $tLayout = _GDIPlus_RectFCreate (10, 10, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, $sString, $hFont, $tLayout, $hFormat)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)


    ; Loop until user exits
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
            _GDIPlus_FontDispose ($hFont)
            _GDIPlus_FontFamilyDispose ($hFamily)
            _GDIPlus_StringFormatDispose ($hFormat)
            _GDIPlus_BrushDispose($hBrush)
            _GDIPlus_GraphicsDispose ($hGraphic)
            _GDIPlus_Shutdown ()
                Exit
            Case $label
                MsgBox(0, "Test", "Clicked on GFX")
        EndSwitch
    WEnd

    ; Clean up resources

EndFunc   ;==>_Main

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

Link to comment
Share on other sites

  • Moderators

E1M1,

I am trying to code my own input control

To do that you will need to code a keylogger - and you know that you are not allowed to discuss such thing here. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Isnt there other way around? I dont think that all edit controls and inputs works like keylogger. I mean there are many custom controls out there in where you can type text.. Just lets think about scite. It's also custom control.

I am not discussing keylogger here. I am sure there are method to write this control with out having to write kelogger.

I wonder if there's any properties for doing what I want?Something like this $Graphic.class = $Input or something.

Problem is that when you look at my GUI with AutoIt Window info tool you won't see my custom control which means that my graphic is not even registered as control.

Maybe if I manage to register it as edit control I wouldn't have to write anything that looks like keylogger. I think once it's registered as input control windows automatically handles text I type.

Since no one has done this before in autoit I guess I would have to put that code into C++ and ask in msdn forums.

If I am right in C I could just write something like OnGraphic_Click() {...}

edited

Link to comment
Share on other sites

I think you would be very surprised if you could see how much code it takes for windows to draw a simple input box control, manage it and handle user interaction with it. Creating custom controls is a far from trivial task. Melba23 is correct, to be able to do it would require detecting all user input actions in a way that would be very useful to someone wanting to create a key logger, I realise that this is not your intention.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

You may be right. I go sleep now. Since scintilla is open source I am going to dig there when I wake up again. if anyone knows any open source custom controls let me know.

Edited by E1M1

edited

Link to comment
Share on other sites

E1M1,

Did some Google searching and found these that you may be interested in:

http://www.google.com/url?sa=t&source=web&cd=3&sqi=2&ved=0CDkQFjAC&url=http%3A%2F%2Fwww.codeproject.com%2FKB%2Fmiscctrl%2Fcustbutton001.aspx&ei=cGpgTb_WOdO1tgf3672qDA&usg=AFQjCNGp_MfIDBbezOor0aU2AM8__uV2Pg

http://www.google.com/url?sa=t&source=web&cd=5&sqi=2&ved=0CE4QFjAE&url=http%3A%2F%2Fwww.drdobbs.com%2F184409155&ei=cGpgTb_WOdO1tgf3672qDA&usg=AFQjCNE8fr0Zr8nRGyyhwawg6KLxejRjPQ

http://www.google.com/url?sa=t&source=web&cd=8&sqi=2&ved=0CGQQFjAH&url=http%3A%2F%2Fwww.catch22.net%2Ftuts%2Fcustctrl&ei=cGpgTb_WOdO1tgf3672qDA&usg=AFQjCNGEfC7vC48bn9RtytgZbNc77p0RKA

I don't know "C" but could follow most of whats going on.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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