June 22, 2024, 07:55:39 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


print behaviour when printing both to the console and in a window/dialog

Started by Dogge, May 16, 2007, 08:48:28 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dogge

This short program shows my problem. I use Print to a window because my background is a gif file and statics doesn't have transparent backgrounds.
I keep the console open to print information when I'm testing and it ends up looking kinda messy in my window.
How can I work around this?

CONST BUTTON_1 = 1
CONST BUTTON_2 = 2
DIALOG d1
CREATEDIALOG d1,0,0,300,202,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@BUTTON,"Print to console",79,21,143,24,0x50000000,BUTTON_1
CONTROL d1,@BUTTON,"Print to window",79,62,143,24,0x50000000,BUTTON_2

openconsole
domodal d1
closeconsole
end

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1
IF @NOTIFYCODE = 0
print "Printing to the console"
ENDIF
CASE BUTTON_2
IF @NOTIFYCODE = 0
move d1, 10,100
print d1, "Printing to my dialog"
ENDIF
ENDSELECT
ENDSELECT
RETURN
ENDSUB


To see the problem just click "print to console" then click "print to window" and then click "print to console" again.

Based on the manuals I don't think it should work like this.

/Douglas

LarryMc

I duplicated your problem exactly.
You're right; it shouldn't act that way.

Paul will probably have to explain this one.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Statics can have transparent backgrounds.  It's a style you set.

If you are going to use PRINT in a dialog then you have to do it in response to the @IDPAINT message.  Dialogs don't double buffer (autodraw)  so anything you PRINT will be lost when the dialog is invalidated (something coverting it like the console).

Paul.
Ionic Wind Support Team

Dogge

Quote from: Paul Turley on May 16, 2007, 10:29:21 AM
Statics can have transparent backgrounds.  It's a style you set.

If you are going to use PRINT in a dialog then you have to do it in response to the @IDPAINT message.  Dialogs don't double buffer (autodraw)  so anything you PRINT will be lost when the dialog is invalidated (something coverting it like the console).

Paul.
I couldn't find the style flag for it in the EBasic documentation and not in the windows.inc file either so I would appreciate if you could point me in the right direction for that.

The behaviour for the print command is the same if I use a regular window. Here is an example.

CONST BUTTON_1 = 1
CONST BUTTON_2 = 2
window d1
openwindow d1,0,0,300,202,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@BUTTON,"Print to console",79,21,143,24,0x50000000,BUTTON_1
CONTROL d1,@BUTTON,"Print to window",79,62,143,24,0x50000000,BUTTON_2
openconsole
run=1
waituntil run=0
closeconsole
end
SUB d1_handler
SELECT @MESSAGE
CASE @IDCLOSEWINDOW
CLOSEwindow d1
run=0
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1
IF @NOTIFYCODE = 0
print "Printing to the console"
ENDIF
CASE BUTTON_2
IF @NOTIFYCODE = 0
move d1, 10,100
print d1, "Printing to my window"
ENDIF
ENDSELECT
ENDSELECT
RETURN
ENDSUB


I am actually using it in a captionless window docked to a dialog. And in this situation I have come across another odd thing but I haven't had time to write a test program to research it more thoroughly.
In a dialog that I open a captionless window which is docked to the dialog so I can show images in it I can't get Tab to work for moving between controls.
I have tabstop on the controls and enabletabs for the window. Have someone seen this and worked around it. if not I'll try to repoduce it in a clean example and post it.

/Douglas

Ionic Wind Support Team

The style flags you have for your dialog would probably not work for a window.  Just an FYI.

Paul.
Ionic Wind Support Team

Dogge

Quote from: Paul Turley on May 16, 2007, 04:21:33 PM
The style flags you have for your dialog would probably not work for a window.  Just an FYI.

Paul.
Yes, thanks, I just changed the CreateDialog command to OpenWindow without changing the flags. Changing the OpenWindow command to proper flags still gives the same result in the end, after printing in my window subsequent print commands that I believe should go to the console are shown in the window.
Knowing that you have a difficult situation right now I'll appreciate if you can look into this when you find the time as I find it very useful for development and debugging.

Thanks
/Douglas

