Link to home
Start Free TrialLog in
Avatar of RNMisrahi
RNMisrahiFlag for United States of America

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of systan
systan
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of RNMisrahi

ASKER

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?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oops! sorry!
I understand,
DevelopmentGuru got good comments.
Listening...

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!