Good luck reading the numbers on the pin screen
Problem?
EDIT: Well well well, if it isnt Mr SunAwtCanvas

Posting code later today, not quite finished
EDIT: YES!!! THERE IS A GOD! Found out my bitmap copying was flawed and spent hours probind the DC shit for nothing lol
As I promised: (If this is any use for anyone, esp. if the problem with grabbing the canvas still persists feel free to use this if its any use)
/*
* Created by SharpDevelop.
* User: admin
* Date: 4.1.2011
* Time: 18:56
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Net.Mail;
using System.Runtime.InteropServices;
using System.Threading;
using System.Text;
using System.Diagnostics;
namespace PinLogger
{
class Program
{
internal delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
internal delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter);
class GDI32
{
[DllImport("GDI32.dll")]
public static extern bool BitBlt(int hdcDest,int nXDest,int nYDest,int nWidth,int nHeight,int hdcSrc,int nXSrc,int nYSrc,int dwRop);
[DllImport("GDI32.dll")]
public static extern int CreateCompatibleBitmap(int hdc,int nWidth, int nHeight);[DllImport("GDI32.dll")]
public static extern int CreateCompatibleDC(int hdc);
[DllImport("GDI32.dll")]
public static extern bool DeleteDC(int hdc);
[DllImport("GDI32.dll")]
public static extern bool DeleteObject(int hObject);
[DllImport("GDI32.dll")]
public static extern int GetDeviceCaps(int hdc,int nIndex);
[DllImport("GDI32.dll")]
public static extern int SelectObject(int hdc,int hgdiobj);
}
class User32
{
[DllImport("User32.dll")]
public static extern int GetDesktopWindow();
[DllImport("User32.dll")]
public static extern int GetWindowDC(int hWnd);
[DllImport("User32.dll")]
public static extern int ReleaseDC(int hWnd,int hDC);
[DllImport("user32.dll") ]
public static extern int GetWindowText(int hWnd, StringBuilder text, int count);
[DllImport("user32.dll")]
public static extern int GetWindow(int hWnd, GW uCmd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll")]
public static extern uint RealGetWindowClass(IntPtr hwnd, [Out] StringBuilder pszType, uint cchType);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(HandleRef hwnd, out RECT lpRect);
}
public enum GW : int
{
HWNDFIRST = 0,
HWNDLAST = 1,
HWNDNEXT = 2,
HWNDPREV = 3,
OWNER = 4,
CHILD = 5,
}
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
private static bool EnumWindow(IntPtr handle, IntPtr pointer)
{
GCHandle gch = GCHandle.FromIntPtr(pointer);
List<IntPtr> list = gch.Target as List<IntPtr>;
if (list == null)
{
throw new InvalidCastException("GCHandle Target could not be cast as List<IntPtr>");
}
list.Add(handle);
return true;
}
public String GetWindowCaption(int Hwnd)
{
const int nChars = 256;
StringBuilder builder = new StringBuilder(nChars);
String result = "";
if (User32.GetWindowText(Hwnd, builder, nChars) > 0 )
result = builder.ToString();
return result;
}
public IntPtr FindWindowByTitle(String WindowTitle)
{
Process[] p = Process.GetProcesses();
IntPtr hWnd;
foreach(Process proc in p)
{
if ((hWnd = proc.MainWindowHandle) != IntPtr.Zero)
{
if (GetWindowCaption(hWnd.ToInt32()).Contains(WindowTitle))
return hWnd;
}
}
return IntPtr.Zero;
}
public IntPtr[] GetChildWindows(IntPtr Parent)
{
List<IntPtr> children = new List<IntPtr>();
GCHandle listHandle = GCHandle.Alloc(children);
try
{
EnumWindowsProc childProc = new EnumWindowsProc(EnumWindow);
User32.EnumChildWindows(Parent, childProc, GCHandle.ToIntPtr(listHandle));
}
finally
{
if (listHandle.IsAllocated)
listHandle.Free();
}
return children.ToArray();
}
public String GetWindowC(IntPtr hWnd)
{
StringBuilder s = new StringBuilder();
User32.RealGetWindowClass(hWnd, s, 255);
return s.ToString();
}
public IntPtr SearchChildWindows(IntPtr[] ChildWindows, String caption)
{
foreach(IntPtr i in ChildWindows)
{
if (i != IntPtr.Zero)
{System.Console.WriteLine(GetWindowC(i));
if (GetWindowC(i).Contains(caption)) {
System.Console.WriteLine(";;;"+GetWindowC(i));
IntPtr x = new IntPtr(User32.GetWindow(i.ToInt32(), GW.CHILD));
while (User32.GetWindow(x.ToInt32(), GW.CHILD) != 0)
{
x = new IntPtr(User32.GetWindow(x.ToInt32(), GW.CHILD));
}
return x;
}
}
}
return IntPtr.Zero;
}
public IntPtr FindChildWindow(String parent, String childtext)
{
return SearchChildWindows(GetChildWindows(FindWindowByTitle(parent)), childtext);
}
public void CaptureScreen(string fileName,ImageFormat imageFormat)
{
RECT r;
User32.GetWindowRect(new HandleRef(this, FindChildWindow("RuneScape", "SunAwtCanvas")), out r);
int w = r.right-r.left;
int h = r.bottom-r.top;
IntPtr hWnd = FindChildWindow("RuneScape", "SunAwtCanvas");
int hdcSrc = User32.GetWindowDC(hWnd.ToInt32()),
hdcDest = GDI32.CreateCompatibleDC(hdcSrc),
hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, w, h);
User32.GetWindowRect(new HandleRef(this, FindChildWindow("RuneScape", "SunAwtCanvas")), out r);
System.Console.WriteLine("Width :" + (r.right-r.left) + " Height: "+(r.bottom-r.top));
GDI32.SelectObject(hdcDest,hBitmap);
GDI32.BitBlt(hdcDest,0,0,w,
h,hdcSrc,0,0,0x00CC0020);
SaveImageAs(hBitmap,fileName,imageFormat);
Cleanup(hBitmap,hdcSrc, hWnd, hdcDest);
}
private void Cleanup(int hBitmap,int hdcSrc, IntPtr hWnd, int hdcDest)
{
User32.ReleaseDC(hWnd.ToInt32(), hdcSrc);
GDI32.DeleteDC(hdcDest);
GDI32.DeleteObject(hBitmap);
}
private void SaveImageAs(int hBitmap,string fileName,ImageFormat imageFormat)
{
Bitmap image = new Bitmap(Image.FromHbitmap(new IntPtr(hBitmap)),
Image.FromHbitmap(new IntPtr(hBitmap)).Width,
Image.FromHbitmap(new IntPtr(hBitmap)).Height);
image.Save(fileName,imageFormat);
}
public static void Main(string[] args)
{
Program d = new Program();
d.CaptureScreen("C:/Users/Admin/RS.Png", ImageFormat.Png);
Thread.Sleep(10000);
}
}
}
Also, not going to take shit for not shortening code by 2 lines at some possible places, first time with C#