|
Hi
Could you tell me how can I set size property for IDC_STATIC in my project? because when I change my Windows forms user control with IDC_STATIC by DDX it is not fit to the dialog box same as Dock property in windows form controls or anchor 
|
|
|
|
|
My control was not painting until after it was resized. To "correct" the issue I added the following call:
GetDlgItem(IDC_FOO)->RedrawWindow(); where IDC_FOO is the resource ID in which the CWinFormsControl will be painting.
FYI.
|
|
|
|
|
|
Hi,
I have one dll containing 3 MFC com component and some 2-3 MFC dailog. I want to load one Managed (C#) control in one of the dialog. I have added managed control in MFC dialog, compiler option for file set to /clr. dll created without any error.
But when I call CreateInstance for any of the MFC component, it fails saying "0x80040111 ClassFactory cannot supply requested class ". It works fine if i remove managed control from dialog.
Further, I investigated and found that whether I add managed control or not it does not have any effect. Only when i include <afxwinforms.h> in any file and compile using /clr option; CreateInstance falis with above error. if i remove <afxwinforms.h> and keep /clr option then it works fine.
your answer will be very helpful for me.
Nagesh
|
|
|
|
|
Hi,
I have been testing out MFC to .NET connection. I have been through a number of hurdles. This one is
beyond me.
#pragma once
using namespace System;
using namespace System::ComponentModel;
#using <mscorlib.dll>
ref class CManagedClass1
{
public:
array<int>^ MyArr;
// default indexer
[Category("MyArrFIX")]
property int default[int] {
int get(int index) {
return MyArr[index];
}
void set(int index, int value) {
MyArr[index] = value;
}
}
bool bCanStretch;
[Category("Appearance")]
property Boolean CanStretch
{
Boolean get() { return bCanStretch; }
void set(Boolean value)
{
bCanStretch = value;
}
}
enum class suit{clubs,diamonds,spade,hearts};
[Category("MyPropertysuit")]
property suit MyPropertysuit
{
void set( suit value )
{
}
suit MyPropertysuit::get()
{
// Getter code here:
return(suit::clubs);
}
}
CManagedClass1(void);
};
Out of 3 properties defined above, I do not know why property "MyArrFIX" DOES NOT WORK.
Am I missing something here.
Thanks in anticipation.
|
|
|
|
|
When the DataGridView is not data-bound and the user has set the focus to
edit one of the cell's in the DataGridView and alt-tabs away from the
application and then back, the application hangs. You would like to know why
this is hanging and how to avoid it.
- This will reproduce with either the data-bound or non-data-bound control,
so long as there is an editable field to accept the keyboard focus. The
problem occurs when the Dialog attempting to find the default button when it
is activated. This search goes into an infinite loop. It starts with the
control with the focus (the edit control inside the DataGridView's cell) and
searches until it either finds a control which responds to WM_GETDLGCODE with
DLGC_DEFPUSHBUTTON or it gets back to the control it started on. The problem
is that the DataGridView is not marked as containing focusable child controls
(with the WS_EX_CONTROLPARENT style), and so the dialog doesn't search into
the DataGridView. Since it never searches in the DataGridView it doesn't
find the edit control it started on and never finishes the loop. If you
watch the application in Spy++ you will see that it is not completely locked
but is forever receiving WM_GETDLGCODE messages. This can be fixed by adding
the WS_EX_CONTROLPARENT style to the DataGridView. This can be done external
to the DataGridView by sinking the HandleCreated event or within the
DataGridView by inheriting and overriding CreateParams to add the style. It
is essentially the same problem as is documented for CPropertySheets in
Q149501 Control.CreateParams Property (System.Windows.Forms) WM_GETDLGCODE Notification CreateWindowEx Function
Quoted from A problem with using DataGridView control in an MFC CDialog
|
|
|
|
|
Hi Nish,
Excellent article!
I have a situation in which I need to add a Winform control to an existing MFC MDI application, but I cannot have the /clr switch on for the entire project. I can, however, switch on the /clr support for individual cpp files.
Can you please suggest the necessary modifications in your example so that the enitre project needn't be CLR compiled and all .Net related code can be put in cpp files that I can have with CLR option.
I'd highly appreciate your help.
Thanks
Anirban
|
|
|
|
|
I'm basically trying to do what you do in the article, only my dialog is in an MFC DLL. When I try to load the dialog I get an access violation.
Unhandled exception at 0x78456544 (mfc80ud.dll) in MyApp.exe:
0xc0000005: Access violation reading location 0x00000000.
Execution breaks in CWnd::InitControlContainer in occcont.cpp.
Any ideas?
-- Rubio
|
|
|
|
|
I had a similar problem.
I've create an extended mfc dll exporting a dialog with a winform component inside.
I've solved adding
CoInitialize (NULL);
statement before starting the mixed dialog.
In my case:
<br />
void CTestAppDlg::OnBnClickedBtnDialog()<br />
{<br />
CoInitialize (NULL);<br />
ExportData dll;<br />
dll.CallDlg();<br />
}<br />
I suggest the reading of this[^] discussion.
|
|
|
|
|
It turns out in my case the call to AfxEnableControlContainer was not being made by my application. I'm no MFC junkie, so I don't know if that's unusual or not, but it was definitely required. Making the call cleared up the problem.
|
|
|
|
|
When the same thing is done inside an MFC ActiveX Control, the inner WinForms contents remain inactive. Any hint on how to make them active? Anyone faced similar thing?
|
|
|
|
|
Hi,
I created the menu and tool strip using winforms and created an container class using mfc and combined both after getting the portion of space for container the tool and menustrip bar is remain undrawn(or u can say it as blank) all controls which are placed are present but the part of area is remain unpaint.
can any one help me in this regard.
Thank you
Sunil
|
|
|
|
|
Hi Nish,
did you ever try the same thing for a MFC ActiveX? I'm running into major problems trying this.
I perform the same steps like hosting a WinForms control in a "stand-alone" application like described in your article or on MSDN here[^]. But it currently gives me two major problems:
(1) When starting a debug session Visual Studio (VS2005 by the way) starts our client app, which implements an ActiveX container, and loads the MFC WinForms ActiveX during startup. In the moment the client app is about to load the MFC WinForms ActiveX, Visual Studio freezes and hangs infinitely. Last messages I see in VS output window are that the CLR DLLs are being loaded. Looks like the LoaderLock problem described here[^]. But until now I didn't figure out how to prevent this LoaderLock. If the client app is started normally, means not via Visual Studio, it starts without problems.
(2) This leads to the next problem: When the MFC WinForms ActiveX is about to be displayed I get a crash in 'CWinFormsControl::InternalCreateManagedControl' (\vc\atlmfc\include\afxwinforms.inl). An analogous crash occurs when using the CWinFormsDialog template class instead of CWinFormsControl. Could be this known bug[^] which seems to be fixed with VS2005 Service Pack 1. But I didn't install and try it until now.
So do you have any experiences with hosting WinForms controls inside MFC ActiveXs?
Any help would really be appreciated!
cheers,
mykel
If they give you lined paper, write the other way!
|
|
|
|
|
1. I do not have AfxWinforms.h. What package is it a part of? Is it Dundas specific?
2. I am trying to populate a CWnd ( specifically a CView ) with a winform. Can this be accomplished in the same manner?
|
|
|
|
|
beausmom wrote: 1. I do not have AfxWinforms.h. What package is it a part of? Is it Dundas specific?
this is available only in VS2005. So, if you are using a previous version of Visual Studio, sorry then.
beausmom wrote: 2. I am trying to populate a CWnd ( specifically a CView ) with a winform. Can this be accomplished in the same manner?
You can use CWinFormsView for that.
"Some people believe football is a matter of life and death.
I'm very disappointed with that attitude.
I can assure you it is much, much more important than that. -- Bill Shankly"
|
|
|
|
|
Hi ,
I have given CLR Support to a VC8 MFC Application and am trying to use a .Net Windows in MFC Form. When i try to use
CWinFormsControl<system::windows::forms::form> m_ctrl1;
i get the following error
error C2143: syntax error : missing ';' before '<'
Can any one help
|
|
|
|
|
CWinFormsControl is a template class and you need to specify the template type parameter.
|
|
|
|
|
An alternative to setting the /clr flag for the entire project which needs to use .NET controls is to set the /clr flag for only the source file which uses the control (the dialog class source file for example).
- similar to doing it for the whole project, but with the following
differences
- move the #include <afxwinforms.h> from stdafx.h into the source file
where the control is being used
- leave /clr off for the project, but turn it on for the source file
- set exception handling to /EHa for the source file
- disable use of pre-compiled headers for the source file (since the
non-clr precompiled header won't be compatible with the clr source file)
- create a forward-declared inner class in the dialog class using the
control; this class is the control holder
- declare the control holder class in the source file, having it contain
the template instantiation (CWinFormsControl) class
- to use the control just refer to m_controlHolder.m_myControl
The holder class is necessary because you don't want to include the
afxwinforms header in the dialog's header or you'll pollute the rest of the
project.
|
|
|
|
|
Your message concerning the use of /clr only at the source file level is very interesting but it is not clear for me of how creating this class holder in the source file. Do you have a sample?
Régis
|
|
|
|
|
Does this work?... and if so could you please expand on how to do it. I am getting a "use of undefined type" error whenever I try to access m_controlHolder from unmanaged code. I can't declare it in the unmanaged code, however, because it requires CWinFormsControl, which requires CLR
|
|
|
|
|
Nice article! I was stuck on this until reading your article. Thanks
I built a sample MFC app with a Windows Forms control to test this technique and it worked great. I then put it on a machine which did not have the .NET 2.0 runtime installed. When I tried running, the app just silently exited.
I was hoping it would give an error to the user indicating that they need the .NET 2.0 runtime installed (like you get if you create a C# .NET app and try and run without the runtime installed).
Any ideas on this? Is there something which can be done to ensure this sort of error gets displayed instead of having the app just exit?
|
|
|
|
|
Hi, can an application of this type work with a .Net Framework older then 2.0?
Or does one have to force all users to upgrade to .Net 2.0?
|
|
|
|
|
I am running into some kind of deadlock situation using CWinFormsControl with a DataGridView. I can reproduce the problem with a simple SDI application and a CFormView that contains a CWinFormsControl<datagridview>, a couple of buttons, and a textbox. When focus leaves the CWinFormsControl<datagridview> to the buttons and/or text edit and then I put focus back into a cell in the grid, the application hangs. I can reproduce the problem every time and there is no external or 3rd party software involved. Has anyone else experience problems with deadlocks using MFC/.NET interop?
Jeff Boenig
|
|
|
|
|
The DataGridView doesn't really work smoothly in MFC applications using the CWinFormsControl and similar classes. It may be better to spawn off a WinForms form that contains the CWinFormsControl control from the MFC parent window (either a dialog or a view).
Regards,
Nish
|
|
|
|
|
Thanks for the reply Nish. It locks up very reliably. "Doesn't really work smoothly" is putting it mildly. For all intents and purposes, it doesn't work at all. I was also able to reproduce the same behavior with a 3rd party .NET grid control. It seems to me that there is a serious flaw lurking somewhere in the CWinFormsControl. I was trying to embed a .NET user control that contains a 3rd party grid on a tab of a tab control in MFC. I'm having to abandon that effort and popup a modal dialog instead. I'd still like to understand why it doesn't work, but your feedback is reassuring in the sense that I'm not the only one that has had trouble with it.
Thanks alot!
Jeff Boenig
|
|
|
|