Page 1 of 1

Posted: Sat Mar 02, 2002 9:17 am
by BackupUser
Restored from previous forum. Originally posted by PB.

I haven't actually coded a multiple-window app yet, and I was testing one today.
However, when I close the second window, the first one spits the dummy about
objects not being initialized.

So rather than waste time by asking if anyone could debug it, could someone please
just post a small example here that does the following:

(1) Opens an initial window with a single ButtonGadget on it.
(2) When clicking this gadget, a second window opens, also with its own Button.
(3) When clicking the second window's button, a messagebox pops up.
(4) When clicking the close gadget on the second window, it closes.

Sound simple? Well, it's not working for me! Please enlighten me...


PB - Registered PureBasic Coder

Edited by - PB on 02 March 2002 11:07:18

Posted: Sat Mar 02, 2002 2:05 pm
by BackupUser
Restored from previous forum. Originally posted by tranquil.

Hi PB,

where is your problem!? I do this in my app and it works fine. I found no problems.
I opened a new window, create a new Gadgetlist to this (dont forget this, or it will not work!) and then attaching new gadgets to it.

Try this, if this is the problem you have, otherwise I will code a small x-ample tomorrow for you if you still want it.

Bye

Tranquilizer/ Secretly!
Registred PureBasic User

Posted: Sat Mar 02, 2002 3:11 pm
by BackupUser
Restored from previous forum. Originally posted by MrVainSCL.

Hmm... Yes tranquil, you do this in our big project without any problems... Do you remember when i told you the small problem when opening a new (second) window and if you close this, the first will be closed too? :wink: I found a small way for my test app... But when we started coding on our final big project, we get managed it without trouble...

PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten

Posted: Sat Mar 02, 2002 3:43 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.

Hey PB, you asked this back in September and Mr.Skunk gave you the solution.
Here is my version of his answer with a little more error checking:

Code: Select all

