SRL Archive - Research & Development Lounge

Magnifier fun!


Metagen

2009-06-01 17:06:47

Yay for c#

My form obviously doesn't work properly, because i really dont care. But try turning on follow cursor and putting it over rs :o i had lots of fun.

I attatched an exe

Feechurs incl00d:

1. Zoom in and out to rediculous numbers
2. invert colors.
3. turn on and off R G and/or B
4. you can make a magnifier portal :o (zoom out and turn on follow cursor, then put it over itself)




Below is the only code of interest.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;


namespace WindowsFormsApplication12
{
class BitManager
{
[DllImport("gdi32.dll")]
static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int x, int y);

[DllImport("gdi32.dll")]
static extern IntPtr SelectObject(IntPtr hdc, IntPtr hbmp);

[DllImport("gdi32.dll")]
static extern IntPtr DeleteObject(IntPtr hbmp);

[DllImport("gdi32.dll")]
static extern IntPtr CreateCompatibleDC(IntPtr hdc);

[DllImport("gdi32.dll")]
static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, long SRCCOPY);

[DllImport("user32.dll")]
static extern IntPtr GetDesktopWindow();

[DllImport("user32.dll")]
static extern IntPtr GetDC(IntPtr hwnd);

[DllImport("user32.dll")]
static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);

[DllImport("gdi32.dll")]
static extern Int32 DeleteDC(IntPtr hdc);

Bitmap theBMP;
const long SRCCOPY = 13369376;

public void LoadBits(int x1, int y1, int x2, int y2, double zoom, bool invert, bool r, bool g, bool b)
{
zoom = zoom + zoom;
int dx = (x2 - x1);
int dy = (y2 - y1);
int cx = (x2 + x1) / 2;
int cy = (y2 + y1) / 2;

x1 = cx - ((int)(dx / zoom));
x2 = cx + ((int)(dx / zoom));
y1 = cy - ((int)(dy / zoom));
y2 = cy + ((int)(dy / zoom));


IntPtr HWND = GetDesktopWindow();
IntPtr DC = GetDC(HWND);
IntPtr myDC = CreateCompatibleDC(DC);
IntPtr myBMP = CreateCompatibleBitmap(DC, x2 - x1, y2 - y1);
SelectObject(myDC, myBMP);
BitBlt(myDC, 0, 0, x2, y2, DC, x1, y1, SRCCOPY);
theBMP = null;
try
{
theBMP = Bitmap.FromHbitmap(myBMP);
}
catch (Exception)
{
}
finally
{
DeleteObject(myBMP);
ReleaseDC(HWND, DC);
DeleteDC(myDC);
}
if (invert ||! r || !g ||! b)
unsafe
{

BitmapData bitmapData = theBMP.LockBits(new Rectangle(0, 0, theBMP.Width, theBMP.Height),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

byte* pos = (byte*)(bitmapData.Scan0.ToPointer());

for (int j = 0; j < bitmapData.Height; j++)
{
for (int i = 0; i < bitmapData.Width; i++)
{
if (!g)
pos[0] = 0;
if (!b)
pos[1] = 0;
if (!r)
pos[2] = 0;
if (invert)
{
// add modifier code here
pos[0] = (byte)(255 - pos[0]);
pos[1] = (byte)(255 - pos[1]);
pos[2] = (byte)(255 - pos[2]);
}
pos += 4;
}
}
theBMP.UnlockBits(bitmapData);

}

}


public void DrawToForm(System.Windows.Forms.Form form)
{
if (theBMP == null)
return;

using (Graphics g = Graphics.FromHwnd(form.Handle))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;

g.DrawImage(theBMP, 0, 0, form.Width, form.Height);
}
theBMP.Dispose();

}
}
}

ShowerThoughts

2009-06-01 17:10:09

Nice, good job!
I saw it when you were starting C#, I must say I never have made something like this, but yeah good job for a 12th application :).

marpis

2009-06-01 17:13:03

hoah, a tool like that could be usable to find best colors on screen :)

Metagen

2009-06-01 17:17:56

oh
lol yes application 12 :D

probably should have named it…

