|
|
ok, thanks. I'm going to explore this way.;P
There is no spoon.
|
|
|
|
|
Hello all!
I am tasked to work on a project that draws moving objects on the screen dynamically using the co-ordinates and data provided through a stream, let's say a FileStream. I also would like to be able to "delete" the object from the screen. The method(s) that I have been using is that I used Threading to extract the co-ordinates and other info from the FileStream and map them on the screen. By doing this, the screen is littered with objects since the old objects have not been getting rid of. I have tried re-painting the "old" objects with the color same as the background so that they would "disappear". As I tried to do that, the program kept crashing on me. I guess that I don't have an efficient code to manage the buffering.
So, if have experienced with graphics in the past, please give me some hints. Thanks a whole lot in advance!
Tim
|
|
|
|
|
Just keep a reference to these objects and either dispose of them or simply move them to new coordinates. If you create new controls each time you read from the stream, you need to dispose those objects. If it's simply a matter of repainting, then make sure you're repainting the background and then the these other objects so that the "old" objects are not still painted on the on-screen bitmap.
Without knowing more about your implementation, it's difficult to answer your question.
Just consider how controls are painted on a form, though. Each control that is contained in the Controls collection property is sent the WM_PAINT message and paints itself after the container has invalidated it's surface, repainting the background as necessary. This is basically how all painting is done by the Window manager (i.e., Windows).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
When managing our .NET projects with Visual SourceSafe, we encounter this problem:
DeveloperA works on a .NET project. This project has a reference to a COM object. DeveloperA checks in his files into SourceSafe.
Next day, DeveloperB works on the same .NET project. Although he has the same COM oject installed on his computer, the reference is invalid (indicated by a yellow triangle with an exception mark inside). DeveloperB has to delete the reference, and set a new reference to the same COM object.
Is there any way to avoid this deleting and re-creating of references?
|
|
|
|
|
DeveloperB doesn't seem to be getting the interop assemblies created by DeveloperA. We put our interop assemblies used throughout our application in SourceSafe as well, which SourceSafe does not do by default (it doesn't add assembly references, only project files). The project still thinks it's there, however, since the .csproj file has a reference to that assembly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I want to create an owner drawn track bar,
to look something like a volume control, i.e.
<br />
*****<br />
****<br />
-----<br />
**<br />
*<br />
something like that....
any hints for me?
|
|
|
|
|
I have absolutely no idea what you mean...
Do you want to do this in a console / on a form? webpage?
-Ernst
There are only 10 kinds of programmers - those who understand binary, and those who don't.
|
|
|
|
|
Yeah, don't extend the TrackBar because you'll have a much more difficult time painting what you need since the TrackBar control simply encapsulates the native Trackbar common control. Instead, just create your own Control from scratch that works in a similar fashion (besides, a control like you want probably doesn't need to draw tick marks anyway).
There are several articles I've seen here on CodeProject regarding such controls. I suggest you search CodeProject to find examples.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I am trying to open a word template that has auto macros that fire when the template is opened. I need to disable these programmatically.
In Delphi you can use the following to achieve this:-
OleVaraint(myWordApp.WordBasic).DisableAutoMacros;
myWordApp.Documents.Open(blaa...blaaa...blaa...
I really need a way to do this in C#
Any help would be most appreciated.
P.S. Anybody know any other good places to ask?
|
|
|
|
|
Which version of Word is it? The delphi code you post is COM automation code - you might try creating a wrapper for that type library, and reference it in your .NET project - you should then be able to do the same in C#.
HTH!
-Ernst
There are only 10 kinds of programmers - those who understand binary, and those who don't.
|
|
|
|
|
I think I'm being some what thick and this is my 3rd day with C# but I'm not sure what type library I'm supposed to wrap.
I'm using the Microsoft Word 10.0 Object Library.
It has a Word.Application.WordBasic property but it is of type object. I am unsure what I should cast it to to simulate the Delphi code.
Also I think WordBasic is no longer used much. The Application object model is supposed to have replaced its functionality. However I still cannot find a similar method/property. It should be simple but it's driving me nuts.
Some times I hate programming.
Dominic Godin.
|
|
|
|
|
The thing about OLE automation (and COM in general) is that it works practically the same in whatever language you use as a client (though the syntax may be slightly different).
Unfortunately, ApplicationClass.WordBasic returns an object and because of the Common Type System - a component of the .NET Framework - you can't simply call the method like you could in Delphi or VB (which internally uses the DISPID to invoke the dispatch function with any DISPARAMs you might specify).
There is a way, though, and it's not too easy. You need to declare the IDispatch interface in COM (merging the IUnknown methods in the same interface - do not inherit from a declared IUknown ). Then you call IDispatch.GetIDsOfNames to get the DISPID for DisableAutoMacros , and then use that in the call to IDispatch.Invoke .
The last line is easy and there are many eamples here on CodeProject that show examples, though it's pretty easy. The following is, of course, the method signature for Documents.Open :
public Document Open(
ref object FileName,
ref object ConfirmConversions,
ref object ReadOnly,
ref object AddToRecentFiles,
ref object PasswordDocument,
ref object PasswordTemplate,
ref object Revert,
ref object WritePasswordDocument,
ref object WritePasswordTemplate,
ref object Format,
ref object Encoding,
ref object Visible,
ref object OpenAndRepair,
ref object DocumentDirection,
ref object NoEncodingDialog); So, if you wanted to open a document and don't want/need to provide all those parameters, you can simply using Missing.Value (or null ):
object fileName = "C:\Example.doc";
object missing = Missing.Value;
Document doc = app.Documents.Open(ref fileName, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing); If you wanted to open the document as read-only, add the following line before calling Open and change the third parameter to ref readOnly :
object readOnly = true;
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Can you tell me if I'm on the right track?
So far I've got:
Type t = Type.GetTypeFromProgID("Word.Application.10");
object MSWord = Activator.CreateInstance(t);
object WordBasic = MSWord.GetType().InvokeMember("WordBasic", BindingFlags.GetProperty,
null, MSWord, null);
WordBasic.GetType().InvokeMember("DisableAutoMacros", BindingFlags.Default |
BindingFlags.InvokeMethod | BindingFlags.Static, null,
WordBasic, new object [] {});
I've also tried :
Word.Application MSWord = new Word.ApplicationClass();
object o = MSWord.WordBasic;
o.GetType().InvokeMember("DisableAutoMacros",
BindingFlags.Default | BindingFlags.InvokeMethod |
BindingFlags.Static, null, o, new object [] {});
I have tried the InvokeMember call with many different Binding Flags but it always throws an Exception. Any help would again be most welcome.
|
|
|
|
|
This won't work. As I mentioned, the Common Type System (CTS) is what defines how types and members are defined and accessed by the runtime (basically). You can't simply get types that don't exist or invoke members that aren't defined on that type. The Type.GetTypeFromProgId , for example, still requires that the ProgID refers to a managed Type.
Instead, you must declare the IDispatch interface in managed code as I mentioned, then doing basically what you're doing above (in concept, not the actual code) to invoke the dispatch method DisableAutoMacros .
You can declare the IDispatch in managed code like so:
[Guid("00020400-0000-0000-c000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IDispatch
{
[PreserveSig] int GetTypeInfoCount();
UCOMITypeInfo GetTypeInfo(
[MarshalAs(UnmanagedType.U4)] int iTInfo,
[MarshalAs(UnmanagedType.U4)] int lcid);
[PreserveSig] int GetIDsOfNames(
ref Guid riid,
string[] rgsNames,
[MarshalAs(UnmanagedType.U4)] int cNames,
[MarshalAs(UnmanagedType.U4)] int lcid,
out int[] rgDispId);
[PreserveSig] int Invoke(
int dispIdMember,
ref Guid riid,
[MarshalAs(UnmanagedType.U4)] int lcid,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
ref DISPPARAMS pDispParams,
[Out] object[] pVarResult,
ref EXCEPINFO pExcepInfo,
[Out] IntPtr[] pArgErr);
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Firstly thanks for you help. I'm only a Student on my work placement and this type of thing is well above my head.
how about this sort of thing?
IDispatch wb = (IDispatch)WordBasic;
string[] rgsNames = {"disableAutoMacros"};
int[] rgDispId = {0};
Guid blank = Guid.Empty;
int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID;
int result = wb.GetIDsOfNames(ref blank, rgsNames, 1, lcid ,out rgDispId);
rgDispId Array is set to null doing this. Am I now on the right track? Or have I still not got it?
Thanks
|
|
|
|
|
You're on the right track. Just familiarize yourself with how dispatch interfaces work and you should be able to do what you need to.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Bugger still stuck
Word.Application MSWord = new Word.ApplicationClass();
IDispatch wb = (IDispatch)MSWord.WordBasic;
int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID;
string[] rgsNames = {"DisableAutoMacros"};
int[] rgDispId = {};
Guid nullGUID = Guid.Empty;
int result = wb.GetIDsOfNames(ref nullGUID, rgsNames, 2, lcid, out rgDispId);
This code returns a result of -1073741819. There is little info on this error code. I have tried this with the Word.Application object MSWord with methods I know are there and I still get the same error code. Also the rgDispId is always set to null.
It seems I'm still missing a key point of understanding here.
|
|
|
|
|
Actually, try removing the out keyword from the last parameter declaration of GetIDsOfNames since an int[] array is already a reference type. The caller (you) must also allocate the array, so try int[] rgDispId = new int[1]; instead of creating an empty array.
This is definitely the right track, though I've never tried using the dispatch interface in managed code like this.
Another way would be to call IDispatch.GetTypeInfo and use the UCOMITypeInfo interface (which is fortunately defined in the FCL so you don't have to declare it) and use it's member methods to basically do the same thing.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Still get the same error. rgDispId isn't set to null anymore but contains 0, or what ever value I put in it to start with. It must be failing in the GetIDsOfNames method before it gets to assign anything.
Does this have anything to do with OleInitialize and CoCreateInstance . I thought Word.Application MSWord = new Word.ApplicationClass(); called these behind the scenes.
Also
IDispatch wb = (IDispatch)MSWord.WordBasic;
int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID
UCOMITypeInfo tpInf = (UCOMITypeInfo)wb.GetTypeInfo(0, lcid);
Throws the exception No such interface supported .
However
IDispatch ms = (IDispatch)MSWord;
int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID
UCOMITypeInfo tpInf = (UCOMITypeInfo)ms.GetTypeInfo(0, lcid);
doesn't. Can I get at it this way?
|
|
|
|
|
ComInitialize is called behind the scenes by the CLR, and you already have an instance of the WordBasic object so long as it isn't null. The fact that you're getting the IDispatch reference when you cast - for which the CLR performs a QueryInterface - shows that it supports automation, so I'm surprised that GetTypeInfo fails.
At this point, I would recommend going to the Word newsgroup (NNTP news server is msnews.microsoft.com) and seeing if there is another way to disable macros on startup.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Will do. I have a feeling it isn't possible mind
Thanks for all the help, I've learned a great deal this last few days.
|
|
|
|
|
Got it working!!
Needed a few changes to the interface thats all.
[Guid("00020400-0000-0000-c000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IDispatch
{
[PreserveSig] int GetTypeInfoCount();
UCOMITypeInfo GetTypeInfo(
[MarshalAs(UnmanagedType.U4)] int iTInfo,
[MarshalAs(UnmanagedType.U4)] int lcid);
[PreserveSig] int GetIDsOfNames(
ref Guid riid,
[MarshalAs(UnmanagedType.LPArray,
ArraySubType=UnmanagedType.LPWStr)]
string[] rgsNames,
int cNames,
int lcid,
[MarshalAs(UnmanagedType.LPArray)] int[] rgDispId);
[PreserveSig] int Invoke(
int dispIdMember,
ref Guid riid,
[MarshalAs(UnmanagedType.U4)] int lcid,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
ref DISPPARAMS pDispParams,
[MarshalAs(UnmanagedType.LPArray)][Out] object[] pVarResult,
ref EXCEPINFO pExcepInfo,
[MarshalAs(UnmanagedType.LPArray)][Out] IntPtr[] pArgErr);
}
Thanks again.
|
|
|
|
|
Glad you got it working, but I find this interesting since the declaration I gave you was pulled out of the .NET FCL assemblies (written by Microsoft). Oh well, whatever works, right?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I need to get a list of computers which are currently logged on a local area network. I can get the server ip by using DNS (API). However, I can not figure out how to get the list of computer . Please help me to figure out this problem.
Thanks,
Nemo
|
|
|
|
|