Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Command Bars
  New Posts New Posts RSS Feed - ComboBox - supress Popup
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

ComboBox - supress Popup

 Post Reply Post Reply
Author
Message
DDTech View Drop Down
Groupie
Groupie


Joined: 10 October 2007
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote DDTech Quote  Post ReplyReply Direct Link To This Post Topic: ComboBox - supress Popup
    Posted: 25 December 2008 at 11:26am

I have a xtpControlComboBox member in one of my toolbars where I would like to show a form (with a date-picker) instead of the popup.

I thought the right place to look at would be ControlNotify. In this I check the incoming Control.id and if the "code" is 7 (XTP_CBN_DROPTDOWN), I set handled to .t. and expect the popup not to appear. Hovever the control is not impressed of my doing so.

Any other idea how to acomplish this?

VFP 9 SP2, WinXP SP2, XtremeCommandbars 12.1.1

Thanks for any hint

regards (and merry christmas)

Frank
Back to Top
DDTech View Drop Down
Groupie
Groupie


Joined: 10 October 2007
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote DDTech Quote  Post ReplyReply Direct Link To This Post Posted: 27 December 2008 at 10:14am
Oleg,

any hint on that?

This is what I want to achieve.



This is what I currently do:

In an initialization procedure, after loading Designerbars, I do some size-Optimization and set the Combo's Dropdown to a width of 1 px. and the ItemCount to 0. This does not make the dropdown not appear but it's only a few pix in size so that the user does not realize.


    loCBO = loToolbar.FindControl(5, ID_SCHEDMAIN_DATE)

    *-- resize the combo's width to the space needed for
    *-- display of current date + room for the dropdown-
    *-- arrow + some "air"
    loCBO.Width = ;
      txtWidth(dtoc(date()), this.Text1.FontName, this.Text1.FontSize, "B")*;
      fontMetric(6, this.Text1.FontName, this.Text1.FontSize, "B")+;
      + sysMetric(5) + lnWidthAdd
         
     *-- try to hide as much of the combo as possible 
     loCBO.DropdownWidth     = 1
     loCBO.DropDownItemCount = 0


I then listen to the ControlNotify-event and show the calendar as soon as the user clicks on the down-arrow. The actual ShowCalendar() procedure is separated from the event by calling it via timer with a short delay. This way we can leave the event immediately, which is crucial to avoid "letters to Bill" as I call them (a GPF is almost a sure thing when an error occurs within VFP-Code while still being in some kind of ActiveX-event). A delay of 20ms or even less is safe enough and almost not to realize,

PROCEDURE ControlNotify(Control as Object, Code as Long, NotifyData as variant, Handled as Variant)
    if Control.ID =
ID_SCHEDMAIN_DATE 
        if Code=7 && Dropdownarrow clicked and popup is about to open
            *-- "handled" is coming in via reference.
            *-- setting it to .T. should tell the toolbar
            *-- "I'll take care of it. Unfortunately it
            *-- does not seem to care. But we're good
            *-- good guys and do behave.
            Handled = .t.
           
            *-- this causes an immediate GPF:           
            *oForm = Create("FORM")
            *oForm.halfHeightcaption = .T.
            *oForm.Show
            *--> letter to Bill

            *-- ... so call the ShowCalender via timer and
            *-- let the event return immediately
            thisform.tmrAction.doCommand("thisform.ShowCalendar("+ trans(
ID_SCHEDMAIN_DATE) +")")
           
        endif
    endif
ENDPROC


ShowCalendar opens and positions the form below the control

PROCEDURE ShowCalendar(tnControlID as integer) as boolean
tnControlID = iif(vartype(tnControlID) = "N", tnItemID, 1101)

public oCal
local  a,b,c,d,a1,b1,c1,d1, loTB, loCBO, loCB

store 0 to a,b,c,d, a1,b1,c1,d1

loTB    = this.TB
loCBO   = this.TB.FindControl(5, tnControlID)

