April 25, 2024, 03:33:29 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Text Region

Started by GWS, September 21, 2012, 08:19:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

Hi,

Here's a conversion of ZeroDog's tip from 2006, for creating a window region from a text string.

A nice bit of innovative coding from ZD as usual ..  :)


' Something Interesting, if not useless <grin> IBPro Version - (converted to Creative Basic GWS Sept 2012)

' Press any key to change mode,
' ESC to exit    -= ZeroDog =-d

DECLARE "gdi32",EndPath(hdc:INT),INT
DECLARE "gdi32",BeginPath(hdc:INT),INT
DECLARE "gdi32",PathToRegion(hdc:INT),INT
DECLARE "gdi32",TextOutA(hdc:INT, x:INT, y:INT, lpSTRING:STRING, nCount:INT),INT
DECLARE "user32",SetWindowRgn(hWnd:INT, hRgn:INT, bRedraw:INT),INT
DECLARE "gdi32",DeleteObject(hObject:INT),INT
DEF win:WINDOW
DEF WindowHDC,TextRegion,TextWidth,TextHeight,l,t,w,h:INT
DEF TextString,TextString2,TextStyle:STRING

TextString = "   ZeroDog   "
TextString2 =" Productions "
TextStyle = ""

'Acquire the size of window we need for the size of text we need
window win,0,0,0,0,@NOCAPTION,0,"",winproc
SetFont win,"Courier New",64,800
GETTEXTSIZE win, TextString, TextWidth, TextHeight
closewindow win

'Open our new window with the appropriate size
window win,10000,10000,TextWidth,TextHeight*2,@NOCAPTION|@BORDER,0,"ZeroDog",winproc
SetFont win,"Courier New",64,800

'our default is inverted text
Gosub InvertText

run = 1
waituntil run = 0
closewindow win
end

SUB winproc
   SELECT @CLASS
      CASE @IDCHAR
         if (@CODE = 0x1B) : 'ESC Key Exits, any other switches TextStyle
            run = 0
         else
            if TextStyle = "TRANSPARENT"
               GOSUB InvertText
            else
               GOSUB NormalText
            endif
         endif

      CASE @IDCLOSEWINDOW
         run = 0
   endselect
RETURN


SUB InvertText
   GETSIZE win,l,t,w,h
   SETSIZE win,10000,10000,w,h :' hide the window offscreen for a cleaner display
   Drawmode win,@Opaque
   SETWINDOWCOLOR win, 0
   WindowHDC=getHDC(win) :' get the handle for the device contect of the window
   BeginPath(WindowHDC) :' begins the path for the region
      move win,0,0
      TextOutA(WindowHDC, 0, 0, TextString, Len(TextString)) :' output the text to the path
      move win,0,TextHeight
      TextOutA(WindowHDC, 0, TextHeight, TextString2, Len(TextString2)) :' output the text to the path
   EndPath(WindowHDC) :' ends the path for the region
   TextRegion = PathToRegion(WindowHDC) :' creates a region from the path
   SetWindowRgn(win.hwnd, TextRegion, 1) :' apply the region to the window
   DeleteObject(TextRegion) :' free the memory used by the created region
   TextStyle="OPAQUE"
   ReleaseHDC(win, WindowHDC) :'free memory used by the HDC
   'draw some color blending in the window
   windowcolor=rgb(0,255,255)
   for x = 0 to textheight
      line win,0,textheight-x,textwidth,textheight-x,windowcolor||rgb(x,x,0)
   next x
   windowcolor=rgb(255,255,0)
   for x = 0 to textheight
      line win,0,textheight+x+2,textwidth,textheight+x+2,windowcolor||rgb(0,x,x)
   next x
   centerwindow win
RETURN


SUB NormalText
   GETSIZE win,l,t,w,h
   SETSIZE win,10000,10000,w,h :' hide the window offscreen for a cleaner display
   Drawmode win,@Transparent
   SETWINDOWCOLOR win,0
   WindowHDC=getHDC(win) :' get the handle for the device contect of the window
   BeginPath(WindowHDC) :' begins the path for the region
      move win,0,0
      TextOutA(WindowHDC, 0, 0, TextString, Len(TextString)) :' output the text to the path
      move win,0,TextHeight
   TextOutA(WindowHDC, 0, TextHeight, TextString2, Len(TextString2)) :' output the text to the path
   EndPath(WindowHDC) :' ends the path for the region
   TextRegion = PathToRegion(WindowHDC) :' creates a region from the path
   SetWindowRgn(win.hwnd, TextRegion, 1):' apply the region to the window
   DeleteObject(TextRegion):' apply the region to the window
   ReleaseHDC(win, WindowHDC) :'free memory used by the HDC
   TextStyle="TRANSPARENT"
   'draw some color blending in the window
   windowcolor=rgb(0,255,255)
   for x = 0 to textheight
      line win,0,textheight-x,textwidth,textheight-x,windowcolor||rgb(x,x,0)
   next x
   windowcolor=rgb(255,255,0)
   for x = 0 to textheight
      line win,0,textheight+x+2,textwidth,textheight+x+2,windowcolor||rgb(0,x,x)
   next x
   centerwindow win
RETURN



best wishes, :)

Graham
Tomorrow may be too late ..

LarryMc

Over the year ZD, as well as yourself, have come up with some pretty nat coding examples.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library