Dynamic Numbering for Gadgets, Help.

Just starting out? Need help? Post your questions and find answers here.
Master Games
User
User
Posts: 22
Joined: Mon Oct 06, 2003 1:42 am

Dynamic Numbering for Gadgets, Help.

Post 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.
Thanks,
Master Games

System: P4 1.9 GHZ, 1 GB DDR Memory, 80 GB Hard Drive, WinXP Home Edition with Latest Patch, Creative labs Audigy Sound Blaster Platinum Sound Card, Geforce 3 Graphics card with 52.16 drivers
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
Master Games
User
User
Posts: 22
Joined: Mon Oct 06, 2003 1:42 am

Post by Master Games »

Thanks, that works.
Thanks,
Master Games

System: P4 1.9 GHZ, 1 GB DDR Memory, 80 GB Hard Drive, WinXP Home Edition with Latest Patch, Creative labs Audigy Sound Blaster Platinum Sound Card, Geforce 3 Graphics card with 52.16 drivers
Post Reply