Page 1 of 1

How to run Window on 2nd monitor screen (Desktop 5)

Posted: Sat Mar 21, 2015 9:47 am
by Kamarro
Hi there,

I'm running the demo version to test everything before buy, but I have a few doubts and problems before continue. I am a quite well experienced user, but PureBasic is really new for me:

- How can I define a program to run only and directly on external monitor of my iMac 20" (earlier 2008) ?

I have a DELL ST2220T (touch is not my question now) and I want to use it's 1920 pixel wide. I found that I can use window (0,1920,0... etc to make ir display on right monitor, but program is still running on left (Mac) screen and it returns to it for everything but a pence.

Can anybody help me with this question? Did you already try something similar?

Thanks guys.

Re: How to run Window on 2nd monitor screen (Desktop 5)

Posted: Sat Mar 21, 2015 3:31 pm
by wilbert
I don't know the restrictions of the demo version.
If it supports CocoaMessage , you can use NSScreen to get the information for a second screen.

Code: Select all

ScreenArray = CocoaMessage(0, 0, "NSScreen screens")
If CocoaMessage(0, ScreenArray, "count") < 2
  Debug "No second screen"
Else
  CocoaMessage(@Frame.NSRect, CocoaMessage(0, ScreenArray, "objectAtIndex:", 1), "visibleFrame")
  AppWindow = OpenWindow(#PB_Any, 0, 0, 0, 0, "Second screen window", #PB_Window_SystemMenu)
  If AppWindow
    CocoaMessage(0, WindowID(AppWindow), "setFrame:@", @Frame, "display:", #YES)
        
    WebGadget(0, 10, 10, WindowWidth(AppWindow) - 20, WindowHeight(AppWindow) - 20, "http://www.purebasic.com")
    
    Repeat
    Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
EndIf

Re: How to run Window on 2nd monitor screen (Desktop 5)

Posted: Sun Mar 22, 2015 9:48 am
by Kamarro
Many thanks Wilbert

I tested it on my system and it looks fine for my needs. I'll check now all possible variations: Only 1st screen, only 2nd, one window on each, etc...

I have almost 30 years of programming on QuickBasic and love this language. Always tried to convince people that Basic is all you need. (well, including some libraries, of course).
After getting tired of changes (Mac OS, QB versions, Win versions, No more stable and powerful MSDOS, bugs in QB64 and small problems with PDS 7.1), last week I decided to change my old QB64 and Parallel's PDS 7.1 to another "more Mac" language. Chipmunk looks nice, but no compiler. A few more look less powerful and stable than PureBasic, so, I changed.

I am happy until now, but with such a big program and large instructions set, documentation always fails somewhere. Can you, or anybody else, help me with my next questions?

1 - Where to find, or what are PB limitations for MacOS?
2 - How long/big a source program can be?
3 - Where is old Basic "Locate and Print" instructions?
4 - How to make PB execution change from one name.pb to another. I tried RunProgram but without success. Where is CHAIN or SHELL commands?

Sorry for asking all this, but 80 euros for me is money. I am a 52 disabled guy who decides to build a very big robotic tabletop game, controlled by Arduinos and remotely accessible by Android phones and tablets. Mac is for console operation of all system. Is really a big project but only for my use and joy. My basement is full of old stuff and will be a planet full of aliens and spartan miniatures, scale 1:100. Includes thousands of LEDs, more than 20 Arduino systems, a lot of robotised instruments. It's almost all made by me from scratch.

It's how I decided to look at my incapacities. Why not?

Sorry for long text, and Thank you all!

Re: How to run Window on 2nd monitor screen (Desktop 5)

Posted: Sun Mar 22, 2015 1:47 pm
by wilbert
Kamarro wrote:1 - Where to find, or what are PB limitations for MacOS?
2 - How long/big a source program can be?
3 - Where is old Basic "Locate and Print" instructions?
4 - How to make PB execution change from one name.pb to another. I tried RunProgram but without success. Where is CHAIN or SHELL commands?
1. When a command is not supported on OSX it's mentioned in the help file but the majority of the PureBasic commands is cross platform.
It's a difficult question to answer what the limitations are. It's easier if you ask if something you need is possible or not.

2. As big as you want unless your system runs out of memory.

3. They don't exist. If you create a console program you can output a line of text with PrintN but for a GUI program you need to use something like EditorGadget to output your text to or use an image and draw text using DrawText. If you want to simulate it you could use a monospaced font like "Menlo" or "Courier New" combined with an EditorGadget. You can change a specific line of text and use space characters to align.

4. PB is a compiled language, not an interpreted one so you can't switch to another .pb source. You can use IncludeFile to include multiple sources in one application. If you need to start a compiled application form another one you can use RunProgram.

Re: How to run Window on 2nd monitor screen (Desktop 5)

Posted: Sun Mar 22, 2015 2:39 pm
by Kamarro
wilbert wrote:
Kamarro wrote:1 - Where to find, or what are PB limitations for MacOS?
2 - How long/big a source program can be?
3 - Where is old Basic "Locate and Print" instructions?
4 - How to make PB execution change from one name.pb to another. I tried RunProgram but without success. Where is CHAIN or SHELL commands?
1. When a command is not supported on OSX it's mentioned in the help file but the majority of the PureBasic commands is cross platform.
It's a difficult question to answer what the limitations are. It's easier if you ask if something you need is possible or not.

2. As big as you want unless your system runs out of memory.

3. They don't exist. If you create a console program you can output a line of text with PrintN but for a GUI program you need to use something like EditorGadget to output your text to or use an image and draw text using DrawText. If you want to simulate it you could use a monospaced font like "Menlo" or "Courier New" combined with an EditorGadget. You can change a specific line of text and use space characters to align.

4. PB is a compiled language, not an interpreted one so you can't switch to another .pb source. You can use IncludeFile to include multiple sources in one application. If you need to start a compiled application form another one you can use RunProgram.
Thanks again for your answer. I think I understood everything.

1 - About issue 1, as you say, I will work until any limits appear! (Close issue 1)

2 - About this issue, I usually create a program made with a lot of small programs (as they were Subroutines) and I chain from one to another (what leaves a lot of memory free for each module). As I told before, that's what i've done with QBasic. (Close issue 2)

3 - My problem is this: I have a screen, a regular PNG screen (it works. I loaded PNG LIB before), where I want to show system time working, but it only works and update when I move mouse; without a forced Event Repaint it remains as it is. My problem (I think) is with repeat cycle. If I don't use it and move mouse or so, window gets blank, so I need a Repaint, right? I give you my Routine as a better example of what I'm saying.

Ecran3:

SoundVolume(#PB_All, 30)

If OpenWindow(0, 0, 0, 1920, 1080, "Alien - The Last Queen", #PB_Window_Maximize)
CreateMenu(0, WindowID(0))
MenuTitle("Your Command")
MenuItem(1, "Back")
MenuItem(2, "Continue")
CreateImage(0, 1920, 1080,32)
StartDrawing(ImageOutput(0))
LoadImage(0, #Paths$+"Images/Second.png",0)
ResizeImage(0,1920,1080)
StopDrawing()
Repeat

Event = WaitWindowEvent()

Select Event
Case #PB_Event_Repaint
StartDrawing(WindowOutput(0))
DrawImage(ImageID(0), 0,0)
StopDrawing()
Hora$ = FormatDate("%hh:%ii:%ss", Date())
StartDrawing(WindowOutput(0))
DrawingMode(#PB_2DDrawing_Default)
Box(1700, 900, 150, 55 , RGB(0,0,0))
DrawingFont(FontID(3))
DrawText(1800, 910, Hora$, RGB(0,255,255))
StopDrawing()

Case #PB_Event_Menu
Select EventMenu()
Case 1 : CloseWindow( #PB_All):Goto Ecran2
Case 2 : End
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf

I also tried to copy DrawText block to other positions inside routine, but it's the same or worst. Is there any way of keeping screen active and showing PNG without Repeat or Repaint?
What's wrong with this? Or with me?

4 - About issue 4, I've done a few tests until now and I really can't figure how it works. With a friend's machine using full version, I compiled my Alien.pb program to Alien.app and another simple program from Main.pb to Main.app
When my Main.app calls RunProgram("Alien.app") it doesn't work at all. I tried with Path, full path, no path at all... No error, but Alien.app don't start.

5 - A new question: What about the fullscreen option without System Bar or even Dock? Is there a way to get a really Fullscreen instead of a Maximized one?

Sorry my english, because I live in UK, but I'm Portuguese and never learned english at school, only French.
I apology too for so many questions, but that's what for forums are, ya?

Big thanks for you
Cheers
Paulo (a.k.a. Kamarro)

Re: How to run Window on 2nd monitor screen (Desktop 5)

Posted: Sun Mar 22, 2015 3:46 pm
by wilbert
First a few general remarks ...

It's best not to ask all questions in one topic.
You are currently posting in the Mac OSX forum with a thread about a 2nd monitor.
There's probably not that much OSX users who are interested in this topic while your recent questions are about other things.
If you create a topic with a proper title for those questions, most likely more people will read it so you get a better chance of a good answer to your questions.

When posting code, you can use the special Code option when you reply which makes it better readable.
Kamarro wrote:3 - My problem is this: I have a screen, a regular PNG screen (it works. I loaded PNG LIB before), where I want to show system time working, but it only works and update when I move mouse; without a forced Event Repaint it remains as it is. My problem (I think) is with repeat cycle. If I don't use it and move mouse or so, window gets blank, so I need a Repaint, right? I give you my Routine as a better example of what I'm saying.
In general it's not a good idea to draw directly onto a window.
In your case you are probably better off with a CanvasGadget and use AddWindowTimer to add a timer event so you can update the time display when that event occurs.
Kamarro wrote:4 - About issue 4, I've done a few tests until now and I really can't figure how it works. With a friend's machine using full version, I compiled my Alien.pb program to Alien.app and another simple program from Main.pb to Main.app
When my Main.app calls RunProgram("Alien.app") it doesn't work at all. I tried with Path, full path, no path at all... No error, but Alien.app don't start.

Code: Select all

RunProgram("open","/Applications/Utilities/Console.app","")
Kamarro wrote:5 - A new question: What about the fullscreen option without System Bar or even Dock? Is there a way to get a really Fullscreen instead of a Maximized one?
This thread about Cocoa has a lot of tips
http://www.purebasic.fr/english/viewtop ... 19&t=50795
it also mentions fullscreen
http://www.purebasic.fr/english/viewtop ... 06#p417806

Re: How to run Window on 2nd monitor screen (Desktop 5)

Posted: Sun Mar 22, 2015 4:14 pm
by Kamarro
wilbert wrote:First a few general remarks ...
OMG, you're right. I should know that...
Okay, let's try to end this, and I'll take more care about Post Titles. :oops:
wilbert wrote:In general it's not a good idea to draw directly onto a window. In your case you are probably better off with a CanvasGadget and use AddWindowTimer to add a timer event so you can update the time display when that event occurs.
Probably my mistake when posing problem. I need a clock time, working as a counter alive on display. While user (me) stays IDLE, looking at screen, clock continues working. Let me try a regular Basic routine:

Code: Select all

K$=""
While K$=""
    K$=Inkey$
    Locate x,y: Print Time$;
Wend

Only this... Just an active timer. (But your answer will be useful anywhere later, I'm sure.)
wilbert wrote:

Code: Select all

RunProgram("open","/Applications/Utilities/Console.app","")
Thanks for RunProgram tip, because nothing in my manual talks about the "Open" parameter. This is what I had:

Code: Select all

[b]Syntax[/b]
Result = RunProgram(Filename$ [, Parameter$, WorkingDirectory$ [, Flags [, SenderProgram]]])
(After testing it, I get an "RunProgram(): Incorrect number of parameters"). Not solved yet.
wilbert wrote:
Kamarro wrote:5 - A new question: What about the fullscreen...
This thread about Cocoa has a lot of tips
http://www.purebasic.fr/english/viewtop ... 19&t=50795
it also mentions fullscreen
http://www.purebasic.fr/english/viewtop ... 06#p417806
Once again, thanks a lot.

Re: How to run Window on 2nd monitor screen (Desktop 5)

Posted: Sun Mar 22, 2015 5:34 pm
by wilbert
Timer example

Code: Select all

LoadFont(0, "Menlo", 16)

If OpenWindow(0, 0, 0, 400, 100, "Timer Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  TextGadget(0, 10, 10, 100, 30, "")
  SetGadgetFont(0, FontID(0))
  AddWindowTimer(0, 0, 500)
  
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_Timer And EventTimer() = 0
      SetGadgetText(0, FormatDate("%hh:%ii:%ss", Date()))
    EndIf    
    
  Until Event = #PB_Event_CloseWindow
EndIf
With canvas gadget

Code: Select all

LoadFont(0, "Menlo", 16)

If OpenWindow(0, 0, 0, 400, 100, "Timer Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  CanvasGadget(0, 0, 0, WindowWidth(0), WindowHeight(0))
  StartDrawing(CanvasOutput(0))
  Box(0, 0, WindowWidth(0), WindowHeight(0), $ff0000)
  StopDrawing()
  
  AddWindowTimer(0, 0, 500)
  
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_Timer And EventTimer() = 0
      StartDrawing(CanvasOutput(0))
      DrawingFont(FontID(0))
      DrawText(20, 20, FormatDate("%hh:%ii:%ss", Date()), $ffffff, $ff0000)
      StopDrawing()
    EndIf    
    
  Until Event = #PB_Event_CloseWindow
EndIf

Re: How to run Window on 2nd monitor screen (Desktop 5)

Posted: Sun Mar 22, 2015 5:40 pm
by Shardik
Example displaying time and pressed key in CanvasGadget:

Code: Select all

OpenWindow(0, 270, 100, 300, 270, "Wait for key press and display time")
CanvasGadget(0, 10, 10, 280, 250, #PB_Canvas_Border | #PB_Canvas_Keyboard)
LoadFont(0, "Arial", 18)
SetActiveGadget(0)
AddWindowTimer(0, 0, 1000)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Timer
      StartDrawing(CanvasOutput(0))
        DrawingFont(FontID(0))
        DrawText(200, 5, FormatDate("%hh:%ii:%ss", Date()), 0, $FFFFFF)
      StopDrawing()
    Case #PB_Event_Gadget
      If EventGadget() = 0 And EventType() = #PB_EventType_Input
        StartDrawing(CanvasOutput(0))
          DrawingFont(FontID(0))
          DrawText(85, 110, "Last key:   ", 0, $FFFFFF)
          DrawText(160, 110,
            Chr(GetGadgetAttribute(0, #PB_Canvas_Input)), 0, $FFFFFF)
        StopDrawing()
      EndIf
  EndSelect
ForEver

Re: How to run Window on 2nd monitor screen (Desktop 5)

Posted: Sun Mar 22, 2015 10:35 pm
by Kamarro
Thank you man!

With this good three examples I have enough to continue my program. In fact there's so much differences between this PB and QB... Oh, God, if I had something like this when I was a real programmer. Now, much older and disabled (to much heart attacks, hearth arrests, coma and brain stroke) is a bit more difficult to achieve my goals. 24/7 is not much when we need to check forums, read manuals, build, paint and robotise models...

I appreciate very much your help. Thanks.

My project will be fully Open Source and everything will be available on my site, as soon as I finish some steps first.