Add your own alternative version
Stats
235.8K views 3.5K downloads 73 bookmarked
Posted
20 Dec 2005
|
Comments and Discussions
|
|
Take a look at the comment labelled
"Editing a cell in DataGridView and alt-tabs away and then back causes hang"
Would it be something like that?
|
|
|
|
|
Hello Nishant,
Thanks for this excellent example illustrating interaction between winforms controls and MFC dialogs.
In your example however, the calling MFC application is compiled with /clr.
I am interested in exploring this interoperability with .NET controls. However, we have huge MFC code base and a lot of MFC extenstion dlls in our project. I do not want to compile the entire project or even a DLL with /clr (and have not been successful doing so anyway).
In a specific situation, I have an MFC extension dll which has a lot of dialogs which are invoked by client application.
In one of the dialogs, i compiled with /clr and embedded a winforms control in header file as in your example.
But since the header file is referenced by calling -unmanaged- client application i had to put the managed objects within the
#if MANAGED ....
CWinFormsControl<system::windows::forms::button> m_wfBtn;
#endif
but this in effect changes the memory layout of the object depending on where it is referenced from. What happens to member variables that are defined after the managed objects? I also noticed that there is stack corruption when the dialog is terminated.
any feedback is appreciated.
thank you raghu.
|
|
|
|
|
Sorry for the late reply, but you could try this :-
#ifdef _MANAGED<br />
CWinFormsControl^ ...<br />
#else<br />
void* ...<br />
#endif
A handle and a * take up the same number of bytes - so you won't change the layout.
Regards,
Nish
|
|
|
|
|
I've added a datagrid to MFC Dialog.
After binding data to datagrid, visible rowcount is still 0.
Why is it so?
The same databinding works fine in Winforms.
|
|
|
|
|
I also seem to have a problem using the DataGrid/DataGridView within a MFC dialog (using the CWinFormsControl< > template).
I create a DataSet from a Xml file and then set it to the DataSource. I also set the DataMember to the appropriate table name, but nothing is displayed in the grid view. I tried other various approaches, but nothing seems to work.
I have no problem setting this up in WinForms - it just won't display in MFC. I know the data's there because I can actually step right into it from the DataGrid object - it just won't display - the ColumnCount is still 0.
What's the problem? Have you or anyone else figured this issue out yet?
I just don't understand why this won't work.
|
|
|
|
|
I have managed to include a DataGridView in an MFC-based
dialog but I can't figure out how to put column headings
in it or populate it with data.
Anyone have any snippets of code that can do the trick ?
|
|
|
|
|
When the DataGridView is bound to a DataTable in a DataSet the rows
and columns for that DataTable do not appear in the Grid.
- This is failing because data-binding requires that the bound control have
a BindingContext. Normally the DataGridView would use the BindingContext
belonging to the Form it is on, but since the test application's DataGridView
is on an MFC dialog rather than on a Form it cannot use its parent's context.
To use data-binding with the MFC-hosted DataGridView will require that the
application either create and manage the BindingContext on its own or host
the DataGridView inside a ContainerControl (such as a UserControl) which will
manage a binding context for its children. You can find more information
about BindingContexts at: BindingContext Class (System.Windows.Forms) Control.BindingContext Property (System.Windows.Forms)
Quoted from A problem with using DataGridView control in an MFC CDialog
|
|
|
|
|
I must have missed something. The .Net assemtly winform thing (I'm new to all this .net stuff, so bear with me) loads up fine, but it's just black. The background of the control is usually black, so it's like the rest of it isn't drawn. I should also be able to right click on the control it's self and get a menu to configure the control. I've been struggling with this all day and can't figure it out.
|
|
|
|
|
Hello Nish,
I want to ask you the things. I dont have VC++ 2005 but I want to buy it. Before buying I just want to confirm some of the follwoing things.
1. I have a large project written in MFC VC6. Can I do further modification in that project?
2. Can I convert whole MFC base project in to Form base project ?
Thank you
Mahesh
|
|
|
|
|
Hello Mahesh
msonawane wrote: 1. I have a large project written in MFC VC6. Can I do further modification in that project?
Yes, you can convert the project to VC++ 2005 (a wizard pops up automatically) and you can continue modifying it as a pure native project. Depending on how good your code was, the transition may involve varying levels of difficulty. The VC6 compiler was pretty bad, while the 2005 compiler is among the best C++ compilers out there in terms of ISO C++ compliance. So, you may find that some of your old code will have to be rewritten to confirm to the newer/stricter compiler.
msonawane wrote: 2. Can I convert whole MFC base project in to Form base project ?
That will not be easy, as you would manually have to port it to Windows Forms. Also, since WPF is around the corner, you may want to wait till WPF is out, and then port to that instead of to Forms which is just a transient (IMHO) technology.
Regards,
Nish
|
|
|
|
|
Hello Nish,
Thank you very much for valuable information.
Have a nice day.
Regards
Mahesh
|
|
|
|
|
Nice article Nishant.
I was already looking for such this solution.
|
|
|
|
|
Thanks, Majid 
|
|
|
|
|
Hi Nish...
Great work. Uptill now, we were looking at this[^]
way of doing this. Microsoft has yet again made it easier to handle. I am looking forward to VC 8.0 now :->
|
|
|
|
|
Yep, it was far tougher and basically a pain in the ass to do this in VC++ 2003. VC++ 2005 has made it real nice and easy for us 
|
|
|
|
|
Congratulations Nishant! Had there not been a giant ocean between us, the beer would have been on me!
--
Pictures[^] from my Japan trip.
|
|
|
|
|
Heh
Thanks Jörgen
|
|
|
|
|
congrets !....A Century
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Thanks, Alok 
|
|
|
|
|
Hi,
I have this code for connecting to SQL Server:
CString sql;
CDatabase m_database ;
sql.Format("DRIVER=SQL Server;SERVER=myserver;DATABASE=test;UID=administrator; PWD=admin;Trusted_Connection=No");
m_database.SetLoginTimeout(10);
m_database.SetQueryTimeout(10);
TRY{
m_database.OpenEx (sql,CDatabase::noOdbcDialog );
}
CATCH(CDBException, e){
m_database.Close();
MessageBox("Connection failed");
}
END_CATCH
I am connecting to a remote sql server. This code works fine if I'm connected in the network and i was able to catch the Exception, however, when I disconnect the host pc from network, an unknown exception was thrown. "Unknown software exception (0x0000409)..." . Is there any way to catch this exception ? It also happen when I mispelled the server name.
Mar Solero Jr.
|
|
|
|
|
What made you post this here? Your question should be posted in the Visual C++ forum. 
|
|
|
|
|
Sorry..got a mistake...I'll post it to Visual C++ forum.
Thanks!
Mar Solero Jr.
|
|
|
|
|
mhar wrote: Sorry..got a mistake...I'll post it to Visual C++ forum.
Thanks!
No problem 
|
|
|
|
|
Yes, it is easy to do so in VS 2005. Is the reverse process also supported.. i.e hosting MFC control on the Winform window ? There are such articles present here but they dated back to VS 2001 to VS 2003. I like to know whether in VS 2005, this process is easier or not ?
Imtiaz
|
|
|
|
|
Imtiaz Murtaza wrote: Yes, it is easy to do so in VS 2005. Is the reverse process also supported.. i.e hosting MFC control on the Winform window ? There are such articles present here but they dated back to VS 2001 to VS 2003. I like to know whether in VS 2005, this process is easier or not ?
No, there aren't any classes available (as far as I know) that let you put an MFC control into a WinForms form.
|
|
|
|
|
|
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
|