Jump to content

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

GDI Gui



  • Please log in to reply
6 replies to this topic
tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
Hello,
Been a little while since I asked for help. I did some searching but couldnt find any examples so Let me explain a little about my intent. What I want is a GDI shape as a GUI. I then intend to attatch some standard and some non standard controls.

So first things first how would I display a simple edit control on a GDI shape so something like

Gdip.Tutorial.8-Write.text.onto.a.gui.ahk
Gui, 1: Add, Edit,x100 y100 h20 w200,text
If I can pull this off, I can add other controls when I desire, I can easily use images and take this code and duplicate check boxes and radios https://ahknet.autoh...tToGraphics.zip

But I wonder how to make a custom edit control with GDI





_________________________
Composed/Posted with WYSIWYG BBCode Editor
Never lose.
WIN or LEARN.

closed
  • Members
  • 509 posts
  • Last active: Jan 14 2012 06:14 PM
  • Joined: 07 Feb 2008
Some time ago i have been looking at this but gave up beyond simple input edit because it is so much work to get even simple editing like caret position indication!

This is a simple input window concept i was working on:

#SingleInstance, Force
#NoEnv
SetBatchLines, -1

; Uncomment if Gdip.ahk is not in your standard library
;#Include, Gdip.ahk

; Start gdi+
If !pToken := Gdip_Startup()
{
	MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
	ExitApp
}
OnExit, Exit

w=300
h=100

Gui, 1:  -Caption +E0x80000 +LastFound +OwnDialogs +Owner +alwaysontop
Gui, 1: Show, NA x0 y0
gui +lastfound
hwnd := WinExist()


hbm := CreateDIBSection(w,h)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)


font =arial
If !hFamily := Gdip_FontFamilyCreate(Font)
{
MsgBox,  Font error! exit app!
exitapp
}

Gdip_SetCompositingMode(G, 1)
pBrush:=Gdip_BrushCreateSolid(0xDE000000)
pBrush1:=Gdip_BrushCreateSolid(0x50000000)
Gdip_FillRectangle(G, pBrush, 0, 0, w, h)
Gdip_SetCompositingMode(G, 1)
Gdip_FillRectangle(G, pBrush1, 50, 20, 200, 20)

Gdip_SetCompositingMode(G, 0)
Options = x50 y19 w200 cff000000 Left r4 s14
rc:=Gdip_TextToGraphics(G, "press F4 to edit enter to quit", Options, font)



UpdateLayeredWindow(hwnd, hdc,0,0,w,h)
WinMove, ahk_id %hwnd%,,300,300
OnMessage(0x201, "WM_LBUTTONDOWN")
Return


f4::
gosub update
gosub edit
return

edit:
hotkey,Backspace,on

loop 
{
Input, SingleKey,  L1
if (singlekey="`n")
break
a  .=singlekey

tooltip %a%
gosub update

}
hotkey,Backspace,off
return



update:
Gdip_SetClipRect(G, 50, 20, 200, 20)
Gdip_SetCompositingMode(G, 1)
Gdip_FillRectangle(G, pBrush1, 0, 0, w,h)
Gdip_ResetClip(G)

display_text:= a

Gdip_SetCompositingMode(G, 0)
Options = x50 y19 w200 cff000000 Left r4 s14
rc:=Gdip_TextToGraphics(G, display_text, Options, font)

UpdateLayeredWindow(hwnd, hdc)

return


!v::listvars


~Backspace::
stringtrimright,a,a,1
gosub update
return


WM_LBUTTONDOWN()
{
	PostMessage, 0xA1, 2
}



esc::
Exit:
Gdip_DeleteBrush(pBrush)
Gdip_DeleteBrush(pBrush1)

SelectObject(hdc, obm)

DeleteObject(hbm)

DeleteDC(hdc)

Gdip_DeleteGraphics(G)

Gdip_Shutdown(pToken)
ExitApp
Return


tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
Thanks Thanh00

if thats what it takes then so be it. seems to perform ok so i will do some experimenting. I guess imporvements might be selecting text copy paste option and detecting need of scrollbars

For the record i know all of this is easier to do in other environments but i want to stretch AHK a bit

Now my big hurdle is attatching a standard control to the GDI drawing or at least overlaying it and moving it with it
Never lose.
WIN or LEARN.

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010
Tank, do you have any function for displaying GDI images on tab controls, and maybe to simply Gui, Add, Pic, but as a GDI control (to allow for better transparency?). I

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
GDI being attatched to standard GUI's is covered elsewhere
I am trying to not use a standard gui window and attatch standard gui controls to it

EDIT: SUCH AS HERE
<!-- m -->https://ahknet.autoh... ... rd.gui.ahk<!-- m -->
Never lose.
WIN or LEARN.

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

Now my big hurdle is attatching a standard control to the GDI drawing or at least overlaying it and moving it with it

Tic wrote "Hacked Tutorial 7". I can't post a link to that example, don't remember where it is, so I'll post code here (Tic, I hope you're OK with that)
; gdi+ ahk tutorial 7 written by tic (Tariq Porter)
; Requires Gdip.ahk either in your Lib folder as standard library or using #Include
;
; Tutorial to draw a rounded rectangle as a gui that you can drag

#SingleInstance, Force
#NoEnv
SetBatchLines, -1

; Uncomment if Gdip.ahk is not in your standard library
#Include, %A_ScriptDir%\Gdip.ahk

; Start gdi+
If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}
OnExit, Exit

; Set the width and height we want as our drawing area, to draw everything in. This will be the dimensions of our bitmap
Width := 300, Height := 200

; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop

; Show the window
Gui, 1: Show, NA

; Get a handle to this window we have created in order to update it later
hwnd1 := WinExist()

Gui, 2:Font, q5
Gui, 2: -Caption +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 2: Margin, 0, 0
hwnd2 := WinExist()
Gui, 2: Add, Edit, % "x0 y0 w" Width-40 " h" Height-40, Hacked Tutorial 7`n`nThank you for trying this example      ;%

; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
hbm := CreateDIBSection(Width, Height)

; Get a device context compatible with the screen
hdc := CreateCompatibleDC()

; Select the bitmap into the device context
obm := SelectObject(hdc, hbm)

; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(hdc)

; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
Gdip_SetSmoothingMode(G, 4)

; Create a partially transparent, black brush (ARGB = Transparency, red, green, blue) to draw a rounded rectangle with
pBrush := Gdip_BrushCreateSolid(0x77000000)

; Fill the graphics of the bitmap with a rounded rectangle using the brush created
; Filling the entire graphics - from coordinates (0, 0) the entire width and height
; The last parameter (20) is the radius of the circles used for the rounded corners

Gdip_SetClipRect(G, 20, 20, Width-40, Height-40, 4)

Gdip_FillRoundedRectangle(G, pBrush, 0, 0, Width, Height, 20)

; Delete the brush as it is no longer needed and wastes memory
Gdip_DeleteBrush(pBrush)


; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; With some simple maths we can place the gui in the centre of our primary monitor horizontally and vertically at the specified heigth and width
UpdateLayeredWindow(hwnd1, hdc, (A_ScreenWidth-Width)//2, (A_ScreenHeight-Height)//2, Width, Height)

; By placing this OnMessage here. The function WM_LBUTTONDOWN will be called every time the user left clicks on the gui
OnMessage(0x201, "WM_LBUTTONDOWN")
OnMessage(0x46, "WM_WINDOWPOSCHANGING")
Gui, 1: Show, Center

; Select the object back into the hdc
SelectObject(hdc, obm)

; Now the bitmap may be deleted
DeleteObject(hbm)

; Also the device context related to the bitmap may be deleted
DeleteDC(hdc)

; The graphics may now be deleted
Gdip_DeleteGraphics(G)
return

;#######################################################################

; This function is called every time the user clicks on the gui
; The PostMessage will act on the last found window (this being the gui that launched the subroutine, hence the last parameter not being needed)
WM_LBUTTONDOWN()
{
   PostMessage, 0xA1, 2
}

;#######################################################################

WM_WINDOWPOSCHANGING(wParam, lParam)
{
    if (A_Gui = 1 && !(NumGet(lParam+24) & 0x2)) ; SWP_NOMOVE=0x2
    {
        x := NumGet(lParam+8),  y := NumGet(lParam+12)
        x += 20,  y += 20
        Gui, 2: Show, X%x% Y%y% NA
    }
}

;#######################################################################

Exit:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp
return


tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
Perfect thanks for this Unless Tic(or someone else for that matter) has since come up with more code around this i think i have enuff to work with
Never lose.
WIN or LEARN.