473,394 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problems with modal dialog when calling C# from C++

I have main application (with main window) created in C++/MFC. From
there I call function in C# class library to display a modal WPF
dialog. Dialog shows up OK, but it doesn't behave really modal. While
it is not possible to go to the main window by clicking directly on it
(dialog keeps focus), the application shows twice in the taskbar (1
entry for main window, 1 entry for the WPF dialog). Through the
taskbar I can switch to main window and even though it behaves
disabled, this definitely doesn't look profesional. The application is
supposed to show up in the taskbar only once.

I tried to pass from C++ a window handle to C#, using it to construct
NativeWindow and pass it as an owner, however, Window.Owner doesn't
accept NativeWindow type.

Any ideas how to make this work?

Thank you,

LK
Dec 13 '07 #1
4 4431
Lester,

You probably want to use the WindowInteropHelper class:

http://msdn2.microsoft.com/en-us/lib...rophelper.aspx

Once you pass the instance of your Window that you want to show, you can
use the Handle and Owner properties to set the owner of the window, and to
get the handle to work with.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Lester" <lk****@gmail.comwrote in message
news:22**********************************@a35g2000 prf.googlegroups.com...
>I have main application (with main window) created in C++/MFC. From
there I call function in C# class library to display a modal WPF
dialog. Dialog shows up OK, but it doesn't behave really modal. While
it is not possible to go to the main window by clicking directly on it
(dialog keeps focus), the application shows twice in the taskbar (1
entry for main window, 1 entry for the WPF dialog). Through the
taskbar I can switch to main window and even though it behaves
disabled, this definitely doesn't look profesional. The application is
supposed to show up in the taskbar only once.

I tried to pass from C++ a window handle to C#, using it to construct
NativeWindow and pass it as an owner, however, Window.Owner doesn't
accept NativeWindow type.

Any ideas how to make this work?

Thank you,

LK
Dec 13 '07 #2
With WindowInteropHelper, it is not possible to get the focus back on
the parent (C++) window. However, both windows (parent C++ and child
C# WPF dialog) still show in the taskbar.

Is there any way to remove WPF dialog from the taskbar, or prevent it
from showing up there?

Thank you,

Lester

On Dec 13, 7:33 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Lester,

You probably want to use the WindowInteropHelper class:

http://msdn2.microsoft.com/en-us/lib....interop.windo...

Once you pass the instance of your Window that you want to show, you can
use the Handle and Owner properties to set the owner of the window, and to
get the handle to work with.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
Dec 13 '07 #3
Lester,

With the window handle, you will have to make it so that the extended
window handle does not have the WS_EX_APPWINDOW bit set, so that it doesn't
appear in the taskbar.

Or, you could create a .NET form, host the WPF control in that, and then
set the ShowInTaskbar property of the form to false.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Lester" <lk****@gmail.comwrote in message
news:94**********************************@d4g2000p rg.googlegroups.com...
With WindowInteropHelper, it is not possible to get the focus back on
the parent (C++) window. However, both windows (parent C++ and child
C# WPF dialog) still show in the taskbar.

Is there any way to remove WPF dialog from the taskbar, or prevent it
from showing up there?

Thank you,

Lester

On Dec 13, 7:33 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
>Lester,

You probably want to use the WindowInteropHelper class:

http://msdn2.microsoft.com/en-us/lib....interop.windo...

Once you pass the instance of your Window that you want to show, you
can
use the Handle and Owner properties to set the owner of the window, and
to
get the handle to work with.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
Dec 13 '07 #4
Sorry, that should be "extended window style", not "extended window
handle".
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:DB**********************************@microsof t.com...
Lester,

With the window handle, you will have to make it so that the extended
window handle does not have the WS_EX_APPWINDOW bit set, so that it
doesn't appear in the taskbar.

Or, you could create a .NET form, host the WPF control in that, and
then set the ShowInTaskbar property of the form to false.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Lester" <lk****@gmail.comwrote in message
news:94**********************************@d4g2000p rg.googlegroups.com...
>With WindowInteropHelper, it is not possible to get the focus back on
the parent (C++) window. However, both windows (parent C++ and child
C# WPF dialog) still show in the taskbar.

Is there any way to remove WPF dialog from the taskbar, or prevent it
from showing up there?

Thank you,

Lester

On Dec 13, 7:33 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
>>Lester,

You probably want to use the WindowInteropHelper class:

http://msdn2.microsoft.com/en-us/lib....interop.windo...

Once you pass the instance of your Window that you want to show, you
can
use the Handle and Owner properties to set the owner of the window, and
to
get the handle to work with.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
Dec 14 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RobJUK66 | last post by:
have a 3rd party .Net dll that wraps a set of further unmanaged dll's. The ..Net DLL basically uses pinvoke to wrap the calls. The low level dlls provide an API to talk to a complex device which...
4
by: Paul Aspinall | last post by:
Can anyone advise how to display a form on top, and modal, without using ShowDialog?? Thanks
2
by: cassidyc | last post by:
Hi, I was wondering if anyone has come accross this issue? And if they have any solutions I have that can create new copies of itself Form1 as = new form1(); af.show(); This form can also...
10
by: Guadala Harry | last post by:
I have a modal dialog that currently does all of the following except item 4. 1. lets users select a graphic from a list of thumbnails (and when selected, displays the full-size image in a...
1
by: Ganesh Ramamurthy | last post by:
Hi Experts, I am having a serious problem now. I am using IE for developing my asp.net application. My application need not run in Netscape. I have a peculiar problem. I have an aspx page from...
1
by: Lance | last post by:
I want to prevent a form from closing when the user clicks the form's Close button in the form's ControlBox (i.e., the button with the "X" in the upper-right corner of the form). Instead, I just...
4
by: mpreston | last post by:
I'm following the example from the MSDN library on how to create modal dialog boxes in C#, but something isn't working properly. If I create a modal dialog box and show it using ShowDialog(), the...
4
by: Johnny Jörgensen | last post by:
In my current project I've got some DataGridViews containing multiple hidden columns. For some reason 8 of the 10 grids I've got on my form has suddenly started showing 1 of the hidden columns...
2
by: diogenes | last post by:
I have created many shortcut/popup (aka context, or right-click) menus for my application - instead of toolbars or standard drop-down menus. Within my custom menu, I am using...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.