OpenTextWindow

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

OpenTextWindow

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by Franco.

Hi Folks, here another silly window, but it shows what is possible with PureBasic.
Maybe somebody likes a intro window like that, or whatever...

Code: Select all

; (c) 2001 - Franco's template - absolutely freeware
; OpenTextWindow(ID,Height,Width,Thickness,Flag,Font$,Text$)
; Well, the big part is to adjust Height, Width and Thickness to the lenght of the String and the Font.
; You will see :)
;
; Height = Window Height
; Width  = Window Width
; Thickness =FontThickness
; Flag can be: #RGN_AND or #RGN_XOR

Procedure OpenTextWindow(ID,Height,Width,Thickness,Flag,Font$,Text$)
  RectRegion.Rect

  If OpenWindow(ID, GetSystemMetrics_(#SM_CXSCREEN), GetSystemMetrics_(#SM_CYSCREEN), Width, Height, Text$,#PB_Window_SystemMenu|#WS_POPUP)
    SetForegroundWindow_(WindowID(ID))
    WindowDC= GetDC_(WindowID(ID))
    Font = SelectObject_(WindowDC,CreateFont_(Height,0,0,0,Thickness,0,0,0,#ANSI_CHARSET,#OUT_CHARACTER_PRECIS,#CLIP_DEFAULT_PRECIS,#PROOF_QUALITY,0,Font$))
    BeginPath_(WindowDC)
    TextOut_(WindowDC,0,0,Text$,Len(Text$))
    EndPath_(WindowDC)
    Region1 = PathToRegion_(WindowDC)
    GetRgnBox_(Region1,RectRegion)
    Region2 = CreateRectRgnIndirect_(RectRegion)
    CombineRgn_(Region2,Region2,Region1,Flag) 
    DeleteObject_(Region1)
    ReleaseDC_(WindowID(ID),WindowDC)
    SetWindowRgn_(WindowID(ID),Region2,1)
    SelectObject_(WindowDC,Font)
    SetWindowPos_(WindowID(ID),#HWND_TOPMOST,(GetSystemMetrics_(#SM_CXSCREEN)/2)-(WindowWidth(ID)/2),(GetSystemMetrics_(#SM_CYSCREEN)/2)-(WindowHeight(ID)/2),Width,Height,0)
  Else
    ProcedureReturn 0
  EndIf
  ProcedureReturn 1
EndProcedure

If OpenTextWindow(0,150,600,300,#RGN_XOR,"Verdana","PureBasic")
  Repeat
    EventID = WaitWindowEvent()
  Until EventID = #PB_Event_CloseWindow
EndIf


Have a nice day...
Franco


Edited by - franco on 20 October 2001 00:10:58
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by Franco.

This is an example what you can do with that:

Code: Select all

; (c) 2001 - Franco's template - absolutely freeware
; OpenTextWindow(ID,Height,Width,Thickness,Flag,Font$,Text$)
; Well, the big part is to adjust Height, Width and Thickness to the lenght of the String and the Font.
; You will see :)
;
; Height = Window Height
; Width  = Window Width
; Thickness =FontThickness
; Flag can be: #RGN_AND or #RGN_XOR

Procedure OpenTextWindow(ID,Height,Width,Thickness,Flag,Font$,Text$)
  RectRegion.Rect

  If OpenWindow(ID, GetSystemMetrics_(#SM_CXSCREEN), GetSystemMetrics_(#SM_CYSCREEN), Width, Height, Text$,#PB_Window_SystemMenu|#WS_POPUP)
    SetForegroundWindow_(WindowID(ID))
    WindowDC= GetDC_(WindowID(ID))
    Font = SelectObject_(WindowDC,CreateFont_(Height,0,0,0,Thickness,0,0,0,#ANSI_CHARSET,#OUT_CHARACTER_PRECIS,#CLIP_DEFAULT_PRECIS,#PROOF_QUALITY,0,Font$))
    BeginPath_(WindowDC)
    TextOut_(WindowDC,0,0,Text$,Len(Text$))
    EndPath_(WindowDC)
    Region1 = PathToRegion_(WindowDC)
    GetRgnBox_(Region1,RectRegion)
    Region2 = CreateRectRgnIndirect_(RectRegion)
    CombineRgn_(Region2,Region2,Region1,Flag) 
    DeleteObject_(Region1)
    ReleaseDC_(WindowID(ID),WindowDC)
    SetWindowRgn_(WindowID(ID),Region2,1)
    SelectObject_(WindowDC,Font)
    SetWindowPos_(WindowID(ID),#HWND_TOPMOST,(GetSystemMetrics_(#SM_CXSCREEN)/2)-(WindowWidth(ID)/2),(GetSystemMetrics_(#SM_CYSCREEN)/2)-(WindowHeight(ID)/2),Width,Height,0)
  Else
    ProcedureReturn 0
  EndIf
  ProcedureReturn 1
EndProcedure

OpenTextWindow(0,150,600,300,#RGN_XOR,"Verdana","PureBasic")
Delay(1000)
CloseWindow(0)
OpenTextWindow(1,150,900,100,#RGN_XOR,"Verdana","Feel The Pure")
Delay(1000)
CloseWindow(1)
Delay(500)
OpenTextWindow(2,150,560,1500,#RGN_AND,"Verdana","POWER")
Delay(500)
CloseWindow(2)
Delay(500)
OpenTextWindow(3,150,560,1500,#RGN_AND,"Verdana","POWER")
Delay(500)
CloseWindow(3)
Delay(500)
OpenTextWindow(4,150,560,1500,#RGN_AND,"Verdana","POWER")
Delay(500)
CloseWindow(4)


Have a nice day...
Franco
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Mr.Skunk.

Hi,

Another Great examples Franco.

Thanks very much.

Mr Skunk

Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st
Post Reply