what happens if I open 2 WindowedScreen ?
Posted: Fri Jul 04, 2008 10:18 pm
Does each screen have a specific drawing output ?
http://www.purebasic.com
https://www.purebasic.fr/english/
we will see that you are a mighty magician...eddy wrote:what happens if I open 2 WindowedScreen ?
The manual wrote: Note: Only one windowed screen can be opened at one time.
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