Simple GDI Class

Post your working scripts, libraries and tools
GeekDude
Posts: 695
Joined: 02 Oct 2013, 22:13

Simple GDI Class

05 Jan 2015, 17:14

A class aiming to make using low-level GDI functions simple.

Example use code: Simple button
Image

Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus



The library code:
Last edited by GeekDude on 05 Jan 2015, 17:41, edited 3 times in total.
User avatar
joedf
Posts: 5416
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: Simple GDI Class

05 Jan 2015, 17:24

Nice!
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
GitHub: visionary1
Location: Seoul
Contact:

Re: Simple GDI Class

07 Jan 2015, 22:56

oh.. nice
AutoHotkey & AutoHotkey_H v1.1.22.07
vasili111
Posts: 696
Joined: 21 Jan 2014, 02:04
Location: Georgia

Re: Simple GDI Class

18 Jan 2015, 11:43

Please also add link here: viewtopic.php?f=6&t=3851&start=60
DRAKON-AutoHotkey: Visual programming for AutoHotkey.
GeekDude
Posts: 695
Joined: 02 Oct 2013, 22:13

Re: Simple GDI Class

18 Jan 2015, 12:49

It's not really beautiful, but I'll post it anyways if you want me to
User avatar
joedf
Posts: 5416
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: Simple GDI Class

19 Jan 2015, 00:00

But! It will facilitate new GUIs using GDI
dfdfdf

Re: Simple GDI Class

19 Jan 2015, 22:34

where is GDI.ahk?
lblb
Posts: 121
Joined: 30 Sep 2013, 11:31

Re: Simple GDI Class

14 Apr 2016, 23:29

Hi Geekdude,

This is cool and simple! Thanks for your work.

Is there any way that this could be adapted to make circular buttons? There are ellipse functions in Tic's Gdip library so I'm guessing it may be possible, but adding it to your class is way over my head. Thanks in advance for the help you may be able to provide.
GeekDude
Posts: 695
Joined: 02 Oct 2013, 22:13

Re: Simple GDI Class

14 Apr 2016, 23:39

Greetings lblb,

You should be able to take the code for FillRectangle and modify it to use a DllCall for Ellipse instead of for Rectangle. It looks like it takes all the same parameters as Rectangle, so it should be as simple as copying that class method and changing the name Rectangle to Ellipse. I'd probably also remove that 1x1 pixel check, since it doesn't really apply to an ellipse in the same way it might a rectangle.

Here is the documentation page for Ellipse
lblb
Posts: 121
Joined: 30 Sep 2013, 11:31

Re: Simple GDI Class

14 Apr 2016, 23:52

Hi Geekdude,

Thanks a lot for the quick reply and for the info, much appreciated.

I'm willing to work on it but this is quite new to me. So before I invest some time into this, maybe I should ask if you think it would be possible to reach my objective. What I am trying to do is to have individual floating circle buttons that react as you showed in your test script. So I would make the Gui background transparent in order to only see the circle buttons (and have some free space between the buttons). If I can come up with the Ellipse code, I'm not sure what to expect: since the Fill functions seem to act by changing the color of the progress control, would I be stuck with the corner of the rectangular progress control sticking out of the ellipse shape?
lblb
Posts: 121
Joined: 30 Sep 2013, 11:31

Re: Simple GDI Class

15 Apr 2016, 03:11

Hi Geekdude,

Thanks a lot for your help. I think I'm getting close to what I need. Here is the code I have so far:

Spoiler


And then in GDI.ahk, I replaced FillRectangle with:

Spoiler


When you run the script above, there should be two round buttons at the middle of the screen.

A few questions:


1) I made the default state of the buttons transparent by using

Code: [Select all] [Download] GeSHi © Codebox Plus

Winset, Transcolor, 0x000000

It was necessary to use 0x000000 for Transcolor (and for the Gui background color) because the corners of the progress control that are outside of the ellipse are black. Is there any way to control the color of these corners outside of the ellipse?


2) As you can see, the edges of the circle and of the text are a bit jagged. In Tic's Gdip library, it's possible to adjust the antialiasing using the Quality functions. Would it be possible to do the same here? I have no clue how I could include this function in your code.

Spoiler



3) I'm trying to put different text on each button. That works well by itself using something like:

Code: [Select all] [Download] GeSHi © Codebox Plus

Default()
{
global LasthWnd
global hwnd
if (hWnd == MyButton.hWnd)
this.Draw("Hover1", 0x000000, 0x00000F)
Else if (hWnd == MyButton2.hWnd)
this.Draw("Hover2", 0x000000, 0x00000F)
}


But I'm running in some issues when I combine this with the function to reset the buttons when the cursor leaves the buttons. When the cursor leaves the the buttons, I use the following to reset the buttons:

Code: [Select all] [Download] GeSHi © Codebox Plus

OnMessage(0x2A2, "WM_NCMOUSELEAVE")
SetTimer, CheckIfMouseIsOutsideGui,10


If you hover on and off over button 1 (or button 2), the text is updated correctly. But if you hover over button 1, then go over button 2, the first time you hover over button 2 the hover text is not updated correctly. Can you see where the mistake is?


Thanks a lot for all your help. This is really challenging for me as I'm not used to working with functions and classes (so for example, I'm not really sure the WM_NCMOUSELEAVE and CheckIfMouseIsOutsideGui are deployed correctly) but I'm learning a whole lot. So thanks in advance for any support you may be able to offer.
Guest

Re: Simple GDI Class

19 Apr 2016, 09:34

I'm running into some issues with multiple buttons too...
It seems they get switched around for some reason. Can't pinpoint why yet.
There seems to be some HWND weirdness going on.

Could you provide an example of using more than one button Geekdude? Thanks.
Like this it seems kinda confusing to get things right. (I usually don't work with HWNDS to get things done)
GeekDude
Posts: 695
Joined: 02 Oct 2013, 22:13

Re: Simple GDI Class

20 Apr 2016, 12:16

Sorry for the late replies. Here's some code with multiple round buttons. I took advantage of some newer AHK features that let me handle the messages for each button individually instead of having a single message handler that handles all the buttons. Also, I fixed WM_MOUSELEAVE (had to do some research for this one, and modified it to be both 32 and 64 bit compatible). See the original post for the updated GDI.ahk with FillEllipse.

As for making things smoother/less pixelated, it's not really possible. My class strictly uses GDI (not plus) functions, which don't have such features. That kind of functionality is only present in GDI+. If you want good transparency and aliasing (smoothing), you'll need to use either tic's gdip or his gdip2 beta (also class based). https://github.com/tariqporter/Gdip/blo ... /Gdip2.ahk

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Guest

Re: Simple GDI Class

20 Apr 2016, 13:18

Cheers :beer:

I managed to get things looking smooth enough with your library so no need for gdip on my end.

Now if only i could find some bass.dll help i'd be set :lol: lol
lblb
Posts: 121
Joined: 30 Sep 2013, 11:31

Re: Simple GDI Class

25 Apr 2016, 01:53

Hi GeekDude,

Sorry for the late reply as I just got back into this. Thanks a lot for modifying the GDI.ahk and for modifying my script. I really appreciate it. I'll look into what you wrote and will write back here if I encounter any issues. Thanks a lot!

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Randy31416 and 16 guests