OK, I'm stuck. What I'm trying to do is place MSN Messenger IM windows inside my form. The first way I thought of doing this was to use SetParent on them, remove the title bar, and resize it accordingly. This works well, except there are a lot of focus problems: you click in the IM window and my window does not get focus. This leads to many, many problems.

So, I thought, why not take just the actual chat box, and not the IM window. For those of you who don't know, there is the main IM window, which is of the IMWindowClass, and inside there is one child control called DirectUIHWND. So I thought I could just pull that out. This actually works, but there are redrawing issues, and I don't think the IM Window wants to let its only child go.

Below is the code I'm using... I'm wondering if anyone knows how to get it to redraw correctly., or how to possibly tell the main IM window to get over the fact the DirectUIHWND window is gone.

Fire up VB, make the form plenty big, put a command button in the top corner, paste the code below, start MSN, open a chat window, and run the project and click the button.

VB Code:
  1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  2. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
  3. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
  4. Private Declare Function MoveWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal x As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
  5.  
  6. Private Declare Function RedrawWindow Lib "user32" (ByVal hwnd As Long, lprcUpdate As Any, ByVal hrgnUpdate As Long, ByVal fuRedraw As Long) As Long
  7.  
  8. Private Const RDW_ALLCHILDREN As Long = &H80
  9. Private Const RDW_ERASE As Long = &H4
  10. Private Const RDW_INVALIDATE As Long = &H1
  11.  
  12.  
  13. Sub RefreshWindow()
  14.     RedrawWindow Me.hwnd, ByVal 0&, ByVal 0&, RDW_INVALIDATE Or RDW_ALLCHILDREN Or RDW_ERASE
  15. End Sub
  16.  
  17.  
  18. Private Sub Command1_Click()
  19.     Dim IMWindow As Long, dui As Long
  20.  
  21.     IMWindow = FindWindow("IMWindowClass", vbNullString)
  22.     diu = FindWindowEx(IMWindow, 0&, "DirectUIHWND", vbNullString)
  23.     'Stop
  24.     SetParent diu, Me.hwnd
  25.     MoveWindow dui, 0, Command1.Height, Me.ScaleWidth, Me.ScaleHeight - Command1.Height, 1  'Doesn't work for some reason
  26.     RefreshWindow
  27. End Sub
  28.  
  29. Private Sub Form_Resize()
  30.     RefreshWindow
  31. End Sub