Page 1 of 1

Cannot select main window after opening & Closing a seco

Posted: Tue Aug 12, 2008 10:59 pm
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

Posted: Wed Aug 13, 2008 12:08 am
by Sparkie
Can you post code that actually runs as well as shows the problem you are experiencing?

Posted: Wed Aug 13, 2008 12:15 am
by Kaeru Gaman
yap, post executable code pse.

Posted: Wed Aug 13, 2008 5:54 am
by Arcee_uk
The full code is:


Removed as not what was asked for. Opppsss..

I hope that helps.

Posted: Wed Aug 13, 2008 1:01 pm
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. ;)

Posted: Wed Aug 13, 2008 7:08 pm
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

Posted: Wed Aug 13, 2008 7:27 pm
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...

Posted: Wed Aug 13, 2008 7:41 pm
by srod
:lol:

Posted: Wed Aug 13, 2008 7:43 pm
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

Posted: Wed Aug 13, 2008 7:48 pm
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.

Posted: Wed Aug 13, 2008 7:56 pm
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...

Posted: Wed Aug 13, 2008 8:22 pm
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

Posted: Wed Aug 13, 2008 8:26 pm
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! :)

Posted: Wed Aug 13, 2008 8:44 pm
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