|
Is there an alternative to the Win32 API function GetAsyncKeyState(...) in C#???
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
Hi Rickard,
When I ported Joe's AutoRepeat class I had this same issue too. I couldn't find anything equivalent. For all I know, there might be a not so well known class, that does just this. But I believe it's not there.
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
Rickard,
Found it!!! It's amusing that I didnt find it when I wanted it, but I found it when I was just looking at random
Control.ModifierKeys Property is what you want
if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt)
{
\\Alt key is down
}
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
That only gives you the modifier keys though, leaving out the other non-modifiers; from MSDN "Gets a value indicating which of the modifier keys (SHIFT, CTRL, and ALT) is in a pressed state."
James
Simplicity Rules!
|
|
|
|
|
Oh well. I guess I celebrated too soon.
Back to the drawing board gentlemen.
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
How to show a modal form!?
Form2 MyForm = new Form2();
MyForm.Show(); // This is a modeless.... but I want modal!!
Hope you understand and can help moi!
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
Try ShowDialog() instead.
--
Andrew.
|
|
|
|
|
when i click the window form's minimize box!
how to minimize it to tray icon(when the app is started,the app tray icon is displayed)!
and then how to display it again!
is the notifyicon's contextmenu event click-form1.show() enough!
the vs.net and c# is all new to me!
so if anyone knows,please tell me.thanks!
|
|
|
|
|
I'm trying to add a preview to my screensaver, but no matter what I do to the string coming in ( which should be a HWND ), I cannot get a graphics object that I can draw to - the preview window stays black. Any suggestions ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
In this mode, you should be drawing using screen coordinates.
I would check that...
|
|
|
|
|
That was weird, I tested that this morning and now it wants client coordinates???
|
|
|
|
|
I was using Graphics.Clear, and also FillRectangle to fill a HUGE rectangle so that my problem was not related to coordinates, because the screensaver preview window is pretty small.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
What I have working is this:
I am getting the HWND and the Graphics object with something a little more robust but equivalent to:
IntPtr hWnd = (IntPtr) uint.Parse(args[1]);
.
.
.
Graphics g = Graphics.FromHwnd(hWnd);
.
.
.
I call GetClientRect on the hWnd, and use that for all of my drawing...
|
|
|
|
|
How do I call GetClientRect in C# ?
This does not work for me:
if (args[0] == "/p")
{
IntPtr hWnd = (System.IntPtr)uint.Parse(args[1]);
Graphics g = Graphics.FromHwnd(hWnd);
g.Clear(Color.Orange);
}
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
If you create a Control from the hWnd you can use that.
Control previewWindow = Control.FromHwnd(hWnd);<br />
Rectangle rect = previewWindow.ClientRectangle;
BTW, just picked up a Radeon 7500 (dual-head) so I can use dual monitors now
James
Simplicity Rules!
|
|
|
|
|
James T. Johnson wrote:
BTW, just picked up a Radeon 7500 (dual-head) so I can use dual monitors now
Yummy - looks like I got the dual monitor support into the screen saver just in time.....
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
This code:
IntPtr hWnd = (System.IntPtr)uint.Parse(args[1]);
Graphics g = Graphics.FromHwnd(hWnd);
Control previewWindow = Control.FromHandle(hWnd);
Rectangle rect = previewWindow.ClientRectangle;
SolidBrush brush = new SolidBrush(Color.Orange);
g.FillRectangle(brush, rect);
Gives me a Null reference error, leading me back to the belief that I am unable to parse the hWnd in a meaningful manner.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Christian Graus wrote:
leading me back to the belief that I am unable to parse the hWnd in a meaningful manner
If this statement was true, my code wouldn't be running...
Take a look at the API definition I posted to the other part of this thread.
Regards
|
|
|
|
|
It's obviously working for you, but are you doing it in the context of the screensaver preview ? If you are, then I have no idea why I cannot get it to work for me. If I have a valid HWND in my variable, why can't I use the code I posted to get it into a control ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Yes, I am drawing in the context of the preview from the screen saver tab of the desktop properties.
I am not using a control, you don't need it in the preview mode.
|
|
|
|
|
Well, in that case, you're obviously a better man than I am. Could you please zip the project and mail it to me so I can have a look at it and figure out what I am missing ?
Thanks.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
You have mail...
Just a quick app made from pieces I gutted from mine, and enough to show the steps involved to draw in the property sheets preview.
I would suggest separating your drawing code from your form and calling it from both the preview mode and your full display mode.
Regards
|
|
|
|
|
Christian Graus wrote:
why can't I use the code I posted to get it into a control ?
The Control was just used to get away from making a direct call into unmanaged land. I forgot to say that in my original post though
James
Simplicity Rules!
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[DllImport("user32.dll")]
private static extern int GetClientRect(IntPtr hWnd, ref RECT rect);
|
|
|
|
|
In the course of recent enlightenment I have a better solution that will reuse your form as is…
In the preview mode (/p) do this:
if (IntPtr.Zero != hWnd)
{
Application.Run(new MainForm(hWnd));
}
In your form class do this:
private IntPtr parentWindow;
public MainForm(IntPtr parent)
{
parentWindow = parent;
if (IntPtr.Zero != parent)
this.TopLevel = false;
.
.
.
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Parent = parentWindow;
return cp;
}
}
Works like a champ!
|
|
|
|