Repaint a window

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by StSchnell.

Hello community,
I have a window with lines and other graphic things on it. If I move
the window, e. g. outside of my screen, and put it back, on the screen,
all graphic elements are destroyed.
I test with #WM_MOVE, #WM_PAINT and #PB_EVENT_REPAINT, but nothing
works.
What is the right way to restore a window with graphic elements after
a move or so?
Thanks for tips.
Bye
Stefan
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by LJ.

Hi StSchnell:

There are several ways. The way I like best taught to me by Danillo, Frank, and Fred is to put your graphics and text inside an image. Images are automatically updated when sizing, minimizing, ALT-Tabbing, whatever. The code below demonstrates this. Also included is a cool ToolTip bubble. You will notice also that this code is proper in that it destroys all the screen objects when it re-draws the screen in the Update Window so that it doesn't leak memory, you may or may not find this useful. Run the code then practice re-sizing, ALT-TABing, and minimizing.

Global ToolTipControl

Procedure AddButtonToolTip(Handle,Text$)
#TTS_BALLOON = $40
ToolTipControl=CreateWindowEx_(0,"tooltips_class32","",$D0000000|#TTS_BALLOON,0,0,0,0,WindowID(),0,GetModuleHandle_(0),0)
sendMessage_(ToolTipControl,1044,0 ,0) ;ForeColor Tooltip
sendMessage_(ToolTipControl,1043,$58F5D6,0) ;BackColor Tooltip
sendMessage_(ToolTipControl,1048,0,180) ;Maximum Width of tooltip
Button.TOOLINFO\cbSize=84 ; SizeOf( TOOLINFO )
Button\uFlags=$11
Button\hWnd=Handle
Button\uId=Handle
Button\lpszText=@Text$
SendMessage_(ToolTipControl,$0404,0,Button)
ProcedureReturn ToolTipControl ; Return the handle !
EndProcedure

OpenWindow(1, 0, 0, 796, 550, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget, "Background image example")
CreateGadgetList(WindowID())
CreateImage(1, 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()
ImageGadget(1, 0, 0, WindowWidth(), WindowHeight(), UseImage(1))
ButtonGadget = ButtonGadget(0, 80, 64, 160, 128, "My Button")
ButtonGadgettwo = ButtonGadget(2, 80, 204, 160, 128, "My Button Two")
ToolTipHandle1 = AddButtonToolTip(ButtonGadget,"Test message for Button 1")
ToolTipHandle2 = AddButtonToolTip(ButtonGadgettwo,"Test message for Button 2")
LoadFont(0, "Times New Roman", 16)

Repeat
EventID = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()

Case 0
Gosub UpdateWindow

Case 2
Gosub UpdateWindow

EndSelect
EndIf
Until EventID = #PB_EventCloseWindow
End

UpdateWindow:
DestroyWindow_(ToolTipHandle1)
DestroyWindow_(ToolTipHandle2)
FreeGadget (0):FreeGadget(2)
UseImage(1)
StartDrawing(ImageOutput())
Box(0, 0, WindowWidth(), WindowHeight(), $ff)
FrontColor(0, 0, 0)
DrawingMode(1)
DrawingFont(UseFont(0))
Locate(64, 32)
DrawText("Test image")
StopDrawing()
ButtonGadget = ButtonGadget(0, 80, 64, 160, 128, "My Button")
ButtonGadgettwo = ButtonGadget(2, 80, 204, 160, 128, "My Button Two")
ToolTipHandle1 = AddButtonToolTip(ButtonGadget,"Test message for Button 1")
ToolTipHandle2 = AddButtonToolTip(ButtonGadgettwo,"Test message for Button 2")
SetGadgetState(1, UseImage(1))
ActivateGadget(0)
Return
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ebs.

LJ,

Is it necessary to destroy and recreate the button gadgets and tooltips? You can just update the background image and redraw the window:

Code: Select all

UpdateWindow:
UseImage(1)
StartDrawing(ImageOutput())
Box(0, 0, WindowWidth(), WindowHeight(), $ff)
FrontColor(0, 0, 0)
DrawingMode(1)
DrawingFont(UseFont(0))
Locate(64, 32)
DrawText("Test image")
StopDrawing()
RedrawWindow_(WindowID(), 0, 0, #RDW_INVALIDATE)
ActivateGadget(0)
Return
Eric
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by StSchnell.

Hi LJ,
it is a good idea, thanks for your tip.
I see in the forum your correspondence and now I use the tip from El_Choni, with the CallBackFunction to redraw the window with the WM_PAINT message.
Bye
Stefan


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

Post by BackupUser »

Restored from previous forum. Originally posted by LJ.

Hi ebs:

Yes in some cases, no in others. In my application, this snippet was the beginning of the "engine" for my program. With over 1,000 screens to loop through and redraw, including the need to change the text in the ToolTips on the fly, the ability to display 30 buttons on the screen at one time, but only certain groupings of the buttons depending on what screen the user is viewing, and displaying jpeg or bmp images in the main screen area that change when the screen changes,made it necessary to destroy each screen item when the forward or backward area was clicked. Before realizing this, my .exe leaked about 16K every 3 screens.

So what you have in that code snippet is the base of a very large engine. But you are correct, if you are only interested in redrawing a window, much of this is not necessary like StSchnell is, then much of this is simply not necessary.
Post Reply