Notifications
Clear all
[Closed] catching mouseclicks
Page 2 / 2
Prev
Jun 10, 2013 3:10 pm
Great stuff and I really like your code, clean and easy to read! Congrats and thanks.
Jun 10, 2013 3:10 pm
Thanks Artur, that’s appreciated!
I’ve left one feature out however which I didn’t get to work. Maybe you have some ideas.
I want to preview the window the mouse is hovering over by outlining it with a red border. This happens a lot in other screencapture programs and it makes the user a lot more aware of what he’s actually going to capture. I have some code, but it draws the borders inconsistently and also removes them inconsistently. It gives you a rough idea however of what I’m trying to do.
Here’s the script
And here is the assembly I’m using to make it happen
str="using System;
"
str+="using System.Runtime.InteropServices;
"
str+="using System.Drawing;
"
str+="namespace HotTrack
"
str+="{
"
str+="class DrawOnScreen
"
str+="{
"
--these flags: http://www.blitzbasic.com/Community/posts.php?topic=32334
str+=" private const int RDW_FRAME = 0x0400;
"
str+=" private const int RDW_INVALIDATE = 0x0001;
"
str+=" private const int RDW_UPDATENOW = 0x0100;
"
str+=" private const int RDW_ALLCHILDREN = 0x0080;
"
str+=" public static Graphics G;
" --move the Graphics object out here.
str+=" [DllImport(\"user32.dll\")]
"
str+=" private static extern IntPtr GetWindowDC(IntPtr hWnd);
"
str+=" [DllImport(\"user32.dll\")]
"
str+=" private static extern bool InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase );
"
str+=" [DllImport(\"user32.dll\")]
"
str+=" private static extern bool UpdateWindow(IntPtr hWnd);
"
str+=" [DllImport(\"user32.dll\")]
"
str+=" private static extern bool RedrawWindow(IntPtr hWnd, IntPtr lprcUpdate, IntPtr hrgnUpdate, int flags);
"
str+=" [DllImport(\"user32.dll\")]
"
str+=" public static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC);
"
--resetting the window fails inconsistently. sometimes the red border is removed, sometimes not
str+=" public static void ResetWindow(IntPtr hWnd)
"
str+=" {
"
str+=" InvalidateRect(hWnd, IntPtr.Zero, true);
"
str+=" UpdateWindow(hWnd);
"
str+=" RedrawWindow(hWnd, IntPtr.Zero, IntPtr.Zero, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN);
"
str+=" }
"
-- http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/c581ef21-2833-47e5-90d7-9b8c4f38646c/
str+=" public void DrawWindow(IntPtr hWnd, int width, int height)
"
str+=" {
"
str+=" IntPtr hdc = GetWindowDC(hWnd);
"
str+=" using (var pen = new Pen(Color.Red, 4))
"
str+=" {
"
str+=" using (G = Graphics.FromHdc(hdc))
"
str+=" {
"
str+=" G.DrawRectangle(pen, 2,2, width-4, height-4);
"
str+=" }
"
str+=" }
"
str+=" ReleaseDC(hWnd, hdc);
"
str+=" }
"
str+="}
"
str+="}
"
Page 2 / 2
Prev