Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ ActivateClient Alternative
|
ActivateClient Alternative
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Morat
(18 posts) Bio
|
| Date
| Fri 15 Jan 2010 06:58 PM (UTC) Amended on Sat 23 Jan 2010 08:28 AM (UTC) by Morat
|
| Message
| You may have noticed that when you try and bring MUSHclient to the foreground using the function ActivateClient that it just flashes the taskbar button a few times.
I wrote some c code for a dll that does the following:
- test if MUSHclient is in the foreground (use to trigger a sound when in another window)
- set MUSHclient as the foreground window instead of flashing the taskbar button
focus.c
#pragma comment(lib, "lua5.1.lib")
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "luaconf.h"
#include <windows.h>
static int get_foreground_window(lua_State *L)
{
HWND hForeground = GetForegroundWindow();
lua_pushlightuserdata(L, hForeground);
return 1;
}
static int set_foreground_window(lua_State *L)
{
HWND hForeground = GetForegroundWindow();
HWND hMUSHclient = lua_touserdata(L, 1);
DWORD hForegroundId = GetWindowThreadProcessId(hForeground, NULL);
DWORD hMUSHclientId = GetWindowThreadProcessId(hMUSHclient, NULL);
AttachThreadInput(hForegroundId, hMUSHclientId, 1); /* attach */
SetForegroundWindow(hMUSHclient);
AttachThreadInput(hForegroundId, hMUSHclientId, 0); /* detach */
if (IsIconic(hMUSHclient))
ShowWindow(hMUSHclient, SW_RESTORE);
else
ShowWindow(hMUSHclient, SW_SHOW);
return 0;
}
static const luaL_reg focuslib[] =
{
{"get_foreground_window", get_foreground_window},
{"set_foreground_window", set_foreground_window},
{NULL, NULL}
};
LUALIB_API int __declspec(dllexport) luaopen_focus(lua_State *L)
{
luaL_openlib(L, "focus", focuslib, 0);
return 1;
}
build files:
focus.c
lua.h
lualib.h
lauxlib.h
luaconf.h
lua5.1.lib
lua5.1.dll
http://www.gammon.com.au/files/mushclient/lua5.1_extras/lua5.1_lib.zip
build command using MinGW (GCC):gcc -shared -o focus.dll focus.c -L.\ -llua5.1
I'm using MinGW (GCC) from Bloodshed Dev-C++ 5.0 Beta 9.2 (4.9.9.2) with MinGW/GCC 3.4.2.
http://www.bloodshed.net/dev/devcpp.html
script examples:assert(package.loadlib("focus.dll", "luaopen_focus"))()
if focus.get_foreground_window() == GetFrame() then
print("foreground window is MUSHclient")
else
print("foreground window is not MUSHclient")
end
assert(package.loadlib("focus.dll", "luaopen_focus"))()
if focus.get_foreground_window() ~= GetFrame() then
Sound("C:/WINDOWS/Media/notify.wav")
end
assert(package.loadlib("focus.dll", "luaopen_focus"))()
focus.set_foreground_window(GetFrame())
reference:
Extending Lua scripting with your own code
http://www.gammon.com.au/forum/?id=4915
Launching Apps in the Foreground
http://www.ddj.com/windows/184405755 | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
11,081 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top