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(hwnd
Ctl), 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(hwnd
Ctl), 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.com
Start Free Trial