mirror of
https://github.com/greenshot/greenshot
synced 2025-07-14 00:53:51 -07:00
Removed unneeded scroll code. Fixed a potential null-pointer bug in CaptureRectangle. Fixed a bug with GDI captures being black by counting the pixels and if there is a difference taking the screen shot instead.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2238 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
fd46837c8d
commit
35b16e8fd9
4 changed files with 48 additions and 110 deletions
|
@ -1111,114 +1111,6 @@ namespace GreenshotPlugin.Core {
|
|||
return returnRegion;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PrintWindow but with VScroll loop
|
||||
/// </summary>
|
||||
/// <returns>Image with all the scroll contents</returns>
|
||||
public Image PrintWithVScroll() {
|
||||
SCROLLINFO scrollinfo = new SCROLLINFO();
|
||||
scrollinfo.cbSize = Marshal.SizeOf( scrollinfo );
|
||||
scrollinfo.fMask = (int) ScrollInfoMask.SIF_ALL;
|
||||
User32.GetScrollInfo(Handle, (int) ScrollBarDirection.SB_VERT, ref scrollinfo );
|
||||
|
||||
LOG.DebugFormat("nMax {0}", scrollinfo.nMax);
|
||||
LOG.DebugFormat("nMin {0}", scrollinfo.nMin);
|
||||
LOG.DebugFormat("nPage {0}", scrollinfo.nPage);
|
||||
LOG.DebugFormat("nPos {0}", scrollinfo.nPos);
|
||||
LOG.DebugFormat("nTrackPos {0}", scrollinfo.nTrackPos);
|
||||
|
||||
// WindowStyleFlags style = WindowStyle;
|
||||
// LOG.InfoFormat("before: {0}", style);
|
||||
// style = style.Remove(WindowStyleFlags.WS_HSCROLL);
|
||||
// WindowStyle = style;
|
||||
// if (!User32.SetWindowPos(Handle, IntPtr.Zero, 0,0,0,0, WindowPos.SWP_NOMOVE | WindowPos.SWP_NOSIZE | WindowPos.SWP_NOZORDER | WindowPos.SWP_FRAMECHANGED| WindowPos.SWP_DRAWFRAME | WindowPos.SWP_NOACTIVATE)) {
|
||||
// Exception e = new Win32Exception();
|
||||
// LOG.Error("error with SetWindowPos", e);
|
||||
// }
|
||||
// style = WindowStyle;
|
||||
// LOG.InfoFormat("before: {0}", style);
|
||||
// style = style.Remove(WindowStyleFlags.WS_VSCROLL);
|
||||
// WindowStyle = style;
|
||||
// LOG.InfoFormat("After: {0}", style);
|
||||
// if (!User32.SetWindowPos(Handle, IntPtr.Zero, 0,0,0,0, WindowPos.SWP_NOMOVE | WindowPos.SWP_NOSIZE | WindowPos.SWP_NOZORDER | WindowPos.SWP_FRAMECHANGED| WindowPos.SWP_DRAWFRAME | WindowPos.SWP_NOACTIVATE)) {
|
||||
// Exception e = new Win32Exception();
|
||||
// LOG.Error("error with SetWindowPos", e);
|
||||
// }
|
||||
|
||||
Rectangle viewableRectangle = ClientRectangle;
|
||||
// As we work with bitmap coordinates, recalculate the location
|
||||
viewableRectangle.Offset(-WindowRectangle.X, -WindowRectangle.Y);
|
||||
|
||||
int width = viewableRectangle.Width;
|
||||
int height = viewableRectangle.Height * (scrollinfo.nMax / scrollinfo.nPage);
|
||||
int pageSkip = scrollinfo.nPage;
|
||||
if (width * height == 0) {
|
||||
LOG.Error("No window content!!");
|
||||
return null;
|
||||
}
|
||||
Bitmap returnBitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
|
||||
|
||||
using (Graphics graphicsTarget = Graphics.FromImage(returnBitmap)) {
|
||||
int location = 0;
|
||||
int y = 0;
|
||||
do {
|
||||
VScroll(location);
|
||||
Thread.Sleep(200);
|
||||
|
||||
Rectangle destination = new Rectangle(0, y, viewableRectangle.Width, viewableRectangle.Height);
|
||||
using (Image printedWindow = PrintWindow()) {
|
||||
if (printedWindow != null) {
|
||||
graphicsTarget.DrawImage(printedWindow, destination, viewableRectangle, GraphicsUnit.Pixel);
|
||||
graphicsTarget.Flush();
|
||||
y += viewableRectangle.Height;
|
||||
}
|
||||
}
|
||||
location += pageSkip;
|
||||
//if (location < scrollinfo.nMax && location > scrollinfo.nMax - scrollinfo.nPage) {
|
||||
// location = scrollinfo.nMax - scrollinfo.nPage;
|
||||
//}
|
||||
} while (location < scrollinfo.nMax);
|
||||
}
|
||||
VScroll(scrollinfo.nPos);
|
||||
return returnBitmap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Does the window have a HScrollbar?
|
||||
/// </summary>
|
||||
/// <returns>true if a HScrollbar is available</returns>
|
||||
public bool HasHScroll() {
|
||||
return WindowStyle.Has(WindowStyleFlags.WS_HSCROLL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Does the window have a VScrollbar?
|
||||
/// </summary>
|
||||
/// <returns>true if a VScrollbar is available</returns>
|
||||
public bool HasVScroll() {
|
||||
return WindowStyle.Has(WindowStyleFlags.WS_VSCROLL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scroll the window to the hpos location
|
||||
/// </summary>
|
||||
/// <param name="hpos"></param>
|
||||
public void HScroll(int hpos) {
|
||||
User32.SetScrollPos(Handle, Orientation.Horizontal, hpos, true);
|
||||
User32.PostMessage(Handle, (int)WindowsMessages.WM_HSCROLL, (int)ScrollbarCommand.SB_THUMBPOSITION + (hpos<<16), 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scroll the window to the vpos location
|
||||
/// </summary>
|
||||
/// <param name="vpos"></param>
|
||||
public void VScroll(int vpos) {
|
||||
User32.SetScrollPos(Handle, Orientation.Vertical, vpos, true);
|
||||
int ptrWparam = (int)ScrollbarCommand.SB_THUMBTRACK + (vpos << 16);
|
||||
int ptrLparam = 0;
|
||||
User32.SendMessage(Handle, (int)WindowsMessages.WM_VSCROLL, ptrWparam, ptrLparam);
|
||||
}
|
||||
|
||||
private bool CanFreezeOrUnfreeze(string titleOrProcessname) {
|
||||
if (string.IsNullOrEmpty(titleOrProcessname)) {
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue