|
Hello,
With the Win32 API I could get a handle to the system icons by calling LoadIcon with a NULL instance handle (eg. hIcon = LoadIcon(NULL, IDI_HAND) ).
How can I get the system stop icon in totally managed way? (without P/Invoke)
[EDIT: And if I require P/Invoke, what's the equivalent of MAKEINTRESOURCE ?]
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Sorry about the vote of 1. I wasn't thinking and clicked the wrong link.
For questions like this you really should consult the header. If you look at the definition for the MAKEINTRESOURCE in Winuser.h (which is documented as the header in which it's declared in the Platform SDK documentation), you'd see:
#define MAKEINTRESOURCEA(i) (LPSTR)((ULONG_PTR)((WORD)(i)))
#define MAKEINTRESOURCEW(i) (LPWSTR)((ULONG_PTR)((WORD)(i)))
#ifdef UNICODE
#define MAKEINTRESOURCE MAKEINTRESOURCEW
#else
#define MAKEINTRESOURCE MAKEINTRESOURCEA
#endif // !UNICODE What's going on here? Well, certain APIs like LoadIcon want a string, and since an integer isn't a string you need to pack the integer into a string which the API will handle.
To declare a similar macro (or, rather, a method) in C# isn't nearly as straight forward, since a short (same as a WORD ) isn't a string.
To get around this, declare LoadIcon like the following in order to pass a parameter of the correct size (size of a pointer):
[DllImport("user32.dll", SetLastError=true)]
static extern IntPtr LoadIcon(IntPtr hInstance, IntPtr lpIconName);
public IntPtr LoadIcon(short id)
{
IntPtr i new IntPtr((int)id);
return LoadIcon(hInstance, i);
} If you need to overload LoadIcon to pass a string you can still do that. SendMessage , for example, is overloaded many different ways in the .NET BCL assemblies where it's used. So long as the parameter size is still the same (which is why you simply can't overload it and pass a short ) you're fine, so long as the right data is passed as that parameter.
Once you have the IntPtr return you can use Bitmap.FromHicon to load the icon into memory.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath Stewart wrote:
Sorry about the vote of 1. I wasn't thinking and clicked the wrong link.
Don't worry!
Thanks, I got it working with P/Invoke. But I wish there were a a managed way of doing it.
Thanks!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Not to load an icon from a Win32 resource, no. Once you obtain a handle to the icon, however, you can use the method I mentioned in my first reply.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello dear all
i want to display a notify message in windows application if user will get any new information then show one notify message in bottom right of window screen please help me how can i display a message
|
|
|
|
|
|
no basically i wnat to diaplay notify message like gmail notify do you have nay idea how we can show this type of alert
|
|
|
|
|
|
hello leppie
Thanks for solving my problem. yes i want to show exactally like that
|
|
|
|
|
Hi,
I was under the impression that if I wanted to center a MessageBox over any window, then I could use this class:
public class Win32Window : IWin32Window<br />
{<br />
private IntPtr m_hWnd;<br />
<br />
public Win32Window( System.Windows.Forms.Control ctrl )<br />
{<br />
m_hWnd = ctrl.Handle;<br />
}<br />
<br />
public System.IntPtr Handle<br />
{<br />
get<br />
{<br />
return m_hWnd;<br />
}<br />
}<br />
}
and then call the MessageBox like this:
Win32Window win = new Win32Window( this );<br />
MessageBox.Show( win, "Nú er gaman" );
but it doesn't work. Does anyone have a clue?
Best regards,
Daniel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Whatever gave you that idea? From the documentation:<bockquote>The IWin32Window the message box will display in front of.That is, the IWin32Window is the owner of the MessageBox , but that doesn't mean the MessageBox will be centered over the owner.
Also, you don't need to implement IWin32Window . The Control class - even from which the Form class derives - implements IWin32Window . You just need to pass a Control reference. What you did was unnecessary.
In order to center a dialog over a particular control or form, you'll need to define your own class that extends Form with all the bells and whistles you need. Make sure you pass an owner Control and set Form.StartupPosition to FormStartupPosition.CenterParent .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
i don't know wheres the error but i'm tired of searching so i'll let u to explore it,
my xml file is like the following.
<code><xml version="1.0" encoding="utf-8">
<VoteData>
<Question id="0" name="do you believe in think tanks?">
<Choice choiceid="1" votes="0" name="Yes">
<Vote ip="192.168.1.1"></Vote>
</Choice>
<Choice choiceid="2" votes="0" name="No">
</Choice>
</Question>
</VoteData></code> i'm trying to use SelectNodes() method to select nodes,
<br />
XmlDocument VoteData = new XmlDocument();<br />
VoteData.Load(@"C:\VoteData.xml");<br />
XmlElement xElement = VoteData.DocumentElement;<br />
XmlNodeList xList = xElement.SelectNodes("/VoteData/Question[@id='0']");<br />
the problem that xList is always empty, no results !
thanx in advance
|
|
|
|
|
Try validating your XML in explorer/any other Xml aware application and you will see its badly formed.
You are missing ? marks in the xml declaration line... its should read:
< ? xml version="1.0" encoding="utf-8" ? >
|
|
|
|
|
the xml is well formed, about the question mark "?" i just removed them when i did the copy and patse here, i think itsn't the problem,
thanx for ur reply
|
|
|
|
|
Xpath can be tricky :p Try some variations eg
/VoteData/Question[@id='0']/
/VoteData/Question[@id='0']/*
VoteData/Question[@id='0']
I cant recall the exact syntax, but something normally is just in the wrong place :p
Also, why not call SelectNodes from the VoteData xml doc itself? that mite be causing the Xpath not to match the VoteData bit.
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
i tried all this variations b4 i post this problem, but i'd like to ask somthin, why its tricky ? no standard ?
thanx for reply
|
|
|
|
|
Its tricky for me as I rarely use it, and tend to forget the exactly syntax. XPath is simply Regular Expressions for XML. The is a complete standard for it. .NET supports version 1.1 I think.
The easiest way to test things is just to start with "*" and continue up to "*/*/*" and see what is really being matched, from there is should be easy, except if you are using XmlNamespaces (which u are not). Your problem looks like a context problem, iow you are starting at the wrong node, like I mentioned in my previous post.
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
Why do you have the in you xml file? Check if xElement is empty
I use something like this and see if sId has some value
XmlNode node;
node = xml.FirstChild;
while (node.Name != "Ticket" & !(node == null))
{
node = node.NextSibling;
}
string sId;
sId = node.Attributes("id").Value;
|
|
|
|
|
while (node.Name != "Question" & !(node == null))
{
node = node.NextSibling;
}
|
|
|
|
|
|
the file may be large and that way may take a long time to select the node i need, do u think that XPath using this way to select nodes ? i dunno
|
|
|
|
|
|
yea thats right, but am implementing a stand alone component that don't relies on database, it has its own data file, thanks
|
|
|
|
|
The XPath is fine, that is not where your problem lies. I just made your XML valid and tested it.
If I have trouble with an XPath, I use XSLerator or something similar to test it, and build it one step at a time.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
i think i caught where the problem lies, the problem is me, damn, sorry guys, i didn't paste the exactly code as in my project , its my first time using xml so don't blame me, i think i'm using a namespace, and heres my exactly xml file
<?xml version="1.0" encoding="utf-8"?>
<VoteData xmlns="http://tempuri.org/VoteData.xsd">
<Question id="0" name="do you believe in think tanks?">
<Choice choiceid="1" votes="7" name="Yes">
<Vote ip="192.168.1.1" />
<Vote IP="50.50.20.10" xmlns="" />
<Vote IP="50.50.20.10" xmlns="" />
</Choice>
<Choice choiceid="2" votes="1" name="No">
<Vote IP="50.50.20.10" xmlns="" />
</Choice>
</Question>
<Question id="2" name="bet7eb Sawsan?">
<Choice choiceid="0" votes="0" name="aiwa" />
<Choice choiceid="1" votes="0" name="la2" />
<Choice choiceid="2" votes="0" name="moot" />
<Choice choiceid="3" votes="0" name="ya3ney" />
</Question>
</VoteData>
i didn't think that will be a diffrent while using namespace, so now, what should i change in my C# code to let XPath work ?
sorry guys again and thanx
|
|
|
|