![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Toggle Hider (ToggleHide in C)
I just wrote this because I said I would here.
CTRL + ALT + h = Hide/unhide the active window. CTRL + ALT + q = Kill ToggleHide, if there is a window hidden it will be shown. The code is not commented, because it's fairly straight-forward. It's released under the GPL, because I don't see anyone use this in any personal project. So just share if you modify/extend. ![]() /*
ToggleHide 1.0 - Toggle hides the active or hidden window.
Copyright (C) 2006 Ruben aka nnxion aka rubenisme (rubenisme.com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
#include <windows.h>
char * className = "HotkeyHide";
char * captionName = "HotkeyHide Application";
int APIENTRY WinMain( HINSTANCE, HINSTANCE, LPSTR, int );
BOOL InitApplication( HINSTANCE );
BOOL InitInstance( HINSTANCE, int );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
MSG msg;
if (!InitApplication(hInstance))
return FALSE;
if (!InitInstance(hInstance, nCmdShow))
return FALSE;
while((GetMessage(&msg, NULL, 0, 0)) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
BOOL InitApplication( HINSTANCE hInstance )
{
WNDCLASS WndClass;
WndClass.style = 0;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.hInstance = hInstance;
WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = className;
return RegisterClass(&WndClass);
}
BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
{
HWND hwnd = CreateWindow(className, captionName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 230, 50, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
if(!hwnd)
return FALSE;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return TRUE;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
static ATOM hkToggleHide, hkKillSelf;
static HWND hActiveWindow;
static BOOL one = FALSE;
switch(message)
{
case WM_CREATE:
if(!(hkToggleHide = GlobalAddAtom("ToggleHide_hkToggleHide")))
return 1;
if (!(RegisterHotKey(hwnd, hkToggleHide, MOD_CONTROL | MOD_ALT, VkKeyScan('h'))))
return 1;
if(!(hkKillSelf = GlobalAddAtom("ToggleHide_hkKillSelf")))
return 1;
if (!(RegisterHotKey(hwnd, hkKillSelf, MOD_CONTROL | MOD_ALT, VkKeyScan('q'))))
return 1;
CreateWindow("button", "Kill App", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, 0, 0, 100, 20, hwnd, (HMENU) 1, (HINSTANCE)GetWindowLong (hwnd,GWL_HINSTANCE), NULL);
return 0;
case WM_COMMAND:
if(HIWORD(wParam) == BN_CLICKED)
{
if(LOWORD(wParam) == 1)
{
SendMessage(hwnd, WM_HOTKEY, hkKillSelf, lParam);
}
}
return 0;
case WM_HOTKEY:
if(wParam == hkToggleHide)
{
if(one)
ShowWindow(hActiveWindow, SW_SHOW);
else if((hActiveWindow = GetForegroundWindow()) != NULL)
ShowWindow(hActiveWindow, SW_HIDE);
one =! one;
}
else if(wParam == hkKillSelf)
{
if(hActiveWindow != NULL)
ShowWindow(hActiveWindow, SW_SHOW);
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
return 0;
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_DESTROY:
GlobalDeleteAtom(hkToggleHide);
UnregisterHotKey(0, hkToggleHide);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#2 |
|
Programmer
|
Very Nice
, havn't tested because I'm unfamiliar with the programming language (I'm unfamiliar with anything non-vb oriented , and please don't make an issue about that..), not as functional as Cloak.. but thats because its not a full program (if you did make a full program I'm sure it would beat Cloak into the ground ), I don't have the option to hide the active window though... and that seems like a VERY good idea, I'm gonna put that in the next version. Great job again ![]() |
|
|
|
|
|
#3 | ||
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
Quote:
Thanks for the feedback.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
||
|
|
|
|
|
#4 |
|
Programmer
|
Cloak can set the translucency of a window (not hard, just another API... Cloak is a simple project, theres no denying that, it really wasn't that hard to make), the title (SetWindowText API), and a bit more advanced hotkeys..
You target windows by selecting them, not by pushing a button and whatever window you have focused on will dissappear. G'day to ya ![]() |
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Minor correction + some defines to reduce size to 2.5 KB and only one instance of the program at a time.
/*
ToggleHide 1.0 - Toggle hides the active or hidden window.
Copyright (C) 2006 Ruben aka nnxion aka rubenisme (rubenisme.com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*#define MAKE_SMALL*/
#ifdef MAKE_SMALL
#pragma comment(linker,"/ENTRY:WinMain")
#pragma comment(linker,"/MERGE:.rdata=.data")
#pragma comment(linker,"/MERGE:.text=.data")
#pragma comment(lib,"msvcrt.lib")
#define WIN32_LEAN_AND_MEAN
#endif
#include <stdio.h>
#include <windows.h>
char * className = "HotkeyHide";
char * captionName = "HotkeyHide Application";
int APIENTRY WinMain( HINSTANCE, HINSTANCE, LPSTR, int );
HANDLE OneInstance( LPCTSTR lpName );
BOOL InitApplication( HINSTANCE );
BOOL InitInstance( HINSTANCE, int );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
MSG msg;
HANDLE hMutex = OneInstance("ToggleHide");
if(!hMutex)
return FALSE;
if (!InitApplication(hInstance))
return FALSE;
if (!InitInstance(hInstance, nCmdShow))
return FALSE;
while((GetMessage(&msg, NULL, 0, 0)) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
HANDLE OneInstance( LPCTSTR lpName )
{
HANDLE hMutex = CreateMutex(NULL, TRUE, lpName);
switch(GetLastError())
{
case ERROR_SUCCESS:
break;
case ERROR_ALREADY_EXISTS:
hMutex = NULL;
break;
default:
hMutex = NULL;
break;
}
return hMutex;
}
BOOL InitApplication( HINSTANCE hInstance )
{
WNDCLASS WndClass;
WndClass.style = 0;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.hInstance = hInstance;
WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = className;
return RegisterClass(&WndClass);
}
BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
{
HWND hwnd = CreateWindow(className, captionName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 250, 55, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
if(!hwnd)
return FALSE;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return TRUE;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
static ATOM hkToggleHide, hkKillSelf;
static HWND hActiveWindow;
static BOOL one = FALSE;
switch(message)
{
case WM_CREATE:
if(!(hkToggleHide = GlobalAddAtom("ToggleHide_hkToggleHide")))
return 1;
if (!(RegisterHotKey(hwnd, hkToggleHide, MOD_CONTROL | MOD_ALT, VkKeyScan('h'))))
return 1;
if(!(hkKillSelf = GlobalAddAtom("ToggleHide_hkKillSelf")))
return 1;
if (!(RegisterHotKey(hwnd, hkKillSelf, MOD_CONTROL | MOD_ALT, VkKeyScan('q'))))
return 1;
CreateWindow("button", "Kill App", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, 0, 0, 100, 20, hwnd, (HMENU) 1, (HINSTANCE)GetWindowLong (hwnd,GWL_HINSTANCE), NULL);
return 0;
case WM_COMMAND:
if(HIWORD(wParam) == BN_CLICKED)
{
if(LOWORD(wParam) == 1)
{
SendMessage(hwnd, WM_HOTKEY, hkKillSelf, lParam);
}
}
return 0;
case WM_HOTKEY:
if(wParam == hkToggleHide)
{
if(one)
{
ShowWindow(hActiveWindow, SW_SHOW);
one =! one;
}
else if((hActiveWindow = GetForegroundWindow()) != NULL)
{
ShowWindow(hActiveWindow, SW_HIDE);
one =! one;
}
}
else if(wParam == hkKillSelf)
{
if(hActiveWindow != NULL)
ShowWindow(hActiveWindow, SW_SHOW);
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
return 0;
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_DESTROY:
GlobalDeleteAtom(hkToggleHide);
UnregisterHotKey(0, hkToggleHide);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|