Hello- I am trying to dock a CDialog window in a System.Windows.Form.TabPage in a System.Windows.Controls.TabControl. So far I have tried getting the HWND ptr from the CDialog control and adding to it to the TabPages Containter via something like:
IntPtr diagHandle = someHelper.GetDiagHandle();
Control tabHost = Control.FromChildHandle(errLogHandle);
if (tabHost != null)
However, Control tabHost = Control.FromChildHandle(errLogHandle); is always returning null.
On the C++ side of things, I tried similar code; trying to set the parent window of the CDialog object to the TabPage I want to dock it in, via code similar to this: To start, in C#,
someHelper.SetDiagHandle(tabPageStatusLog.Handle);
Then in C++:
CWnd *parent = CWnd::FromHandlePermanent(handle);
if (parent)
pEventLog->SetParent(parent);
Again, in this case, CWnd *parent = CWnd::FromHandlePermanent(handle); is always returning as null.
Now these were the only two ways I could figure out as to how to do this. Are there others? Or is this not very possible?
Other facts that might be useful is that the communication between the C# and the C++ is done through COM.
Thanks in advance for any help provided, Tyzack
}
}
{
void helperClass::SetDiagHandle(HWND handle)
{
{
tabPageStatusLog.Container.Add(tabHost);
}
- Moved byRong-Chun ZhangMSFT, ModeratorMonday, September 07, 2009 7:41 AMMove to WinForm forum to involve more experts (From:.NET Base Class Library)
-
| | tyzack Friday, September 04, 2009 8:17 PM | Hello, Thanks for your post on MSDN forum. I am very sure about the problem. Did you mean that you have difficult in using MFC control in a Windows Form application(Managed)? Please correct me if there is any misunderstanding. It would be more helpful if you could provide a simple sample project that can reproduce the issue. So that we can investigate the issue on my side. Usually, to use MFC control in .NET world, we can using one of the following ways.
- Making the control as a ActiveX control and using the ActiveX control instead on Windows Form applications
http://msdn.microsoft.com/en-us/library/yc13as7d.aspx http://msdn.microsoft.com/en-us/library/ms973200.aspx
- Creating a managed wrapper class in C++/CLI. For example
http://www.codeproject.com/KB/miscctrl/mfcandwindowsforms.aspx This sample using Managed C++ to wrap the control, but it is easy to convert to C++/CLI.
More info http://msdn.microsoft.com/en-us/library/x0w2664k.aspx Let me know if this helps. Thanks, Rong-Chun Zhang MSDN Subscriber Support in Forum If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Edited byRong-Chun ZhangMSFT, ModeratorMonday, September 07, 2009 7:44 AMadding link
- Marked As Answer bytyzack Wednesday, September 16, 2009 12:13 PM
-
| | Rong-Chun Zhang Monday, September 07, 2009 7:40 AM | Hello, >why do the calls Seem to fail? I am confused that the handle that passed to these method, could you please show us a sample project that can reproduce the issue. I will dig into the issue on my lad and let you know what I found. However, the reason why it returns null is that the TabPage is not derive from the CWnd class, and so does the CDialog class. To host the Dialog into a Winform control I suggest call(PInvoke) the SetParent and MoveWindow WinAPI to set the TabPage as the parent of the Dialog and move the dialog to the right position. For example: http://www.codeproject.com/KB/miscctrl/AppControl.aspx Thanks, Rong-Chun Zhang MSDN Subscriber Support in Forum If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Marked As Answer bytyzack Wednesday, September 16, 2009 12:13 PM
-
| | Rong-Chun Zhang Wednesday, September 09, 2009 10:16 AM | Hello, Thanks for your post on MSDN forum. I am very sure about the problem. Did you mean that you have difficult in using MFC control in a Windows Form application(Managed)? Please correct me if there is any misunderstanding. It would be more helpful if you could provide a simple sample project that can reproduce the issue. So that we can investigate the issue on my side. Usually, to use MFC control in .NET world, we can using one of the following ways.
- Making the control as a ActiveX control and using the ActiveX control instead on Windows Form applications
http://msdn.microsoft.com/en-us/library/yc13as7d.aspx http://msdn.microsoft.com/en-us/library/ms973200.aspx
- Creating a managed wrapper class in C++/CLI. For example
http://www.codeproject.com/KB/miscctrl/mfcandwindowsforms.aspx This sample using Managed C++ to wrap the control, but it is easy to convert to C++/CLI.
More info http://msdn.microsoft.com/en-us/library/x0w2664k.aspx Let me know if this helps. Thanks, Rong-Chun Zhang MSDN Subscriber Support in Forum If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Edited byRong-Chun ZhangMSFT, ModeratorMonday, September 07, 2009 7:44 AMadding link
- Marked As Answer bytyzack Wednesday, September 16, 2009 12:13 PM
-
| | Rong-Chun Zhang Monday, September 07, 2009 7:40 AM | Thank you for your assitance in this matter.
However, modifing the original MFC dialog is not possible, and I need more evidence to argue for writting a wrapper around it.
My remaining question, then, is, why can't I simply assign a new parent to the MFC dialog, or dock it in the C# control? More specifically, why do the calls: CWnd *parent = CWnd::FromHandlePermanent(handle); and Control tabHost = Control.FromChildHandle(errLogHandle);
Seem to fail? | | tyzack Tuesday, September 08, 2009 8:07 PM | Hello, >why do the calls Seem to fail? I am confused that the handle that passed to these method, could you please show us a sample project that can reproduce the issue. I will dig into the issue on my lad and let you know what I found. However, the reason why it returns null is that the TabPage is not derive from the CWnd class, and so does the CDialog class. To host the Dialog into a Winform control I suggest call(PInvoke) the SetParent and MoveWindow WinAPI to set the TabPage as the parent of the Dialog and move the dialog to the right position. For example: http://www.codeproject.com/KB/miscctrl/AppControl.aspx Thanks, Rong-Chun Zhang MSDN Subscriber Support in Forum If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Marked As Answer bytyzack Wednesday, September 16, 2009 12:13 PM
-
| | Rong-Chun Zhang Wednesday, September 09, 2009 10:16 AM | Hello, I am writing to check the status of the issue on your side. Would you mind letting me know the result of the suggestions? If you have any additional question, welcome to post here. Have a great day! Thanks, Rong-Chun Zhang MSDN Subscriber Support in Forum If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Marked As Answer bytyzack Wednesday, September 16, 2009 12:13 PM
- Unmarked As Answer bytyzack Wednesday, September 16, 2009 12:13 PM
-
| | Rong-Chun Zhang Wednesday, September 16, 2009 11:37 AM | Mr. Zhang-
We have decided to go about implementing this in a different way. I am still personally curious as to how this all works, so when I get some free time at home, I do plan on trying to making managed C++ wrapper, along with the WinAPI suggestions you have made above.
I don't know when I'll do this, but I can post my code/results if you are still curious.
-Tyzack | | tyzack Wednesday, September 16, 2009 12:13 PM |
|