InitGadget(2)
hWnd1=OpenWindow(0,100,100,200,250,#PB_Window_SystemMenu,"Main Window")
hWnd2=OpenWindow(1,200,200,200,250,#PB_Window_SystemMenu|#WS_VISIBLE,"Sub Window")
If hWnd1=0 Or hWnd2=0:End:EndIf
; 
If CreateGadgetList(hWnd1)
  ButtonGadget(1,20,20,100,30,"Open Window")
EndIf
If CreateGadgetList(hWnd2)
  ButtonGadget(2,20,20,100,30,"Message")
EndIf
; 
totalwindow=1
Repeat
  EventID.l = WaitWindowEvent()
  If EventID=#PB_EventCloseWindow
    If totalwindow=1 And EventWindowID()=0
      totalwindow-1
    EndIf   
    If totalwindow=2 And EventWindowID()=1
      ShowWindow_(hWnd2,0)
      totalwindow-1      
    EndIf
  EndIf   
;
  If EventID=#PB_EventGadget
    Select EventGadgetID()
      Case 1
      If totalwindow=1
        totalwindow+1
        ShowWindow_(hWnd2,1)
      EndIf 
;
      Case 2
      MessageRequester("Test","This is a test",0)
    EndSelect
  EndIf
;
Until totalwindow=0
End

Posted: Sat Mar 02, 2002 8:28 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> you asked this back in September and Mr.Skunk gave you the solution.

I know I asked back then, but Mr Skunk's solution doesn't apply to what I'm
doing, which is why I asked again.

Okay, here's the problem: I've got 2 source files, both windows. Both are
resizable, in that resizing either makes all gadgets on either resize to match.

Now, when I click a button on the first window to open the second, and then I
close the second, the first window crashes. The two files are too long to post
here, so I've put them here so you (or anyone else) can take a look and see
what I'm doing wrong. Thanks!

http://www.bowlay.com/Test.zip

Hope you can solve this for me...

PB - Registered PureBasic Coder

Posted: Sat Mar 02, 2002 8:58 pm
by BackupUser
Restored from previous forum. Originally posted by cor.
Okay, here's the problem: I've got 2 source files, both windows. Both are
resizable, in that resizing either makes all gadgets on either resize to match.

Now, when I click a button on the first window to open the second, and then I
close the second, the first window crashes

PB - Registered PureBasic Coder
I tested it like you said in the readme file.
No crash on my system.

I use Win 98 SE Dutch version
Compiling with PB 2.95


Using Windows 98 SE
Registered PB version : 2.90 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com

Posted: Sat Mar 02, 2002 9:04 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> I tested it like you said in the readme file.
> No crash on my system.

Thanks for looking at it.

Now then... please make an exe of it and try this:

(1) Maximize the first window and then restore it. All gadgets resize.
(2) Click "Cmd" at the bottom-middle of the first window.
(3) Close the second window immediately.
(4) Maximize the first window again -- no gadgets resize (Bug #1).
(5) Restore the first window's size again.
(6) Click "Cmd" again and maximize the second window.
(7) Click the button on the second window, and close the second window.
(8) Repeat steps (6) and (7) a few times and the app will crash (Bug #2).

What to do?

PB - Registered PureBasic Coder

Edited by - PB on 02 March 2002 21:22:27

Posted: Sat Mar 02, 2002 10:44 pm
by BackupUser
Restored from previous forum. Originally posted by cor.
> I tested it like you said in the readme file.
> No crash on my system.

Thanks for looking at it.

Now then... please make an exe of it and try this:
No, I have the same problem as you.

Error at kernel dll



Using Windows 98 SE
Registered PB version : 2.90 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com

Posted: Sat Mar 02, 2002 10:55 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> Here is my version of his answer with a little more error checking:

Thanks for your example, Paul, but... I notice your app doesn't close the
windows but merely just hides them. I don't know if that gives a toll on
the system -- what if each hidden window is around 100k in size? Also, your
example would be impractical with many windows -- what if the user was to
have say 20 of these "secondary" windows? That's why I'd prefer just to
IncludeFile the secondary windows instead, as it makes editing the overall
app much easier.

Or is that the wrong approach to take? I'm open to suggestions...


PB - Registered PureBasic Coder

Posted: Sat Mar 02, 2002 11:51 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
> you asked this back in September and Mr.Skunk gave you the solution.

I know I asked back then, but Mr Skunk's solution doesn't apply to what I'm
doing, which is why I asked again.

Okay, here's the problem: I've got 2 source files, both windows. Both are
resizable, in that resizing either makes all gadgets on either resize to match.

Now, when I click a button on the first window to open the second, and then I
close the second, the first window crashes. The two files are too long to post
here, so I've put them here so you (or anyone else) can take a look and see
what I'm doing wrong. Thanks!

http://www.bowlay.com/Test.zip

Hope you can solve this for me...

PB - Registered PureBasic Coder
OK, i've checked your code some... So here's some suggestions.
first put UseGadgetList(WindowID()) inside your 'DrawItems()' procedure i did it like this:

Code: Select all

Procedure Form1_DrawItem(hWnd.l)
  UseGadgetList(hWnd)
  ...
EndProcedure
...
Form1_DrawItem(Form1_hWnd)
...
My second tip is to use unique gadget numbers for all your forms.
The third tip is to remove InitGadget in all forms except from the main form and thus avoid the "#Gadget object number out of range"-error
Also when you come back from closing the other window you should use UseWindow(0) to make the window the current one.

Hope this will help some, i got it to work pretty well, if you can't seem to make my suggested changes work i could send the altered files to you...

Posted: Sun Mar 03, 2002 1:10 am
by BackupUser
Restored from previous forum. Originally posted by PB.

> if you can't seem to make my suggested changes work i could send the
> altered files to you...

Thanks, Pupil (I got the E-Mail): I didn't realise that InitGadget was only
supposed to be used ONCE in code, and that UseGadgetList was needed when
activating different windows.


Edited by - PB on 03 March 2002 05:28:14

Posted: Sun Mar 03, 2002 6:22 am
by BackupUser
Restored from previous forum. Originally posted by Franco.
I didn't realise that InitGadget was only supposed to be used ONCE in code, and that UseGadgetList was needed when activating different windows.
...well it is since version 2.8 (if I recall it right).
Before that I used to use InitGadget more than once, but code with that didn't work after upgrading.
Don't know why Fred changed this.


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.