04-29-2009 04:56 PM
I've created a Form in .NET and have made it a parent of an ActiveX control by way of the Win32 API. Unfortunatly this is causing a problem since it takes the focus away from the main window causing the title bar to change colour.
I made a Form because I was using an ActiveX control in the .NET control but when I called the constructor for the control, I had an "ActiveX control '<GUID>' cannot be instantiated because the current thread is not in a single-threaded apartment".
This was because the apartment state was MTA (multi threaded) instead of STA (single threaded). Is there a way of forcing the .NET calls to be in a single threaded apartment context? Otherwise, is there a way of keeping the titlebar from showing that it has lost focus? I've tried to set the active window, but that causes button clicks to be missed on the control and would cause text not to be entered in text boxes. 😞
Any help would be apprecitated.
Thanks,
Adrian
Solved! Go to Solution.
04-29-2009 05:12 PM
I'm missing where the LabVIEW question is in this...
Be aware that LabVIEW 7.0 had mixed (at best, and I use that term loosely) support for .NET. For one thing, it was limited to .NET 1.1. LabVIEW 7.1.1 had support for .NET 2.0. Sort of.
04-30-2009 01:38 PM - edited 04-30-2009 01:41 PM
Yes, well I'm trying to bypass the limitations. The .NET interface is there, and for the most part it really doesn't need to know about what the .NET code it is doing. Rendering has been successfully pushed off on the ActiveX container. I'm just having a little problem with focus. I have been able to stop the focus from jumping by using this wonderful piece of code:
protected override CreateParams CreateParams
{
get
{
const int WS_EX_NOACTIVATE = 0x08000000;
CreateParams parms = base.CreateParams;
parms.ExStyle = parms.ExStyle | WS_EX_NOACTIVATE;
return parms;
}
}
But, I'll have an issue with text boxes as I will no longer be able to shift the focus to the Form which is what is needed when dealing with edit boxes.
Fun stuff 😞
But my original question was if I could somehow force a .NET call to be done in a STA (single threaded apartment)
Thanks,
Adrian
04-30-2009 02:10 PM
04-30-2009 02:48 PM
I'm using both, the ActiveX for geting an HWND to get my .NET control to be a child of.
I thought I tried to search before, but I guess I didn't use the right keywords. By setting the Peferred Execution System to "user interface" It now works as a control!!
Creating a .NET control in LabVIEW 7.0 is now EASY! The only thing that I missout on is the events, but ActiveX Events sucked in LV7.0 since it was broken, so polling was the only way to go anyway, so I'm not loosing anything!
This is an AWESOME KLUDGE!
04-30-2009 03:51 PM - edited 04-30-2009 03:53 PM
BTW smercurio, the search terms you gave, was not useful for LabVIEW, but made me try my search again with other terms.
Thanks!
Adrian
04-30-2009 04:26 PM
Been bitten by LabVIEW wrote:BTW smercurio, the search terms you gave, was not useful for LabVIEW,
They weren't intended to be. Your specific question was how to do .NET calls in a single threaded apartment context. That doesn't have anything to do with LabVIEW, and it wasn't clear to me what you were doing in the first place. Regardless, you found your answer, so that's the important part.