|
Of what? Your form? You can use Form.PointToScreen(this.Bounds) to get a Point in scren coordinates, where this is your Form class. PointToScreen is actually a static method inheritted from Control .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i dont want to get the form coordinates but i have the handle of specific window and i want to get its coordinates i knew the Fn. but i dont know how to use it in C# the Function is bool GetWindowRect(HWnd,LpRect)
i donot know how use the pointer.
|
|
|
|
|
P/Invoke the API:
[DllImport("user32.dll")]
private static extern bool GetWindowRect(IntPtr hWnd, out RECT rc); You must also define the RECT structure, since System.Drawing.Rectangle doesn't have the same meaning for its fields:
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
} Then, just pass the handle of the Window in which you're interested to get back the RECT :
RECT rc;
GetWindowRect(hWnd, out rc); Now you've got your coordinates.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am currently trying to implement some functionality that was originally done in vb6. I want to do something similar to the getObject method. I need to find an assembly that is currently in memory, and make function calls to that assembly. So my question is two fold, when creating an assembly to run, do I need to create registry entries to "publish" that running assembly that will be used by other assemblies. Secondly, what method should I use to search for that running assembly, connect to it, and use its functions. I should of mentioned this earlier, it needs to be done through COM because the assembly will be called from an unmanaged c++ assembly.
Thanks for the help everyone,
Ryan
|
|
|
|
|
Sounds like you're talking about the Running Object Table (ROT). .NET provides a way to get an object publishes in the ROT using Marshal.GetActiveObject (using a ProgID). This, of course, is not what you want.
In order to accomplish this, you need to P/Invoke the RegisterActiveObject and RevokeActiveObject APIs and properly expose your .NET component as a CCW. This means that you must use regasm.exe (or your own implementation that registers the type) either using the /codebase option to register the full path to the assembly, or without if your assembly is in the GAC. Use /tlb to create and register the typelib. With that typelib, you can easily call late-bound methods on the COM object after getting it from the ROT.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
Hello all!
I am a VB developer and I used API Viewer.
I would like to know if Visual Studio .NET 2003 have a similar tool ?
Thanks for all,
Alexsander "Axia" Antunes
|
|
|
|
|
The API Viewer just displayed some of the Win32 functions in VB form once it was supplied a text file. So far, no tools have been written that do something similar for any .NET languages (to my knowledge). Some Microsoft employees have discussed this idea (via their blogs) of creating a tool, however it has been deemed too time consuming. If you are using C# (I am assuming this since you are in the C# forum) you will need to P/Invoke the Win32 method signatures to call them from C#, VB.NET or any .NET language in particular. Read into the DllImportAttribute Class[^] for more information.
- Nick Parker My Blog
|
|
|
|
|
I'm trying to protect one of my classes using PrincipalPermissionAttribute. I'm setting it to only allow the code to execute only if a specific user is trying to run it.
Here is the class declaration:
[PrincipalPermissionAttribute(SecurityAction.Demand, Authenticated:=True, name:="MYDOMAIN\\Mauricio")] public class foo
This code works fine but the problem is that it allows the usage of an GenericPrincipal object and I want it to use a WindowsPrincipal object. Allow it to use a GenericPrincipal will anyone to create a GenericPrincipal with that user name and execute the code. Like this:
GenericIdentity oIdent = new GenericIdentity("MYDOMAIN\\Mauricio", "NTLM");
GenericPrincipal oPrinc = new GenericPrincipal(oPrinc, null);
foo oFoo = new foo();
My question is: is there anyone to demand that a code only accepts WindowsPrincipals, and don't accept GenericPrincipals ?
thanks
Mauricio Ritter - Brazil
Sonorking now: 100.13560 MRitter
English is not my native language so, if you find any spelling erros in my posts, please let me know.
|
|
|
|
|
The only way you'll be able to do this is to extend the PrincipalPermission and PrincipalPermissionAttribute classes, or create your own. You could do the very same things, except check the Type against WindowsPrincipal that you get back from Thread.CurrentPrincipal . The current implementation doesn't care about the Type, so long as it implements IPrincipal .
If you want to know exactly what the current classes mentioned above are doing, you can use ildasm.exe that ships with the .NET Framework SDK if you know IL (and it wouldn't hurt to know anyway), or use a good decompiler like .NET Reflector[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have 2 panels, one docked to the left and the other docked to the bottom. I hide the left panel on startup but during runtime when i show it, i "pushed" the bottom panel to make room for itself. How can i prevent this. i.e. The left panel should be above the bottom panel.
<font=arial>Weiye Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
It's all about the order in which controls are added. Controls that are added first take precedence when docking over controls that are added later. When using Control/ControlCollection.AddRange , you need to add these in reverse order. How exactly are you "hiding" this control?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes, i am adding them in the reverse order.
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.panelLeft, this.panelBottom, ...});
Heath Stewart wrote:
How exactly are you "hiding" this control?
In the designer, both panels' Visible flags are set to false. In my application, there are 2 toggle buttons each calling the Hide() and Show() methods of the panels.
<font=arial>Weiye Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
I'm not sure if this will work, but try re-creating the handle for each control after changing the visibility of one (perhaps override OnVisibleChanged and doing it from within there after the call to base.OnVisibleChanged ). Since it appears that the control is re-created when changing the visibility of the current control, you could always handle the VisibleChanged event of the other control and re-create your own handle as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I just got it to work by inserting another control between the 2 panels during AddRange(...)
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.panelLeft, this.progressBar, this.panelBottom, ...});
But this doesn't make sense. The progress bar is located far away from the panels. Ah, never mind.... Thanks anyway...
<font=arial>Weiye Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
Deal all ,
in win32 API we can get a control HDC from its handel then we can use that hdc as a sourec for drawing functions like bitblt , streatchblt ...
but in .net farmework how can a do a simmilar jop by using GDI+ where any image drawing function use just the iamge object ???
Regs.
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
I am not sure if this is what u wanted:
Graphics graphics = Graphics.FromHwnd(MyControl.Handle);
<font=arial>Weiye Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
Dear Sir,
Thanks for help But this inforamtion not usefull for my question, let me giv you an example,
if you like to capture the desktop in win32 API you can call
SourceHdc = GetDC(GetDesktopWindow())
then to draw the picture you can use
BitBlt ( TargetHDC , SourceHDC , 0 , 0 ....
so how can i do it in GDI+ without using HDC
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
Or use the CreateGraphics method inherited from Control . You can also override OnPaint in a Control derivative or handle the Paint event on a Control derivative outside that class (like by its container).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Dear Sir,
Thanks for help But this inforamtion not usefull for my question, let me giv you an example,
if you like to capture the desktop in win32 API you can call
SourceHdc = GetDC(GetDesktopWindow())
then to draw the picture you can use
BitBlt ( TargetHDC , SourceHDC , 0 , 0 ....
so how can i do it in GDI+ without using HDC
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
GDI+ still uses handles. As the first reply mentioned, you can use Graphics.FromHwnd . Since you're not going to find a method that equates to BitBlt , you're most likely going to have to get an IntPtr representing the HDC from Graphics.GetHdc (call Graphics.ReleaseHdc when finished with the HDC ) anyway. You could also skip this overhead and P/Invoke the GetDC API, passing Control.Handle that is the HWND . This type of solution is very common. Handles are still very much used in the implementations of every Windows Forms control, and many other classes (like ImageList ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
so you mean that we could not throw WIN32 API down and depend just on .Net classes, ...
No problem thanks for help again
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
first thanks for you
and i hope to help me again i create managed c++ class library and used com in it when i compiled it any errors not found but when i build the library this error found
(unresolved token IID_IACCESSCONTROLENTRY)
|
|
|
|
|
|
Dear All,
I want to capture the keycode from keyboard buffer in VB.Net or C# Compact Framework.
Actually, I want to make a TSR(Terminate And Stay Resident) utility
which continuously look at the key strocks of keyboard and as soon as
a special key combination is pressed, it will invoke a function to
perform a series of actions.
For this purpose, I need to capture the keycode at system level not at
form level. So, how can i get keycode from keyboard buffer directly?
Tell me about some API for this purpose.
Regards,
Muhammad Arif
|
|
|
|