Advertisement

08.16.2000 at 07:25AM PDT, ID: 11020261
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.6

SetParent on a UserControl's child - window events/msgs and repaint problems

Asked by rlively in Visual Basic Programming

Tags: , ,

I have a UserControl in which I dynamically load CheckBoxes into a CheckBox
control array (there is one with index 0 on the UserControl to begin with)
using Load(Check1(Check1.Ubound +1)) whenever I need a new one.  What I want
to do then is use the SetParent API to place the new CheckBox on a Form or
another UserControl:

  Call SetParent(Check1(NewIndex).hWnd, GetParent(ctl.hWnd))

Where ctl is a control that was passed into a Method in this UserControl.
What it does is put the new CheckBox on the same parent/container as the
control that was passed in.  I then move the checkbox to be positioned
immediately to the right of the passed-in control.

This works perfectly if my UserControl .ctl is in the same project as the
Form or UserControl, the problem comes when I compile the control into an
.OCX.  When I try to access this UserControl from a new .EXE project, there
is a box the right size and shape for the new checkboxes, but they never get
repainted correctly - they look like whatever background happened to be
behind the window when they were created (If in the VB development
environment, you might see bits of code painted onto the CheckBox face).
They also do not get click events at all.

I found an MSKB article (Article ID: Q104069
http://support.microsoft.com/support/kb/articles/Q104/0/69.asp) that looks
like it /might/ be in some way related to what's happening, but when I tried
implementing what it says to do I still get the same results.  The article
states:

An edit, list box, or combo box control sends notifications to the original
parent window even after SetParent has been used to change the control's
parent.
If it is required that notifications go to the new parent window, code must
be added to the old parent's window procedure to pass on the notifications
to the new parent.

For example:

   case WM_COMMAND:
     hwndCtl = LOWORD(lParam);

     // If notification is from a control and the control is no longer this
     //   window's child, pass it on to the new parent.
     if (hwndCtl && !IsChild(hWnd, hwndCtl))
         SendMessage(GetParent(hwndCtl), WM_COMMAND, wParam,  lParam);
     else Do normal processing;

----------

I tried this method by subclassing my usercontrol and changing the
WindowProc to this:

Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal
wParam As Long, ByVal lParam As Long) As Long

Dim hwndCtl As Integer
Dim retval As Long

  Select Case uMsg
    Case WM_COMMAND
      hwndCtl = LoWord(lParam)
      If (hwndCtl And (Not IsChild(hWnd, hwndCtl))) Then
      ' If notification is from a control and the control is no longer this
      '   window's child, pass it on to the new parent.
        Call SendMessage(GetParent(hwndCtl), WM_COMMAND, wParam, lParam)
      Else
        retval = CallWindowProc(pOldProc, hWnd, uMsg, wParam, lParam)
        ' Have this function return whatever the function above returned.
        WindowProc = retval
      End If
  End Select

  retval = CallWindowProc(pOldProc, hWnd, uMsg, wParam, lParam)
  ' Have this function return whatever the function above returned.
  WindowProc = retval

End Function

----------

Does anyone have any ideas about what I could do to remedy this problem or
what might be causing it?  Any help would be greatly appreciated

Russell Lively
rlively@lawco.comStart Free Trial
 
 
[+][-]08.16.2000 at 09:01AM PDT, ID: 3952621

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.17.2000 at 09:05AM PDT, ID: 3968975

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.17.2000 at 09:31AM PDT, ID: 3969384

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.19.2000 at 07:03PM PDT, ID: 3995808

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.20.2000 at 12:40PM PDT, ID: 4000543

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.06.2000 at 09:45AM PDT, ID: 4211144

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Visual Basic Programming
Tags: setparent, vb, parent
Sign Up Now!
Solution Provided By: rlively
Participating Experts: 3
Solution Grade: A
 
 
[+][-]09.14.2000 at 12:38PM PDT, ID: 4307937

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.14.2000 at 02:53AM PDT, ID: 4728479

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]10.14.2000 at 02:53AM PDT, ID: 4728480

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.14.2000 at 02:54AM PDT, ID: 4728482

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32