Thanks a lot! I'll put your name in the credits for this :)
CyberKewl
Posts
-
VBScript to C# -
VBScript to C#Thanks. It works (at least on WinXP) but i'm wondering how to get the other one to work : set SRP = getobject("winmgmts:\\.\root\default").InstancesOf ("systemrestore") for each Point in SRP msgbox point.creationtime & vbcrlf & point.description & vbcrlf & "Sequence Number= " & point.sequencenumber next
-
VBScript to C#I'm trying to write an app that handles system restore related stuff and would like to know how to convert the VBScript(s) in the following page into C# equivalent: http://support.microsoft.com/default.aspx?scid=KB;en-us;295299&
-
Keyboard hooks - ProblemI have a problem with keyboard hooks - every time i press hold the CTRL+SHIFT key for quite some time, my application will crash with the error message : "An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll Additional information: Object reference not set to an instance of an object." I've searched high and low for a solution to this matter but to no avail. Here's the code that i am using, it is meant to disable keys like ALT+TAB, CTRL+ESC, etc: protected delegate int LowLevelKeyboardProcDelegate(int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam); [ DllImport( "user32.dll", EntryPoint="SetWindowsHookExA", CharSet=CharSet.Ansi )] protected static extern int SetWindowsHookEx(int idHook , LowLevelKeyboardProcDelegate lpfn, int hMod , int dwThreadId); [ DllImport( "user32.dll")] protected static extern int CallNextHookEx(int hHook,int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam); [ DllImport("user32.dll")] protected static extern int UnhookWindowsHookEx(long hhook); const int WH_KEYBOARD_LL = 13; public struct KBDLLHOOKSTRUCT { public int vkCode; int scanCode; public int flags; int time; int dwExtraInfo; } protected int intLLKey = 0; protected int LowLevelKeyboardProc(int nCode,int wParam,ref KBDLLHOOKSTRUCT lParam) { bool blnEat = false; switch (wParam) { case 256: case 257: case 260: case 261: //Alt+Tab, Alt+Esc, Ctrl+Esc, Windows Key if (((lParam.vkCode == 9) && (lParam.flags == 32)) || ((lParam.vkCode == 27) && (lParam.flags == 32)) || ((lParam.vkCode == 27) && (lParam.flags == 0)) || ((lParam.vkCode == 91) && (lParam.flags == 1)) || ((lParam.vkCode == 92) && (lParam.flags == 1)) || ((true) && (lParam.flags == 32))) { blnEat = true; } break; } if (blnEat) return 1; else { return CallNextHookEx(0, nCode, wParam, ref lParam); } } public void KeyboardHook() { intLLKey = SetWindowsHookEx(WH_KEYBOARD_LL, new LowLevelKeyboardProcDelegate(LowLevelKeyboardProc), System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]).ToInt32(),0); }
-
Getting the height of a main menuThanks. That did the trick.
-
Getting the height of a main menuIs there any way of obtaining the height of a main menu (menubar) or is it always the same size regardless of the screen resolution (i think its 20 pixels). The reason why i need to know the height is that i'm trying to make a form with a picturebox inside a panel and resize the form so that it can view the whole image (assuming that my screen res is larger than the image). So i need to do some calculations and stuff..
-
Database, ODP.NET, ADODCI'm currently using ODP.NET (Oracle Data Provider) to connect to an oracle database. Is there a replacement control for ADODC (to go to the previous and next records) or do i have to create buttons myself for the navigational purposes?
-
Getting the active window handleYeah more or less. Here's the exact code : hWnd = FindWindow(null, "Form1"); RECT rc = new RECT(); GetWindowRect(hWnd, ref rc); this.Text = "LEFT" + rc.left + " RIGHT " + rc.right + " TOP " + rc.top; Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Graphics gr1 = Graphics.FromImage(myImage); IntPtr dc1 = gr1.GetHdc(); IntPtr dc2 = GetDC(hWnd); BitBlt(dc1, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, dc2, 0, 0, 13369376); gr1.ReleaseHdc(dc1); ReleaseDC(GetDC(hWnd)), dc2); GC.Collect(); Graphics gr = Graphics.FromHwnd(pictureBox1.Handle); pictureBox1.Image = myImage;
-
Getting the active window handleI would like to know how to get the handle of the currently active window. I've tried using Findwindow and it works, but i want the whole view of the active window (including the toolbar and menubar) as i would like to create a program to take a screenshot of the active window (something like ALT+PRINTSCREEN but using BitBlt to do the capturing).
-
BitBlt performance in C#No, that doesn't make much difference. The code is now : Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Graphics gr1 = Graphics.FromImage(myImage); IntPtr dc1 = gr1.GetHdc(); IntPtr dc2 = GetDC(GetDesktopWindow()); BitBlt(dc1, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc2, 0, 0, 13369376); gr1.ReleaseHdc(dc1); ReleaseDC(GetDesktopWindow(), dc2); GC.Collect(); return myImage; I fail to mention earlier that i am utilising a savejpgwithcompression function and after some checking, it appears that it is the cause of the problem. It could be the compression part, but it is essential to make the file size smaller. Here's the code : private void SaveJPGWithCompressionSetting( Image image, string szFileName, long lCompression ) { EncoderParameters eps = new EncoderParameters(1); eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, lCompression ); ImageCodecInfo ici = GetEncoderInfo("image/jpeg"); image.Save( szFileName, ici, eps ); } private ImageCodecInfo GetEncoderInfo(string mimeType) { ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); foreach (ImageCodecInfo codec in codecs) { if (codec.MimeType == mimeType){return codec;} } return null; }
-
BitBlt performance in C#I'm using the following code to capture a screenshot : Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Graphics gr1 = Graphics.FromImage(myImage); IntPtr dc1 = gr1.GetHdc(); IntPtr dc2 = GetDC(GetDesktopWindow()); BitBlt(dc1, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc2, 0, 0, 13369376); gr1.ReleaseHdc(dc1); GC.Collect(); return myImage; I'm trying to capture a screenshot of the entire desktop and transferring it to a remote PC (to create a program like PcAnywhere). The thing is, i set my screenshot timer to something like 450 ms and on my machine (Athlon XP 2000+), it uses up around 30% of the CPU power. However, if i test it on my old P3-700 Mhz machine, the CPU utilisation is very high, ranging between 75-90%. Is there any way to reduce the CPU utilisation (maybe like reducing the color depth of the image? but how)?
-
Cursor detection problemCursor.Current only detects the cursor within the form. I need to detect the cursor system-wide (i.e: both inside and outside the form).
-
Cursor detection problemI'm trying to detect which cursor is currently shown on the screen, whether it is a wait cursor, arrow cursor, etc. Right now, the detection works perfectly EXCEPT that there are 3 cursors that i can't seem to detect sometimes - the hand cursor, horizontal and vertical splitter cursors. The code i'm using is (with the GetCursorInfo API): Info.Size = Marshal.SizeOf(Info.GetType()); GetCursorInfo(out Info); if (Info.Cursor == Cursors.WaitCursor.Handle) CurrentCursor = "Wait"; else if (Info.Cursor == Cursors.Default.Handle) CurrentCursor = "Default"; else if (Info.Cursor == Cursors.AppStarting.Handle) CurrentCursor = "Loading"; else if (Info.Cursor == Cursors.Hand.Handle) CurrentCursor = "Hand"; .... After i did some tests, i noticed that when i convert the values to string, the two values of Info.Cursor and Cursors.Hand.Handle (along with the HSplit and VSplit values as well) do not tally and they tend to change over and over again almost every time i run my application again. The tests were done by displaying the values of Info.Cursor and Cursors.Hand.Handle using codes like these: MessageBox.Show(Info.Cursor.ToString()); MessageBox.Show(Cursors.Hand.Handle.ToString()); I did the tests mostly on Applications that have a weblink and also on web browsers. When using a web browser, the detection seems fine (for the hand cursor at least) but when i run an app that has a weblink somewhere and the hand cursor shows up, the values of Info.Cursor and Cursors.Hand.Handle are totally different. Is there a way around this?
-
GetCursorInfo in C#?Thanks a lot. That did the trick.
-
GetCursorInfo in C#?No, i just need to know the name of the cursor whether it is a normal cursor showing or wait cursor showing - system-wide (not just within the current form). From my understanding, if you use Cursor.Current, you can only get the name of the cursor that is showing within the form. If the cursor moves outside of the form, the name of the cursor will not be changed.
-
GetCursorInfo in C#?I'm aware of that. The thing is, i don't understand how to use GetCursorInfo. I just need some help in getting the cursor image which is vital for my program, that's all. Anyway, i'll try reading again.
-
GetCursorInfo in C#?Thanks for the quick reply but i'd like to know how to use it too. I'd like to know how to get the cursor image (or icon) using GetCursorInfo.
-
GetCursorInfo in C#?Does anyone know how i can use the GetCursorInfo API in C#? I'd like to know the dllimport and an example code. Click here to view the GetCursorInfo API.
-
How to get system-wide cursor status in c#?After some extensive digging, i found out that to get the cursor "image" or icon, we need to use GetCursorInfo() but i don't know how to write the codes (particularly the dllimport part) and get it working in C#. Does anyone have any ideas?
-
How to get system-wide cursor status in c#?Is it possible to obtain a system-wide cursor status? I've tried using Cursor.current.tostring() but it only returns the status of the cursor within the application running. This means that if the cursor status is updated OUTSIDE of the application, the status is not updated at all.