if ! isNull(loCBO)
    && !!!! More generic - Test only !!!
    loCB = loTB.ActiveMenubar.Commandbars(3)

    *-- get rectangles for control and commandbar
    loCB.GetWindowRect(@a,@b,@c,@d)
    loCBO.GetRect(@a1,@b1,@c1,@d1)

    *-- frmDatePick is a class that releases itself
    *-- on lostfocus and binds itself to a target
    *-- it reports to in case a positive date-selection
    *-- is made
    oCal = newObject("frmDatePick", "SCHED_FORMS", "", ThisForm.txtDatum)

    *-- move the form below the date-combo, align with the
    *-- right border
    oCal.Move(;
        a+c1-oCal.Width-2-_screen.left,;
        b-_screen.Top + d1+3)

    oCal.Show
endif  && ! isNull(...)

ENDPROC

This works pretty well, though not the ideal solution. I'd really like to get rid of the combo's popup although the trick is almost perfect.  Any recommendations gladly welcome.

Frank.




Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 05 January 2009 at 2:52am
Hi,
 
This code works for Visual Basic:
 
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Sub CommandBars_TrackingModeChanged(ByVal CommandBar As XtremeCommandBars.ICommandBar, ByVal Mode As Boolean)
    If (CommandBar.BarID = 100) Then
            DestroyWindow CommandBar.hwnd
    End If
End Sub
Private Sub Form_Load()
CommandBars.EnableOffice2007Frame True
Dim Combo As CommandBarComboBox
Set Combo = CommandBars.ActiveMenuBar.Controls.Add(xtpControlComboBox, 100, "Date")
Combo.DropDownListStyle = False
Combo.Text = "01/01/2009"
Dim ComboDropDown As CommandBar
Set ComboDropDown = CommandBars.Add("ComboDropDown", xtpBarPopup)
ComboDropDown.BarID = 100
Set Combo.CommandBar = ComboDropDown

End Sub
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
DDTech View Drop Down
Groupie
Groupie


Joined: 10 October 2007
Status: Offline
Points: 23
Post Options Post Options   Thanks (0) Thanks(0)   Quote DDTech Quote  Post ReplyReply Direct Link To This Post Posted: 06 January 2009 at 1:38pm
Originally posted by oleg oleg wrote:

 
This code works for Visual Basic:
 
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Sub CommandBars_TrackingModeChanged(ByVal CommandBar As XtremeCommandBars.ICommandBar, ByVal Mode As Boolean)
    If (CommandBar.BarID = 100) Then
            DestroyWindow CommandBar.hwnd
    End If
End Sub
....


BANG - this directly sends VFP to hell. Same when I try to do it from within the ControlNotify.

However,  the tip pointed into the right direction. Destroying the window only once seems to be enough, and when I do that directly after initializing the toolbar all further calls report a window handle of "0" and no popup appears.

So the working code now looks like this:

    loCBO = loToolbar.FindControl(5, ID_SCHEDMAIN_DATE)

    *-- resize the combo's width to the space needed for
    *-- display of current date + room for the dropdown-
    *-- arrow + some "air
       
    loCBO.Width = ;
          txtWidth(dtoc(date()), this.Text1.FontName, this.Text1.FontSize, "B")*;
          fontMetric(6, this.Text1.FontName, this.Text1.FontSize, "B") + sysMetric(5) + lnWidthAdd
       
       
    *-- DD changed on 06.01.09
    *-- directly delete the combo's Commandbar-Window and
    *-- by that way prevent it from ever showing up.
 
    if loCBO.CommandBar.hWnd > 0
        declare long DestroyWindow in USER32 as CB_DestroyWindow long hWnd
        CB_DestroyWindow(loCBO.CommandBar.hWnd)
        clear Dlls CB_DestroyWindow
   endif
   ...

This seems to work like a charm and clicking the down-arrow shows the calendar as if it ever belonged there.
 
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.