Page 1 of 2
					
				A Skeleton Window
				Posted: Fri Feb 22, 2013 2:13 pm
				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
 
			 
			
					
				Re: A Skeleton Window
				Posted: Fri Feb 22, 2013 2:19 pm
				by Kiffi
				
take a look at the possible window flags: 
http://purebasic.com/documentation/wind ... indow.html
Greetings ... Kiffi
 
			 
			
					
				Re: A Skeleton Window
				Posted: Fri Feb 22, 2013 3:05 pm
				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 ..  
 
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
 
			 
			
					
				Re: A Skeleton Window
				Posted: Fri Feb 22, 2013 3:33 pm
				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.
			 
			
					
				Re: A Skeleton Window
				Posted: Fri Feb 22, 2013 4:10 pm
				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
			 
			
					
				Re: A Skeleton Window
				Posted: Fri Feb 22, 2013 5:19 pm
				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 ..  

  .. 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 ..  
 
Thanks anyway ..  
 
Graham
 
			 
			
					
				Re: A Skeleton Window
				Posted: Fri Feb 22, 2013 6:24 pm
				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? 
EDIT: PS... There seems nothing wrong with your method for your skeleton window, IMO.
 
			 
			
					
				Re: A Skeleton Window
				Posted: Fri Feb 22, 2013 6:26 pm
				by c4s
				GWS wrote:ts-soft .. that's true, but I still have to stare at the long lines ..  

 
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)
  
 
			 
			
					
				Re: A Skeleton Window
				Posted: Fri Feb 22, 2013 6:49 pm
				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
 
			 
			
					
				Re: A Skeleton Window
				Posted: Fri Feb 22, 2013 7:45 pm
				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
 
			 
			
					
				Re: A Skeleton Window
				Posted: Fri Feb 22, 2013 8:10 pm
				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 ..   
 
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 ..  
 
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.
 
			 
			
					
				Re: A Skeleton Window
				Posted: Fri Feb 22, 2013 9:58 pm
				by Kwai chang caine
				Nice window Netmaestro, i love it, thanks  

 
			 
			
					
				Re: A Skeleton Window
				Posted: Fri Feb 22, 2013 10:08 pm
				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 
 
			 
			
					
				Re: A Skeleton Window
				Posted: Fri Feb 22, 2013 10:58 pm
				by rsts
				Nice skeleton, Mr maestro.
cheers
			 
			
					
				Re: A Skeleton Window
				Posted: Fri Feb 22, 2013 11:09 pm
				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!!!