Evil callback problem:):)

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 Fangbeast.

I use the callback below to resize a form and its' gadgets as well as colour some objects on that one window and I don't want to resize or colour any other sub window. It's okay as long as no other windows are opened (originally designed only for that one window) but when you open any of the other sub windows, either they are the wrong size or the main window gets resized incorrectly.

How do I prevent the callback from working on any other window except the one I want? Something to do with #WM_GETMINMAXINFO I think.

Code: Select all

Procedure MyWindowCallback(WindowID, Message, wParam, lParam)

  Result = #PB_ProcessPureBasicEvents 

  Select message
    Case #WM_CTLCOLOREDIT
      SetTextColor_(wParam, #Foreground_Edit)
      SetBkMode_(wParam, #TRANSPARENT)
      Result = ColorBrush_Edit
    Case #WM_GETMINMAXINFO      ; Restrict the minimum size to 500x(307 + MenuHeight()), borders included
      Result = 0
      *ptr.MINMAXINFO       = lParam
      *ptr\ptMinTrackSize\x = 500
      *ptr\ptMinTrackSize\y = 306 + MenuHeight()
    Case #WM_SIZE ; Form's size has changed.
      winwidth.l  = WindowWidth()
      winheight.l = WindowHeight()
      RatioW.f   = winwidth  / OriginalWidth   ; Get horizontal difference.
      RatioH.f   = winheight / OriginalHeight  ; Get vertical difference.
      width.l    = 295 * RatioW
      height.l   = winheight - 82

      ResizeGadget(#Gadget_chatbox_chatframe,       5,          0,           width + 3,             height + 3)
      ResizeRichEdit(#Gadget_chatbox_chatbox,       5,         10,           width - 7,             height - 14)
      
      ResizeGadget(#Gadget_chatbox_entryframe,     -1,         height,       width + 3,             35)
      ResizeGadget(#Gadget_chatbox_entrybox,       10,         height + 10,  width - 7,             20)
      
      ResizeGadget(#Gadget_chatbox_userframe,      width + 11, -1,           winwidth - width - 17, height + 3)
      ResizeGadget(#Gadget_chatbox_userbox,        width + 16, -1,           winwidth - width - 27, height - 12)
      
      ResizeGadget(#Gadget_chatbox_buttonframe,    width + 11, height,       winwidth - width - 17, 35)
      xpos.l = width + 25
      RatioW = (winwidth - width - 35) / 170
      ResizeGadget(#Gadget_chatbox_sendtext,       xpos - 10,  height + 10,  50 * RatioW + 3,       20)
      xpos + (50 * RatioW)
      ResizeGadget(#Gadget_chatbox_savelog,        xpos -  7,  height + 10,  50 * RatioW + 3,       20)
      xpos + (50 * RatioW)
      ResizeGadget(#Gadget_chatbox_disconnect,     xpos -  4,  height + 10,  70 * RatioW + 4,       20)
      UpdateStatusBar(#StatusBar_chatbox)
      RedrawWindow_(WindowID(), 0, 0, #RDW_INVALIDATE)
  EndSelect
  
  ProcedureReturn Result

EndProcedure 
We are Dyslexic of Borg, prepare to have your ass laminated!
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 Berikco.

Code: Select all

Procedure MyWindowCallback(WindowID, Message, wParam, lParam)
  
  Result = #PB_ProcessPureBasicEvents
  If WindowID = WindowID(#yourwindow)
    Select message
      Case #WM_CTLCOLOREDIT
        SetTextColor_(wParam, #Foreground_Edit)
        SetBkMode_(wParam, #TRANSPARENT)
        Result = ColorBrush_Edit
      Case #WM_GETMINMAXINFO      ; Restrict the minimum size to 500x(307 + MenuHeight()), borders included
        Result = 0
        *ptr.MINMAXINFO       = lParam
        *ptr\ptMinTrackSize\x = 500
        *ptr\ptMinTrackSize\y = 306 + MenuHeight()
      Case #WM_SIZE ; Form's size has changed.
        winwidth.l  = WindowWidth()
        winheight.l = WindowHeight()
        RatioW.f   = winwidth  / OriginalWidth   ; Get horizontal difference.
        RatioH.f   = winheight / OriginalHeight  ; Get vertical difference.
        width.l    = 295 * RatioW
        height.l   = winheight - 82
        
        ResizeGadget(#Gadget_chatbox_chatframe,       5,          0,           width + 3,             height + 3)
        ResizeRichEdit(#Gadget_chatbox_chatbox,       5,         10,           width - 7,             height - 14)
        
        ResizeGadget(#Gadget_chatbox_entryframe,     -1,         height,       width + 3,             35)
        ResizeGadget(#Gadget_chatbox_entrybox,       10,         height + 10,  width - 7,             20)
        
        ResizeGadget(#Gadget_chatbox_userframe,      width + 11, -1,           winwidth - width - 17, height + 3)
        ResizeGadget(#Gadget_chatbox_userbox,        width + 16, -1,           winwidth - width - 27, height - 12)
        
        ResizeGadget(#Gadget_chatbox_buttonframe,    width + 11, height,       winwidth - width - 17, 35)
        xpos.l = width + 25
        RatioW = (winwidth - width - 35) / 170
        ResizeGadget(#Gadget_chatbox_sendtext,       xpos - 10,  height + 10,  50 * RatioW + 3,       20)
        xpos + (50 * RatioW)
        ResizeGadget(#Gadget_chatbox_savelog,        xpos -  7,  height + 10,  50 * RatioW + 3,       20)
        xpos + (50 * RatioW)
        ResizeGadget(#Gadget_chatbox_disconnect,     xpos -  4,  height + 10,  70 * RatioW + 4,       20)
        UpdateStatusBar(#StatusBar_chatbox)
        RedrawWindow_(WindowID(), 0, 0, #RDW_INVALIDATE)
    EndSelect
  EndIf
  ProcedureReturn Result
  
EndProcedure
Regards,

Berikco

http://users.pandora.be/berikco/purebasic.htm
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 Fangbeast.

Thanks Berikco but despite following this and what you said on IRC, I still can't stop the windows from resizing to the last one that has been on the screen. Sorry that I can't understand what to do, but no experience with such things. Have tried all you said though.

We are Dyslexic of Borg, prepare to have your ass laminated!
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 Justin.

In the #WM_SIZE msg resize the window only if it matches the WindowID (handle).
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 Pupil.

Try to use the command UseWindow(#YourWindow) before you use WindowWidth() and WindowHeight() inside your callback...
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 Fangbeast.

@Justin I did try that, some strange things were happening because I had already put a check in at the top of the callback for the window id.

@Pupil Thanks, that did it, would not have occured to me even if you had hit me with a dead trout that it could work.

@Bericko thanks for your modifications as well, they made things a little easier to deal with

We are Dyslexic of Borg, prepare to have your ass laminated!
Post Reply