Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Beginner question about text with GDI+ [SOLVED]


  • Please log in to reply
4 replies to this topic
berban_
  • Members
  • 202 posts
  • Last active: Aug 05 2014 11:52 PM
  • Joined: 16 Mar 2011
Hey,

I'm trying to learn tic's awesome GDI+ library, but have gotten a little confused about text.

Below is a sample of code adapted from example #8 in the GDI+ documentation.

#Include, Gdip.ahk
pToken := Gdip_Startup()
Width = 300
Height = 200
Options = x10p y30p w80p Centre cbbffffff r4 s20 Underline Italic
Text = Tutorial 8`n`nThank you for trying this example
Font = Arial

DetectHiddenWindows, On
Gui, 1:  -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
hwnd1 := WinExist()
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
pBrush := Gdip_BrushCreateSolid(0xAA000000)
[color=red]Gdip_FillRoundedRectangle(G, pBrush, 0, 0, Width, Height, 20)[/color]
Gdip_DeleteBrush(pBrush)
[color=violet]Gdip_TextToGraphics(G, Text, Options, Font, Width, Height)[/color]
UpdateLayeredWindow(hwnd1, hdc, (A_ScreenWidth-Width)//2, (A_ScreenHeight-Height)//2, Width, Height)
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gui, 1: Show, NA w300 h300
Return

Esc::
[color=orange]Gdip_Shutdown(pToken)[/color]
ExitApp

This code draws a rectangle and writes the given message onto the rectangle. (This occurs at the line in violet.)

What I would like to do is to JUST write the text onto a gui without a rectangle. Sort of like the green OSD example in the GUI documentation, or like the screenshot in this script <!-- m -->http://www.autohotke...topic63584.html<!-- m --> . However, when I remove the line in red (the one that creates the rectangle), NOTHING happens. No text or rectangle.

How do I just add text to a bare canvas? Am I missing something?

(Also, is doing Gdip_Shutdown really necessary if I will be exiting the script anyway? Just curious.)

Thanks!!!

Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

However, when I remove the line in red (the one that creates the rectangle), NOTHING happens. No text or rectangle.

:lol: Text is displayed but you can't see it well because it's white. Change text color and you'll see it better. Example: Options = x10p y30p w80p Centre cbbff0000 r4 s20 Underline Italic

Also, is doing Gdip_Shutdown really necessary

Yes

berban_
  • Members
  • 202 posts
  • Last active: Aug 05 2014 11:52 PM
  • Joined: 16 Mar 2011
Oh my gosh :x you have got to be kidding me. Hahahahah.
Thanks for pointing out my silly ignorance! :D

Now it works great and exactly as expected

jleslie48
  • Members
  • 145 posts
  • Last active: Sep 28 2017 07:13 PM
  • Joined: 29 Jun 2010
I love it! hey I'd like to use this ahk script as a replacement for tool tip, how would you go about making this a callable function and adding a timeout parameter (number of milliseconds to display message before disappearing.)

berban_
  • Members
  • 202 posts
  • Last active: Aug 05 2014 11:52 PM
  • Joined: 16 Mar 2011

I love it! hey I'd like to use this ahk script as a replacement for tool tip, how would you go about making this a callable function and adding a timeout parameter (number of milliseconds to display message before disappearing.)


Hey! That certainly sounds like a cool idea. To be honest though I think it would be easier with a text control in a transparent window. You can see an example of this on the GUI page - towards the bottom there is an example of an OSD (on screen display). Search the page for "OSD" to find it.
Another example of this sort of functionality can be seen in this script: <!-- m -->http://www.autohotke...topic63584.html<!-- m -->