AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Color Zoomer/Picker & Screen Magnifier
Goto page Previous  1, 2, 3, 4, 5  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Scape



Joined: 04 Mar 2009
Posts: 7

PostPosted: Wed Mar 04, 2009 8:37 pm    Post subject: Reply with quote

Useful script. One issue I found is that grey colors created a balloon window that was grey on grey. While in theory making the baloon the selected color & the inverse seems good there are cases near grey where it makes it near unreadable. I modified the foloowing two lines to use plain white on black so that no matter the color it's easy to read:

Original code:
Code:

   SendMessage, 1043, nColor, 0,, ahk_id %hWnd%
   SendMessage, 1044,~nColor & 0xFFFFFF, 0,, ahk_id %hWnd%


Modified code:
Code:

   SendMessage, 1043, 0x000000, 0,, ahk_id %hWnd%
   SendMessage, 1044, 0xFFFFFF, 0,, ahk_id %hWnd%


That was the only issue / suggestion I had. Solid work!
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2208

PostPosted: Thu Mar 05, 2009 12:58 am    Post subject: Reply with quote

Scape wrote:
One issue I found is that grey colors created a balloon window that was grey on grey.
Use Shift+Esc or Shift+RightClick which will copy the color into the clipboard.

Code:
SendMessage, 1043, 0x000000, 0,, ahk_id %hWnd%
SendMessage, 1044, 0xFFFFFF, 0,, ahk_id %hWnd%
They aren't necessary, just remove the two lines, then the system default colors will be used.
Back to top
View user's profile Send private message
Psycho.Mario



Joined: 21 Mar 2009
Posts: 28

PostPosted: Tue Apr 07, 2009 1:45 pm    Post subject: Borderless Reply with quote

How did you make the window so it had no border? I am trying to make a GUI which shows a webpage, sort of like an rss feed, so far i have this:

Code:
Gui +AlwaysOnTop +Resize +ToolWindow
GoSub, GuiOpen
pweb :=   COM_AtlAxCreateControl(WinExist(), "Shell.Explorer")
psink:=   COM_ConnectObject(pweb, "Web_")
COM_Invoke(pweb, "Silent", True)
COM_Invoke(pweb, "Navigate2", "http://news.google.co.uk/nwshp?hl=en&tab=wn")
Return

Navigate:
COM_Invoke(pweb, "Navigate2", _URL_)
Return

GuiOpen:
Gui, +Resize +LastFound
Gui, Show, w975 h750 Center, Blades
COM_AtlAxWinInit()
Return

GuiClose:
COM_Release(psink)
COM_Release(pweb)
Gui, Destroy
COM_AtlAxWinTerm()
ExitApp

Web_NewWindow3(prms)
{
   Global   _URL_:=   COM_DispGetParam(prms,4)
   COM_DispSetParam(-1,prms,1,11)
   SetTimer, Navigate, -10
}


I adapted this from another script. I want to have the edges borderless, like the magnifier. How do i do this?

Thanks
Back to top
View user's profile Send private message MSN Messenger
Guest






PostPosted: Tue Apr 07, 2009 1:51 pm    Post subject: Reply with quote

Quote:
How do i do this?
Search for 'border' in the AHK help. Check the first hit. Gotcha. Rolling Eyes
Back to top
Psycho.Mario



Joined: 21 Mar 2009
Posts: 28

PostPosted: Tue Apr 07, 2009 1:52 pm    Post subject: Reply with quote

thanks for the quick reply, i just added
Code:
-Caption
on the end of line 14
Back to top
View user's profile Send private message MSN Messenger
Guest






PostPosted: Sat May 30, 2009 9:22 pm    Post subject: Reply with quote

I hit ^+Z and zoom window appears, but +Esc and +RButton doesn't works for me at all. Please help Confused
Back to top
ArchCarrier



Joined: 03 Jun 2008
Posts: 20

PostPosted: Fri Jun 12, 2009 8:58 am    Post subject: Reply with quote

I tried to modify the original script so that clicking would send the color code to the clipboard and close the zoomer window, but only six zeros are copied to the clipboard whenever I click. Any suggestions?

Code:
#NoEnv
#SingleInstance, Force
SetWinDelay, 10

nZ := 3            ; Zoom Factor
nR := 100         ; Rectangle of the Zoomer

CoordMode, Mouse
CoordMode, Pixel

ToolTip, %A_Space%

