|
Thanks, but I think there's something I don't get about using delegates. I've been reading up on it, and I've been following the example here:
http://www.java2s.com/Code/Cpp.net/Delegate/Fireeventsandeventhandlers.htm[^]
Now my code looks like this:
#include "stdafx.h"
#include <iostream>
using namespace System;
using namespace System::Windows::Forms;
using namespace UserActivityMonitor;
using namespace std;
ref class MyEventArgs : MouseEventArgs
{
public:
property String^ Info;
MyEventArgs(String^ info, MouseButtons button, int clicks, int x, int y, int delta) : MouseEventArgs(button, clicks, x, y, delta)
{
Info = info;
}
};
delegate void MyEventHandler(Object^ sender, MouseEventArgs^ args);
int _tmain(int argc, _TCHAR* argv[])
{
Events^ events = gcnew Events();
HookManager::MouseMove += gcnew MouseEventHandler(events, &Events::HookManager_MouseMove);
while (true)
{
::System::Threading::Thread::Sleep(100);
}
return 0;
}
It compiles, but when it runs, nothing happens. And I'm not sure what the line starting with delegate void MyEventHandler is supposed to accomplish - my code compiles fine without it, and the example code makes no reference to it. Attempts to read up on managed C++ delegates are making me very confused.
|
|
|
|
|
I'm working on a large MFC application in VS2005, where a complete rewrite is not an option as it would take years.
Instead I'm trying to enable support for .NET plugins, so expert users of the MFC application can write their own .NET classes, which can be loaded dynamically into the MFC application.
I'm using the following example as inspiration:
Hosting a WinForms User Control in an MFC Application[^]
I'm curious if anyone is having any experience in this scenario. I have found that starting a .NET WinForm as a modal CDialog is very easy as one just can call ShowModal. But integrating a .NET WinForm as a CFormView requires that it is a .NET usercontrol within a MFC window.
Not sure if I should require that any .NET WinForm should by implemented as a usercontrol, independent of it should work as a CDialog or CFormView ?
|
|
|
|
|
|
The example you have posted puts a text box control on a MFC Dialog using the CWinFormsControl. Pretty sure that CWinFormsControl cannot host anything but .NET controls.
I don't see anywhere that they take WinForm and hosts it in a MFC CFormView. I have tried to use CWinFormsView and it fails when given the typeid of a .NET Winform, but succeeds when given the typeid of a .NET Control.
I'm looking for people with experience in this area, that might show some light in this tunnel where I'm walking.
I'm curious of how one would solve the issue with getting the .NET control to close the MFC CFormView, change icon/title of the MFC CFormView. The .NET control doesn't get a parent window-object, but only a win32 window handle (integer). My current solution is to have an explicit SetParent on the user-control and make my CWinFormsView-object also inherit from a parent-interface. I don't want my .NET user-control to know anything about the awful world of CLI/Interop.
modified on Thursday, September 23, 2010 3:11 AM
|
|
|
|
|
I've never had to do that yet but here's one way I would have approached it:
Write a generic .NET user control that can host a WinForms form. And then the CWinFormsView will host this user-control. So your end-users can add their forms and then when you want to host it in the view, you host it via the user-control (which will wrap the form).
It will be tricky to do I guess, but certainly worth a shot.
|
|
|
|
|
I like the idea of hosting a WinForm, but do you have any idea how to do this ?
So far the only thing I have found is how to host a WinForm inside af WPF form. I don't know if I should get into hosting a WPF-Control, that hosts a WinForm-control using WindowsFormsHost.
I guess it will require even more code on the generic user-control to wrap around the custom WinForm so it reacts properly to its events.
modified on Thursday, September 23, 2010 9:42 AM
|
|
|
|
|
Rolf Kristensen wrote: I guess it will require even more code on the generic user-control to wrap around the custom WinForm so it reacts properly to its events.
It will require a fair bit of work, but once you do it, then your end clients won't have to repeat all that extra work each time they write a plugin/add-on. Since I've never had to do that I can't think of any immediate ideas off the top of my head. If I do get some time, I may try and work on a simple prototype (at least that way I can establish if it's practically doable or not). Alternatively, if you start on something and hit a hurdle, it'd be great if you can continue discussing it here.
|
|
|
|
|
Attempting to dig into C++/CLI by wrapping VLC with it. You'd know the very fist thing I run across is conversions between arrays in C++/CLI and C++.
Are there any 'conversion' libraries/utilities out there??
Thanks,
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
Ed K wrote: Conversion between array<String^>^ and const char *const* and back
You don't need any library functions to do this. It's simple enough to write.
Converting String^ to char*
String^ str = "Hello world!";
IntPtr p = Marshal::StringToHGlobalAnsi(str);
char *nativeString = static_cast<char*>(p.ToPointer());
Marshal::FreeHGlobal(p);
Converting char* to String^
const char* native = "hello world";
String^ managed = gcnew String(f); Now you know the basic conversions and it will be easy to create const char *const* from a managed string array.
Best wishes,
Navaneeth
|
|
|
|
|
If you are using .Net 3.5 or newer, you can use the marshalling library:
http://msdn.microsoft.com/en-us/library/bb384865.aspx[^]
For your example, the marshal_context methods are probably most appropriate, then you can leave RAII to clear up the HGlobal stuff internally. You will still need to loop over the array elements though.
|
|
|
|
|
ian__lindsay wrote: For your example, the marshal_context methods are probably most appropriate, then you can leave RAII to clear up the HGlobal stuff internally.
Correct. Beauty of stack semantics!
Best wishes,
Navaneeth
|
|
|
|
|
N a v a n e e t h wrote: It's simple enough to write.
Really? why does C++ need another type of string for each new string? after all, a string is a string.
|
|
|
|
|
Luc Pattyn wrote: why does C++ need another type of string for each new string? after all, a string is a string.
Not sure I got you
Best wishes,
Navaneeth
|
|
|
|
|
It seems C++ offers more string types than I have strings in a typical app. Just wondering why that is.
|
|
|
|
|
Luc Pattyn wrote: It seems C++ offers more string types than I have strings in a typical app. Just wondering why that is.
Ok. I guess you are talking about the various string types shown in the marshal_context MSDN page. std::string is the only string type that C++ standard provides. Rest everything is non-standard. When it comes to C++/CLI, System::String^ is the standard string type. CString is Microsoft's implementation for MFC.
Best wishes,
Navaneeth
|
|
|
|
|
#include "apue.h"
Did you have the head file?
Or Did you have the book source code?
It is The 2nd Edition better , but the 1st edition maybe suitably.
Thx.
|
|
|
|
|
Try a Google search, as far as I recall there is a website for the book's source code. Although it is some years since I last looked.
It's time for a new signature.
|
|
|
|
|
Thinks your good answer very much.
|
|
|
|
|
Hi everyone,
Ho do I exchange info between two forms. I have done in C# but do not know how to do it C++/CLI
I have a click even where I want to populate another form for user input then close it but use those info
that was provided by the user.
thanks
|
|
|
|
|
jashimu wrote: I have done in C# but do not know how to do it C++/CLI
What you did in C#, you can do in C++/CLI too. They both offer the same object-orientation and the same set of Framework classes.
|
|
|
|
|
Hi Luc Pattyn, This is simple in C# but I don't see anything like this.
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
}
thanks for your reply.
|
|
|
|
|
As I said, you can do exactly the same in C++/CLI.
If you don't know the correct syntax, study a book on the language.
If you tried and failed, show us your code and the compiler's reaction to it.
If all else fails, use a conversion tool to convert your C# source file into C++/CLI
(or build a C# program, then use .NET Reflector to show you the equivalent source code in the language of your choice; C++/CLI is called MC++ inside Reflector)
|
|
|
|
|
|
jashimu wrote: I have done in C#
How you did it on C#? The basic idea is to pass the necessary information from one from to other through the constructor or public methods on the other form.
Best wishes,
Navaneeth
|
|
|
|
|
Hi All,
I am using windows media player activex control using c++ builder. It is working fine to play the url but when I adjust the height and width from the code this is adjust to the old position which i use onto the form.
for example I adjust the activex player width 720 and height 576
now I adjust the player width and height from the code like
WindowsMediaPlayer1->Width = 320;
WindowsMediaPlayer1->Height =240;
but it will resize to old width height.
how i resolve this problem.
|
|
|
|