Cannot select main window after opening & Closing a seco

Just starting out? Need help? Post your questions and find answers here.
Arcee_uk
User
User
Posts: 29
Joined: Fri Jul 25, 2008 6:09 am
Location: England

Cannot select main window after opening & Closing a seco

Post by Arcee_uk »

Hi.

I am having trouble returning focus back to my main window after lunching a second window off a gadget icon selection.

This is my main loop (the Debug commands are there to tell me what has focus at key points, the DisplayEntry() line is a procedure which displays data on this screen and is not relavant to the problem):

Code: Select all

If Window_WindowMain()
  SetWindowCallback(@WindowCallback())

DisplayEntry()
Debug "Entry Displayed on main window: " + Str(GetActiveWindow())
  quitWindowMain=0
  Repeat
    EventID  =WaitWindowEvent()
    MenuID   =EventMenu()
    GadgetID =EventGadget()
    WindowID =EventWindow()

    Select EventID
      Case #PB_Event_CloseWindow
        If WindowID=#Window_WindowMain
          quitWindowMain=1
        EndIf


      Case #PB_Event_Gadget
        Select GadgetID
          Case #Gadget_WindowMain_MagCover
            Select EventType()
              Case #PB_EventType_LeftDoubleClick
              Case #PB_EventType_RightDoubleClick
              Case #PB_EventType_RightClick
              Default
            EndSelect
          Case #Gadget_WindowMain_Panel3
          Case #Gadget_WindowMain_Mdb_ExitButton
            Exit_Mdb()
          Case #Gadget_WindowMain_Mdb_No
          Case #Gadget_WindowMain_Mdb_Search
          Case #Gadget_WindowMain_Mdb_Yes
          Case #Gadget_WindowMain_Mdb_Del
          Case #Gadget_WindowMain_Mdb_Edt
          Case #Gadget_WindowMain_Mdb_Add
            NewEntry_WindowSwapTo()          
            NewEntry_MainLoop()
            NewEntry_WindowSwapBack()
            Debug "Back To Main Loop: " + Str(GetActiveWindow())
            SetActiveWindow(#Window_WindowMain) 
            Debug "SetActiveWindow command run: " + Str(GetActiveWindow())
          Case #Gadget_WindowMain_Mdb_Prev
          Case #Gadget_WindowMain_Mdb_Next
          Case #Gadget_WindowMain_Mdb_Config
        EndSelect

    EndSelect
  Until quitWindowMain
  CloseWindow(#Window_WindowMain)
EndIf
End
It calls three routines to enable the opening/access/closing of the second window. These are:

Code: Select all

Procedure NewEntry_MainLoop()

Repeat 

Until WaitWindowEvent() = #PB_Event_CloseWindow 

EndProcedure

Procedure NewEntry_WindowSwapTo()
Debug "About to Open NewEntry Window: " + Str(GetActiveWindow())
DisableWindow(#Window_WindowMain,1) 
HideWindow(#Window_WindowMain,1) 
Window_WindowNewEntry()
 Debug "NewEntry Window Open: " + Str(GetActiveWindow())
EndProcedure

Procedure NewEntry_WindowSwapBack()
DisableWindow(#Window_WindowNewEntry,1) 
HideWindow(#Window_WindowNewEntry,1) 
CloseWindow(#Window_WindowNewEntry)
Debug "NewEntry Closed: " + Str(GetActiveWindow())
HideWindow(#Window_WindowMain,0) 
EndProcedure
When I run it I get the following results from the Debug Command:


Entry Displayed on main window: 1
About to open NewEntry Window: 1
NewEntry WIndow Open: 2
NewEntry Closed: -1
Back to Main Loop: 1
SetActiveWindow Command run: 1


To me this says the main window (1) is active until the NewEntry Window (2) is opened so focus is switched to that. When I close the window nothing has focus (-1) and then when the main window (1) is unhidden focus goes back to that.


But when I try to click on the window I get the alarm "ding" sound when I click the mose anywhere on thw window and the window cannot be selected or touched. I cannot close the window and have to force PB to kill the program,

Can anyone explain why this happening and guide me on how to correct it so I get the main window back after the NewEntry one closes.

Many thanks

Arcee
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Can you post code that actually runs as well as shows the problem you are experiencing?
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

yap, post executable code pse.
oh... and have a nice day.
Arcee_uk
User
User
Posts: 29
Joined: Fri Jul 25, 2008 6:09 am
Location: England

Post by Arcee_uk »

The full code is:


Removed as not what was asked for. Opppsss..

I hope that helps.
Last edited by Arcee_uk on Wed Aug 13, 2008 7:08 pm, edited 1 time in total.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

What I was asking for was a bare bones example (sans any external includes/ dependencies) that shows the problem. I still cannot execute the code as posted so I can't be of any help.

In other words, can you post executable code that shows a problem like...
Arcee_uk wrote:...returning focus back to my main window after lunching a second window off a gadget icon selection.
Eliminate external dependencies and this should help narrow down the culprit. ;)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Arcee_uk
User
User
Posts: 29
Joined: Fri Jul 25, 2008 6:09 am
Location: England

Post by Arcee_uk »

Sparkie wrote:What I was asking for was a bare bones example (sans any external includes/ dependencies) that shows the problem. I still cannot execute the code as posted so I can't be of any help.

In other words, can you post executable code that shows a problem like...
Arcee_uk wrote:...returning focus back to my main window after lunching a second window off a gadget icon selection.
Eliminate external dependencies and this should help narrow down the culprit. ;)
Sorry I misunderstood. In that case go with these bits:

test.pb

Code: Select all

XIncludeFile "test_Constants.pb"
XIncludeFile "test_Windows.pb"


;{ Custom Includes
XIncludeFile "Includes\New_Entry_Handling.pb"
;}






;- Main Loop
If Window_Form1()

  quitForm1=0
  Repeat
    EventID  =WaitWindowEvent()
    MenuID   =EventMenu()
    GadgetID =EventGadget()
    WindowID =EventWindow()

    Select EventID
      Case #PB_Event_CloseWindow
        If WindowID=#Window_Form1
          quitForm1=1
        EndIf


      Case #PB_Event_Gadget
        Select GadgetID
          Case #Gadget_Form1_String4
          Case #Gadget_Form1_Button5
            NewEntry_WindowSwapTo()          
            NewEntry_MainLoop()
            NewEntry_WindowSwapBack()
            Debug "Back To Main Loop: " + Str(GetActiveWindow())
            SetActiveWindow(#Window_Form1) 
        EndSelect

    EndSelect
  Until quitForm1
  CloseWindow(#Window_Form1)
EndIf
End
test_Windows.pb

Code: Select all

XIncludeFile "test_Constants.pb"


Procedure.l Window_Form1()
  If OpenWindow(#Window_Form1,289,220,400,300,"Work Form1",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
    If CreateGadgetList(WindowID(#Window_Form1))
      TextGadget(#Gadget_Form1_Text2,165,100,60,15,"Text2")
      TextGadget(#Gadget_Form1_Text3,55,190,60,15,"Text3")
      StringGadget(#Gadget_Form1_String4,230,185,80,20,"")
      ButtonGadget(#Gadget_Form1_Button5,55,105,60,20,"Button5")
      HideWindow(#Window_Form1,0)
      ProcedureReturn WindowID(#Window_Form1)
    EndIf
  EndIf
EndProcedure


Procedure.l Window_Form6()
  If OpenWindow(#Window_Form6,173,159,760,609,"Work Form6",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
    If CreateGadgetList(WindowID(#Window_Form6))
      HideWindow(#Window_Form6,0)
      ProcedureReturn WindowID(#Window_Form6)
    EndIf
  EndIf
EndProcedure

test_Constants.pb

Code: Select all

;- Global Variables and Constants
Global BubbleTipStyle.l:BubbleTipStyle=0

;- Window Constants
Enumeration 1
  #Window_Form1
  #Window_Form6
EndEnumeration
#WindowIndex=#PB_Compiler_EnumerationValue


;- Gadget Constants
Enumeration 1
  ;Window_Form1
  #Gadget_Form1_Text2
  #Gadget_Form1_Text3
  #Gadget_Form1_String4
  #Gadget_Form1_Button5


  ;Window_Form6
EndEnumeration
#GadgetIndex=#PB_Compiler_EnumerationValue
Very quick and rough windows created and exported from PurevisonXP. Same control code in the same sort and resulting in the same problem. Should run off any PC without any problems as no external files / bits needed.

When you exit the second window the first original window to open cannot be selected in any respect and I have to physically "Kill" the program within PB to close it down, rather than use the exit button on the top right.


I hope this helps.

Arcee
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

Arcee_uk wrote:

Code: Select all

XIncludeFile "Includes\New_Entry_Handling.pb"
holy cow! Image
... seems to be incredibly difficult to post a snippet of code we could copy/paste into the IDE and run...
oh... and have a nice day.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

:lol:
I may look like a mule, but I'm not a complete ass.
Arcee_uk
User
User
Posts: 29
Joined: Fri Jul 25, 2008 6:09 am
Location: England

Post by Arcee_uk »

Kaeru Gaman wrote:
Arcee_uk wrote:

Code: Select all

XIncludeFile "Includes\New_Entry_Handling.pb"
holy cow! Image
... seems to be incredibly difficult to post a snippet of code we could copy/paste into the IDE and run...
I'll ignore the scarcasm....

I forgot that bit as it was posted before. but to clarify and reconfirm (and make sure EVERYONE can see all the code needed etc):

New_Entry_Handling.pb

Code: Select all

Procedure NewEntry_MainLoop()

;NewEntry_WindowSwapTo()

Repeat 

Until WaitWindowEvent() = #PB_Event_CloseWindow 

;NewEntry_WindowSwapBack()

EndProcedure

Procedure NewEntry_WindowSwapTo()

DisableWindow(#Window_Form1,1) 
HideWindow(#Window_Form1,1) 
Window_Form6() 
        
EndProcedure

Procedure NewEntry_WindowSwapBack()

DisableWindow(#Window_Form6,1) 
HideWindow(#Window_Form6,1) 
CloseWindow(#Window_Form6)
HideWindow(#Window_Form1,0) 

EndProcedure
My oversight.

Arcee
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

On closing the second window the first one remains disabled because of the DisableWindow(#Window_Form1,1).

You thus need to add a DisableWindow(#Window_Form1,0) at an appropriate juncture; probably in the NewEntry_WindowSwapBack() procedure.
I may look like a mule, but I'm not a complete ass.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

Arcee_uk wrote:I'll ignore the scarcasm....
you don't need to... it was free of charge.


> (and make sure EVERYONE can see all the code needed etc)

to clarify: YOU asked for help. none of us earns wages to help you!
so, make it easier for people to help you.

if you had posted a single runable code at first, you possibly would have had an answer last night...
oh... and have a nice day.
Arcee_uk
User
User
Posts: 29
Joined: Fri Jul 25, 2008 6:09 am
Location: England

Post by Arcee_uk »

srod wrote:On closing the second window the first one remains disabled because of the DisableWindow(#Window_Form1,1).

You thus need to add a DisableWindow(#Window_Form1,0) at an appropriate juncture; probably in the NewEntry_WindowSwapBack() procedure.
Thank you. I had a feeling it would be something simple and obvious I had missed!

Got it, placed the command: DisableWindow(#Window_Form1,0) just before the first window is called back into view and bingo, works a teat.

Thanks again Srod for pointing that out. Sometimes you cannot see the wood for all the trees....

Arcee
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Glad it helps.

You do need to post as small a snippet as possible though. Copying code directly from PureVision does make things a little difficult for those who would otherwise help out. Normally a problem like this would have been solved in a matter of minutes! :)
I may look like a mule, but I'm not a complete ass.
Arcee_uk
User
User
Posts: 29
Joined: Fri Jul 25, 2008 6:09 am
Location: England

Post by Arcee_uk »

srod wrote:Glad it helps.

You do need to post as small a snippet as possible though. Copying code directly from PureVision does make things a little difficult for those who would otherwise help out. Normally a problem like this would have been solved in a matter of minutes! :)
Points taken on board. I will bear this in mind the next time I need to seek help.

I appreicate it is a pain to look at other peoples work as it is often done differnetly to how the person examiniing it may approach the problem.

Thanks again.

Arcee
Post Reply