Page 3 of 4

Posted: Mon May 08, 2006 7:04 pm
by netmaestro
When I ran your code I got a green box showing around the clock 128px square. Using the #LWA_COLORKEY | #LWA_ALPHA flags together is something I didn't try in my testing, and it exposes a weakness in the dll. But I fixed it now and your code shows correct now. The fixed version is posted for download at the same link.

Nice piece of code, btw flype. Your thoroughness and sense of order and structure are quite impressive.

The setting of Alpha 50% is very nice, it gives the transparent look of my original VistaClock without the redraw issues.

Posted: Mon May 08, 2006 9:11 pm
by netmaestro
OK, there is one more (hopefully the last) version of Vistaclock available. It is packaged in the form of a true PureBasic gadget and you use it like this:

VistaClockGadget(#gadget, x, y, width, height, color, floating)

That's it. Nothing more to it. It'll tick happily away by itself and you can resize it with the normal PB ResizeGadget() command. An example is included with the library help chm.

It's the best and easiest VistaClock yet, I hope you enjoy it!

http://www.networkmaestro.com/VistaClockGadget.zip

If you want to make a semitransparent desktop clock with it, I suggest flype's code a couple posts up. It's excellent.

Posted: Mon May 08, 2006 9:21 pm
by Trond
I am working on a clock with alpha transparency, no flickering and it works literally everywhere. But I'm not really good drawing clocks. Where did you get the components to yours? I have a good framework for the clock itself but I'm lacking the pointers (what are they called?) and their shadows.

Posted: Mon May 08, 2006 9:39 pm
by netmaestro
I surfed around to various sites where the new Windows Vista clock is shown, did screenshots and started from there. (hence the name "vista clock"). The images had to be seriously cut up and all the alpha layer stuff built from scratch and added in Photoshop, drop shadows & highlights, and I had to make a glass crystal. If you're not very skilled in Photo editing you'll probably find it difficult. I wouldn't mind giving you what I have but yours should probably have its own look.

Posted: Tue May 09, 2006 12:33 am
by Flype
good idea to implement it as a userlibrary

it is almost perfect,
but on my computer, there's still the annoying color around the clock.
( try with #color = #Green or #Red )

my example updated to your update :D
and some more features :wink:

Code: Select all

; VistaClock II by netmaestro, 2006
; Written for Purebasic 4.0+

EnableExplicit

Macro MoveWindow(window)
  ReleaseCapture_()
  SendMessage_(WindowID(window), #WM_NCLBUTTONDOWN, #HTCAPTION, #Null) 
EndMacro
Macro SizeWindow(window, bool)
  If bool
    SetWindowLong_(WindowID(window), #GWL_STYLE, GetWindowLong_(WindowID(window), #GWL_STYLE) | #WS_SIZEBOX)
  Else
    SetWindowLong_(WindowID(window), #GWL_STYLE, GetWindowLong_(WindowID(window), #GWL_STYLE) & ~#WS_SIZEBOX)
  EndIf
  SetWindowPos_(WindowID(window), 0, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_NOZORDER | #SWP_FRAMECHANGED)
EndMacro
Macro AlphaWindow(window, color, alpha)
  SetWindowLong_(WindowID(window), #GWL_EXSTYLE, GetWindowLong_(WindowID(window), #GWL_EXSTYLE) | #WS_EX_LAYERED) 
  SetLayeredWindowAttributes_(WindowID(window), color, ((alpha)*255)/100, #LWA_COLORKEY | #LWA_ALPHA)
EndMacro

#color = #White

If ExamineDesktops() And OpenWindow(0, 0, 0, 80, 80, "VistaClock", #PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)
  
  StickyWindow(0, #True)
  SetWindowColor(0, #color)
  AlphaWindow(0, #color, 50)
  
  If CreateGadgetList(WindowID(0))
    VistaClockGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), #color, #True)
  EndIf
  
  If CreatePopupMenu(0) 
    MenuItem(0, "VistaClock")
    DisableMenuItem(0, 0, #True)
    MenuBar()
    OpenSubMenu("Alpha...")
    MenuItem(1, "25%") 
    MenuItem(2, "50%") 
    MenuItem(3, "75%") 
    MenuItem(4, "100%") 
    CloseSubMenu()
    OpenSubMenu("Resize...")
    MenuItem(5, "50px") 
    MenuItem(6, "75px") 
    MenuItem(7, "100px") 
    MenuItem(8, "125px") 
    MenuItem(9, "150px") 
    MenuBar()
    MenuItem(10, "Set...")
    CloseSubMenu()
    OpenSubMenu("Position...")
    MenuItem(11, "Up Left") 
    MenuItem(12, "Up Right") 
    MenuBar()
    MenuItem(13, "Bottom Left") 
    MenuItem(14, "Bottom Right") 
    CloseSubMenu()
    MenuBar()
    MenuItem(15, "Sticky")
    SetMenuItemState(0, 15, #True)
    MenuBar()
    MenuItem(16, "Exit") 
  EndIf
  
  HideWindow(0, #False) 
  
  Repeat 
    
    Select WaitWindowEvent() 
      
      Case #PB_Event_CloseWindow
        Break
        
      Case #PB_Event_SizeWindow
        ResizeGadget(0, 0, 0, WindowWidth(0), WindowHeight(0))
        
      Case #PB_Event_Gadget
        Select EventType()
          Case #PB_EventType_LeftClick
            MoveWindow(0)
          Case #PB_EventType_RightClick
            DisplayPopupMenu(0, WindowID(0)) 
        EndSelect
        
      Case #PB_Event_Menu
        Select EventMenu()
          Case 1: AlphaWindow(0, #color, 25)
          Case 2: AlphaWindow(0, #color, 50)
          Case 3: AlphaWindow(0, #color, 75)
          Case 4: AlphaWindow(0, #color, 100)
          Case 5: ResizeWindow(0, #PB_Ignore, #PB_Ignore, 50, 50)
          Case 6: ResizeWindow(0, #PB_Ignore, #PB_Ignore, 75, 75)
          Case 7: ResizeWindow(0, #PB_Ignore, #PB_Ignore, 100, 100)
          Case 8: ResizeWindow(0, #PB_Ignore, #PB_Ignore, 125, 125)
          Case 9: ResizeWindow(0, #PB_Ignore, #PB_Ignore, 150, 150)
          Case 10: SetMenuItemState(0, 10, #True - GetMenuItemState(0, 10))
            SizeWindow(0, GetMenuItemState(0, 10))
          Case 11: ResizeWindow(0, 25, 25, #PB_Ignore, #PB_Ignore)
          Case 12: ResizeWindow(0, DesktopWidth(0) - WindowWidth(0) - 25, 25, #PB_Ignore, #PB_Ignore)
          Case 13: ResizeWindow(0, 25, DesktopHeight(0) - WindowHeight(0) - 25, #PB_Ignore, #PB_Ignore)
          Case 14: ResizeWindow(0, DesktopWidth(0) - WindowWidth(0) - 25, DesktopHeight(0) - WindowHeight(0) - 25, #PB_Ignore, #PB_Ignore)
          Case 15: SetMenuItemState(0, 15, #True - GetMenuItemState(0, 15)) : StickyWindow(0, GetMenuItemState(0, 6))
          Case 16: Break
        EndSelect
        
    EndSelect
    
  ForEver
  
EndIf

End

Posted: Tue May 09, 2006 12:38 am
by netmaestro
This is your code converted to the Gadget version. Transparent color is green. It shows perfect on my machine, no box visible. Could you try it there?

Code: Select all

; VistaClock II 

EnableExplicit 


Macro MoveWindow(window) 
  ReleaseCapture_() 
  SendMessage_(WindowID(window), #WM_NCLBUTTONDOWN, #HTCAPTION, #Null) 
EndMacro 

Macro AlphaWindow(window, color, alpha) 
  SetWindowLong_(WindowID(window), #GWL_EXSTYLE, GetWindowLong_(WindowID(window), #GWL_EXSTYLE) | #WS_EX_LAYERED) 
  SetLayeredWindowAttributes_(WindowID(window), color, ((alpha)*255)/100, #LWA_COLORKEY | #LWA_ALPHA) 
EndMacro 

Define hClock.l 

If OpenWindow(0, 0, 0, 160, 160, "VistaClock", #PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible) 
  
  SetWindowColor(0, #Green) 
  StickyWindow(0, #True) 
  AlphaWindow(0, #Green, 100) 
  
  If CreateGadgetList(WindowID(0)) 
    VistaClockGadget(0,0,0,144,144,#Green,#True)
  EndIf 
  
  If CreatePopupMenu(0) 
    MenuItem(1, "Alpha, 25%") 
    MenuItem(2, "Alpha, 50%") 
    MenuItem(3, "Alpha, 75%") 
    MenuItem(4, "Alpha, 100%") 
    MenuBar() 
    MenuItem(0, "Exit") 
  EndIf 
  
  HideWindow(0, #False) 
  
  Repeat 
    Select WaitWindowEvent(25) 
      Case #PB_Event_Menu 
        Select EventMenu() 
          Case 1: AlphaWindow(0, #Green, 25) 
          Case 2: AlphaWindow(0, #Green, 50) 
          Case 3: AlphaWindow(0, #Green, 75) 
          Case 4: AlphaWindow(0, #Green, 100) 
          Case 0: Break 
        EndSelect 
      Case #PB_Event_CloseWindow 
        Break 
      Case #PB_Event_Gadget 
        Select EventType() 
          Case #PB_EventType_LeftClick:  MoveWindow(0) 
          Case #PB_EventType_RightClick: DisplayPopupMenu(0, WindowID(0)) 
        EndSelect 

    EndSelect 
  ForEver 
  
EndIf 

End 

Posted: Tue May 09, 2006 12:47 am
by netmaestro
OK, I see what you mean. The native size of the clock is 144, any other size is probably going to have an annoying color around it in floating mode. It'll look fine against a window. I don't know if anything can be done about that.

Posted: Tue May 09, 2006 12:51 am
by mskuma
@netmaestro, on my machine, the latest demo code using the gadget produced a clock with a green ring inside the clock, whereas Flype's version was fine. I also had no colour problem with Flype's previous version using the lib (I think I grabbed the lib before it was updated).

@Flype - thanks so much for illustrating some excellent demo applications.

Between the 2 of you, it's a wonderful thing to see.. Thanks alot netmaestro & Flype for your time. :)

Posted: Tue May 09, 2006 1:01 am
by mskuma
I assume this gadget goes into \PureLibraries\UserLibraries

When using the gadget version, should the dll & lib version be discarded? I guess it would make sense. I've noticed some weird things going on (e.g. clock appears with no min/hour hands) if I run the gadget version of Flype's demo code, and the dll & lib are left in the same folder as the pb code.

Posted: Tue May 09, 2006 12:59 pm
by Trond
netmaestro wrote:I surfed around to various sites where the new Windows Vista clock is shown, did screenshots and started from there. (hence the name "vista clock"). The images had to be seriously cut up and all the alpha layer stuff built from scratch and added in Photoshop, drop shadows & highlights, and I had to make a glass crystal. If you're not very skilled in Photo editing you'll probably find it difficult. I wouldn't mind giving you what I have but yours should probably have its own look.
Yes, I can do it from scratch. Besides, I can make it customizable.

Posted: Wed May 10, 2006 12:33 am
by mskuma
Going back to the original DLL version of the clock..
mskuma wrote:in this demo I can't see anything.. I've checked the return value from the openlibrary function & it's non-zero so I guess it's loading ok but no clock.
I finally realised why this happened with the DLL. Maybe you can reproduce it to double-check it. My default compiler option setting is 'create unicode executable'. When that is checked, no clock. When unchecked, I see the clock. This issue is non-existent for the lib version. Maybe this is a bug? I've noticed a similar problem with another DLL. [edit: this problem seems to be there with PB4 final. It would be great If some people could kindly double-check this issue & report here, before I raise a bug].

Posted: Thu May 11, 2006 5:59 am
by mskuma
This is kinda straying off topic, but I've found a solution to the above 'create unicode exe' issue. After reading about prototypes in the help, and it perhaps suggesting it was 'unicode friendly', I tried to convert the original DLL code to a prototype version & I could see a clock now with 'create unicode exe' compiler setting. Thanks to Flype for giving a good code example elsewhere about prototype usage (it helped me alot :) )

Code: Select all

; Add a clock gadget to your gui 

If OpenLibrary(0,"VistaClock128.dll") = #False 
  Debug "DLL load fail"
  End 
EndIf 

Prototype InitClock(colour.l, floatFlag.l) 
Prototype UpdateClock() 

InitClock.InitClock = GetFunction(0,"InitClock") 
UpdateClock.UpdateClock = GetFunction(0,"UpdateClock") 

OpenWindow(0,0,0,320,240,"VistaClock",#PB_Window_ScreenCentered|#PB_Window_SystemMenu) 
CreateGadgetList(WindowID(0)) 
ImageGadget(0,80,40,144,144,0) 

InitClock(RGB(224,223,227), 0) ; pass it your window color and 0 = no floating. 

Repeat 
  EventID=WaitWindowEvent(1) 
  
  ret = UpdateClock()
  If ret 
    SetGadgetState(0,ret) 
  EndIf 
Until EventID=#PB_Event_CloseWindow
I'm still struggling to understand why the original CallFunction style would fail. [edit: I'm raising this question as a new topic >here<- this code hopefully will be of interest to someone..]

Posted: Wed Feb 07, 2007 5:49 am
by Rook Zimbabwe
well I would love to see this... the second libnk does not work for me... ad 1 silly question... where do we put the gadget file?

Posted: Tue Jan 22, 2008 10:37 pm
by Rook Zimbabwe
Netmaestro... I have two clocks in my program in two different windows.

One is #Clock and one is #Clock_A in enumeration.

However the first one is simply a black square...

Is this due to the resources (PNG files) it uses?

My program is quite large (4788+ lines) but I feel your clock gadget will be a nice addition. I would hope I can use it.

:)

Help!!!

{{The following is only sample code... but no clocks show up!}}

Code: Select all


Enumeration
  #Window_1
  #Window_0
EndEnumeration

Enumeration
  #Button_1
  #Clock
  #Button_0
  #Clock_A
EndEnumeration

Structure VisualDesignerGadgets
  Gadget.l
  EventFunction.l
EndStructure

Global NewList EventProcedures.VisualDesignerGadgets()

Procedure Button_1_Event(Window, Event, Gadget, Type)
  Debug "#Button_1"
EndProcedure

Procedure Clock_Event(Window, Event, Gadget, Type)
  Debug "#CLOCK"
EndProcedure

Procedure Button_0_Event(Window, Event, Gadget, Type)
  Debug "#Button_0"
EndProcedure

Procedure Clock_A_Event(Window, Event, Gadget, Type)
  Debug "#CLOCK _ A"
EndProcedure

Procedure RegisterGadgetEvent(Gadget, *Function)
  
  If IsGadget(Gadget)
    AddElement(EventProcedures())
    EventProcedures()\Gadget        = Gadget
    EventProcedures()\EventFunction = *Function
  EndIf
  
EndProcedure

Procedure CallEventFunction(Window, Event, Gadget, Type)
  
  ForEach EventProcedures()
    If EventProcedures()\Gadget = Gadget
      CallFunctionFast(EventProcedures()\EventFunction, Window, Event, Gadget, Type)
      LastElement(EventProcedures())
    EndIf
  Next
  
EndProcedure

Procedure Open_Window_0()
  
  If OpenWindow(#Window_0, 5, 5, 400, 185, "Window 0",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
      VistaClockGadget(#Clock,10, 10, 140, 140, GetSysColor_(#COLOR_BTNFACE), 0) 
      RegisterGadgetEvent(#Clock, @Clock_Event())
      ButtonGadget(#Button_0, 222, 24, 162, 36, "GO TO Window 1")
      RegisterGadgetEvent(#Button_0, @Button_0_Event())
      
    EndIf
  EndIf
EndProcedure

Procedure Open_Window_1()
  If OpenWindow(#Window_1, 62, 52, 400, 185, "Window 1",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_1))
      VistaClockGadget(#Clock_A,222, 10, 140, 140, GetSysColor_(#COLOR_BTNFACE), 0) 
      RegisterGadgetEvent(#Clock_A, @Clock_A_Event())
      ButtonGadget(#Button_1, 12, 12, 168, 36, "Back to WINDOW 0")
      RegisterGadgetEvent(#Button_1, @Button_1_Event())
    EndIf
  EndIf
EndProcedure
Open_Window_1()

Open_Window_0()

Repeat
  
  Event  = WaitWindowEvent()
  Gadget = EventGadget()
  Type   = EventType()
  Window = EventWindow()
  
  Select Event
    Case #PB_Event_Gadget
      CallEventFunction(Window, Event, Gadget, Type)
      
  EndSelect
  
Until Event = #PB_Event_CloseWindow

End
8)

Posted: Thu Jan 24, 2008 2:44 am
by Q*bert
Is this still available for download somewhere?

None of the links seem to work...