WinGet, hWnd, ID, ahk_class tooltips_class32
WinSet, ExStyle, +0x00000020, ahk_id %hWnd%

hDC_SC := DllCall("GetDC", "Uint",    0)
hDC_TT := DllCall("GetDC", "Uint", hWnd)

Loop
{
   MouseGetPos, xmouse, ymouse
   DllCall("StretchBlt", "Uint", hDC_TT, "int", 0, "int", 0, "int", nR*2, "int", nR*2, "Uint", hDC_SC, "int", xmouse-nR//nZ, "int", ymouse-nR//nZ, "int", nR//nZ*2, "int", nR//nZ*2, "Uint", 0x00CC0020)
   WinMove, ahk_id %hWnd%,, xmouse-nR, ymouse-nR, nR*2, nR*2
   WinSet, AlwaysOnTop, On, ahk_id %hWnd%
}

LButton::
Clipboard := GetColor()
Goto Exit

Esc::
Goto Exit

Exit:
DllCall("ReleaseDC", "Uint",    0, "Uint", hDC_SC)
DllCall("ReleaseDC", "Uint", hWnd, "Uint", hDC_TT)
ExitApp

GetColor()
{
   VarSetCapacity(nColor, 6)
   SendMessage, 1046, 0, 0,, A
   DllCall("wsprintf", "str", nColor, "str", "%06X", "Uint", ErrorLevel, "Cdecl")
   Return nColor
}

Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2208

PostPosted: Fri Jun 12, 2009 10:26 am    Post subject: Reply with quote

ArchCarrier wrote:
but only six zeros are copied to the clipboard whenever I click.
To see what you did wrong, run the code inside GetColor().
Code:
WinGetClass, sClass, A
MsgBox, % sClass
Use hWnd instead. Next, even with hWnd you'll only get the default background color of tooltip. So, you should rewrite the code.
Back to top
View user's profile Send private message
ArchCarrier



Joined: 03 Jun 2008
Posts: 20

PostPosted: Tue Jun 16, 2009 7:05 am    Post subject: Reply with quote

Sean, thanks for the reply (although I'm afraid I didn't understand it). I got it working now, using a script from Skrommel's collection:

Code:
#NoEnv
#SingleInstance, Force
SetWinDelay, 10

nZ := 3           ; Zoom Factor
nR := 100         ; Rectangle of the Zoomer

CoordMode, Mouse
CoordMode, Pixel

ToolTip, %A_Space%

WinGet, hWnd, ID, ahk_class tooltips_class32
WinSet, ExStyle, +0x00000020, ahk_id %hWnd%

hDC_SC := DllCall("GetDC", "Uint",    0)
hDC_TT := DllCall("GetDC", "Uint", hWnd)

Loop
{
   MouseGetPos, xmouse, ymouse
   DllCall("StretchBlt", "Uint", hDC_TT, "int", 0, "int", 0, "int", nR*2, "int", nR*2, "Uint", hDC_SC, "int", xmouse-nR//nZ, "int", ymouse-nR//nZ, "int", nR//nZ*2, "int", nR//nZ*2, "Uint", 0x00CC0020)
   WinMove, ahk_id %hWnd%,, xmouse-nR, ymouse-nR, nR*2, nR*2
   WinSet, AlwaysOnTop, On, ahk_id %hWnd%
}

LButton::
Clipboard := GetColor()
Goto Exit

Esc::
Goto Exit

Exit:
DllCall("ReleaseDC", "Uint",    0, "Uint", hDC_SC)
DllCall("ReleaseDC", "Uint", hWnd, "Uint", hDC_TT)
ExitApp

GetColor()
{
  MouseGetPos,x,y
  PixelGetColor,rgb,x,y,RGB
  StringTrimLeft,rgb,rgb,2
  Return %rgb%
}
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2208

PostPosted: Tue Jun 16, 2009 10:09 am    Post subject: Reply with quote

Yes, it'll work, although it's redundant here.
Code:
LButton::
VarSetCapacity(nColor, 6)
DllCall("wsprintf", "str", nColor, "str", "%06X", "int", DllCall("GetPixel", "Uint", hDC_SC, "int", xmouse, "int", ymouse), "Cdecl")
Clipboard := nColor
Esc::
DllCall("ReleaseDC", "Uint",    0, "Uint", hDC_SC)
DllCall("ReleaseDC", "Uint", hWnd, "Uint", hDC_TT)
ExitApp
Back to top
View user's profile Send private message
Drugwash



Joined: 08 Sep 2008
Posts: 608
Location: Ploiesti, RO

PostPosted: Wed Jun 17, 2009 6:04 pm    Post subject: Reply with quote

Hey, Sean! In your first post you say your script will never work in Win9x. Oh well... not in its official form, but with a few minor changes, it does. Cool

Personally I run Win98SE with some WinME, Win2000, WinXP and even Win2003 system files upgraded. As such, balloon tips display fine when called (see the topics on balloon tips posted around, where I've performed tests). The only drawback is that the close button won't show up so can't be used to close the balloons and also links won't show up (but that doesn't pertain to your script; sorry for the digression).

The color zoomer rectangle appears fine with the cross cursor in the middle of it, but it won't show anything inside, because the layered style used is not supported by the 9x USER32.DLL library and all it captures is the zoom rectangle itself. As such, I'd be grateful if you could offer an alternate option of showing the zoom rectangle as a tooltip to the side of the cross cursor, similar to the magnifier; when so, the script would also work correctly at least in a stock WinME, along with any updated Win98SE such as mine.

The other necessary changes would be:
- replace RtlFillMemoryULong calls with NumPut
- replace CreateWindowEx with CreateWindowExA
- replace SetClassLong with SetClassLongA

Code:
   DllCall("ntdll\RtlFillMemoryUlong", "Uint", &ti + 4, "Uint", 4, "Uint", 0x20)
   DllCall("ntdll\RtlFillMemoryUlong", "Uint", &ti +36, "Uint", 4, "Uint", &nColor)

   hWnd := DllCall("CreateWindowEx", "Uint", 0x08000008, "str", "tooltips_class32", "str", "", "Uint", 0x3, "int", 0, "int", 0, "int", 0, "int", 0, "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0, "UInt")

   DllCall("SetClassLong", "Uint", hWnd, "int", -12, "int", DllCall("LoadCursor", "Uint", 0, "Uint", 32515))

would become:
Code:
    NumPut(0x20, ti, 4, "UInt")
    NumPut(&nColor, ti, 36, "UInt")


   hWnd := DllCall("CreateWindowExA", "Uint", 0x08000008, "str", "tooltips_class32", "str", "", "Uint", 0x3, "int", 0, "int", 0, "int", 0, "int", 0, "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0)

   DllCall("SetClassLongA", "Uint", hWnd, "int", -12, "int", DllCall("LoadCursor", "Uint", 0, "Uint", 32515))


The magnifier works fine with the exception of a flickering rectangle to the top-left side of the magnified window, containing the original clipped region unzoomed. Probably a recreation/initialization of the tooltip. I haven't yet checked that particular code to see for a fix.

[EDIT] OK, I've checked the magnifier code and the fix (actually workaround) is pretty simple: check for mouse coordinates and if not changed between loop iterations, just continue the loop. This way it will only flicker while the mouse is moved. Wink
Here's the relevant part fo the code:
Code:
   Loop
   {
      MouseGetPos, xCursor, yCursor
      if (oldX = xCursor && oldY = yCursor)
   continue

      DllCall("BitBlt", "Uint", hDC_LW, "int", 0, "int", 0, "int", 2*nW, "int", 2*nH, "Uint", hDC_SC, "int", xCursor-nW, "int", yCursor-nH, "Uint", 0x40CC0020)
      If bInvert
      DllCall("BitBlt", "Uint", hDC_LW, "int", 0, "int", 0, "int", 2*nW, "int", 2*nH, "Uint", 0, "int", 0, "int", 0, "Uint", 0x00550009)
      Cursor(hDC_LW, nW, nH)      ; Capture magnified mouse cursor.
      DllCall("StretchBlt", "Uint", hDC_TT, "int", 0, "int", 0, "int", 2*nW*nZ, "int", 2*nH*nZ, "Uint", hDC_LW, "int", 0, "int", 0, "int", 2*nW, "int", 2*nH, "Uint", 0x00CC0020)
;      Cursor(hDC_TT, nW*nZ, nH*nZ)   ; Capture un-magnified mouse cursor.
      WinMove, ahk_id %hWnd%,, xCursor-(nW*nZ+1), yCursor+nH, 2*(nW*nZ+1), 2*(nH*nZ+1)
      oldX := xCursor
      oldY := yCursor

      If GetKeyState("Esc")
         Break
   }


Thank you so much for the script! Wink
Back to top
View user's profile Send private message Yahoo Messenger
Sean



Joined: 12 Feb 2007
Posts: 2208

PostPosted: Thu Jun 18, 2009 12:00 am    Post subject: Reply with quote

Drugwash wrote:
because the layered style used is not supported by the 9x USER32.DLL library and all it captures is the zoom rectangle itself.
It's a little unclear to me. So, you can or cannot use a transparent window? Actually a tooltip window with Layered ExStyle defaultly is a feature of v6.0 of comctl32.dll. If not using it, you have to set the Layered ExStyle manually even in XP, via e.g.
Code:
WinSet, Transparent, 255, ahk_id %hWnd%

Quote:
- replace CreateWindowEx with CreateWindowExA
- replace SetClassLong with SetClassLongA
Why? It's supposed to be done by AHK itself. There are no exported APIs CreateWindowEx/SetClassLong in XP either.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2208

PostPosted: Thu Jun 18, 2009 3:04 am    Post subject: Reply with quote

Drugwash wrote:
The magnifier works fine with the exception of a flickering rectangle to the top-left side of the magnified window, containing the original clipped region unzoomed.
OK, I now realized what you meant. I recalled that I was concerned about this when I wrote it, but was unnoticeable in my system. I guess your system is rather slow. In that case, the cure is simple. Use mem DC in place of hDC_LW, i.e., use CreateCompatibleDC. Don't forget then you have to adjust the followings appropriately like creating/selecting bitmap etc.
Back to top
View user's profile Send private message
Drugwash



Joined: 08 Sep 2008
Posts: 608
Location: Ploiesti, RO

PostPosted: Thu Jun 18, 2009 1:21 pm    Post subject: Reply with quote

Sean wrote:
It's a little unclear to me. So, you can or cannot use a transparent window?
No, in Win9x I cannot, unfortunately. WinSet, Transparent cannot work either.
Quote:
Why? It's supposed to be done by AHK itself. There are no exported APIs CreateWindowEx/SetClassLong in XP either.
For some reason, it doesn't do it on my 98SE system. I stumbled into this issue many times when I didn't pay enough attention to MSDN and didn't check the actual function names in the dlls. Anyway, if there's no explicit need for the Unicode versions of the functions, the ANSI versions can safely be hardcoded in the script, to ensure it would work under most Windows versions.
Quote:
I guess your system is rather slow. In that case, the cure is simple [...].
It's a 667MHz Pentium III. Since I'm not at all familiar with the GDI API, I'm afraid the aforementioned workaround will have to do for me (forgot to mention the break hotkey check should be placed in the very beginning of the loop so it wouldn't require a mouse move to exit the magnifier). But if you think it's not worth changing the code, I'll just use it locally.

Thanks for taking the time to answer.
Back to top
View user's profile Send private message Yahoo Messenger
Sean



Joined: 12 Feb 2007
Posts: 2208

PostPosted: Thu Jun 18, 2009 4:05 pm    Post subject: Reply with quote

Drugwash wrote:
Since I'm not at all familiar with the GDI API
You better learn about it. It could pay you back unexpected reward/solution for one of your problems. Anyway it's easy to adopt the code from another script of mine
http://www.autohotkey.com/forum/topic18146.html

Before the loop:
Code:
hDC_TT := DllCall("GetDC", "Uint", hWnd)
hDC_SC := DllCall("GetDC", "Uint",    0)
hDC_LW := DllCall("CreateCompatibleDC", "Uint", hDC_SC)
hBM := DllCall("CreateCompatibleBitmap", "Uint", hDC_SC, "int", 2*nW, "int", 2*nH)
oBM := DllCall("SelectObject", "Uint", hDC_LW, "Uint", hBM)
DllCall("SetStretchBltMode", "Uint", hDC_TT, "int", 4)

After the loop:
Code:
DllCall("SelectObject", "Uint", hDC_LW, "Uint", oBM)
DllCall("DeleteObject", "Uint", hBM)
DllCall("DeleteDC", "Uint", hDC_LW)
DllCall("ReleaseDC", "Uint",    0, "Uint", hDC_SC)
DllCall("ReleaseDC", "Uint", hWnd, "Uint", hDC_TT)

Quote:
But if you think it's not worth changing the code, I'll just use it locally.
It's not a matter of whether I think it's worth or not. I just don't want to be trapped into keeping constantly updating the old codes I posted.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5  Next
Page 3 of 5

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group