Page 1 of 1

Refresh 2d drawings

Posted: Mon Jul 28, 2003 12:14 pm
by webba
Hi all!

I wonder if anyone has done what I'm trying to do...?

I have an app partly developed that needs a very specific calendar type object. The kind of thing you would probably make as an activex in VB. Since I dont want the bloat of a VB activex, I'm trying to draw the control elements onto a panel gadget using the 2d commands. It's working quite well...

My problem is that the bits I'm drawing disappear when other windows move over the top of the app, or the app is moved offscreen, etc...

I've tried redrawing on event: #PB_Event_Repaint but it only seems to trap when the app has been minimised then maximised.

I've searched the forum but nothing seems quite to match my problem. Any ideas?

OS: Windows 2000, but I'd like something for any Windows...

Thanks in advance for any help you can give!

Posted: Mon Jul 28, 2003 1:10 pm
by Flype
Hi,

I'll answer to your question, but before you should try this piece of code (from CodeArchive). Perhaps, you'll be very interesting of it :

Code: Select all

; German forum: http://robsite.de/php/pureboard/viewtopic.php?t=1063&highlight=
; Author: Andreas
; Date: 19. May 2003

Procedure.s GetTimeString(Picker.l) 
    SendMessage_(Picker,4097,0,@s.SYSTEMTIME) 
    Hour$ = Str(s\wHour) 
    Minute$ = Str(s\wMinute) 
    Second$ = Str(s\wSecond) 
    If Len(Hour$) = 1 : Hour$ = "0"+Hour$:EndIf 
    If Len(Minute$) = 1 : Minute$ = "0"+Minute$:EndIf 
    If Len(Second$) = 1 : Second$ = "0"+Second$:EndIf 
    Time$ = Hour$+":"+Minute$+":"+Second$+" " 
    ProcedureReturn Time$ 
EndProcedure 


Procedure.s GetDateString(Picker.l) 
    SendMessage_(Picker,4097,0,@s.SYSTEMTIME) 
    Month$ = Str(s\wMonth) 
    Day$ = Str(s\wDay) 
    If Len(Month$) = 1 : Month$ = "0"+Month$:EndIf 
    If Len(Day$) = 1 : Day$ = "0"+Day$:EndIf 
    Date$ = Day$+"."+Month$+"."+Str(s\wYear) 
    ProcedureReturn Date$ 
EndProcedure 

Procedure SetDate(Picker.l,y,m,d) 
SendMessage_(Picker,4097,0,@s.SYSTEMTIME) 
s\wYear = y 
s\wMonth = m 
s\wDay = d 
SendMessage_(Picker,4098,0,s) 
EndProcedure 

Procedure SetTime(Picker.l,h,m,s) 
SendMessage_(Picker,4097,0,@st.SYSTEMTIME) 
st.SYSTEMTIME 
st\wHour = h 
st\wMinute = m 
st\wSecond = s 
SendMessage_(Picker,4098,0,st) 
EndProcedure 

Structure ICC_S 
a.l 
b.l 
EndStructure 


If OpenWindow(0, 10, 200, 300, 200, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window") 
SetForegroundWindow_(WindowID()) 
Dim ICC.ICC_S(0) 
ICC(0)\a = SizeOf(ICC_S) 
ICC(0)\b = $FFF 
InitCommonControlsEx_(ICC(0)) 
DatePicker.l = CreateWindowEx_(0,"SysDateTimePick32","",$56000000,10,10,120,20,WindowID(),0,GetModuleHandle_(0),0) 
TimePicker.l = CreateWindowEx_(0,"SysDateTimePick32","",$56000009,130,10,120,20,WindowID(),0,GetModuleHandle_(0),0) 

If CreateGadgetList(WindowID()) 
    ButtonGadget(1, 10, 40,  80, 24, "Datum") 
    ButtonGadget(4, 100, 40,  180, 24, "Datum und Zeit setzen") 
    TextGadget(2, 10, 70,  120, 24, "Datum") 
    TextGadget(3, 10, 100,  120, 24, "Zeit") 
EndIf 
Repeat 
    EventID.l = WaitWindowEvent() 
    If EventID = #PB_Event_CloseWindow 
        Quit = 1 
    EndIf 
    If EventID = #PB_EventGadget 
        Select EventGadgetID() 
        Case 1 
            SetGadgetText(2,GetDateString(DatePicker)) 
            SetGadgetText(3,GetTimeString(TimePicker)) 
        Case 4 
            SetDate(DatePicker,2004,12,24) 
            SetTime(TimePicker,11,55,00) 
        EndSelect 
    EndIf 
Until Quit = 1 

EndIf

Posted: Mon Jul 28, 2003 1:22 pm
by Flype
and for your drawing problem try something like that :

Code: Select all

Procedure WindowCallBack( hWnd, Msg, wParam, lParam )
  Result.l = #PB_ProcessPureBasicEvents
  Select Msg
    Case #WM_PAINT      : Debug "Window should be repainted"
    Case #WM_ERASEBKGND : Debug "Background has been erased"
  EndSelect
  ProcedureReturn Result
EndProcedure

OpenWindow(0,200,200,400,300,#PB_Window_SystemMenu|#PB_Window_SizeGadget,"")
SetWindowCallback( @WindowCallBack() )

While WaitWindowEvent() <> #WM_CLOSE : Wend

Posted: Mon Jul 28, 2003 4:14 pm
by webba
Flype,

Thanks for the WindowCallBack routine! It works a treat!

I didn't try the other code you supplied - I looked over it and, after seeing that it uses the datetimepicker control, decided it wouldn't give me the flexibility I need.

My calendar must only show Sunday's and have some other very specific behavior regarding how it displays data for each day...

Since the routine to repaint the calendar will take quite a long time (sqlite disk access etc...) I think I'll have to draw the data to a buffer and copy the picture to the screen on the #WM_PAINT event, but hopefully I'll be able to work that out myself...

Thanks again for the help! Purebasic is great and the support here is second to none!

Posted: Tue Jul 29, 2003 12:34 am
by Flype
Hello,
Is the datetimepicker gadget considered as an activex object ? If you need help, ask us. I'm wondering if you know the ContainerGadget() function. It could be useful for doing a complex gadget.

Posted: Wed Jul 30, 2003 12:34 pm
by webba
Flype,

Thanks for your continued interest in my project!

Yes the dattimepicker is an activex - but that's not the reason I can't use it. I've worked with it before in VB and I remember the different modes it works in. It is a picker not a displayer of data.

I am slightly familiar with the ContainerGadget() - I believe the panel gadget is very similar. I'm using the panel gadget with only 1 panel as the basis for my calendar 'object'.

I'll let you know how I get on...

Thanks again!

Posted: Sat Aug 02, 2003 8:36 pm
by Flype
So, after some days, is your project in the good way ?

Posted: Wed Aug 06, 2003 10:13 am
by webba
Flype,

Arrggg! I need about 100 hours in a day! Since we last spoke I have done nothing on the app. This project is a favour to a charity and all my other projects are fighting for my time.

My real work has been taking me away...
I am also making an amateur movie and the cast have all been available the last few weekends so I've been caught up with filming and editing...

Ho hum....