Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


A Window in a VB form?

Posted on 1998-09-11
Medium Priority
Last Modified: 2010-04-30
I would like my VB to take control of another window APP whcih is a stand along. The other app has it's gui. I would like to show it's graphics but do not want to user to be able to interact with it.  What I am thinking is to shell start the app, abd shows only part of the other App's GUI. SO idealy would be have a hole or a window in my VB form, so  the user does not see the menu, the title bar, and some of the command buttons...

Anyone have a way of disable the controling part of another App?

I can give more points for a real working solution.  Any comments that helped in find a solution would also get some credit.
Question by:DBDN1011
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
  • +1
LVL 14

Expert Comment

ID: 1434281
I have just found code to do domething like that a few minutes ago.

I have downloaded it, but not yet tested. If you want I can send it to you by e-mail.

Here is the url :

Expert Comment

ID: 1434282

It was a interesting project waty posted.  Good job, waty!

I have a code to make a form transparent, but I have not worked it out for a portion of the form. I post it here and you may experiemtnwith it to see if it works for you.



Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRECT As RECT) As Long

Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRECT As RECT) As Long

Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long

Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long

Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
       Public Const RGN_AND = 1
       Public Const RGN_COPY = 5
       Public Const RGN_DIFF = 4
       Public Const RGN_OR = 2
       Public Const RGN_XOR = 3

       x As Long
       Y As Long
End Type

       Left As Long
       Top As Long
       Right As Long
       Bottom As Long
End Type

Public Sub MakeTransparent(frm As Form)

       '     'This code was takin from a AOL Visual Basic
       '     'Message Board. It was submited by: SOOPRcow
       Dim rctClient As RECT, rctFrame As RECT
       Dim hClient As Long, hFrame As Long
       '     '// Grab client area and frame area
       GetWindowRect frm.hWnd, rctFrame
       GetClientRect frm.hWnd, rctClient
       '     '// Convert client coordinates to screen coordinates
       lpTL.x = rctFrame.Left
       lpTL.Y = rctFrame.Top
       lpBR.x = rctFrame.Right
       lpBR.Y = rctFrame.Bottom
       ScreenToClient frm.hWnd, lpTL
       ScreenToClient frm.hWnd, lpBR
       rctFrame.Left = lpTL.x
       rctFrame.Top = lpTL.Y
       rctFrame.Right = lpBR.x
       rctFrame.Bottom = lpBR.Y
       rctClient.Left = Abs(rctFrame.Left)
       rctClient.Top = Abs(rctFrame.Top)
       rctClient.Right = rctClient.Right + Abs(rctFrame.Left)
       rctClient.Bottom = rctClient.Bottom + Abs(rctFrame.Top)
       rctFrame.Right = rctFrame.Right + Abs(rctFrame.Left)
       rctFrame.Bottom = rctFrame.Bottom + Abs(rctFrame.Top)
       rctFrame.Top = 0
       rctFrame.Left = 0
       '     '// Convert RECT structures to region handles
       hClient = CreateRectRgn(rctClient.Left, rctClient.Top, rctClient.Right, rctClient.Bottom)
       hFrame = CreateRectRgn(rctFrame.Left, rctFrame.Top, rctFrame.Right, rctFrame.Bottom)
       '     '// Create the new "Transparent" region
       CombineRgn hFrame, hClient, hFrame, RGN_XOR
       '     '// Now lock the window's area to this created region
       SetWindowRgn frm.hWnd, hFrame, True
End Sub

Expert Comment

ID: 1434283
I was trying to do it with a picture box, and was hoping to make the pixture box area transparent and thus you can have the other app under it...I can make the picture box transperent in the form, but the form's backgrounfd is still there...

You can add a toolbar and menus in the form, put your controling stuff in menu and tool bar, and make the form transperent. Hopefully, your form's tilte bar, toolbar and menu can cover the other app's.


Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 1434284
Thank you for the posting.  I downloaded the prokect and it was pretty cool.
However, It does not really suit my need.  I do not want the other app's control. This one will replace my nemu with the other apps. it is basally like I shell start the other one, and minimize my self. Beside, I have other MDI child which causes problem.
I think this code still need some debugging, since my three tries end up with illegal function and shutdown.

I am still trying Dalin's. It's more like what I am look for. But I was not able to dig a hole in the form

Thanks for the help so far, gentlemen.


Expert Comment

ID: 1434285
I spend a little more time on the problem. Unforturnately, I was not able to dig a hole in the form yet. But I think what you can do is to prepare a couple of tileless forms, and shows around the 3rd party app to cover the things you want. make those form to be Always on top. Since it does not have title bar, it will not move..
I will let you know if I get a better idea.

Author Comment

ID: 1434286
I think I am getting an good results from your solution. Let me know if you have more thoughts.
The problem is more difficult than I thought. I will increase the points.

waty, Thank you for the posting, Although it did not work in my case, I am grateful for your answer. While I would like to credit this to Dalin, I am award you some points too.

Thanks to all.

Expert Comment

ID: 1434287
Here is Some Code I Wrote To Do This
Private Declare Function SetParent& Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long)

Private Declare Function SetWindowText Lib "user32" _
    Alias "SetWindowTextA" (ByVal hwnd As Long, _
    ByVal lpString As String) As Long

Private Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$)

Private Sub EnslaveWindow(ObjCage As Object, WindowCaption$, Optional WindowClass As String = "", Optional NewWindowCaption$)
Dim m_lngCagedWindow&
m_lngCagedWindow = FindWindow(ByVal vbNullString, ByVal WindowCaption) 'The Caption isn't Case Sensitive
If m_lngCagedWindow = 0 Then Exit Sub
SetParent m_lngCagedWindow, ObjCage.hwnd
If Not NewWindowCaption = "" Then
SetWindowText m_lngCagedWindow, NewWindowCaption
End If
ObjCage.Enabled = False
End Sub

Private Sub Form_Activate()
EnslaveWindow P1, "Form2", "", "Rex"
End Sub

Private Sub Form_Load()
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload Form2
End Sub


Expert Comment

ID: 1434288
I Almost Forgot, I Need to Point Out that P1 Is A Picture Box, A Way you can Get Only A Portion of the Object is to do this

You could Create 2 Picture Boxes
 The First One Being the Area that you want to view on the form.
  The Second the Form PlaceHolder(object that holds the form)

You Could Place the Second Picture Box Inside the First and Move it until you get the area of the form that you want to view.

Expert Comment

ID: 1434289
Oh yeah I Almost forgot that you'll need o use the SetWindowPos API Call to set the form's Left And Top To 0
Here it is.
Private Declare Function SetWindowPos Lib "User32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal CX As Long, ByVal CY As Long, ByVal wFlags As Long) As Long

You Might have to find out how to use this API Call with this method(i can't get it to work for some stupid reason)

Expert Comment

ID: 1434290
Hey I Also (after reading all the Postings) realized that you could Capture the Form you want to control's hWnd with the FindWindow API Call(captures the hwnd) Which would allow you to create parts of that form transparent(all parts except the area you want) then create a hold on your form the same size then use the setwindowpos api call that would allow you to move it under that hole.

Author Comment

ID: 1434291
I was on vocation. I will check this out.
As I mentioned I would award this points to Dalin. If yours work, I will post a question for  you.
Thanks for your help.

Accepted Solution

Dalin earned 4000 total points
ID: 1434292
Thank you.  I realy don't care that much about points any more.

Author Comment

ID: 1434293
Thanks for all the help

Expert Comment

ID: 1434294
You don't need to give me so many points.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question