Reputation: 21
Transfer the handle of the C# winform parent window to c++ dll via the dllimport function. After that, I would like to call Create Window with the handle as my parent and send the event that occurred in the winform parent window to the generated window. (resize, move, etc.)
(Can I catch an event in onMove, onSize in the mfc window without using postMessage in the winform window?)
Upvotes: 1
Views: 214
Reputation: 1609
Now, to avoid the confusion: Windows is not an event-driven system, it is a message-driven system. I assume by using event you mean message.
I would suggest using a def file to export function from the dll, not the dllexport since dllexport generates mangled (decorated) output. There are other ways to use dllexport to generate unmangles export but using a def file is easiest. So, you export the function from the dll and use it in C# code: [DllImport( @"your.dll", CallingConvention = CallingConvention.Cdecl )] static extern int SetParentHandle(HWND hParent);
Now let's translate: catch an event in onMove, onSize in the MFC window. MFC window is nothing but a native Windows window, and MFC is just a C++ wrapper that uses MC++ classes to wrap windows handle. Hence you do not catch an event, you handle windows’ message (WM_SIZE for example). You can define handler as anything it does not have to be OnSize, but OnSice is a kind of standard used by the class wizard.
To achieve later, without using SendMessage (not a PostMessage) you would have to subclass the main window to handle messages in your own windows procedure, and this is something more complicated. You can also use windows hooking to process certain messages depending on the hook type. Read about subclassing possibly starting here
or windows hooking here.
Read about the difference between SendMessage and PostMessage here
Upvotes: 1