Page 1 of 1

Dynamic Numbering for Gadgets, Help.

Posted: Wed Jun 23, 2004 7:32 pm
by Master Games
Hi,

I get this error "Gadget object not initialized" when I resize. I know the problem must be in the callbackprocedure but I do not know enough why or how to fix it.

Here is the Code:

Code: Select all

;Created By Master Games

;Constants


;Call Back Procedure to handle gadget resizing
Procedure MyWindowCallback(WindowID, Message, wParam, lParam) 
  Result = #PB_ProcessPureBasicEvents 
  
  Select Message
    Case #WM_SIZE
      
      ResizeGadget(string1, -1, -1, WindowWidth(), WindowHeight())
      
  EndSelect
  ProcedureReturn Result 
EndProcedure 


;Creates the Window
If OpenWindow(0, 0, 0, 300, 200, #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar, "Math Tool")
  
  If CreateGadgetList(WindowID())
    
    ;Creates the Menu
    
    ;Creates a Popup Menu
    
    ;Creates the Gadgets
    string1 = StringGadget(#PB_Any, 0, 5, 150, 15, "", #PB_String_BorderLess)
    string2 = StringGadget(#PB_Any, 155, 5, 150, 15, "", #PB_String_BorderLess)
    string3 = StringGadget(#PB_Any, WindowWidth()/2-50, WindowHeight()/2-15, 100, 15, "")
    button1 = ButtonGadget(#PB_Any, WindowWidth()/2-50, WindowHeight()-50, 100, 50, "Click Me")
    
    ;Creates Statusbar
    
  EndIf
  
EndIf ;EndIf for OpenWindow

SetWindowCallback(@MyWindowCallback())


;Main Loop
Repeat
  
  EventID = WaitWindowEvent()
  
  If EventID = #PB_EventGadget
    
    Select EventGadgetID()
      
      Case button1
        answer.s = GetGadgetText(string1) + Space(1) + GetGadgetText(string2)
        SetGadgetText(string3, answer)
        
    EndSelect
    
  EndIf
  
Until EventID = #PB_EventCloseWindow

End
  
I know it might not be the best way to program, but forgive me I am just learning.

Posted: Wed Jun 23, 2004 8:09 pm
by freak
You must make the "string1" variable either "Global" or "Shared", so it is known inside the Callback procedure.

btw, you don't need any callback for this anymore. Just check the result
#PB_Event_SizeWindow from WaitWindowEvent() and do your resizing
there.

Timo

Posted: Wed Jun 23, 2004 8:34 pm
by Master Games
Thanks, that works.