Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 29th, 2005, 2:16 PM   #1
csharp
Newbie
 
Join Date: Oct 2005
Posts: 3
Rep Power: 0 csharp is on a distinguished road
How to to do this using Win32 API?

Hi,

I have a third party application (Application A) and I have my C# WinForm Application. In my WinForm application, I have a popup window that is shown when user clicks a button. Now, the trickest part is, I need to show the popup window as a modal window in Application A's main window.

I tried SetParent API and then used EnableWindow to disable Application A's main window. SetParent was able to show my popup window into the Application A' main window but the problem I found here is I lose mouse activity on my popup window. Keyboard tabbing works fine and if I do Alt-Tab, the popup window is completely inaccessible (disabled) with no activity.

Next, I tried AttachThreadInput and calling SetForeGroundWindow, but nothing works. Although AttachThreadInput returns true for me, I couldn't see any change in behavior.

So, in summary, how do I make my popup window from my app show up as a child window and also a modal window inside Application A' main window?

I'm posting this in C++ section also thinking that hardcore C++ developers might be able to help me.

Appreciate feedbacks.

Rgds.
csharp is offline   Reply With Quote
Old Oct 29th, 2005, 2:21 PM   #2
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 252
Rep Power: 4 Brent is on a distinguished road
you'll get more help if you post this in the C# forum.
Brent is offline   Reply With Quote
Old Oct 29th, 2005, 10:17 PM   #3
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
You might want to have a look at this extract that I just found in the WIN32 API Help file after a quick search on modal dialog boxes. There are a few things in this extract relevant to ensuring you don't lose mouse input.

Quote:
Originally Posted by WIN32 API Help File
A modal dialog box should be a pop-up window having a System menu, a title bar, and a thick border; that is, the dialog box template should specify the WS_POPUP, WS_SYSMENU, WS_CAPTION, and DS_MODALFRAME styles. Although an application can designate the WS_VISIBLE style, Windows always displays a modal dialog box regardless of whether the dialog box template specifies the WS_VISIBLE style. An application must not create a modal dialog box having the WS_CHILD style. A modal dialog box with this style disables itself, preventing any subsequent input from reaching the application.

An application creates a modal dialog box by using either the DialogBox or DialogBoxIndirect function. DialogBox requires the name or identifier of a resource containing a dialog box template; DialogBoxIndirect requires the handle of a memory object containing a dialog box template. The DialogBoxParam and DialogBoxIndirectParam functions also create modal dialog boxes; they are identical to the previously mentioned functions but pass a specified parameter to the dialog box procedure when the dialog box is created.

When creating the modal dialog box, Windows makes it the active window. The dialog box remains active until the dialog box procedure calls the EndDialog function or Windows activates a window in another application. Neither the user nor the application can make the owner window active until the modal dialog box is destroyed.
When the owner window is not already disabled, Windows automatically disables the window and any child windows belonging to it when it creates the modal dialog box. The owner window remains disabled until the dialog box is destroyed. Although a dialog box procedure could potentially enable the owner window at any time, enabling the owner defeats the purpose of the modal dialog box and is not recommended. When the dialog box procedure is destroyed, Windows enables the owner window again, but only if the modal dialog box caused the owner to be disabled.

As Windows creates the modal dialog box, it sends the WM_CANCELMODE message to the window (if any) currently capturing mouse input. An application that receives this message should release the mouse capture so that the user can move the mouse in the modal dialog box. Because Windows disables the owner window, all mouse input is lost if the owner fails to release the mouse upon receiving this message.
To process messages for the modal dialog box, Windows starts its own message loop, taking temporary control of the message queue for the entire application. When Windows retrieves a message that is not explicitly for the dialog box, it dispatches the message to the appropriate window. If it retrieves a WM_QUIT message, it posts the message back to the application message queue so that the application's main message loop can eventually retrieve the message.

Windows sends the WM_ENTERIDLE message to the owner window whenever the application message queue is empty. The application can use this message to carry out a background task while the dialog box remains on the screen. When an application uses the message in this way, the application must frequently yield control (for example, by using the PeekMessage function) so that the modal dialog box can receive any user input. To prevent the modal dialog box from sending the WM_ENTERIDLE messages, the application can specify the DS_NOIDLEMSG style when creating the dialog box.

An application destroys a modal dialog box by using the EndDialog function. In most cases, the dialog box procedure calls EndDialog when the user chooses the Close command from the dialog box's System menu or chooses the OK or Cancel button in the dialog box. The dialog box can return a value through the DialogBox function (or other creation functions) by specifying a value when calling the EndDialog function. Windows returns this value after destroying the dialog box. Most applications use this return value to determine whether the dialog box completed its task successfully or was canceled by the user. Windows does not return control from the function that creates the dialog box until the dialog box procedure has called the EndDialog function.
grumpy is offline   Reply With Quote
Old Oct 31st, 2005, 1:29 PM   #4
csharp
Newbie
 
Join Date: Oct 2005
Posts: 3
Rep Power: 0 csharp is on a distinguished road
This suggestion is great as long as I call dialogbox API myself. But, what I need is to make a window from Application 2 (process 2) as modal to Application A (process 1) from C#. I think the language that it is coded doesn't matter. Also, please note that I don't have the source to Application A since it is a third party application. I only have source code to Application B since it is ours.

Anybody?
csharp is offline   Reply With Quote
Old Nov 1st, 2005, 6:22 AM   #5
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
In general, there is no solution unless you know how Application A is doing things.


most things involving windows (dialogs, etc) rely on windows messages, and the processing of those is in control of the application that (in your case) launches the dialog. If that application happens to ignore messages of a particular type, there is nothing you can do to make the modal dialog respond to them (short of hacking the executable.

You might be able to do something involving SetFocus(), and then sending keystrokes or mouse events to the window when it is in focus. But, as all these methods work by sending windows messages, which can be ignored ....

Your best bet would be to contact the author of the program and request advice on a method to achieve what you want.
grumpy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:20 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC