|
Mfc is exposing interface and events.
I made a wrapper class of MFC ActiveX control and included in my project.
Actually it is MFC ActiveX control without any user interface, it creates window just for messaging and hide it. I want to use this ActiveX control in my C# class library which also has no interface and no windows. When I can trying to create control by calling .CreateControl it give me exception that "windowless ActiveX controls are not supported. Even I tried this in test C# form application and it gives me same error.
Thanks in advance for you help
-Samir.
|
|
|
|
|
|
hi everyone;
i'm working on a project that includes creating a tool that enables the user to create slide shows that will be later viewed on the net. i dont know in what format the slides are going to be saved. does anyone have any idea about the subject . im sure anything would help...
thanks
|
|
|
|
|
The format for saving the slides is up to you. Are you going to code your own viewer or use something off the shelf.
BTW: PowerPoint already does this. All you have to do is install the PowerPoint Viewer[^].
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am rotating text via the Graphics.RotateTransformation technique. After drawing my text string I set the rotation transform back to normal. I then want to draw a "non-rotated" rectangle around the rotated text. Does anyone know how to calculate this rectangle (the largest non-rotated rectangle around the rotated text)??
|
|
|
|
|
Graphics.MeasureString is probably what you want. Depending on your needs, you can resize the SizeF struct you get back. Use that to construct a RectangleF (the PointF for the original will depending on your other transform parameters) and use Graphics.DrawRectangle to draw it.
If you need additional help, please be a little more specific. From what I gather, you want the final surface to display something like this (ASCII art):
_A_
|_B_|
C Is that right?
Software Design Engineer
Developer Division Sustained Engineering, Microsoft
My Articles
|
|
|
|
|
You can use a trick and use Matrix class to rotate points.
For example if you're drawing text within a rectangle (before rotation)
Rectangle rect = ... get draw rectangle ...
... rotate and draw text...
Matrix m = new Matrix();
m.Rotate(angle) or m.RotateAt(m)
Point[] points = new Point[4];
points[0] = new Point(rect.X, rect.Y)
points[1] ... get all 4 corners of the rectangle
for (int i=0; i
|
|
|
|
|
Actually what I needed is a bit more complicated. I first used MeasureString to create a rectangle for the text. Then I want to rotate that rectangle and find the largest "non-rotate" rectangle that rectangle will fit in. I don't care about the location of the largest rectangle, just the width and height. I did figure this out with a bunch of math. here is the routine if anyone is interested.
Note that the rect that is passed into this routine is the rect created using MeasureString.
private RectangleF FindBoundingRect(RectangleF rect, float angle)
{
// Do a quick short cut here if the text is not really rotated
// but is instead horizontal or rotated.
if (angle == 0 || angle == 180 || angle == 360)
{
return new RectangleF(0, 0, rect.Width, rect.Height);
}
else if (angle == 90 || angle == 270)
{
return new RectangleF(0, 0, rect.Height, rect.Width);
}
else if (angle > 360)
{
// Don't handle this case for now.
return new RectangleF(0, 0, 0, 0);
}
// First transform the angle to radians.
float radianAngle = angle * (float)(Math.PI / 180.0F);
float radian90Degrees = 90 * (float)(Math.PI / 180.0F);
// First find the rotated point 1. This is the bottom right point. The radius
// for this point is the width.
float x = (float)(rect.Width * Math.Cos(radianAngle));
float y = (float)(rect.Width * Math.Sin(radianAngle));
PointF p1 = new PointF(x, y);
// Now find point 3 which is also easy. This is the top left point. The
// radius for this point is the height.
x = (float)(rect.Height * Math.Cos(radianAngle + radian90Degrees));
y = (float)(rect.Height * Math.Sin(radianAngle + radian90Degrees));
PointF p3 = new PointF(x, y);
// Point 2, the top right point, is a bit trickier. First find the angle
// from the bottom left up to the top left when the rect is not rotated.
float radianAngleP2 = (float) Math.Atan(rect.Height / rect.Width);
// Now find the length of the diagonal line between these two points.
float radiusP2 = (float) Math.Sqrt((rect.Height * rect.Height) + (rect.Width * rect.Width));
// Now we can find the x,y of point 2 rotated by the specified angle.
x = (float)(radiusP2 * Math.Cos(radianAngle + radianAngleP2));
y = (float)(radiusP2 * Math.Sin(radianAngle + radianAngleP2));
PointF p2 = new PointF(x, y);
// Now based on the original angle we can figure out the width and height
// of our returned rectagle.
float width = 0;
float height = 0;
if (angle < 90)
{
width = p1.X + Math.Abs(p3.X);
height = p2.Y;
}
else if (angle < 180)
{
width = Math.Abs(p2.X);
height = p1.Y + Math.Abs(p3.Y);
}
else if (angle < 270)
{
width = Math.Abs(p1.X) + p3.X;
height = Math.Abs(p2.Y);
}
else
{
width = p2.X;
height = Math.Abs(p1.Y) + p3.Y;
}
return new RectangleF(0, 0, width, height);
}
|
|
|
|
|
Please could you post a full snippet of how to do rotated text as you describe, as that would be useful to know, from my point of view. In olrder apps I have been using LOGFONT stuff and API calls.
Nursey
|
|
|
|
|
To rotate the text use the power of the Graphics class in .net. It has a RotateTransform() method. Here is one link that talks about how to use it. I'm sure you can find other tutorials on the web also.
http://www.c-sharpcorner.com/Code/2004/April/Transformations06.asp
|
|
|
|
|
Hi everybody,,
Very curious to know...
In MFC there were __FILE__ and __LINE__ macro's, which were very helpfull for trace operations.
Are there any equivalents in C# .NET ??
Please let me know.
Thanx in advance.
Saleem
|
|
|
|
|
There are no equivalent directives in C# or VB.NET.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi All,
I feel that what I'm about to ask might be a really silly question, but I'd appreciate any help.
I want to create an application that exposes Functions and possibly Events that can be accessed through CreateObject() in VBScript (simular to the way you can control Office applications).
Where do I begin? Does the application have to be registered on the host machine in someway and if this is the case, is it simply a case of making a Function public in order to expose it?
Rich
|
|
|
|
|
VBScript will only work with late bound COM objects.
You can begin by implementing the COM-based interfaces in your C# code.
First, mark you assembly so that it is visible to COM.
<br />
[COMVisible(true)]<br />
public class myClass
Next tell the compiler to expose the necessary interface that VBScript understands.
<br />
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
Finally tell the compiler that you want a COM-based entity to see you.
In the project properties mark Register for COM Interop = true;
A word of warning: It is not that easy to use overloaded methods in VBScript so you should avoid these as much as possible.
This signature left intentionally blank
|
|
|
|
|
Thanks for the reply RC!
By what name would I then call the Application from VBScript. How does the enviroment know that Excel is an Excel.Application?
Rich
|
|
|
|
|
You would create and access methods within your script like any other COM component. So if your class was csExcelViewer you would do a
CreateInstance(csExcelViewer) and then do your method calls.
This signature left intentionally blank
|
|
|
|
|
C# is not a scripting language, thus you can't create objects of your C# code in a VBScript. You can create late bound objects in C#, is that what you are looking to do, that is what happens in VBScript when you call CreateObject.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Thanks for the comment Nick. But, I was actually wanting to create an application in C# that could be called from VBScript using CreateObject.
Rich
|
|
|
|
|
|
In addition to what Nick and the others say, you could also use the wizard I've created for exactly this task. Take a look here:
A COM class wizard for VS.NET 2003[^].
Regards,
mav
|
|
|
|
|
Has anybody found a way to implement a global message trap, so that no matte what window/control has focus, and no matte where the mouse is pointing, you can listen to the mouse wheel roll messages?
I have seen mouse driver settings that say send messsages to the window being pointed at, rather than the window with focus. I want to develop several controls that respond to mouse wheel events without having focus, and I dont want to set focus to them just so that I can "hear" the mouse wheel messages either.
Any input, pardon the pun, would be great.
Nursey
|
|
|
|
|
It's exactly the same as a keyboard hook, except it looks at mouse messages. Create an implementation of IMessageFilter and call Application.AddMessageFilter[^] to start it. All you have to do is add the code to watch for the mouse wheel message, documented here[^]. Look through the Windows C++ header files (*.h) for MW_MOUSEWHEEL to find what the constant value is for the message.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Please note that what Dave said is only for the message pump for your application. You could also set Control.Capture to true to capture mouse events that you could handle either in WndProc or even the events that are exposed on the Control on which you set its Capture property to true .
You could also implement a system hook, but this is very dangerous and not something to be taken lightly - you're hooking every group of messages for the entire platform and your code has to be clean, efficient, and must be unloaded and gracefully fail should any problems occur. There are several articles here on CodeProject about that. Search for SetWindowsHook to find articles on this site.
Software Design Engineer
Developer Division Sustained Engineering, Microsoft
My Articles
|
|
|
|
|
Thank you both for your advice, that was just what I needed to hear.
I've done quite a bit with subclassing in the past, but as its been a while, and as I would like to know if there is a more ".NET" like way in which this should be done, then it was well worth asking.
If I hook into the application message pump, then presumably, as controls run "in process" I will be able to hook into every Windows Forms App that utilises my controls?
Many thanks once again.
Nursey
|
|
|
|
|
cnurse wrote:
If I hook into the application message pump, then presumably, as controls run "in process" I will be able to hook into every Windows Forms App that utilises my controls?
Most likely, yes. It greatly depends on the container application, though. I don't forsee you having any
The ".NET" way of things has nothing to do with Windows Forms or anything else, actually. .NET is Microsoft's brand of the CLI, or Common Language Infrastructure. Windows Forms is part of the BCL and actually encapsulates the Common Controls (like Edit, Rich Edit, Static, etc.) and many, many other Windows APIs and other Win32 APIs. Handling messages in this way is nothing different from what Microsoft is doing. That's why the Control class defines the WndProc method (among other Windows Platform-related members) - not just so you can use it but so that they can use it to encapsulates the Common Controls.
Software Design Engineer
Developer Division Sustained Engineering, Microsoft
My Articles
|
|
|
|