what happens if I open 2 WindowedScreen ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

what happens if I open 2 WindowedScreen ?

Post by eddy »

Does each screen have a specific drawing output ?
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: what happens if I open 2 WindowedScreen ?

Post by Kaeru Gaman »

eddy wrote:what happens if I open 2 WindowedScreen ?
we will see that you are a mighty magician...
oh... and have a nice day.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

From the manual
The manual wrote: Note: Only one windowed screen can be opened at one time.
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

Why would you want two ?

Just have one and two viewports on the screen, if using 3d then you have two cameras side by side, or one above the other.

:)
Paid up PB User !
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Well, how about having dual monitor setups, with a screen on each monitor? Fred, we need this, the need is obvious, how can one live without this, PureBasic is not worth its salt if we can't open two screens on two monitors, dual screen gaming has the future, even lenin and mao had two screens, and see how far they got!

Uh...

I might have been carried away...

A little.

Just a little.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

Doesn`t a screen work for the whole width (of two monitors)? Well I don`t know, I just got one monitor.

Two screens -> the whole Lib has to be rewritten: e.g.:
openscreen(#screennumber, ....),
clearscreen(#screennumber, RGB(0, 0, 0)), ...
PureBasic for Windows
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Did someone call for a mighty magician? Dunno about that, but it can be done using separate dlls loaded from the main program.

Method:

Compile the second and third code blocks to shared dll's and place in the same folder as the main prog, then run the main prog:

Main prog:

Code: Select all

Global hwnd1, hwnd2

Procedure test1(window)
 hwnd1=CallFunction(0, "Init", window)
 CallFunction(0, "wScreen", hwnd1)
EndProcedure

Procedure test2(window)
  hwnd2=CallFunction(1, "Init", window)
  CallFunction(1, "wScreen", hwnd2)
EndProcedure

OpenLibrary(0, "test1.dll")
OpenLibrary(1, "test2.dll")
OpenWindow(0,0,0,800,600,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

tid1=CreateThread(@test1(),WindowID(0))
tid2=CreateThread(@test2(),WindowID(0))
Repeat:Until WaitWindowEvent()=#WM_CLOSE
CallFunction(0, "Finish", hwnd1)
Repeat
  WaitWindowEvent(1)
Until IsThread(tid1)=0
CallFunction(1, "Finish", hwnd2)
Repeat
  WaitWindowEvent(1)
Until IsThread(tid2)=0
DLL for first windowed screen:

Code: Select all

Global running=1

Procedure wsCallback(hWnd, Message, wParam, lParam)
  Select Message
    Case #WM_CLOSE
      UnregisterClass_("wsWindowClass", GetModuleHandle_(#Null))
      DestroyWindow_(hWnd)
  EndSelect
  Result = DefWindowProc_(hWnd, Message, wParam, lParam)
  ProcedureReturn Result
EndProcedure

ProcedureDLL Init(window)
  InitSprite()
    With wsWindowClass.WNDCLASS
      \style         = #CS_HREDRAW | #CS_VREDRAW
      \lpfnWndProc   = @wsCallback()
      \hInstance     = GetModuleHandle_(#Null)
      \hbrBackground = CreateSolidBrush_(0)
      \lpszClassName = @"wsWindowClass"
    EndWith
    RegisterClass_(wsWindowClass)
    MyhWnd.l = CreateWindowEx_(0, "wsWindowClass", "", #WS_CHILD | #WS_VISIBLE, 0, 0, 320, 240, window, 0, GetModuleHandle_(#Null), 0)
  ProcedureReturn MyHwnd
EndProcedure 

ProcedureDLL wScreen(window)
  OpenWindowedScreen(window, 0, 0, 320, 240, 0, 0, 0)
  CreateSprite(0,32,32)
  StartDrawing(SpriteOutput(0))
    Circle(16,16,16,#Red)
  StopDrawing()
  fwd=1
  Repeat
    PeekMessage_(Message.MSG, window, 0, 0, #PM_NOREMOVE)
    TranslateMessage_(Message)
    DispatchMessage_(Message)
    ClearScreen(#Blue)
    If fwd
      x+3:If x>320-32:fwd=0:EndIf
    Else 
      x-3:If x<0:fwd=1:EndIf
    EndIf
    DisplayTransparentSprite(0,x,100)
    GetCursorPos_(cp.POINT)
    GetWindowRect_(window,wr.RECT)
    
    If  PtInRect_(wr,cp\x,cp\y)
      StartDrawing(ScreenOutput())
        txt$="You're in Screen 1"
        DrawText(320/2-TextWidth(txt$)/2,60,txt$,#Yellow,#Blue)
      StopDrawing()
    EndIf
    Delay(1)
    FlipBuffers()
  Until running=0
  CloseScreen()
EndProcedure

ProcedureDLL Finish(hwnd)
  running=0
  Delay(50)
  SendMessage_(hwnd, #WM_CLOSE,0,0)
EndProcedure
DLL for second windowed screen:

Code: Select all

Global running=1

Procedure wsCallback(hWnd, Message, wParam, lParam)
  Select Message
    Case #WM_CLOSE
      UnregisterClass_("wsWindowClass", GetModuleHandle_(#Null))
      DestroyWindow_(hWnd)
  EndSelect
  Result = DefWindowProc_(hWnd, Message, wParam, lParam)
  ProcedureReturn Result
EndProcedure

ProcedureDLL Init(window)
  InitSprite()
    With wsWindowClass.WNDCLASS
      \style         = #CS_HREDRAW | #CS_VREDRAW
      \lpfnWndProc   = @wsCallback()
      \hInstance     = GetModuleHandle_(#Null)
      \hbrBackground = CreateSolidBrush_(0)
      \lpszClassName = @"wsWindowClass"
    EndWith
    RegisterClass_(wsWindowClass)
    MyhWnd.l = CreateWindowEx_(0, "wsWindowClass", "", #WS_CHILD | #WS_VISIBLE, 400, 0, 320, 240, window, 0, GetModuleHandle_(#Null), 0)
  ProcedureReturn MyHwnd
EndProcedure 

ProcedureDLL wScreen(window)
  OpenWindowedScreen(window, 0, 0, 320, 240, 0, 0, 0)
  CreateSprite(0,32,32)
  StartDrawing(SpriteOutput(0))
    Circle(16,16,16,#Blue)
  StopDrawing()
  fwd=1
  Repeat
    PeekMessage_(Message.MSG, window, 0, 0, #PM_NOREMOVE)
    TranslateMessage_(Message)
    DispatchMessage_(Message)
    ClearScreen(#Green)
    If fwd
      y+3:If y>208:fwd=0:EndIf
    Else 
      y-3:If y<0:fwd=1:EndIf
    EndIf
    DisplayTransparentSprite(0,320/2-16,y)
    GetCursorPos_(cp.POINT)
    GetWindowRect_(window,wr.RECT)
    
    If  PtInRect_(wr,cp\x,cp\y)
      StartDrawing(ScreenOutput())
        txt$="You're in Screen 2"
        DrawingMode(#PB_2DDrawing_Transparent)
        DrawText(320/2-TextWidth(txt$)/2,60,txt$,#Black,#Green)
      StopDrawing()
    EndIf
    Delay(1)
    FlipBuffers()
  Until running=0
  CloseScreen()
EndProcedure

ProcedureDLL Finish(hwnd)
  running=0
  Delay(50)
  SendMessage_(hwnd, #WM_CLOSE,0,0)
EndProcedure
Run as directed and you will see two windowed screens running in harmony on one main window.
BERESHEIT
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

:lol: ok, Maestro...

it's almost cheated, but only almost....
oh... and have a nice day.
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Post by Blue »

Spiffy boucing jellybeans, Maestro. 8)

Do you have any idea what causes Vista to have to suspend its Aero effects when this app runs?
Is it because of the sprites or some other manipulation ?
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
Post Reply