Page 2 of 2
Re: display image
Posted: Mon Sep 25, 2023 2:23 pm
by Janni
There are two different types of computer programs -often with different purposes.
A console app is like a telegraph, where you send and receive messages in plain text, simple and efficient.
A GUI app is where you explore and interact with vibrant visuals, making the experience more engaging and user-friendly.
Attronach : Choose one OR the other for your program.
Re: display image
Posted: Mon Sep 25, 2023 8:05 pm
by Attronach
mk-soft wrote: Mon Sep 25, 2023 1:25 pm
Why Console,
Mixing GUI and Console is not useful. Otherwise, Console and Window of the focus must always be changed with the mouse. In addition, the user input does not work in the GUI part and comes to errors, because here also all events must be processed.
No errors just need to switch to console window to continue (close graphic window and show another text etc...)
So if not possible return active window status back to root process (console window) then that's is bad

Re: display image
Posted: Mon Sep 25, 2023 9:11 pm
by mk-soft
Let's see what you've done so far.
Maybe we can find a solution.
Re: display image
Posted: Tue Sep 26, 2023 9:12 am
by Oso
Attronach's requirement sounds similar to something I needed a few days ago, consequently the requirement sounds reasonable to me. I have an administrative application running as a console, but I wanted to provide a pop-up help window. I didn't want to present the help as console text.
It works well and can be seen at this thread.
viewtopic.php?p=607439#p607439
A possible weakness is that when the help window is open, the console is inoperable, so if a user closes the console, it pauses briefly before closing, which is something I intend to resolve. The revised code — with an added close button — is below.
Code: Select all
EnableExplicit
Define helpwin.i ; Help window number
Define helpdsp.i ; Help gadget number
Define helpcls.i ; Help close button
OpenConsole()
; ** Invoke help window
helpwin.i = OpenWindow(#PB_Any, 0, 0, 500, 240, "Help", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
helpdsp.i = EditorGadget(#PB_Any, 0, 0, 500, 200, #PB_Editor_ReadOnly | #PB_Editor_WordWrap)
AddGadgetItem(helpdsp.i, -1, "Help heading")
AddGadgetItem(helpdsp.i, -1, "")
AddGadgetItem(helpdsp.i, -1, "More help text.")
helpcls.i = ButtonGadget(#PB_Any, 414, 205, 80, 30, "Close", #PB_Button_Default)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow Or EventGadget() = helpcls.i
CloseConsole()
Re: display image
Posted: Tue Sep 26, 2023 12:48 pm
by Attronach
Oso wrote: Tue Sep 26, 2023 9:12 am
Attronach's requirement sounds similar to something I needed a few days ago, consequently the requirement sounds reasonable to me. I have an administrative application running as a console, but I wanted to provide a pop-up help window. I didn't want to present the help as console text.
It works well and can be seen at this thread.
viewtopic.php?p=607439#p607439
A possible weakness is that when the help window is open, the console is inoperable, so if a user closes the console, it pauses briefly before closing, which is something I intend to resolve. The revised code — with an added close button — is below.
Code presented here do almost what I need. Almost.
just try code and you will see what I need.
Code: Select all
OpenConsole()
PrintN ("Text I need to show BEFORE showing Image in separate window")
imagefile.s = "PureBasic.bmp"
If OpenWindow(0, 0, 0, 405, 405, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If LoadImage(0, imagefile)
ImageGadget(0, 0, 0, 256, 256, ImageID(0))
ImageGadget(1, 128, 128, 256, 256, ImageID(0), #PB_Image_Border)
EndIf
EndIf
PrintN ("After showing Image I need feedback from user. Like:")
PrintN ("Press 'A' for Blue Eyes or 'B' for Red Eyes")
PrintN ("")
PrintN ("Now please MANUALY select Console window with mouse and push a or b")
;I don't know how to switch back to Console window !!!!!!!!!!!!!!!!!!!!
Repeat
KeyPressed$ = Inkey()
Until KeyPressed$ = "a" Or KeyPressed$ = "b
;after keypush you can see window will close and retun back to this MAIN code.
CloseWindow(0)
PrintN ("")
PrintN ("If you switch MANUALY back to this console and push a or b you can see program resume after closing window.")
PrintN ("This is exactly what I need.")
PrintN ("")
PrintN ("Now you can push ESC again for close program")
Repeat
KeyPressed$ = Inkey()
Until KeyPressed$ = Chr(27)
CloseConsole()
Re: display image
Posted: Tue Sep 26, 2023 1:21 pm
by Oso
Attronach wrote: Tue Sep 26, 2023 12:48 pm
Code presented here do almost what I need. Almost. just try code and you will see what I need.
Yes, understood. But once the GUI window is open, you no longer have control from the console, so you must provide a way of closing the GUI. In your code, you never reach the CloseWindow(0), because your first keyboard input doesn't ever get satisfied, and that's why your process hangs.
You need a loop for the GUI, so that it doesn't hang and then it can be closed, either with the 'X' or with two buttons A and B. It would be better to copy my Close button and create two buttons in the GUI, A and B. You would then have those button results to process.
If you don't want the buttons in the GUI, then the user must close the GUI, before answering the question in the console window. In my opinion it would be difficult for the user to know how to use this interface though, because you're gving the user instructions in the console about how to operate it, but the user might not even see those instructions because in some cases the GUI will overwrite the console screen and obscure those instructions.
Re: display image
Posted: Tue Sep 26, 2023 3:52 pm
by Attronach
Ok, so because Windows is stupid systems and don't remember create basic elements, I have to NOT display images.
That's sound horrible. God bless old good single window system.
Re: display image
Posted: Tue Sep 26, 2023 4:56 pm
by Caronte3D
I don't know if something like that is what you want:
Code: Select all
OpenConsole()
PrintN ("Text I need to show BEFORE showing Image in separate window")
imagefile.s = "PureBasic.bmp"
If OpenWindow(0, 0, 0, 405, 405, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If LoadImage(0, imagefile)
ImageGadget(0, 0, 0, 256, 256, ImageID(0))
ImageGadget(1, 128, 128, 256, 256, ImageID(0), #PB_Image_Border)
EndIf
EndIf
PrintN ("After showing Image I need feedback from user. Like:")
PrintN ("Press 'A' for Blue Eyes or 'B' for Red Eyes")
PrintN ("")
PrintN ("Now please push a or b")
;I don't know how to switch back to Console window !!!!!!!!!!!!!!!!!!!!
Repeat
WaitWindowEvent()
KeyA = (GetAsyncKeyState_(#VK_A) & $8000)
KeyB = (GetAsyncKeyState_(#VK_B) & $8000)
Until keyA Or KeyB
;after keypush you can see window will close and retun back to this MAIN code.
CloseWindow(0)
PrintN ("")
If keyA
PrintN ("You pressed: [a] key.")
ElseIf KeyB
PrintN ("You pressed: [b] key.")
EndIf
PrintN ("")
PrintN ("Now you can push ESC again for close program")
Repeat
KeyPressed$ = Inkey()
Until KeyPressed$ = Chr(27)
CloseConsole()
Re: display image
Posted: Tue Sep 26, 2023 8:16 pm
by Oso
Caronte3D wrote: Tue Sep 26, 2023 4:56 pm
Code: Select all
If OpenWindow(0, 0, 0, 405, 405, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
I notice that
#PB_Any causes the app to kind of crash (or at least it isn't happy) when the user closes the the console window with
'X'. In your version, you're creating the window as window 0 rather than
#PB_Any. If the user clicks
'X' in yours, it closes the entire application cleanly and immediately. If
#PB_Any was used, there's a long delay, because something isn't right and if it's being run with the debugger on, that comes back with
"The debugged executable quit unexpectedly".
I presume it doesn't like the parent window being closed if the window number was generated with
#PB_Any. Odd though?
Re: display image
Posted: Tue Sep 26, 2023 8:46 pm
by Caronte3D
I just used the latest Attronach code and added the key detection thing, I didn't go further

Anyway I think that would be easy to solve, but the whole approach looks weird to me
That way you can close the window:
Code: Select all
OpenConsole()
PrintN ("Text I need to show BEFORE showing Image in separate window")
imagefile.s = "PureBasic.bmp"
win=OpenWindow(#PB_Any, 0, 0, 405, 405, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If win
If LoadImage(0, imagefile)
ImageGadget(0, 0, 0, 256, 256, ImageID(0))
ImageGadget(1, 128, 128, 256, 256, ImageID(0), #PB_Image_Border)
EndIf
EndIf
PrintN ("After showing Image I need feedback from user. Like:")
PrintN ("Press 'A' for Blue Eyes or 'B' for Red Eyes")
PrintN ("")
PrintN ("Now please push a or b")
;I don't know how to switch back to Console window !!!!!!!!!!!!!!!!!!!!
Repeat
event=WaitWindowEvent()
KeyA = (GetAsyncKeyState_(#VK_A) & $8000)
KeyB = (GetAsyncKeyState_(#VK_B) & $8000)
Until keyA Or KeyB Or event=#PB_Event_CloseWindow
;after keypush you can see window will close and retun back to this MAIN code.
CloseWindow(win)
PrintN ("")
If keyA
PrintN ("You pressed: [a] key.")
ElseIf KeyB
PrintN ("You pressed: [b] key.")
EndIf
PrintN ("")
PrintN ("Now you can push ESC again for close program")
Repeat
KeyPressed$ = Inkey()
Until KeyPressed$ = Chr(27)
CloseConsole()
Re: display image
Posted: Tue Sep 26, 2023 9:13 pm
by Oso
Caronte3D wrote: Tue Sep 26, 2023 8:46 pm
I just used the latest Attronach code and added the key detection thing, I didn't go further
Code: Select all
win=OpenWindow(#PB_Any, 0, 0, 405, 405, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Yes, understood, but aside from that, PB doesn't like the parent console being closed directly if #PB_Any was used. Just thought it was strange, that specifying the window as 0 doesn't cause the weird delay (and the crash if the debugger is on).
Just to clarify, I'm not referring to closing the GUI window, but closing the console while the GUI window is still open. Anyway, maybe it will just remain a mystery

Yes, agreed, the approach seems weird anyway, at least in that application.
Re: display image
Posted: Tue Sep 26, 2023 9:21 pm
by Caronte3D
Ah! You mean closing the console! I understand now... and... yes it's weird

Re: display image
Posted: Tue Sep 26, 2023 9:29 pm
by Oso
Caronte3D wrote: Tue Sep 26, 2023 9:21 pm
Ah! You mean closing the console! I understand now... and... yes it's weird
Yeah, quite weird. I don't like to suggest it's a bug, because this whole approach is a bit of an oddity. I'm just happy that it's possible, because in my case it's given me quite a nice help pop-up window
