public static string GetClassName(IntPtr windowHandle) { string szText; StringBuilder oTitle = new StringBuilder(1024); User32ApiNativeMethods.GetClassName((int)windowHandle, oTitle, oTitle.Capacity - 1); szText = oTitle.ToString(); return(szText); }
public static void LogOff(ShutdownReason reasonFlag) { int Result; Result = User32ApiNativeMethods.ExitWindowsEx(ExitWindows.LogOff, reasonFlag); if (Result == 0) { throw new NolmeGenericException(string.Format(CultureInfo.InvariantCulture, "LogOff Failed")); } }
public static int SendMessage(Control destinationObject, int messageId, int generic16BitsParameter, int generic32BitsParameter) { if (destinationObject == null) { throw new NolmeArgumentNullException(); } int iResult = User32ApiNativeMethods.SendMessage(new HandleRef(destinationObject, destinationObject.Handle), messageId, generic16BitsParameter, generic32BitsParameter); return(iResult); }
/// <summary> /// Collection Constructor with additional options /// </summary> public static ArrayList EnumWindows() { m_aoWndArray = new ArrayList(); //array of windows //Declare a callback delegate for EnumWindows() API call EnumWindowsProc ewp = new EnumWindowsProc(EvalWindow); //Enumerate all Windows User32ApiNativeMethods.EnumWindows(ewp, 0); return(m_aoWndArray); }
//EnumWindows CALLBACK function private static int EvalWindow(int windowHandle, int lParam) { StringBuilder oTitle = new StringBuilder(256); StringBuilder oModule = new StringBuilder(256); User32ApiNativeMethods.GetWindowModuleFileName((int)windowHandle, oModule, oModule.Capacity - 1); User32ApiNativeMethods.GetWindowText((int)windowHandle, oTitle, oTitle.Capacity - 1); User32ApiNativeMethods.GetWindowThreadProcessId((int)windowHandle, 0); m_aoWndArray.Add(new Window(oTitle.ToString(), (IntPtr)windowHandle, oModule.ToString())); return(0); }
/// <summary> /// Resumes drawing and event handling. /// </summary> /// <remarks> /// This method should be called every time a call is made /// made to BeginUpdate. It resets the event mask to it's /// original value and enables redrawing of the control. /// </remarks> public static void EndUpdate(Control sourceRichEdit) { if (sourceRichEdit == null) { throw new NolmeArgumentNullException(); } // Deal with nested calls --updating; if (updating > 0) { return; } // Allow the control to redraw itself User32ApiNativeMethods.SendMessage(new HandleRef(sourceRichEdit, sourceRichEdit.Handle), WM_SETREDRAW, 1, 0); // Allow the control to raise event messages User32ApiNativeMethods.SendMessage(new HandleRef(sourceRichEdit, sourceRichEdit.Handle), EM_SETEVENTMASK, 0, oldEventMask); }
/// <summary> /// Maintains performance while updating. /// </summary> /// <remarks> /// <para> /// It is recommended to call this method before doing /// any major updates that you do not wish the user to /// see. Remember to call EndUpdate when you are finished /// with the update. Nested calls are supported. /// </para> /// <para> /// Calling this method will prevent redrawing. It will /// also setup the event mask of the underlying richedit /// control so that no events are sent. /// </para> /// </remarks> public static void BeginUpdate(Control sourceRichEdit) { if (sourceRichEdit == null) { throw new NolmeArgumentNullException(); } // Deal with nested calls ++updating; if (updating > 1) { return; } // Prevent the control from raising any events oldEventMask = User32ApiNativeMethods.SendMessage(new HandleRef(sourceRichEdit, sourceRichEdit.Handle), EM_SETEVENTMASK, 0, 0); // Prevent the control from redrawing itself User32ApiNativeMethods.SendMessage(new HandleRef(sourceRichEdit, sourceRichEdit.Handle), WM_SETREDRAW, 0, 0); }
public static void Shutdown(ShutdownReason reasonFlag) { int Result; bool BooleanResult; TokenPrivileges tp = new TokenPrivileges(); long LocallyUniqueIdentifier; IntPtr hproc = (IntPtr)ApiNativeMethods.GetCurrentProcess(); int htok = 0; BooleanResult = ApiNativeMethods.OpenProcessToken((int)hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok); if (BooleanResult == false) { throw new NolmeGenericException(string.Format(CultureInfo.InvariantCulture, "OpenProcessToken Failed")); } tp.Count = 1; tp.LocallyUniqueIdentifier = 0; tp.Attributes = SE_PRIVILEGE_ENABLED; LocallyUniqueIdentifier = 0; BooleanResult = ApiNativeMethods.LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref LocallyUniqueIdentifier); if (BooleanResult == false) { throw new NolmeGenericException(string.Format(CultureInfo.InvariantCulture, "LookupPrivilegeValue Failed")); } tp.LocallyUniqueIdentifier = LocallyUniqueIdentifier; BooleanResult = ApiNativeMethods.AdjustTokenPrivileges(htok, false, ref tp, 0, 0, 0); if (BooleanResult == false) { throw new NolmeGenericException(string.Format(CultureInfo.InvariantCulture, "AdjustTokenPrivileges Failed")); } Result = User32ApiNativeMethods.ExitWindowsEx(ExitWindows.PowerOff | ExitWindows.Shutdown, reasonFlag); if (Result == 0) { throw new NolmeGenericException(string.Format(CultureInfo.InvariantCulture, "Shutdown Failed")); } }
public static bool ShowConsole() { bool bResult = User32ApiNativeMethods.ShowWindow((int)Win32ConsoleUtility.ConsoleWindow, (int)ShowWindow.Show); return(bResult); }
public static int SendMessage(IntPtr windowHandle, int messageId, int generic16BitsParameter, object parameter) { int iResult = User32ApiNativeMethods.SendMessage((int)windowHandle, messageId, generic16BitsParameter, (int)parameter); return(iResult); }
public static int SendMessage(HandleRef windowHandle, int messageId, int generic16BitsParameter, int generic32BitsParameter) { int iResult = User32ApiNativeMethods.SendMessage(windowHandle, messageId, generic16BitsParameter, generic32BitsParameter); return(iResult); }
public static Bitmap Capture(System.Windows.Forms.Control control) { if (control == null) { throw new NolmeArgumentNullException(); } // http://www.csharphelp.com/archives2/archive393.html //Variable to keep the handle of the btimap. IntPtr m_HBitmap; //Variable to keep the refrence to the desktop bitmap. System.Drawing.Bitmap bmp = null; //In size variable we shall keep the size of the screen. int Width, Height; //Here we get the handle to the desktop device context. IntPtr hDC = User32ApiNativeMethods.GetDC(control.Handle); //IntPtr hDC = User32ApiNativeMethods.GetDC(User32ApiNativeMethods.GetDesktopWindow()); //Here we make a compatible device context in memory for screen device context. IntPtr hMemDC = Gdi32ApiNativeMethods.CreateCompatibleDC(hDC); //We pass SM_CXSCREEN constant to GetSystemMetrics to get the X coordinates of screen. //Width = User32ApiNativeMethods.GetSystemMetrics (User32ApiNativeMethods.SM_CXSCREEN); Width = control.Width; //We pass SM_CYSCREEN constant to GetSystemMetrics to get the Y coordinates of screen. //Height = User32ApiNativeMethods.GetSystemMetrics(User32ApiNativeMethods.SM_CYSCREEN); Height = control.Height; //We create a compatible bitmap of screen size and using screen device context. m_HBitmap = Gdi32ApiNativeMethods.CreateCompatibleBitmap(hDC, Width, Height); //As m_HBitmap is IntPtr we can not check it against null. For this purspose IntPtr.Zero is used. if (m_HBitmap != IntPtr.Zero) { //Here we select the compatible bitmap in memeory device context and keeps the refrence to Old bitmap. IntPtr hOld = (IntPtr)Gdi32ApiNativeMethods.SelectObject(hMemDC, m_HBitmap); //We copy the Bitmap to the memory device context. Gdi32ApiNativeMethods.BitBlt(hMemDC, 0, 0, Width, Height, hDC, 0, 0, Gdi32ApiNativeMethods.SRCCOPY); //We select the old bitmap back to the memory device context. Gdi32ApiNativeMethods.SelectObject(hMemDC, hOld); //We delete the memory device context. Gdi32ApiNativeMethods.DeleteDC(hMemDC); //We release the screen device context. User32ApiNativeMethods.ReleaseDC(User32ApiNativeMethods.GetDesktopWindow(), hDC); //Image is created by Image bitmap handle and assigned to Bitmap variable. bmp = System.Drawing.Image.FromHbitmap(m_HBitmap); //Delete the compatible bitmap object. Gdi32ApiNativeMethods.DeleteObject(m_HBitmap); return(bmp); } //If m_HBitmap is null retunrn null. return(null); }