|
Thanks! The code works, but it require the window you want to capture to be active.
Otherwise, you will get whatever inside the area of that window :S
i change the capture code from:
<br />
GDI32.BitBlt(capHDC,0,0,width,height,wndHDC,x,y,GDI32.SRCCOPY); <br />
to:
<br />
USER32.SendMessage( wndHWND, Constants.WM_PRINT, capHDC, (IntPtr)( Constants.PRF_CHILDREN + Constants.PRF_CLIENT + Constants.PRF_OWNED ) );<br />
and i can capture anything anywhere - even the window is not inside the screen - but the problem is...i can't capture another application's window!!!
what happended this time ???
Do i have to get special permission for my application to send messsage to another window?
|
|
|
|
|
There is a API called PrintWindow.
<br />
[DllImport("user32.dll", SetLastError=true)]<br />
static extern IntPtr PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);<br />
|
|
|
|
|
Hi.. i've been trying to get the status of the battery on my laptop, but cant get the thing to work.
here's my code (in my main class)
public struct SystemPowerStatus
{
byte ACLineStatus;
byte batteryFlag;
byte batteryLifePercent;
byte reserved1;
int batteryLifeTime;
int batteryFullLifeTime;
}
[DllImport("kernel32.dll")]
public static extern bool GetSystemPowerStatus(ref SystemPowerStatus systemPowerStatus2);
private void form_load(object sender, EventArgs e)
{
MessageBox.Show("i want to print the battery % status here - how?");
}
how do i make it print out the battery status in the message box ? Can't get the thing to work
|
|
|
|
|
Try something like the following:
[DllImport("Kernel32")]
private static extern Boolean GetSystemPowerStatus(SystemPowerStatus sps);
[StructLayout(LayoutKind.Sequential)]
public class SystemPowerStatus
{
public ACLineStatus _ACLineStatus;
public BatteryFlag _BatteryFlag;
public Byte _BatteryLifePercent;
public Byte _Reserved1;
public Int32 _BatteryLifeTime;
public Int32 _BatteryFullLifeTime;
}
public enum ACLineStatus : byte
{
Offline = 0, Online = 1, Unknown = 255
}
public enum BatteryFlag : byte
{
High = 1,
Low = 2,
Critical = 4,
Charging = 8,
NoSystemBattery = 128,
Unknown = 255
}
Your usage would look like this for example:
private void button1_Click(object sender, EventArgs e)
{
SystemPowerStatus sps = new SystemPowerStatus();
GetSystemPowerStatus(sps);
if (sps != null)
{
MessageBox.Show(string.Format("Current battery life is at {0}%.", sps._BatteryLifePercent));
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
it gives me an error, which says sps does not contain a definition for _BatteryLifePercent... if I let intellisense show the possibilites of sps it just gives me ToString(), GetHashCode(), Equals and so on
|
|
|
|
|
I've updated the post, I forgot to copy over the class from my project in the post.
- Nick Parker My Blog | My Articles
|
|
|
|
|
looks like its working.. thanks
|
|
|
|
|
What is the ListView's equivalent of ListBox's DisplayMember ?
/\ |_ E X E GG
|
|
|
|
|
Unlike the ListBox control, the ListView control does not have a DisplayMember nor does it have a DataSource, ValueMember or any similar property. Because these are properties inherited from ListControl and ListView control is not inherited from that.
If you're going to implement data binding in a ListView control, you'll have to do so by yourself and depending on the structure, you have to populate the ListView's headers, item collection and -if any- subitems manually.
|
|
|
|
|
OK, thanks.
/\ |_ E X E GG
|
|
|
|
|
Hello! I'm a bit confused with an xml program i'm doing. The program goes through a xml-file wich is designed something like this:
<item>
<title> title </title>
<link>link</link>
<description>description</description>
</item>
<item>
... and so on
when it goes through the file i want it to make an instance of a class called Item everytime it finds the start of an item element, then fill the Item class fields (wich are title,link,description) and then put it in a Item array. But i can't get it to work at all.. Could someone give me some hint or anything?
Thanks!
|
|
|
|
|
Hmm, it seems like my xml-code got wiped! well, the root-elemtent(?) is Item, and then it has elements called title,link,description in it
|
|
|
|
|
Hi,
I'm overriding the ProcessDialogKey(Keys keyData) method of a textbox to handle keyboard input. Does anyone know how to convert the Keys values into characters? The usual letters and digits are no problem (A-Z, 1-9), because:
Keys.A = (int)'A' => (char)Keys.A = 'A'
But I can't handle some of the other keys. For example, if the user hits ";", the result of (char)keyData is some weird character ((char)192).
Is it possible to convert a Keys value to a character depending on the current user's keyboard layout? I don't want to use a large switch statement, because that doesn't consider different layouts (e.g. ";" = "ö" in German keyboard layout).
It has to be possible, because after all, the normal textbox just does that, doesn't it? I tried KeyConverters and some API-calls (toascii), but nothing seems to work right.
Any help would be highly appreciated, because I already spent hours on that (shame on me).
|
|
|
|
|
Interesting problem indeed. I also cannot find a solution. Perhaps try overriding protected virtual bool ProcessDialogChar(char charCode); instead? It gives you the char right away.
|
|
|
|
|
Thanks for the suggestion. But I don't think that I can use that method. What I want to do is a simple textbox control that shows the keys the user pressed, including the modifier keys (alt, ctrl, shift). The output should be something like 'Shift + Ctrl + F' or 'Alt + H' or 'Shift + ;'.
Even if I would use a combination of ProcessDialogKey and ProcessDialogChar, I would receive a ':' in ProcessDialogChar for a "real" 'Shift + ;', because ProcessDialogChar already takes the shift key into consideration. Besides that, some other keyboard layouts already need modifiers for some keys that aren't needed in other layouts (like ';' = 'Shift + ,' in German layout). So this will just result in the same problem I described first, but the other way round (how to get the Keys value for a certain character).
So if possible, I'd rather use ProcessDialogKey and convert the Keys to chars. Anyone?
P.S.: if someone knows how to distinguish the left and right shift/ctrl keys... the Keys-enum contains values for them, but the aren't used?
|
|
|
|
|
Here's a solution. Use the MapVirtualKey function located in user32.dll:
[DllImport("user32", EntryPoint = "MapVirtualKey")]
public static extern int MapVirtualKey(int wCode, int wMapType);
It converts scan codes, virtual keys and characters. From the Win32 api help:
Parameters
==========
uCode
[in] Specifies the virtual-key code or scan code for a key. How this value is interpreted depends on the value of the uMapType parameter.
uMapType
[in] Specifies the translation to perform. The value of this parameter depends on the value of the uCode parameter.
0
uCode is a virtual-key code and is translated into a scan code. If it is a virtual-key code that does not distinguish between left- and right-hand keys, the left-hand scan code is returned. If there is no translation, the function returns 0.
1
uCode is a scan code and is translated into a virtual-key code that does not distinguish between left- and right-hand keys. If there is no translation, the function returns 0.
2
uCode is a virtual-key code and is translated into an unshifted character value in the low-order word of the return value. Dead keys (diacritics) are indicated by setting the top bit of the return value. If there is no translation, the function returns 0.
3
Windows NT/2000/XP: uCode is a scan code and is translated into a virtual-key code that distinguishes between left- and right-hand keys. If there is no translation, the function returns 0.
Return Value
============
The return value is either a scan code, a virtual-key code, or a character value, depending on the value of uCode and uMapType. If there is no translation, the return value is zero.
************
This will do a Keys value to character conversion:
(char)MapVirtualKey((int)keyData, 2)
Regards,
kalme
|
|
|
|
|
Before I even start, I apologize for asking a NON-C# question in here. I've posted questions in nearly every forum in this site, and the responses in this one are by far the best. On that note, here is my question:
We have a situation at work where we've encountered a problem with accessing files which are located on another machine as the IIS server. We're using the File System Object to access these remote files. The problem is that the FileExists function always returns false for a file on another machine. This is a permissions issue, and I have some workarounds for it. Setting up a user account on the remote machine for the IUSR_COMPNAME account isn't really feasible, since this needs to be in commercial software, and the password for this account is generated dynamically. Yes, we could hack the registry and get this, but it's something we're trying to avoid. We could also have the ASP page start an external application to access the file, but again, we have the overhead of starting and ending a separate application, as well as the fact that we have to set up some way of giving this application the names of the actual files to access. I guess my question is, is there a method of doing this which actually works? If I search the web, I see that this issue has come up a lot...and the only real work-around I've seen is putting the IUSR account on the remote machine. Is there another way, and if so, what are the steps, or where can I find a quality article on this topic?
Again, while this isn't a pure C# question, it's still an issue that somebody using C# might face, so it's worth sharing. Thanks everybody.
|
|
|
|
|
I think if you are trying to do this with the ASP code you need to explicitely map the logical path to a physical one before trying the FileExists() function. Search on these lines.
|
|
|
|
|
No, it doesn't work by mapping to a virtual directory either. I wouldn't have posted this question if it were that easy...thank you though for the suggestion.
|
|
|
|
|
Hello,
Is there any property for numeric updown control in C# to make the text part of it to be invisible like we had in VB6.
Thanks,
thatsqlguy
|
|
|
|
|
Hi Buddy:
I am going to serialize object in my xml schema.
for this purpose I get public fields and property
and then serialize this to xml.
but in many cases this serialization raise Stackoverflow exeption
please help me...
|
|
|
|
|
hi,
Show the serialisation bolck of your code.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
string tempstr = "";
XmlDocument xml = new XmlDocument();
XmlDocument tempxml = new XmlDocument();
//m_value is object for serialize
Type objecttype = m_value.GetType();
PropertyInfo[] objectproperty = objecttype.GetProperties();
XmlNode node = xml.CreateNodeXmlNodeType.Element, "DataObject", "");
xml.AppendChild(node);
xml["DataObject"].SetAttribute("type", "object");
for(int i = 0; i < objectproperty.Length; i++)
{
object tempobj = new object();
PropertyInfo pi = objectproperty[i];
if(pi.Name != "Item")
{
tempobj = pi.GetValue(m_value,null);
}
//S is static method from DS class for serialize object that switch type of DataObject and then call S method recursively.
tempstr = DS.S(tempobj);
tempstr = "<" + objectproperty[i].Name + ">" + tempstr + "";
tempxml.LoadXml(tempstr);
xml["DataObject"].AppendChild(xml.ImportNode(tempxml.FirstChild, true));
}
return xml.InnerXml;
|
|
|
|
|
Hi buddy:
I going to write a method that read an custom serialized object(in xml format) and then
create object's field dynamically from this xml and then instantiate bject from this
type and then set values of this object.I can't find good article for this purpose.
thank u for your help.
|
|
|
|
|
hi,
Which sort of article you want.
serialisation ?
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|