E1M1 Posted February 19, 2011 Share Posted February 19, 2011 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. expandcollapse popup#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 More sharing options...
UEZ Posted February 19, 2011 Share Posted February 19, 2011 (edited) Try this: expandcollapse popup#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 February 20, 2011 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 More sharing options...
E1M1 Posted February 19, 2011 Author Share Posted February 19, 2011 Thank you UEZ. How do I make it grab keyboard input on mouse click? I want it to act as input control. edited Link to comment Share on other sites More sharing options...
kylomas Posted February 19, 2011 Share Posted February 19, 2011 E1M1, Change guictrlcreatelabel to guictrlcreateinput. I just tried this and it seems to work. 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 More sharing options...
E1M1 Posted February 19, 2011 Author Share Posted February 19, 2011 kylomas, This replaces my graphic with input. I am trying to code my own input control. edited Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 19, 2011 Moderators Share Posted February 19, 2011 E1M1,I am trying to code my own input controlTo do that you will need to code a keylogger - and you know that you are not allowed to discuss such thing here. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
E1M1 Posted February 19, 2011 Author Share Posted February 19, 2011 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 More sharing options...
Bowmore Posted February 19, 2011 Share Posted February 19, 2011 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 More sharing options...
E1M1 Posted February 19, 2011 Author Share Posted February 19, 2011 (edited) 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 February 19, 2011 by E1M1 edited Link to comment Share on other sites More sharing options...
kylomas Posted February 20, 2011 Share Posted February 20, 2011 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now