|
Sounds simple!
I'm calling SHGetFileInfo to get myself a HIMAGELIST, and now I want to create a ImageList so I can access the images.
An example I saw did a SendMessage to set the handle to a control. Unfortunately, I want to use a ComboBox which doesn't have a native ImageList.
So, how can I create a ImageList from a HIMAGELIST pointer?
Thanks!!
|
|
|
|
|
HIMAGELIST is actually a handle, i would attach your HIMAGELIST's handle to your ImageList object?
|
|
|
|
|
Absolutely. Many MFC examples use m_ImageList.Attach( hImageList )
How do I do it in C#?
|
|
|
|
|
I am looking to remotely reboot a server through C#. I have a VBScript example from Microsoft, but I can't seem to figure out how to move it to .NET. I'm also unable to figure out how to use the WMI (System.Management) classes to reboot.
Can anyone help me, either with source code examples or other websites to check?
Thanks!
|
|
|
|
|
Oh know its a case of DLLimport
ExitWindows is the function your after, but you'll have to DLLimport to use it.
|
|
|
|
|
If the server is remote, then you can also use wmi to shut it down.
In your msdn:
ms-help://MS.VSCC/MS.MSDNVS/wmisdk/u_ctrl_2ndx.htm
|
|
|
|
|
I want to do it to a remote computer, so I suspect it's a WMI thing. Anyone have any idea how to do this through WMI?
|
|
|
|
|
Here is an example:
string server = @"\\" + txtServer.Text;
ManagementScope ms = new ManagementScope(server + @"\root\cimv2");
ObjectQuery oq = new ObjectQuery("select * from win32_OperatingSystem");
ManagementObjectSearcher mos = new ManagementObjectSearcher(ms, oq);
ManagementObjectCollection moc = mos.Get();
foreach(ManagementObject mo in moc)
{
string[] ss = {""};
mo.InvokeMethod("Reboot", ss);
MessageBox.Show("The reboot command has been sent.");
}
The only difference between local and remote reboots is the ManagementScope and the optional ConnectionOptions.
Matt is a network administrator for an auditing company in the midwest. He is shamelessly looking for Windows programming side jobs.
|
|
|
|
|
That last one worked like a champ. Thanks!
|
|
|
|
|
How do I connect to a remote SNMP device using the WMI SNMP provider using System.Management objects? Can someone provide an example for me?
Matt is a network administrator for an auditing company in the midwest.
|
|
|
|
|
First try the SNMP provider:
http://www.microsoft.com/downloads/release.asp?ReleaseID=19776
(included on XP?)
http://www.microsoft.com/windows2000/docs/WMIandSNMP.doc
so you can still use WMI from C#.
|
|
|
|
|
Thank you for the links, but I have been to them. I have visited a lot of sites and the best I can get are vb scripts. I think I know in general what I need to do, but I really need a couple of specific examples.
Matt is a network administrator for an auditing company in the midwest. He is shamelessly looking for Windows programming side work.
|
|
|
|
|
Check out:
http://www.c-sharpcorner.com/Code/2002/Sept/SnmpLib.asp
|
|
|
|
|
Is it possible to do ownerdraw of ListView and TreeViews without using the windows API?
I am constrained by a pure C#/.NET framework requirement. This means no COM objects or accessing DLLs unless that functionality is directly exposed by some .NET framework.
All the exmaples I have seen so far seem to use windows API in the least.
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
Absolutely without - I don't know, but to be honest: I don't believe it (at least if even SendMessage is included into the restriction list). However, did you already had a look into the UtilityLibrary from Carlos Perez?? (just search here in CP)It's not only an excellent tutorial, it even has samples for Listbox- and Treeview implementation.
May be this gives you the ultimative hint?? Or you find a way to re-implement the rare API calls into pure C#?
Wish you success! Bye
Matze
|
|
|
|
|
|
every c#'s object like a pointer in c++. But How can i get a pointer point to pointer (**) in c#?
I just work on a undo/redo engine in my c# application.
For example, there is two type of object to be edit in application
class A
{
string aa;
}
class B
{
int bb;
}
The edit operation change the many objects of type A or type B.
I hope to build a stack of object to store the string aa and int bb. Two objects to be cloned, one before the edit operation, another after it.
If the only way to change a memeber of a object is xx.yy = zz, i find it impossible to do the undo. Because i have to know the parent object (A or B) and which type of it (A or B) and judge in code whether to use aa or bb.
I doubt whether reflection ability in c# can help me.
But in c++ style, it is very easy to use object*. something like
*orgin = cloneBefore
or
*orgin = cloneAfter
Do i make some mistake? Please give me some suggestion!!
or any undo/redo engine written by c# or java in the world?
|
|
|
|
|
|
I think you can get the same behavior by simply creating a class to hold your object reference. You would declare instances of that rather than object*, and then you'll be able to look inside your class and change the reference.
|
|
|
|
|
Yes, I think what you said is what i really want to do.
I need to bypass class A to access item aa in such an engine. But don't know whether c# permit it or not.
class A
{
string aa;
}
A someA;
someA.aa = "...";
In function calling, we can use "ref" keyword to have the object reference.
something like:
CallingFunc(ref someA.aa);
But i dont know how to store the object reference. "ref" seems only be used in calling parameters.
like:
store[i] = ref someA.aa ?
Can you show me some simple demo?
Thanks!!
|
|
|
|
|
You'd need to write a class like:
class ObjectReference
{
public object reference; // this could be a property if you wanted...
}
Then, whenever you create something that needs to be undo-able, you wrap it in one of these objects and store the reference to ObjectReference.
Note that this is going to make your code pretty ugly, as you'll have to cast from object to the real type whenever you use an object.
|
|
|
|
|
You should look into using the Command Pattern[^] to create a undo/redo framework.
|
|
|
|
|
Hi all,
I desperately need a hint guiding me the right direction...
I want to retrieve the NCM information using SystemParametersInfo. Well, to define the function call is rather easy, and the structure itself does not make lots of problems, too:
[StructLayout(LayoutKind.Sequential)]
public class NONCLIENTMETRICS
{
public int cbSize;
public int iBorderWidth;
public int iScrollWidth;
public int iScrollHeight;
public int iCaptionWidth;
public int iCaptionHeight;
public LOGFONT lfntCaptionFont;
public int iSMCaptionWidth;
public int iSMCaptionHeight;
public LOGFONT lfntSMCaptionFont;
public int iMenuWidth;
public int iMenuHeight;
public LOGFONT lfntMenuFont;
public LOGFONT lfntStatusFont;
public LOGFONT lfntMessageFont;
public NONCLIENTMETRICS()
{
cbSize = 340;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct LOGFONT
{
public int lfHeight;
public int lfWidth;
public int lfEscapement;
public int lfOrientation;
public int lfWeight;
public byte lfItalic;
public byte lfUnderline;
public byte lfStrikeOut;
public byte lfCharSet;
public byte lfOutPrecision;
public byte lfClipPrecision;
public byte lfQuality;
public byte lfPitchAndFamily;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst=32)]
public string lfFaceName;
public static LOGFONT Empty
{
get
{... }
}
}
[DllImport("User32.dll"]
public static extern bool SystemParametersInfo(int Action, int Param, NONCLIENTMETRICS Param, int WinIni);
The call is
NONCLIENTMETRICS ncm = new NONCLIENTMETRICS();
bool b = SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, ncm, 0);
And now I'm getting confused:
b is true, that means the call succeeded, but ncm has not been touched. Is there anything wrong with the structure layout?? At the end I tried all combinations, instead of a class I declared NCM as a structure and used ref, I tried the IntPtr version... nothing didn't help. And I know that it works since MS does similar to build the SystemInformation members (Menufont is contained in NCM, too).
Somewhere I'm blocked. Can anybody help??
Thanks and bye
Matze
|
|
|
|
|
Matze wrote:
public NONCLIENTMETRICS()
{
cbSize = 340;
}
arrrg! Replace with
cbSize = Marshal.SizeOf(this);
Matze wrote:
DllImport("User32.dll"]
public static extern bool SystemParametersInfo(int Action, int Param, NONCLIENTMETRICS Param, int WinIni);
The call is
NONCLIENTMETRICS ncm = new NONCLIENTMETRICS();
bool b = SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, ncm, 0);
The declaration and method calls doesnt match! Why are you passing ncm.cbSize. Some functions however need to be called twice. 1st to find out what size parameter they need, 2nd the actuall call. this mite be the case. See if values from other paramters change during the call.
Hope this helps
DBHelper - SQL Stored Procedure Wrapper & Typed DataSet Generator for .NET low popularity, please visit
|
|
|
|
|
Hi leppie,
thanks for the answer!
leppie wrote:
bool b = SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, ncm, 0);
The declaration and method calls doesnt match! Why are you passing ncm.cbSize. Some functions however need to be called twice. 1st to find out what size parameter they need, 2nd the actuall call. this mite be the case. See if values from other paramters change during the call.
Hmm, the documentation states that for the GETNONCLIENTMAETRICS action the size of NCM must be told as second parameter, that's why I passed it (and so does MS, as one can see in the Decompiler;)). Actually, when I pass anything else than 340 (==Marshall..;)) the function returns false. No values are changed, unfortunately
leppie wrote:
public NONCLIENTMETRICS()
{
cbSize = 340;
}
arrrg! Replace with
cbSize = Marshal.SizeOf(this);
Yepp, of course I did this, but I thought a number is more informative in the message
|
|
|
|