Simple non-modal custom dialog box closing automatically

Share your advanced PureBasic knowledge/code with the community.
infratec
Always Here
Always Here
Posts: 7620
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Simple non-modal custom dialog box closing automatically

Post by infratec »

A version which uses #PB_Window_WindowCentered.
And don't generate an error :mrgreen:
Therfore UnbindEvent() was needed.

Code: Select all

Procedure CloseAboutWindow()
  
  Protected Win.i
  
  Win = EventWindow()
  
  If GetWindowData(Win)
    RemoveWindowTimer(Win, 1)
    UnbindEvent(#PB_Event_Timer, @CloseAboutWindow(), Win)
  EndIf
  UnbindEvent(#PB_Event_DeactivateWindow, @CloseAboutWindow(), Win)
  CloseWindow(Win)
  
EndProcedure


Procedure About(Timeout.i=0)
  
  Protected Win.i
  
  Win = OpenWindow(#PB_Any, 0, 0, 200, 100, "About", #PB_Window_Tool | #PB_Window_WindowCentered, WindowID(GetActiveWindow()))
  
  TextGadget(#PB_Any, 10, 10, 100, 20, "This is a demo")
  BindEvent(#PB_Event_DeactivateWindow, @CloseAboutWindow(), Win)
  If Timeout
    SetWindowData(Win , #True)
    AddWindowTimer(Win, 1, Timeout)
    BindEvent(#PB_Event_Timer, @CloseAboutWindow(), Win)
  EndIf
  
EndProcedure


Define.i Event

OpenWindow(0, 0, 0, 400, 300, "Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateMenu(0, WindowID(0))
MenuTitle("Help")
MenuItem(1, "About")


About(2000)

Repeat
  
  Event = WaitWindowEvent()
  
  Select Event
    Case #PB_Event_Menu
      If EventMenu() = 1
        About()
      EndIf
  EndSelect
  
Until Event = #PB_Event_CloseWindow
Bernd
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Simple non-modal custom dialog box closing automatically

Post by Blue »

Hi Bernd
You can read into minds now ? Impressive.

I was indeed trying to work out how exactly when, where and how to unBind the event, so i could integrate the genial Bernd Closing Method (gBCM, as we all know it) approach into a large project structured with many modules. It looks, so far, like i won't be able to use separate event loops for different child windows.
Still working it out, so i'll dive into this sometimes this morning, and, garanteed, i'll be back hounding you with questions. :wink:

Presently, i can't avoid being distracted by my smart phone, which is showing me the amazingly squinty face of my first grand-daughter. :shock:
This is a rocking experience, believe me. :o -> :) -> :D -> :lol:

She just stepped into our world 2 hours ago.
Long live [yet unNamed] Baby girl.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
infratec
Always Here
Always Here
Posts: 7620
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Simple non-modal custom dialog box closing automatically

Post by infratec »

Happy Birthday

To .... noname. :mrgreen:
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Simple non-modal custom dialog box closing automatically

Post by Blue »

Isn't it something, to be born in 2015 ?
In 2100, when she turns 75, she'll be coding with
      PureBasic v.272.1 (X64, X128, X256 or X512, your choice)
      (just a bugs correction release)
just like her GrandPa.
Imagine that !
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
blueb
Addict
Addict
Posts: 1116
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Simple non-modal custom dialog box closing automatically

Post by blueb »

Hopefully they can add in the year 2100. :mrgreen: :mrgreen:
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Simple non-modal custom dialog box closing automatically

Post by Blue »

Oh, no, really ? Another bug in PureBasic 6.40 beta 8 ? :shock:
Cross my heart and... Well, you know the rest. :oops:
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
blueb
Addict
Addict
Posts: 1116
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Simple non-modal custom dialog box closing automatically

Post by blueb »

I was referring to the fact that your grandchild will be 85 in 2100 NOT 75! :D
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Simple non-modal custom dialog box closing automatically

Post by Blue »

blueb wrote:I was referring to the fact that your grandchild will be 85 in 2100 NOT 75! :D
I know, BlueB.
I thought i'd get a laugh out of you with some silly attempt at blaming PB for my lousy arithmetic.
Sorry for being obscure. :|
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Simple non-modal custom dialog box closing automatically

Post by Blue »

infratec wrote:A version which uses #PB_Window_WindowCentered.
And don't generate an error :mrgreen:
Therfore UnbindEvent() was needed.
[...code skipped...]

Bernd
Perfect, your version #2. 8)
Your #1 was perfect as well, so I guess this would make #2 plusPerfect (?), of course. :shock:

Version #2 just adds this little extra flexibilty that I didn't even realize i was missing.
And it's a good lesson on where to properly use UnbindEvent().
Thanks.


PS: [Unnamed] baby girl is now known as Charlotte
A name full of promises to come.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Simple non-modal custom dialog box closing automatically

Post by Vera »

Image ~ wishing you lots of fun with your granddad
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Simple non-modal custom dialog box closing automatically

Post by Blue »

Charlotte NMP (newly minted person) says
"Thank you, Vera !
That's the nicest message I've received in my whole life !"


Luckily for you, Vera, I happened to be nearby with my NMC (Newly Minted Code) PB App 8) to decode Charlotte's extensive personal dictionary.
Otherwise, you may have misunderstood her "Arrreuh! Arrreuh!" for something unintelligible.

But then, what are GrandPas for ?
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
Post Reply