It is currently April 19th, 2024, 8:16 pm

RainFocus

Share and get help with Plugins and Addons
User avatar
~Faradey~
Posts: 366
Joined: November 12th, 2009, 4:47 pm
Location: Ukraine

Re: RainFocus

Post by ~Faradey~ »

@mrsalogo, here it is
i wonder what plugin you're writing, hope this code will help u

Code: Select all

#include <WinAPI.au3>

$ConfigName = ""

if $CmdLine[0] = 1 Then $ConfigName = $CmdLine[1]

Local $hControl, $hWin, $aMousePos

if $ConfigName <> "" Then
	$hWin = HWnd('0x' & Hex(GetSkinWindow($ConfigName)))
	WinActivate($hWin)
Else
	$aMousePos = MouseGetPos()
	$hControl=_WindowFromPoint($aMousePos[0],$aMousePos[1])
	; Since _WindowFromPoint() can return 'sub' windows, or control handles, we should seek the owner window
	$hWin=_WinAPI_GetAncestor($hControl,2)
	If _WinAPI_GetClassName($hWin) == "RainmeterMeterWindow" Then
		WinActivate($hWin)
	EndIf
EndIf


Func _WindowFromPoint($iX,$iY)
    Local $stInt64,$aRet,$stPoint=DllStructCreate("long;long")
    DllStructSetData($stPoint,1,$iX)
    DllStructSetData($stPoint,2,$iY)
    $stInt64=DllStructCreate("int64",DllStructGetPtr($stPoint))
    $aRet=DllCall("user32.dll","hwnd","WindowFromPoint","int64",DllStructGetData($stInt64,1))
    If @error Then Return SetError(2,@error,0)
    If $aRet[0]=0 Then Return SetError(3,0,0)
    Return $aRet[0]
EndFunc

Func GetSkinWindow($szConfigName)
   Local Const $hWnd = WinGetHandle("[CLASS:RainmeterTrayClass]")
   If $hWnd <> 0 Then
      Local Const $iSize = StringLen($szConfigName) + 1
      Local Const $pMem = DllStructCreate("wchar[" & $iSize & "]")
      DllStructSetData($pMem, 1, $szConfigName)
      Local Const $pCds = DllStructCreate("dword;dword;ptr")
      DllStructSetData($pCds, 1, 5101)
      DllStructSetData($pCds, 2, ($iSize * 2))
      DllStructSetData($pCds, 3, DllStructGetPtr($pMem))
      Local Const $WM_COPYDATA = 0x004A
      Return _SendMessage($hWnd, $WM_COPYDATA, 0, DllStructGetPtr($pCds))
   EndIf

   Return 0
EndFunc; end func
User avatar
mrsalogo
Posts: 6
Joined: July 28th, 2015, 5:12 pm

Re: RainFocus

Post by mrsalogo »

Its simpler then i thought, Thanks! I am building an extended version of the InputText plugin. I am adding features to make it easier to use in interfaces.
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

Re: RainFocus

Post by Virginityrocks »

RainFocus doesn't seem to be working at all, at least in the latest version of Rainmeter. Absolutely no response or error in log.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5397
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: RainFocus

Post by eclectic-tech »

Virginityrocks wrote:RainFocus doesn't seem to be working at all, at least in the latest version of Rainmeter. Absolutely no response or error in log.
Can you post your Code?

I put this in the [Rainmeter] section of the skin I want to capture focus and it works!?

Code: Select all

MouseOverAction=["#@#Addons\RainFocus\RainFocus.exe"]
User avatar
winterwulf
Posts: 94
Joined: August 17th, 2016, 1:48 am
Location: São Paulo - Brazil

Re: RainFocus

Post by winterwulf »

Isnt working for me neither =(

tried:

MouseOverAction=["#@#Addons\RainFocus.exe"]
MouseOverAction=#@#Addons\RainFocus.exe
MouseOverAction=#@#Addons\RainFocus.exe "#CURRENTCONFIG#"


nothing worked
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5397
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: RainFocus

Post by eclectic-tech »

I have been sing the following code in many skins and it works as intended; the skin will gain focus when the mouse is over it, and execute the OnUnfocusAction bang when focus is lost...

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
Group=#RootConfig#

OnUnfocusAction=[!DeActivateConfig "#RootConfig#\Menus\#MenuLocation#\#MenuName#\#MenuName#Menu" "#MenuName#Menu.ini"]

MouseOverAction=["#@#Addons\RainFocus\RainFocus.exe"]
I use it to ensure my fileview menus close when focus is lost... works every time! :confused:
User avatar
winterwulf
Posts: 94
Joined: August 17th, 2016, 1:48 am
Location: São Paulo - Brazil

Re: RainFocus

Post by winterwulf »

Good evening,
Here it worked now, but only to get focus from a skin to another.
when the focus is on a window or on dekstop, it didnt work for me.

gonna try your method to see what happens.
EDIT
Did the following:

Code: Select all

MouseOverAction=#@#Addons\RainFocus.exe
OnFocusAction=[!DeActivateConfig "#ROOTCONFIG#\Lyrics"]
Only got the OnFocusAction when I acctually click the skin =(

3.3.2 r2609 64-bit (May 16 2016)
Windows 7 Professional 64-bit (build 7601) Service Pack 1
Path: C:\Users\Ville\Dropbox\PortableApps\Rainmeter\
IniFile: C:\Users\Ville\Dropbox\PortableApps\Rainmeter\Rainmeter.ini
SkinPath: C:\Users\Ville\Dropbox\PortableApps\Rainmeter\Skins\
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

Re: RainFocus

Post by Virginityrocks »

Hey Faradey. I'm wondering if you can help me. I'm looking for a way for a plugin (possibly this plugin) to assign focus to a specified program window (ie Google Chrome), instead of a Rainmeter skin.

So, for example, if I press the "Google Chrome" button in Rainmeter, it will switch focus to the Google Chrome window (if one exists)
User avatar
delfore08
Posts: 3
Joined: April 10th, 2020, 12:18 pm

Re: RainFocus

Post by delfore08 »

Nice addon. It solved my trouble. Many thanks to you! =)