• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

Making a drop down control

I am trying to build a custom drop down control. Basically, in this case, I have an ActiveX control that has a text box and a down arrow button. When the arrow button is clicked, I want to display a form that is stored in the control. Now I can do this part.

What I need help with is possitioning the form directly under the ActiveX control on the user's form and how to detect if a mouse click was outside of the newely displayed form.

For the sake of this question, the form being opened can be blank. Later i will add various controls to it that will be used to populate the textbox in the activex control.

Anyone have a chunk of code that can popup a form under any given control then hide it if a mouse click happens outside of the popped form?
0
schworak
Asked:
schworak
  • 3
  • 3
1 Solution
 
anthonycCommented:
I wrote a drop down calendar control once if you want to see it  Let me know..

but as on how to do it.. Do this..

When you show the form (drop down), call "SetCapture" API with the HWND of the form.  Now that will force ALL mouse events to go to the form, NO MATTER where you click.  You'll need to write a function to pass the mouse to the control on your form it really clicked on.  You can do that by passing the X, Y in the mousedown event on the form to a function to find the control.  If the X, Y are negative, OR OUTSIDE the boundaries of the form (width, height) then you can assume it is outside of the control and close the form.

Does that make ssense? W hen you close the form, Call releasecapture to get normal mouse operation back
0
 
schworakAuthor Commented:
anthonyc:

Well, that is part of the answer. I will give you the points, but the only way I can add a comment without accepting first is to reject. So add a little more info as an answer and I will accept that.

Yeah, I would love to see that drop calendar too. glenn@g-world.com if you want to EMail it to me.

Anyway, I will give the set capture to check for the mouse clicks. But could you tell me how you get the form to line up directly under your main control when you do the Drop Down trick? I can't figure out what API to use to capture my control's position relative to the screen not the form it sits on.
0
 
anthonycCommented:
oh I forgot to type that...

Private Sub PositionDropDown()
    Dim rct As RECT
    GetWindowRect UserControl.hwnd, rct
    SetWindowPos m_frmDown.hwnd, -1, rct.Left, rct.Top + UserControl.ScaleY(picCombo.Height, vbTwips, vbPixels), _
                                 0, 0, SWP_NOSIZE
End Sub


The drop down is on the way to glenn@g-world.com
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
schworakAuthor Commented:
Thank you so much!
0
 
schworakAuthor Commented:
Oops! Ran into one little snag...

SetCapture doesn't work for me. I have several controls on the dropdown form that need to be able to be selected/changed. One is a list box.

SetCapture intercepts the first click and loses it's capture on the second click and I can't seem to get it to regain capture.

How do I keep the capture of the mouse events and also allow the control being clicked to also get the mouse events? Do I need some type of subclassing?
0
 
anthonycCommented:
did you remmeber to use releasecapture when the mouse goes up?
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now