• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 482
  • Last Modified:

Need to popup a dialog using a Window as its owner (popup in ocx, window in external app)

I have an ocx that pops up a dialog when a specific method is called.
This dialog sometimes is hidden by the main application. I want to make the main form of the application the owner (or the parent) of the popup window in my ocx.
I can request from the user to give me the handle of the window (the main window of their application or the window that is currently hiding my popup).
I tried doing this by calling popup.CreateParented(handle) where handle is the HWND of the external application, but it doesn't work.
I even wonder if this is possible.
The other option I'm using which I hate is to set the form as StayOnTop. Aside from being  (I believe) a bad programming practice, if another window pops up, the user gets stuck.
0
RNMisrahi
Asked:
RNMisrahi
  • 4
  • 2
  • 2
  • +1
3 Solutions
 
systanCommented:
As far as  I understand, No!,  this is not possible.
You can't force a popup messageBox to other application from your app.
0
 
samenglishCommented:
have you tried the ForceForegroundWindow suggestions from http://stackoverflow.com/questions/5877343/delphi-win7-window-focus-issue/5877472

I lost 50 rep points trying to help you yesterday! First with the registry reloading by killing 'explorer' (not best practice) and then by finding an implementation of ForceForegroundWindow (which the comunity also frowned upon)... and you didn't even give me a single upvote. :-( lol
0
 
RNMisrahiAuthor Commented:
Thanks systan,
Just to make sure that what I posted is clear:
My product is an ocx written in Delphi. Other developers use it and make calls to my ocx to do certain things that, among other things, popup a dialog (not a MessageBox). This dialog usually works fine, but for some developers that use a variety of languages, the window is hidden behind their own application window.
I was hopping to be able to get from them such a window. Since this is an ocx and who knows what language they'll be using, I was hoping I could get an integer that would contain the handle to the application window.
I myself tested with a simple application written in Delphi that uses my ocx and passes on the handle of the main application window, but when I bring up the ocx window parenting it with that handle, even though it comes up correctly inside the main application window, it doesn't seem to be able to be in focus. No mouse, keyboard or anything bring it up in focus. I get stuck there.

samenglish, sorry I don't understand what you say. Maybe you wanted to post this in some other question?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
developmentguruPresidentCommented:
If your current effort is getting the window to always show in front, but not getting focus, maybe try calling SetFocus as the final step?
0
 
RNMisrahiAuthor Commented:
developmentguru: thanks for the suggestion. We already do focus on a specific Control of the Form. The question is, which one is the final step?
I actually loop for a second until I see that the control is focused, but for some reason the window then goes back and the application that called it using the ocx comes up to the front.
Moreover, sometimes the calling application may have the StayOnTop option on, so I need to make it the parent of my ocx window.
A developer told me that he can have two executables A and B and make one of them run within the other. I mean, B will run within the window of program A. Is this possible?
I'll give points for an answer to this.
0
 
RNMisrahiAuthor Commented:
Let me clarify my previous comment:
What I mean an executable inside another executable, I mean that Program A passes on the handle of it's main form to Program B and with this information and this information alone, Program B runs inside Program A's main window.
0
 
developmentguruPresidentCommented:
You can take any windows based windows handle and set it's parent to your window (assuming it does not have an incompatible style).

Say your client app has a panel that is meant to house your OCX.  You can use the windows API function SetParent

http://msdn.microsoft.com/en-us/library/ms633541(v=vs.85).aspx

to set your OCX's parent as the handle that has been passed to you.  I would be certain that this handle is an otherwise blank control, that can have children, within the other application (Not the applications's main form handle).  I have done this in the past... not with an OCX though.  Since the OCX window still must have a windows handle, it should work.
0
 
samenglishCommented:
oops! sorry!
0
 
systanCommented:
I understand,
DevelopmentGuru got good comments.
Listening...

0
 
RNMisrahiAuthor Commented:
What I ended doing was I used the handle of the main application (which needs to be passed on to my ocx) and called ShowWindow(handle, SW_HIDE) when I show my popup window and then ShowWindow(handle, SW_SHOW) when I close it.

My conclusion is that what I wanted to do simply cannot be done.
But that's also good to know!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now