what happens if I open 2 WindowedScreen ?
what happens if I open 2 WindowedScreen ?
Does each screen have a specific drawing output ?

- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: what happens if I open 2 WindowedScreen ?
we will see that you are a mighty magician...eddy wrote:what happens if I open 2 WindowedScreen ?
oh... and have a nice day.
-
- Enthusiast
- Posts: 537
- Joined: Wed Oct 29, 2003 10:35 am
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.
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... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
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:
DLL for first windowed screen:
DLL for second windowed screen:
Run as directed and you will see two windowed screens running in harmony on one main window.
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
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
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
BERESHEIT
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany