May 27, 2024, 05:06:11 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Found A Problem

Started by Zen, December 15, 2005, 06:51:28 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zen

I was just messing around creating some windows and i noticed that CenterWindow does not have an optional peramater to Center a window other that itself.

Is this right or am i just doing things wrong? How can you center another window?

Lewis

Ionic Wind Support Team

CenterWindow is a method of the Window class.   Mywindow.CenterWindow(); YourWindow.CenterWindow(); etc.   

It can only be called by an instance of the class, and not externally.

However there is a trick if you were trying to center an external control.

Paul.
Ionic Wind Support Team

Zen

i guess i would have to make the class variable global though if i wanted to center a window from another source file?

Lewis

Ionic Wind Support Team

Methods are always global.  Perhaps if you show a little code snippet I could help you a bit more.

Global class variables are not recommended and aren't constructed by the compiler yet.   A global class pointer is usable and most OOP GUI toolkits use one to get a handle to the main 'app'.
global TheApp;
MyAppClass *TheApp;

global sub main()
{
MyAppClass ma;
TheApp = &ma;
...
}

The in some other file

extern MyAppClass *TheApp;

--------------

Ionic Wind Support Team

Zen

I didnt actually try to do it from another source file. Its was just something i thought of when i first made this post (how do you do it).

But i know now.

Thanks for clearing that up.
Lewis

Zen

Ok i think this time i might of actually found a problem. lol.

Ive tried to close a window within the main subroutine not from my windows class. Ive tried to use win.Destroy() and it just freezes up.

How can i close a window without listening to the OnClose() method?

Lewis

Ionic Wind Support Team

Are you trying to close after your WAIT loop exits?  All window based classes automatically destroy their windows when the variable goes out of scope so it is usually not necessary to call Destory in your main subroutine.

Please provide code when you ask questions like this.  I am not a mindreader ;)
Ionic Wind Support Team

Zen

Quote
I am not a mindreader
Ohh, i was kind of hoping you were. :D

Heres the code.

Within "global sub main()"


/* Define Variables */

string Version;
pointer pXMLDoecument;
myWindow Main;

/* Initialize Variables */

Version = "Alpha 1";

/* Create The Main Window */

Main.Create(0,0,640,480,AWS_DEFAULT,0,"Control Panel - " + Version,NULL);

pXMLDocument = xmlLoadFile("Package.xml");

if(pXMLDocument = null) {

MessageBox(Main,"Failed To Open XML File","XML Error");
//Main.Destroy();

}

/* Wailt Until Window Is Closed */

do {

wait();

} until Main.m_hwnd = 0;


Lewis

Ionic Wind Support Team

You have to process messages for a window to be created properly.  And before it can be destroyed (closed). 

What your attempting to do is create a window and then immediatly destory it.  Destory does nothing because the messages needed to create the window have not been processed.  Causing an out of order condition.

You should try and load the file first, before creating the window, and then just give the message box and return.  IF you really want to see the window appear for a second during that error condition then process some messages after the window is created.

for(x=0;x<50;x++)
{
   wait(1);
}

And before you try and destroy it.

Ionic Wind Support Team

Zen

But the window does open on my computer. It opens the window, if it cant find the file it displays the message box and then i was hoping for it to close.

That is by no means finished at all. I was just trying different things whilst im still learning. Suppose it is much later on in the program and i want to close it, how would i actually go about doing it?

Lewis

Ionic Wind Support Team

Your WAIT loop is what processes messages.

DO
{
wait();
} until condition;

Later on in your program messages will be processed.  It's just right after the Create call you can't close until Windows itself is finished with the creation process.  When a window is created the OS sends many messages to the handler

WM_CREATE
WM_NCCREATE
WM_SIZE
WM_SIZING
WM_PAINT

And many others before the window is ready to use.  Your program is message based.

Paul.
Ionic Wind Support Team

Zen

So how do i actually close the window if im not trying to close it from within a class method?

Lewis

Ionic Wind Support Team

December 17, 2005, 10:06:07 AM #12 Last Edit: December 17, 2005, 10:07:38 AM by Ionic Wizard
You can do it with Destory().   Just not right after the Create statement.  Understand?

How about this logic:


/* Create The Main Window */

quit = false;

Main.Create(0,0,640,480,AWS_DEFAULT,0,"Control Panel - " + Version,NULL);

pXMLDocument = xmlLoadFile("Package.xml");

if(pXMLDocument = null) {

MessageBox(Main,"Failed To Open XML File","XML Error");
quit = true;

}

/* Wailt Until Window Is Closed */

do {

wait();

} until (Main.m_hwnd = 0) OR quit;



This allows the creation messages to be processed while allowing an early exit from your program.  Failure to load the XML file sets 'quit = true' which will drop out of the wait loop after the first group of messages have been processed.   

The window is automatically destroyed when the subroutine exits.  But you can safely call Destroy.


do {

wait();

} until (Main.m_hwnd = 0) OR quit;

Main.Destroy();


My point is a Windows program must process messages if a window is created.  And it must do so before the window is destroyed.  It would have the same results in IBasic Pro, or C, or any other language.

Paul.
Ionic Wind Support Team

Zen

the reason i tried to do it how i did is because in IBasic you can do it like this.


OPENWINDOW Main,0,0,800,600,@SYSMENU|@CAPTION|@NOAUTODRAW|@MINBOX|@MAXBOX|@SIZE,0,"Window 1",&MainHandler
CLOSEWINDOW Main


I just wondered why it could not be done in Aurora too.

Lewis

Ionic Wind Support Team

And you can in Aurora too


global sub main()
{
window win;
win.Create(0,0,400,300,AWS_CAPTION|AWS_VISIBLE|AWS_BORDER|AWS_SYSMENU|AWS_AUTODRAW|AWS_SIZE,0,"Lines",NULL);
win.Destroy();
return;
}


Guess I wasn't being too clear.  Lets try again...

If you create a window, and immediately call destroy, you shoudn't enter a message loop if it is the only window in your program.  The loop will wait forever for the messages from the now invalid window.  Causing a deadlock condition.

I gave you an example of how you could make your program work.  You could also just 'return' after the destroy in your load file test.

Paul.
Ionic Wind Support Team

Zen

I thought thats what i tried to do though. Obviously doing the if statement to see if the XML file loaded didnt work. I think i like the return idea better, ill try that.

Lewis