|
Hi Covean.
That is all the "hook" code I have. I am not exactly clear what you are asking for. WHEELS
|
|
|
|
|
Ok so this will be the problem. ^^
Without calling SetWindowsHookEx how should the system know what you wanna hook?
Somewhere you should call (for example at form init):
IntPtr hHook = SetWindowsHookEx(WH_KEYBOARD or WH_KEYBOARD_LL(for low-level hook), Proc (delegate to your hook proc), Process.GetCurrentProcess().Handle, 0);
if(hHook == IntPtr.Zero)
{
// hook failed
}
At destruction time call UnhookWindowsHookEx(hHook);
Greetings
Covean
|
|
|
|
|
Now I understand. I have the following:
private void button1_Click(object sender, System.EventArgs e)
{
if (hookHandle == 0)
{
cb = new HookProc(Proc);
hookHandle = SetWindowsHookEx(WH_KEYBOARD, cb, 0,
appdomain.GetCurrentThreadId( ));
}
else
{
textBox1.Text += "Hook already set" + Environment.NewLine;
}
textBox1.Text += "Start: " + hookHandle + Environment.NewLine;
}
private void button2_Click(object sender, System.EventArgs e)
{
textBox1.Text += "End: " + UnhookWindowsHookEx(hookHandle) +
Environment.NewLine;
hookHandle = 0;
}
I am coming up with an error on this line:
hookHandle = SetWindowsHookEx(WH_KEYBOARD, cb, 0,
appdomain.GetCurrentThreadId( ));
appdomain doesn't exist in the current context.
WHEELS
|
|
|
|
|
If you want to hook more than the input to your application, you should set dwThreadId to 0 and just set the instance handle (3rd parameter) to Process.GetCurrentProcess().Handle.
Btw: appdomain does not exists its called AppDomain.
Greetings
Covean
|
|
|
|
|
Still get same error when I capitalize appDomain. WHEELS
|
|
|
|
|
Wheels012 wrote: Still get same error when I capitalize appDomain. WHEELS
Still wrong. There are 2 letters to capatilaze: "AppDomain"
|
|
|
|
|
Hello All…
Hope all is well with you..
Actually I want to write a OutlookAddin it will add a simple dropdown combo box after the subject input area.... Can anyone give me some guideline..Please note that a have done this but the problem is it load at the end of the form.
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
it is a windows application
I want to validate the datagridview cell ,it has to accepct only alphabets and numerics
HFGHFGHFGHFGHFHFHFHFHFHFHFHFHF
|
|
|
|
|
i have program that search for white point in screen, the code is:
namespace CameraLab
{
public class CamManeger
{
Point pp;
public Point PP
{
get
{
return pp;
}
set
{
pp = value;
}
}
[DllImport("user32.dll")]
public static extern void mouse_event(MouseEventType dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
[DllImport("user32")]
public static extern int SetCursorPos(int x, int y);
public enum MouseEventType : int
{
LeftDown = 0x02,
LeftUp = 0x04,
RightDown = 0x08,
RightUp = 0x10
}
public void test(Bitmap bm, int X, int Y, int x, int y ,Point pp,bool L)
{
bool z = false;
for (int i = X; i < x; i++)
{
for (int j = Y; j < y; j++)
{
if (bm.GetPixel(i, j).R == 255 && bm.GetPixel(i, j).G == 255 && bm.GetPixel(i, j).B == 255 && bm.GetPixel(i, j).R == 255)
{
Point p = new Point(Screen.PrimaryScreen.WorkingArea.Width - i, Screen.PrimaryScreen.WorkingArea.Height - j);
Cursor.Position = p;
this.PP = p;
z = true;
break;
}
}
if (z == true)
{
break;
}
}
}
}
}
can i make this code more faster.
|
|
|
|
|
Edit your code and add <pre> tags, because i can very hardly to read
The only thing you could improve (as i see), modify your if statement. But you won't get performance boost
if (bm.GetPixel(i, j) == Color.White)
{
}
Maybe you shoud look into directly into unmanaged GDI. (GDI+ is only a wraper around unmanaged GDI)
Edit: Styleing
modified on Tuesday, January 5, 2010 10:59 AM
|
|
|
|
|
GetPixel is seriously slow. Take a look at this article:
ImageTraverser[^]
Regards,
Rob Philpott.
|
|
|
|
|
|
Sometimes I need to determine the color of different controls. I give a couple a of examples. In a MessageBox I needed a custom made gif-icon and I wanted the background color of the icon to match the color of the MessageBox itself. In another project I wanted to get rid of the little sort-array in the header of a DataGridView and to do that I had to override the Paint-method and paint the arrow with the background color. To determine the colors in these two examples I did a print screen and pasted the screen dump into Paint and used the color picker to get the RGB-values. This works fine on most computer, but I have noticed that on some computers (depending on operating system and other things) the gray color is not the same as on my computer. Something tells me there must be a way to query the color to use instead of determining it by hand and then hardcoding it. How do I do this?
|
|
|
|
|
Gif supports transparency, can't you make the background transparent in your gif images? Would this do what you need?
|
|
|
|
|
Well, in the specific case with a gif-icon I could use transparency. However, I would still like to know how I can determine the color programmatically.
|
|
|
|
|
you could atempt use the folowing
Bitmap bmp;
// <snip>intelizing bmp
if (bmp.GetPixel(x,y) == Color.White) // Color has predefined colors. SystemColor has a system setting colors as predefind
{
}
|
|
|
|
|
I don't understand how to use this. Can you please give an example how I can use it when I override the Paint-method for DataGridViewColumnHeaderCell:
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
|
|
|
|
|
I actually don't remember Paint method has this many parameters. I assume you are inherited from DataGridView
The method I posted was intended from thread above yours. I posted in wrong but I left it because you asked a question in that post that could be correct answer.
It is better to get color from propties instead atempt to read from a point on the screan
DataGridView background color is default to SystemColors.AppWorkspace.
So I suggest you use to get your background color:
this.BackgroundColor
modified on Tuesday, January 5, 2010 10:57 AM
|
|
|
|
|
arnold_w wrote: This works fine on most computer, but I have noticed that on some computers (depending on operating system and other things) the gray color is not the same as on my computer.
That could be cousing also by monitors. Some have Color temperature (or even named as Color Tone) setting
|
|
|
|
|
What I mean is that my DataGridView (in the example above) can look perfect (meaing the arrow is not visible because it has been filled with the correct backgound color) on my computer, but on another computer the arrow is visible, appearing with a slightly different shade of gray. Thus, for some reason the DataGridView is not the same color on all computers, but the arrow I drew has the same color because I hard-coded it. I am therefore confident that this is not a monitor issue.
|
|
|
|
|
arnold_w wrote: Thus, for some reason the DataGridView is not the same color on all computers, but the arrow I drew has the same color because I hard-coded it.
So other background is not hardcoded
if you use static prop ties of class Color (Color.White or Color.Blue). Those colors are hard coded. However class SystemColor has also static proprties, (SystemColor.Window or SystemColor.Control) those properties are system specific tied to color schemes used by windows. These color schemes can be easily changed
|
|
|
|
|
SystemColor seems to be exactly what I was looking for. A big thank you for your help!
|
|
|
|
|
Hi,
I have developed a .net COM automation add-in which includes a UDF and registered using RegAsm.But whenever i tried to execute this UDF in Excel, it is coming as !REF in a cell.
Any idea how to make it working?
|
|
|
|
|
i would like to know if anyone can help me to construct a window application to make a small MCQ (multiple chooice question) game.. i have to do this project for university and i don't know where or how to start.... plz help.. we need to use an XML file and to pick questions randomly from this file and we have to put the 4 possibilities randomly in 4 buttons and the user will then pick the answer .. so help me if you can
|
|
|
|
|
You need to do several things:
1) Create your XMl file full of questions, and four answers per question.
2) Look at XMLReader in the documentation
3) Look at Random in the documentation.
XMLReader isn't difficult: the simplest case is:
XmlTextReader xmlReader = new XmlTextReader("questions.xml");
Console.WriteLine(xmlReader.AttributeCount);
while(xmlReader.Read())
{
Console.WriteLine(xmlReader.Value);
}
It can do loads more than that, but it's a start.
Random is also easy:
Random rnd = new Random;
for (int i = 0; i < 10; i++)
{
Console.WriteLine(rnd.Next(4));
}
Will print 10 random numbers between 0 and 3 inclusive.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|