05/29/2009 04:30 PM <DIR> .
05/29/2009 04:30 PM <DIR> ..
05/25/2009 09:40 AM <DIR> A Service
05/26/2009 09:01 AM <DIR> c++Fun
12/08/2008 11:22 AM <DIR> Cab1
05/25/2009 01:39 PM <DIR> ClassLibrary1
03/06/2009 01:54 PM <DIR> ConsoleApplication1
03/07/2009 03:29 PM 26,100 ConsoleApplication1.zip
05/25/2009 01:37 PM <DIR> ConsoleApplication10
05/25/2009 01:42 PM <DIR> ConsoleApplication11
05/29/2009 01:41 PM <DIR> ConsoleApplication12
04/14/2009 03:03 PM <DIR> ConsoleApplication2
04/15/2009 12:03 PM <DIR> ConsoleApplication3
04/15/2009 12:16 PM <DIR> ConsoleApplication4
04/22/2009 12:39 PM <DIR> ConsoleApplication5
05/06/2009 11:34 AM <DIR> ConsoleApplication6
05/06/2009 11:34 AM <DIR> ConsoleApplication7
05/22/2009 10:50 AM <DIR> ConsoleApplication8
05/22/2009 11:22 AM <DIR> ConsoleApplication9
05/26/2009 09:18 AM <DIR> consolefun
03/23/2009 09:30 AM <DIR> dxtest
02/23/2009 10:15 AM <DIR> GraphicsThing
03/07/2009 03:30 PM 102,834 GraphicsThing.zip
03/20/2009 01:03 PM <DIR> MemPlay
05/25/2009 03:32 PM <DIR> Setup1 <– this is the installer for my virus :D
08/14/2008 02:20 PM 204 Solution1.sln
03/20/2009 03:19 PM <DIR> testx
08/01/2008 10:14 AM <DIR> VSMacros80
08/26/2008 10:24 AM <DIR> WDTWebServices
08/05/2008 09:10 AM <DIR> WebApplication1
08/05/2008 10:33 AM <DIR> WebApplication2
05/26/2009 08:50 AM <DIR> WebApplication3
04/27/2009 03:21 PM <DIR> WebService1
08/01/2008 10:15 AM <DIR> WindowsApplication1
08/01/2008 10:28 AM <DIR> WindowsFormsApplication1
05/25/2009 09:51 AM <DIR> WindowsFormsApplication10
05/25/2009 12:42 PM <DIR> WindowsFormsApplication11
05/26/2009 10:04 AM <DIR> WindowsFormsApplication12
05/29/2009 04:30 PM 114,359 WindowsFormsApplication12.zip
05/29/2009 01:42 PM <DIR> WindowsFormsApplication13
08/01/2008 12:16 PM <DIR> WindowsFormsApplication2
03/06/2009 04:29 PM <DIR> WindowsFormsApplication3
03/06/2009 04:36 PM <DIR> WindowsFormsApplication4
03/13/2009 11:32 AM 58,604 WindowsFormsApplication4.zip
03/27/2009 09:46 AM <DIR> WindowsFormsApplication5
05/12/2009 03:02 PM <DIR> WindowsFormsApplication6
05/13/2009 02:35 PM <DIR> WindowsFormsApplication7
05/22/2009 01:07 PM <DIR> WindowsFormsApplication8
05/25/2009 09:46 AM <DIR> WindowsFormsApplication9
05/25/2009 03:47 PM <DIR> WindowsService1 <– this ones a virus ^.^ (lol closes all firefoxes every 15 seconds)

ShowerThoughts

2009-06-01 17:20:32

You've been doing al lot!
Talk to me on msn, my biggest project still beats you :).

Haven't been programming C# for a few weeks(I am coding Delphi(Scar)).

Metagen

2009-06-01 17:21:34

From: Hermen
Nice, good job!
I saw it when you were starting C#, I must say I never have made something like this, but yeah good job for a 12th application :).


pff. i mde this in like 3 hours

:p ok maaaybe 5 or 6

…

or 7 years… of training.

… with yoda.

Nadeem

2009-06-01 19:33:16

