Page 1 of 1

what happens if I open 2 WindowedScreen ?

Posted: Fri Jul 04, 2008 10:18 pm
by eddy
Does each screen have a specific drawing output ?

Re: what happens if I open 2 WindowedScreen ?

Posted: Fri Jul 04, 2008 10:31 pm
by Kaeru Gaman
eddy wrote:what happens if I open 2 WindowedScreen ?
we will see that you are a mighty magician...

Posted: Sat Jul 05, 2008 8:46 am
by Derek
From the manual
The manual wrote: Note: Only one windowed screen can be opened at one time.

Posted: Sat Jul 05, 2008 2:27 pm
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.

:)

Posted: Sat Jul 05, 2008 6:08 pm
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.

Posted: Sat Jul 05, 2008 9:27 pm
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)), ...

Posted: Sat Jul 05, 2008 9:57 pm
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.

Posted: Sat Jul 05, 2008 11:59 pm
by Kaeru Gaman
:lol: ok, Maestro...

it's almost cheated, but only almost....

Posted: Sun Jul 06, 2008 6:23 am
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 ?