A Skeleton Window

Just starting out? Need help? Post your questions and find answers here.
User avatar
GWS
User
User
Posts: 23
Joined: Tue Sep 27, 2005 9:51 pm
Location: Staffs. UK

A Skeleton Window

Post by GWS »

Hi,

No big deal, but here's my first go at a window skeleton program.

Code: Select all

; skeleton window

EnableExplicit
Define.l Event,wW,wH,run,textW
Define.s a$
#w1 = 1

;(Note: Window Flags: #SysMenu = $80000  #Max = $10000  #Min = $20000   #Size = $40000)
#Center = 1
#Full = $F0000      ;#SysMenu|#Max|#Min|#Size
#Fixed = $A0000     ;#SysMenu|#Min

wW = 500
wH = 300
run = #True

OpenWindow(#w1, 0, 0, wW, wH, "PB Skeleton Window",#Fixed|#Center)
SetWindowColor(#w1, RGB(0,100,120)) 

#B_Exit = 1
ButtonGadget(#B_Exit, (wW-70)/2, 210, 70, 25, "Exit",#BS_FLAT)

; Display some text ..
LoadFont(1, "Arial", 20, #PB_Font_Italic|#PB_Font_Bold)
StartDrawing(WindowOutput(#w1))
DrawingMode(#PB_2DDrawing_Transparent)
FrontColor(RGB(130,150,230))
DrawingFont(FontID(1)) 
a$ = "Welcome to PureBasic"
textW = TextWidth(a$)
DrawText((wW-textw)/2,50,a$)
StopDrawing()


Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_CloseWindow
      run = #False
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #B_Exit
          run = #False
      EndSelect
  EndSelect
Until run = #False

End
There may be a neater way to do it, so open to suggestions .. :)

best wishes,

Graham
Tomorrow may be too late ..
User avatar
Kiffi
Addict
Addict
Posts: 1504
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: A Skeleton Window

Post by Kiffi »

GWS wrote:

Code: Select all

;(Note: Window Flags: ...
take a look at the possible window flags: http://purebasic.com/documentation/wind ... indow.html

Greetings ... Kiffi
Hygge
User avatar
GWS
User
User
Posts: 23
Joined: Tue Sep 27, 2005 9:51 pm
Location: Staffs. UK

Re: A Skeleton Window

Post by GWS »

Thanks for the reply Kiffi ..

Yes, I was aware of the PB window flags .. I'm trying to avoid them .. I hate typing very long parameters .. :wink:
By the time you've Or'ed together a string of them for a window style, the line's stretching off the page.

I'm also not too happy using magic Windows Hex numbers, but I see no alternative in this case.

Take #PB_Window_SystemMenu for instance.

If it had been #W_sys I might have been happier using it.

The PB is always true, the _Window is clear but overlong in this context, and _SystemMenu is again very clear - but a mite too long in my opinion.

I like things concise if I'm going to type them often - lazy I guess .. :)

all the best, :)

Graham
Tomorrow may be too late ..
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Re: A Skeleton Window

Post by eJan »

You can use Templates in PB IDE > Tools > Templates by adding new, editing existing, which can be inserted into code via keyboard shortcut.
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: A Skeleton Window

Post by ts-soft »

long parameter no problem, autocomplete and Line continuation do the work.
If you use your own constants for styles, your program is no more crossplattform!

Greetings - Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
GWS
User
User
Posts: 23
Joined: Tue Sep 27, 2005 9:51 pm
Location: Staffs. UK

Re: A Skeleton Window

Post by GWS »

Thanks eJan .. I'll take a look at that. :)

ts-soft .. that's true, but I still have to stare at the long lines .. :wink: .. and I'm not interested in cross-platform.

But it's not so much the window style parameters that I'm interested in comments on - I'm fairly happy to use the Hex values myself - it's the overall coding method to set up a window and text .. :wink:

Thanks anyway .. :)

Graham
Tomorrow may be too late ..
User avatar
oreopa
Enthusiast
Enthusiast
Posts: 283
Joined: Sat Jun 24, 2006 3:29 am
Location: Edinburgh, Scotland.

Re: A Skeleton Window

Post by oreopa »

Somewhere in your code (or possibly as an include so you can reuse it) define new constants using the PB values...

#W_sys = #PB_Window_SystemMenu

Problem solved, no? :D

EDIT: PS... There seems nothing wrong with your method for your skeleton window, IMO.
Last edited by oreopa on Fri Feb 22, 2013 6:26 pm, edited 1 time in total.
Proud supporter of PB! * Musician * C64/6502 Freak
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: A Skeleton Window

Post by c4s »

GWS wrote:ts-soft .. that's true, but I still have to stare at the long lines .. :wink:
Well, that's wrong. The new release 5.10 of PB supports line continuation so you actually don't have to look at long lines if you don't want to. Here is a very short example:

Code: Select all

OpenWindow(0,
					100, 200,
					195, 260, 
					"PureBasic Window", 
					#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
:wink:
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: A Skeleton Window

Post by netmaestro »

There may be a neater way to do it, so open to suggestions ..

Code: Select all

; Skeleton window sample
; netmaestro 2013

InitNetwork()
file$ = GetTemporaryDirectory()+"sskin2.png"

If FileSize(file$) = -1
  ReceiveHTTPFile("http://www.lloydsplace.com/sskin2.png", file$)
EndIf

UsePNGImageDecoder()
If Not LoadImage(0, file$)
  MessageRequester("oops!", "Couldn't load image... ending now.")
  End
EndIf

Declare PreMultiply(image)

GrabImage(0,1,0,0,267,490)
GrabImage(0,2,267,0,267,490)
GrabImage(0,3,534,0,267,490)
GrabImage(0,4,801,0,267,490)

FreeImage(0)
For i=1 To 4:PreMultiply(i):Next
Global icurrent = 1
CreatePopupMenu(0)
MenuItem(1, "Exit")
MenuItem(2, "Cancel")

OpenWindow(0,0,0,ImageWidth(icurrent),ImageHeight(icurrent),"",#PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_Invisible)
SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_TOOLWINDOW)
StickyWindow(0,1)

Procedure UpdateWindow(uID, uMsg, dwUser, dw1, dw2)
  Static f=1
  If f
    icurrent+1:If icurrent>4:f=0:icurrent=4:EndIf
  Else
    icurrent-1:If icurrent<1:f=1:icurrent=1:EndIf
  EndIf
  If IsImage(icurrent) And IsWindow(0)
    hDC = StartDrawing(ImageOutput(icurrent)) 
      With sz.SIZE
        \cx = ImageWidth(icurrent)
        \cy = ImageHeight(icurrent)
      EndWith
      With BlendMode.BLENDFUNCTION 
        \SourceConstantAlpha = 255 
        \AlphaFormat = 1
      EndWith
      UpdateLayeredWindow_(WindowID(0),0,0,@sz,hDC,@ContextOffset.POINT,0,@BlendMode,2)
    StopDrawing() 
  EndIf
EndProcedure

UpdateWindow(0,0,0,0,0)
HideWindow(0,0)

tid = timeSetEvent_(75,0,@UpdateWindow(),0,#TIME_PERIODIC)

Repeat
  ev=WaitWindowEvent()
  Select ev
    Case #WM_LBUTTONDOWN
      SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
    Case #PB_Event_RightClick
      DisplayPopupMenu(0, WindowID(0))
    Case #PB_Event_Menu
      If EventMenu()=1
        timeKillEvent_(tid)
        Delay(15)
        End
      EndIf
  EndSelect
Until ev = #PB_Event_CloseWindow

Procedure PreMultiply(image)
  StartDrawing(ImageOutput(image))
    DrawingMode(#PB_2DDrawing_AllChannels)
    For j=0 To ImageHeight(image)-1
      For i=0 To ImageWidth(image)-1
        color = Point(i,j)
        Plot(i,j, RGBA(Red(color)*Alpha(color)/$FF,Green(color)*Alpha(color)/$FF,Blue(color)*Alpha(color)/$FF,Alpha(color)))
      Next
    Next
  StopDrawing()
EndProcedure
Last edited by netmaestro on Fri Feb 22, 2013 11:16 pm, edited 2 times in total.
BERESHEIT
buddymatkona
Enthusiast
Enthusiast
Posts: 252
Joined: Mon Aug 16, 2010 4:29 am

Re: A Skeleton Window

Post by buddymatkona »

I like to keep the OpenWindow lines short like this:

Code: Select all

#MsgDrawOptions = #PB_Window_SystemMenu|#PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget

  With *MsgDrawProps
    MsgDrawWin = OpenWindow(#PB_Any,\Xoff,\Yoff,\WinWidth,\WinHeight,"Upcoming Event",#MsgDrawOptions)
  EndWith
User avatar
GWS
User
User
Posts: 23
Joined: Tue Sep 27, 2005 9:51 pm
Location: Staffs. UK

Re: A Skeleton Window

Post by GWS »

Thanks oreopa .. I hadn't thought of equating one constant to another .. that's a useful concept. Glad you thought my approach was OK. :)

c4s .. Yep, that's a good way of spreading the long constants out .. :)

netmaestro .. Oh! .. now you're just showing off .. :lol:
I see I've got a long way to go .. that's very impressive.

You missed 'Type' out of #PB_EventType_RightClick - but easy to correct. An example of what can happen with long constants .. :wink:

Closing the 'window' is a bit obscure if you don't have the code in front of you .. :)

I shall study your code and no doubt learn a lot from it .. many thanks.
Tomorrow may be too late ..
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: A Skeleton Window

Post by Kwai chang caine »

Nice window Netmaestro, i love it, thanks :D
ImageThe happiness is a road...
Not a destination
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: A Skeleton Window

Post by netmaestro »

@GWS: New window event #PB_Event_RightClick was added with version 5.10:
PB History for version 5.10 wrote:- Added: #PB_Event_RightClick, #PB_Event_LeftClick and #PB_Event_LeftDoubleClick events
BERESHEIT
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: A Skeleton Window

Post by rsts »

Nice skeleton, Mr maestro.

cheers
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: A Skeleton Window

Post by netmaestro »

Updated skeleton. Now he waves at you. (my time is sooo valuable and in demand...)

Oh no.. Animations now.. I'm turning into KCC!!!
BERESHEIT
Post Reply