Hahah this is uber nice! :D I have no idea bout C# scripting, might wanna learn it some day when I'm bored :P



~NS

Shuttleu

2009-06-01 19:37:30

does C# work in linux?

~shut

Metagen

2009-06-01 19:49:41

From: Shuttleu
does C# work in linux?

~shut


This uses windows API… so i really doubt it.

ShowerThoughts

2009-06-01 19:54:04

C# = windows only.
To bad though, I really like it.

Metagen

2009-06-01 19:56:29

oh hey i just fixed a bug…


BitBlt(myDC, 0, 0, x2 - x1, y2 - y1, DC, x1, y1, SRCCOPY);
my width and height was wrong :D

ok i uploaded new exe i think

footballjds

2009-06-01 20:05:18

thats why i think Java > C# cause Java works on anything :p[/offtopic]
but nice work!

Metagen

2009-06-01 20:10:31

im too lazy to argue today.

Shady?

2009-06-01 20:44:31

o noes i are can't finds the exe!11!!!11!11one!11!

Whre is it?

ShowerThoughts

2009-06-01 20:45:33

Hmm, someone removed it, I guess, might explain why?

Metagen

2009-06-01 22:18:02

oh maybe i uploaded it wrong… ill put it back :D

i hope the admins dont shoot me :(

ShowerThoughts

2009-06-01 22:23:40

From: Metagen
oh maybe i uploaded it wrong… ill put it back :D

i hope the admins dont shoot me :(


They won't because they should have said something then.

Metagen

2009-06-01 22:36:40

neilsie keeps eyeing up my thread ^.^

Shady?

2009-06-01 23:16:40

Oh yea, now i tried it. Reminds me of Windows Magnifier xD. It could be usefull for color picking.I've made one in Scar once.

Metagen

2009-06-01 23:30:11

From: Shady?
Oh yea, now i tried it. Reminds me of Windows Magnifier xD. It could be usefull for color picking.I've made one in Scar once.


Doesnt scar kindof have one? :D oh u made a magnifier, cool shit. mine can change colors :D

bullzeye95

2009-06-02 22:15:21

Set the magnifier form's "AlphaBlend" value to true. This should stop it from copying itself onto itself. Unless of course you left it like it is on purpose :rolleyes:

EDIT: Hermpie, I assumed it works the same in C# as it is in Delphi. I was wrong?

ShowerThoughts

2009-06-02 22:47:36

From: bullzeye95
Set the magnifier form's "AlphaBlend" value to true. This should stop it from copying itself onto itself. Unless of course you left it like it is on purpose :rolleyes:


Why didn't you mention Delphi?
Not even in white text. :eek:

C#

Da 0wner

2009-06-03 05:46:16

[ArcaVir] 	
2009-06-02 Found nothing
[F-Secure Anti-Virus]
2009-06-02 Found nothing
[Emsisoft A-squared]
2009-06-03 Found nothing
[Ikarus]
2009-06-02 Found nothing
[Avast! antivirus]
2009-06-02 Found nothing
[Kaspersky Anti-Virus]
2009-06-03 Found nothing
[Grisoft AVG Anti-Virus]
2009-06-02 Found nothing
[ESET NOD32]
2009-06-02 Found nothing
[Avira AntiVir]
2009-06-02 Found nothing
[Norman Virus Control]
2009-06-02 Found nothing
[Softwin BitDefender]
2009-06-03 Found nothing
[Panda Antivirus]
2009-06-02 Found nothing
[ClamAV]
2009-06-03 Found nothing
[Quick Heal]
2009-06-01 Found nothing
[CPsecure]
2009-06-03 Found nothing
[Sophos]
2009-06-03 Found nothing
[Dr.Web]
2009-06-03 Found nothing
[VirusBlokAda VBA32]
2009-06-02 Found nothing
[Frisk F-Prot Antivirus]
2009-06-02 Found nothing
[VirusBuster]
2009-06-02 Found nothing

Just for the people that do not trust Meta :p.

P1nky

2009-06-03 06:17:12

woah lol, i remember when you told me you going to start C.

dang dude, maybe teach me a few on MSN :p lol
gj