CONST BUTTON_1 = 1
CONST BUTTON_2 = 2
window d1
openwindow d1,0,0,1024,202,@Caption | @SysMenu,0,"Caption",&d1_handler
CONTROL d1,@BUTTON,"Print to console",79,21,143,24,0x50000000,BUTTON_1
CONTROL d1,@BUTTON,"Print to window",79,62,143,24,0x50000000,BUTTON_2
openconsole
run=1
waituntil run=0
closeconsole
end
SUB d1_handler
SELECT @MESSAGE
CASE @IDCLOSEWINDOW
CLOSEwindow d1
run=0
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1
IF @NOTIFYCODE = 0
print "Printing to the console"
ENDIF
CASE BUTTON_2
IF @NOTIFYCODE = 0
move d1, 10,100
print d1, "Printing to my window"
ENDIF
ENDSELECT
ENDSELECT
RETURN
ENDSUB

Ionic Wind Support Team

The console is limited and is meant to be run in text mode only, and is not usually combined with a win32 GUI program.  However you can work around it by using an NULL window variable.


WINDOW con
con.hwnd = 0
....
PRINT somewindow, "hello": Output text to a window
PRINT con, "hello": Force output to the console.

If all you are doing is debugging then consider using DEBUGPRINT and running your program in debug mode.

Paul.

Ionic Wind Support Team

Dogge

Thanks,
Your workaround was what I was looking for, unfortunately I didn't get it to work.
Attaching the code, appreciate your help.

CONST BUTTON_1 = 1
CONST BUTTON_2 = 2

window d1
openwindow d1,0,0,1024,202,@Caption | @SysMenu,0,"Caption",&d1_handler
CONTROL d1,@BUTTON,"Print to console",79,21,143,24,0x50000000,BUTTON_1
CONTROL d1,@BUTTON,"Print to window",79,62,143,24,0x50000000,BUTTON_2
run=1

window con
con.hwnd=0
openconsole

waituntil run=0
closeconsole
end
SUB d1_handler
SELECT @MESSAGE
CASE @IDCLOSEWINDOW
CLOSEwindow d1
run=0
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1
IF @NOTIFYCODE = 0
print con, "Printing to the console"
ENDIF
CASE BUTTON_2
IF @NOTIFYCODE = 0
move d1, 10,100
print d1, "Printing to my window"
ENDIF
ENDSELECT
ENDSELECT
RETURN
ENDSUB


/Douglas

Dogge

Quote from: Paul Turley on May 16, 2007, 05:07:45 PM
If all you are doing is debugging then consider using DEBUGPRINT and running your program in debug mode.

Right now I'm having more problems with logic and behaviour rather than bugs in the code so DEBUGPRINT is an overkill.

Ionic Wind Support Team

Sorry I can't be of more help right now.  It's been a long time since I looked at the assembly code for the PRINT statement, thought that would work but sadly no.

You see the design of the PRINT statement behavior was so you didn't have to keep specifying the window variable.

PRINT win1, "hello"
MOVE win1, 0,20
PRINT "This goes to win1"

One of those rarely used features.  But it is what is causing you grief.

You have a couple of choices.  Use the API to direct text to the console:


CONST BUTTON_1 = 1
CONST BUTTON_2 = 2
declare import, GetStdHandle(number as int),int
declare import, WriteFile(handle as int, text as pointer, length as int),int



window d1
openwindow d1,0,0,1024,202,@Caption | @SysMenu,0,"Caption",&d1_handler
CONTROL d1,@BUTTON,"Print to console",79,21,143,24,0x50000000,BUTTON_1
CONTROL d1,@BUTTON,"Print to window",79,62,143,24,0x50000000,BUTTON_2
run=1

openconsole
stdout = GetStdHandle(-11)

waituntil run=0
closeconsole
end
SUB d1_handler
SELECT @MESSAGE
CASE @IDCLOSEWINDOW
CLOSEwindow d1
run=0
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1
IF @NOTIFYCODE = 0
WriteConsole("Printing to the console")

ENDIF
CASE BUTTON_2
IF @NOTIFYCODE = 0
move d1, 10,100
print d1, "Printing to my window"
ENDIF
ENDSELECT
ENDSELECT
RETURN
ENDSUB

SUB WriteConsole(text as string)
WriteFile(stdout,text+"\n",len(text)+2)
ENDSUB


Or use the API to write text to the window.  The console method is easier ;)

Paul.



Ionic Wind Support Team

Dogge

Thanks!

I'll use the console method, it will be easy to implement in my program.

Your help is much appreciated.

/Douglas