Print Page | Close Window

Ribbonbar Systembutton

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=11566
Printed Date: 07 October 2024 at 8:27am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Ribbonbar Systembutton
Posted By: JvdH
Subject: Ribbonbar Systembutton
Date Posted: 24 July 2008 at 9:50am
Hi,
 
Is there a way to disable that the app closes when doubleclick on the system button, I cannot find a way to disable that.
 
Thank you :)



Replies:
Posted By: Baldur
Date Posted: 24 July 2008 at 2:31pm

In VB6 use Form_QueryUnload-Event.



Posted By: jpbro
Date Posted: 24 July 2008 at 3:52pm
I'm not sure if there's an easier way (I'd like to know if there is), but using the QueryUnload event as Baldur suggests doesn't differentiate between double-clicking the system button and clicking the X button. You can test for the position of the mouse cursor and make sure it is not in the SystemButton area though, so something like this works:


Private mobjSysBtn As CommandBarPopup

Private Type POINTAPI
   x As Long
   y As Long
End Type

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32.dll" (ByVal hwnd As Long, ByRef lpPoint As POINTAPI) As Long
Private Declare Function PtInRect Lib "user32.dll" (ByRef lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   Dim udtPoint As POINTAPI
   Dim udtRect As RECT
  
   With udtRect
      mobjSysBtn.GetRect .Left, .Top, .Right, .Bottom   ' Get the position of the SystemButton
   End With
  
   If UnloadMode = vbFormControlMenu Then
      GetCursorPos udtPoint    ' Get the position of the mouse pointer
      ScreenToClient Me.hwnd, udtPoint    ' Convert screen coordinates to coordinates relative to the form with the SystemButton
     
      Cancel = PtInRect(udtRect, udtPoint.x, udtPoint.y)    ' Only cancel unloading if the mouse pointer is not above the SystemButton
   End If
End Sub


A potential problem with this approach is that the program won't close if the pointer is above the SystemButton and the user press Ctrl+F4 (probably a rare circumstance, but definitely a limitation of this approach...I suppose you could perform a check to see if the Ctrl key is down and if so ignore the pointer position).

I'd be happy to be shown an easier way to do this. The only other way I know is to subclass the system button and consume WM_LBUTTONDBLCLK (complicated, but I have an example if you are interested).


-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6



Posted By: jpbro
Date Posted: 24 July 2008 at 3:55pm
I should add, make sure to call Set mobjSysBtn = RibbonBar.AddSystemButton() (or equivalent) to assign the SystemButton to the object reference.


-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net