Restored from previous forum. Originally posted by LJ.
I have a screen drawn with an image, a BOX gray strip, then with buttons on the gray strip and with text drawn on the gray strip. When the application is minimized, or ALT-TAB key press to switch to another application, or Window moved, then buttons are drawn okay on the screen along with the image, but the gray strip drawn with the BOX command is gone and so is the text that was drawn on the gray strip. How do I restore the screen or better, prevent ALT-TAB from being used or from the user moving the window?
Redrawing screen after switching to another task..
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by freak.
The Gadgets are automatically redrawn by Windows, but you need to redraw your own drawings yourself.
Check, if WaitWindowEvent() returns #PB_EventRepaint, which indicates, that the Window needs to be redrawn, and then draw all stuff again.
If you want to avoid that, you need to draw everything in an Image, and then display it in an ImageGadget() like this:
If you want to change anything of your drawings later, you can do it like that:
This would be a better solution because then, Windows redraws everything, everytime, and you'll never have to worry about that.
Hope, that helps...
Timo
The Gadgets are automatically redrawn by Windows, but you need to redraw your own drawings yourself.
Check, if WaitWindowEvent() returns #PB_EventRepaint, which indicates, that the Window needs to be redrawn, and then draw all stuff again.
If you want to avoid that, you need to draw everything in an Image, and then display it in an ImageGadget() like this:
Code: Select all
#Image = 1
#ImageGadget = 1
CreateImage(#Image, 100,100)
UseImage(#Image)
StartDrawing(ImageOutput())
;
; draw everything here...
;
StopDrawing()
ImageGadget(#ImageGadget, 10, 10, 100, 100, UseImage(#Image))
Code: Select all
UseImage(#Image)
StartDrawing(ImageOutput())
;
; do your changes here...
;
StopDrawing()
SetGadgetState(#ImageGadget, UseImage(#Image)) ; <- Updates the Image in the Gadget
This would be a better solution because then, Windows redraws everything, everytime, and you'll never have to worry about that.
Hope, that helps...
Timo
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by LJ.
That is very helpful Tito, thank you. That is fascinating to assign all the drawings to an image. Now the problem is that the screen is redrawn like you said, but now the image appears over my buttons. So the gray box rectangle is under the buttons when first drawn. When I hit minimize or ALT-TAB and then come back to the screen, the gray box is over the buttons. If I move the mouse over the gray box and just click where the button should appear, suddenly the button appears. Is there a way to make the image not appear over my buttons when the screen is redrawn using your image method?
That is very helpful Tito, thank you. That is fascinating to assign all the drawings to an image. Now the problem is that the screen is redrawn like you said, but now the image appears over my buttons. So the gray box rectangle is under the buttons when first drawn. When I hit minimize or ALT-TAB and then come back to the screen, the gray box is over the buttons. If I move the mouse over the gray box and just click where the button should appear, suddenly the button appears. Is there a way to make the image not appear over my buttons when the screen is redrawn using your image method?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by El_Choni.
This seems to work:
Bye,
El_Choni
This seems to work:
Code: Select all
Global ButtonGadget
Procedure PaintCallback(hWnd, uMsg, wParam, lParam)
result = #PB_ProcessPureBasicEvents
If uMsg=#WM_PAINT
StartDrawing(WindowOutput())
DrawImage(UseImage(0), 0, 0, WindowWidth(), WindowHeight())
StopDrawing()
RedrawWindow_(ButtonGadget, 0, 0, #RDW_INVALIDATE)
EndIf
ProcedureReturn result
EndProcedure
If OpenWindow(0, 128, 96, 320, 256, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget, "Background image example")
If CreateGadgetList(WindowID())
CreateImage(0, WindowWidth(), WindowHeight())
StartDrawing(ImageOutput())
Box(0, 0, WindowWidth(), WindowHeight(), $ff)
FrontColor(0, 0, 0)
DrawingMode(1)
DrawingFont(LoadFont(0, "Times New Roman", 16))
Locate(64, 32)
DrawText("Background image")
StopDrawing()
ButtonGadget = ButtonGadget(0, 80, 64, 160, 128, "My Button")
SetWindowCallback(@PaintCallback())
Repeat
Until WaitWindowEvent()=#PB_EventCloseWindow
EndIf
EndIf
End
El_Choni
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm