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
Solved

A Window in a VB form?

Posted on 1998-09-11
14
220 Views
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.
0
Comment
Question by:DBDN1011
  • 5
  • 4
  • 4
  • +1
14 Comments
 
LVL 14

Expert Comment

by:waty
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 :
   http://ourworld.compuserve.com/homepages/raymer/kidnap.htm
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1434282
DBDN1011,

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.

Regards
Dalin


'Declare:

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

Type POINTAPI
       x As Long
       Y As Long
End Type


Type RECT
       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
       Dim lpTL As POINTAPI, lpBR As POINTAPI
       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
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1434283
DBDN1011,
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.

Regards

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:DBDN1011
ID: 1434284
waty,
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.

0
 
LVL 9

Expert Comment

by:Dalin
ID: 1434285
DBDN1011,
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.
Regards
0
 

Author Comment

by:DBDN1011
ID: 1434286
Dalin,
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.
0
 
LVL 2

Expert Comment

by:AllenC_Jr
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()
Form2.Show
DoEvents
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload Form2
End Sub

0
 
LVL 2

Expert Comment

by:AllenC_Jr
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.
0
 
LVL 2

Expert Comment

by:AllenC_Jr
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)
0
 
LVL 2

Expert Comment

by:AllenC_Jr
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.
0
 

Author Comment

by:DBDN1011
ID: 1434291
Sorry,
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.
0
 
LVL 9

Accepted Solution

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

Author Comment

by:DBDN1011
ID: 1434293
Thanks for all the help
0
 
LVL 9

Expert Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

808 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