|
I'm working on a c# application and i'd like to get it launchable from Microsoft Word using a new icon. The problem is I don't know how to do, I've been searching throw articles but they often explain how to launch and control Word from an application and not the contrary.
Could someone explain me how to do such a thing, or at least give me a few steps ?
Thank you.
---------
Or not ?
|
|
|
|
|
Can everyone explain me the following lines?
<br />
GCHandle handle = GCHandle.Alloc( savedArray, GCHandleType.Pinned );<br />
int scan0 = (int) handle.AddrOfPinnedObject();<br />
scan0 += (h - 1) * stride;<br />
Bitmap b = new Bitmap( w, h, -stride, PixelFormat.Format24bppRgb, (IntPtr) scan0 );<br />
handle.Free();<br />
What does the GCHandle object? Can I use the "fixed" keyword instead, to get the adress of "savedArry"?
|
|
|
|
|
Can you tell me where the code comes from, and what it's trying to do?
|
|
|
|
|
The code comes from the "SampleGrabberNET" sample on http://www.codeproject.com/useritems/directshownet.asp.
The code should save a memory-image with the Bitmap object.
|
|
|
|
|
I think you should be able to rewrite this as:
Bitmap b;
fixed (byte* pByte = savedArray)
{
IntPtr bits = new IntPtr(pByte + (h - 1) * stride);
b = new Bitmap( w, h, -stride, PixelFormat.Format24bppRgb, bits );
}
If you knew the size of the bitmap, you could also create a new one that size, use LockBitmap to get to the bits, and just copy the memory across.
|
|
|
|
|
I am writing a class that overrides Control and utilizes the non-client area. I need to be able to have hotspots within the non-client area. However, because of what seems to me to be unusual behavior, I am not able to get it working.
I override WndProc to intercept WM_NCMOUSEMOVE and WM_NCPAINT (as well as WM_NCCALCSIZE, WM_NCHITTEST, and WM_LBUTTONDOWN/UP) as follows:
(Please don't flame me for posting VB.NET code. I use both interchangably as they are pretty much the same thing anyways. It just so happens that I wrote this in VB.NET. I posted here because I would guess that C# programmers know more about the Win32 API than VB.NET programmers, and my questions have nothing to do with VB.NET)
Protected Overrides Sub WndProc(ByRef msg As Message)
Select Case msg.Msg
Case 131 'WM_NCCALCSIZE
...
Case 132 'WM_NCHITTEST
...
Case 133 'WM_NCPAINT
Dim dc As Integer
dc = GetDCEx(msg.HWnd.ToInt32(), msg.WParam.ToInt32(), 65536 + 128 + 1)
Dim hdc As IntPtr = New IntPtr(dc)
Dim g As Graphics = Graphics.FromHdc(hdc)
OnPaintNonClient(New PaintEventArgs(g, Rectangle.Round(g.ClipBounds)))
ReleaseDC(msg.HWnd.ToInt32(), hdc.ToInt32())
Case 160 'WM_NCMOUSEMOVE
Dim pt As PointL
pt.x = msg.LParam.ToInt32() Mod 65536
pt.y = msg.LParam.ToInt32() / 65536
Dim ppt As IntPtr = Marshal.AllocHGlobal(8)
Marshal.StructureToPtr(pt, ppt, False)
ScreenToClient(msg.HWnd.ToInt32(), ppt.ToInt32())
pt = Marshal.PtrToStructure(ppt, GetType(PointL))
Dim args As MouseEventArgs = New MouseEventArgs(MouseButtons.None, 0, pt.x, pt.y, 0)
OnNonClientMouseMove(args)
Marshal.FreeHGlobal(ppt)
Case 161 'WM_NCLBUTTONDOWN
...
Case 162 'WM_NCLBUTTONUP
...
Case Else
MyBase.WndProc(msg)
End Select
End Sub
Protected Overridable Sub OnNonClientMouseMove(ByVal args As MouseEventArgs)
If ... Then 'Test hotspots
...
PostMessage(Me.Handle, 133, 0, 0) 'WM_NCPAINT
End If
End Sub
Protected Overridable Sub OnPaintNonClient(ByVal args As PaintEventArgs)
...
End Sub
There are no problems painting the non-client area for resizes, max/min, etc. Intercepting WM_NCMOUSEMOVE and testing for mouse-overs on my hotspots works fine. However, the weird thing is that when my code does the PostMessage call, the WM_NCPAINT message never reaches WndProc .
Does anyone know what is going on?
Does Windows.Forms not send every message on to WndProc ?
Do I have to do something with PreProcessMessage ?
Can what I am trying to do actually be done in Windows.Forms?
Thanks.
|
|
|
|
|
I tried something else out that gave me strange results as well...
Instead of using PostMessage , I switched to using SendMessage . The WM_NCPAINT message is now reaching WndProc , however, the strange thing is that the drawing that I do there does not show up.
The drawing code works fine in response to WM_NCPAINT messages caused by resizes, min/maxes, etc...
Any ideas?
|
|
|
|
|
|
give it a Browsable(false) attribute.
|
|
|
|
|
I tried this and I thought it did not work. I'l try again.
|
|
|
|
|
I tired this and it did not work. I think I need to add that the property I am trying to hide is not one that I added, but rather one that is available via the control that I inherit. I don't want the user to be able to change the property so I need it hidden.
|
|
|
|
|
You could override the property in your control and then just call the base.property.
Example hiding Label.Text or something similiar:
[Browseable(false)]
public override string Text
{
get{ return base.Text; }
set{ base.Text = value; }
}
This would allow get/setting of the property but it would be not be seen in the property grid.
Later,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
On my MDI Parent Form or SDI Parent Form if I have any control i.e. push button, label etc. When I call my child form those parent controls still there? Anybody knows why, I will be thankful if somebody helps me in that.
Thanks in advance.
|
|
|
|
|
Okay its not a bug if you set your WindowState property to Maximize of Child Form it will behave in a way it required. Finally I found this.
|
|
|
|
|
I have a program that connects to a Web Service to authenticate a user.
When the user clicks ok the program access the Web Service through the
internet.
This actually seems to FREEZE the program until it has finished, how can I
solve this problem?
It's really not a good user interface like now!
I mean maybe I could make like when you are loggin in in MSN Messenger, but
how to do it?
Thankx!
"Nelle cose del mondo non e' il sapere ma il volere che puo'."
|
|
|
|
|
What you are seeing is that all the work is being done on one thread, including all the waiting that you have to do while you wait for the webservice to respond.
The solution is to use an Async method or a separate thread. The Async method will use a separate thread but it takes care of all the work for you; while you have to do all the work to use a thread yourself.
If I remember correctly the code that the "Add Web Reference" option generates includes some Async methods. The Async methods begin with Begin and End followed by the name of the method.
Using a method from the CodeProject webservice
ArticleBrief[] GetLatestArticleBrief(int NumArticles);
The Async versions of this method are:
IAsyncResult BeginGetLatestArticleBrief(int NumArticles, AsyncCallback callback, object asyncState); and
ArticleBrief[] EndGetLatestArticleBrief(IAsyncResult asyncResult);
Typical usage is as such
IAsyncResult iar = BeginGetLatestArticleBrief(numArticles, null, null);
if( iar.IsCompleted )
{
articleBriefs = EndGetLatestArticleBrief(iar);
}
else
{
}
Since you wouldn't be doing anything else while the user is logging in I would do this:
IAsyncResult iar = BeginLoginUser(username, password, null, null);
while( !iar.IsCompleted )
{
Application.DoEvents();
}
This is only a brief intro and a limited way of doing things, MSDN contains an entire section on Asynchronous programming which you should read before going much further.
If you use the MSDN that came with VS.NET I found the topic by going to the following nodes: Visual Studio.NET -> .NET Framework -> Programming with the .NET Framework -> Including Asynchronous Calls
HTH,
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
How is late binding done in C#? I'd like to allow for the registration of 'pluggins' (used loosly) for an automation tool for Source Safe. IE as I come across a file type, the appropriate class/library which implements the correct interface is loaded and used to process the file...
|
|
|
|
|
your plugins should implement an interface, which means you don't have to late bind anything beyond checking and casting to the interface.
VB implements its latebinding using reflection behind the scenes (InvokeMember i suppose), which you can do manually in c# if you want.
|
|
|
|
|
But I don't want to have to recompile the code after each time or create a switch/if for each type
ie I don't want to do this
IVSSCheckout itemHandler;
switch (fileExt) {
case "asp":
IVSSCheckout itemHandler = new ASPHandler(); //tight bind is problem
case "cls":
IVSSCheckout itemHandler = new VBFileHandler();
case "cpp":
IVSSCheckout itemHandler = new VCPPPHandler();
}
I would rather do something parallel to:
className = GetFromRegistry( fileExt )
itemHandler = CreateObject( className )
I could very well be missing something quite simple and fundamental as I have just moved into .Net languages from C++ and VB.
|
|
|
|
|
You won't have to if you use an interface.
Here's what you need to do:
1) Write an interface that describes the add-in.
2) Build it to a separate assembly.
3) Reference that assembly both in your main program and in the add-in.
Then it's merely a matter of loading the assembly, finding all the types that implement the interface, creating an instance, and casting it to an interface.
If you look on http://www.gotdotnet.com/team/csharp, you'll find two examples of doing this.
On the information page, there's an "execution time code generation" section that does something nearly identical to what you want to do (from the loading perspective).
On the main page, there's a column on app domains and dynamic loading that does something similar, though it's delegate based instead of interface based.
Hope that helps.
|
|
|
|
|
Thanks a ton... I'll take a look at it those.
|
|
|
|
|
That's great. I knew there would be a way to do it. The reflection namespace was what I was looking for.
I'm not worried about memory resident assemblies as they will be unloaded rather quickly, so loading the Assembly via the Load call appears it will give me what I need. Thanks a lot for your quick responses. And these Reynolds people say you Microsoft guys aren't nice to work with... <sarcasm>
|
|
|
|
|
If you don't have the unload/reload issue, it's a *whole* lot easier to avoid appdomains, put the add-in in the same directory as the exe (or a subdir under it), and just use assembly.Load().
The way appdomains work takes a bit of mind-warping to figure out. It's really like running a process on another machine, from the way you deal with things.
|
|
|
|
|
Eric Gunnerson (msft) wrote:
The way appdomains work takes a bit of mind-warping to figure out.
Hi Eric, i have had my mind warped already (partially)
I understand from your article how to use objects from remote domains in the main app domain, but how does it work the other way around?
Eg. You have main program with an object say A. In my case object A also contains a NetworkStream that should not be disconnected. I want to now load/unload "helper" assmeblies in a remote domain that can reference an instance of object A in the main app. Can this be done, without me landing up in a psychiatric ward?
Reading both parts of the graphing calculator article was already a great help, i cant find any examples on how to do the reverse as described above.
Thanking you in advance
Cheers
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
I think the way you'd do this would be to pass a MarshalByReference object as a parameter to the other app domain when you made a call. That should result in the other app domain having a proxy object to the object in the main app domain.
I haven't tried this, however.
|
|
|
|