home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1996 November
/
VPR9611A.ISO
/
ols
/
win31
/
hmize120
/
hmize120.lzh
/
SOURCE.LZH
/
HIDEMIZE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-15
|
10KB
|
327 lines
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include "global.h"
#include "hidemize.h"
#include "..\hidemaru\menu.h"
#include "edithook.h"
#include "listhook.h"
HINSTANCE hInstance;
BYTE abKeyState[256];
struct SHAREMEMSTRUCT FAR* pshare;
UINT afConfig;
WNDCLASSENUM wndclass;
static char szEnv[] = "Env";
static char szHidemizeKey[] = "Hidemize";
static char szHidemaruIni[] = "HIDEMARU.INI";
static char szEdit[] = "Edit";
static char szListBox[] = "ListBox";
static char szComboBox[] = "ComboBox";
/***************** 秀丸のshare.hからもってきた(秀丸化計画が.Cのため)***/
// ちなみに構造体はパックする必要がある。
#define KEYASSIGN_FUNC 0
#define KEYASSIGN_HOME 12
#define KEYASSIGN_END 13
#define KEYASSIGN_BACK 14
#define KEYASSIGN_RETURN 15
#define KEYASSIGN_INS 16
#define KEYASSIGN_DEL 17
#define KEYASSIGN_UP 18
#define KEYASSIGN_DOWN 19
#define KEYASSIGN_RIGHT 20
#define KEYASSIGN_LEFT 21
#define KEYASSIGN_ASCII 22
#define KEYASSIGN_LESS 54
#define KEYASSIGN_GREAT 55
typedef SHAREMEMSTRUCT FAR* (FAR PASCAL *PGETHIDEMARUSHAREMEM)( void );
HWND hwndClient;
HWND hwndTarget;
static char szTitle[] = "秀丸化計画";
static char szAppName[] = "Hidemizer";
char near szMenuParentClassName[] = "HidemizeMenuParent";
static HHOOK hhookSysMsg;
static HANDLE hmodHidemaruLib;
int GetCommand( WPARAM wParam ) {
GetKeyboardState( (BYTE FAR*)abKeyState );
int cmd = 0;
if( abKeyState[VK_CONTROL] & 0x80 ) {
BYTE FAR* pb;
if( abKeyState[VK_SHIFT] & 0x80 ) {
pb = pshare->key.ctrlshift;
} else {
pb = pshare->key.ctrl;
}
if( wParam >= VK_F1 && wParam <= VK_F12 ) {
cmd = pb[ wParam - VK_F1 ];
} else if( wParam >= '@' && wParam <= 'Z' + 5 ) {
cmd = pb[ wParam - '@' + KEYASSIGN_ASCII ];
// } else if( wParam == VK_HOME ) {
// cmd = pb[ KEYASSIGN_HOME ];
// } else if( wParam == VK_END ) {
// cmd = pb[ KEYASSIGN_END ];
} else if( wParam == VK_RETURN ) {
cmd = pb[ KEYASSIGN_RETURN ];
} else if( wParam == VK_UP ) {
cmd = pb[ KEYASSIGN_UP ];
} else if( wParam == VK_DOWN ) {
cmd = pb[ KEYASSIGN_DOWN ];
} else if( wParam == VK_RIGHT ) {
cmd = pb[ KEYASSIGN_RIGHT ];
} else if( wParam == VK_LEFT ) {
cmd = pb[ KEYASSIGN_LEFT ];
// } else if( wParam == VK_BACK ) {
// cmd = pb[ KEYASSIGN_BACK ];
// } else if( wParam == VK_INSERT ) {
// cmd = pb[ KEYASSIGN_INS ];
// } else if( wParam == VK_DELETE ) {
// cmd = pb[ KEYASSIGN_DEL ];
} else if( wParam == 0x00BC ) {
cmd = pb[ KEYASSIGN_LESS ];
} else if( wParam == 0x00BE || wParam == 0x001D ) {
cmd = pb[ KEYASSIGN_GREAT ];
} else if( wParam == 0x00DE ) {
cmd = pb[ 0x1E + KEYASSIGN_ASCII ]; // '^'
} else if( wParam == 0x00C0 ) {
cmd = pb[ 0 + KEYASSIGN_ASCII ]; // '@'
}
} else if( abKeyState[VK_SHIFT] & 0x80 ) {
if( wParam >= VK_F1 && wParam <= VK_F12 ) {
cmd = pshare->key.shift[ wParam - VK_F1 ];
} else if( wParam == VK_RETURN ) {
cmd = pshare->key.shift[ KEYASSIGN_RETURN ];
}
} else {
if( wParam >= VK_F1 && wParam <= VK_F12 ) {
cmd = pshare->key.func[ wParam - VK_F1 ];
}
}
return cmd;
}
extern "C" int CALLBACK _export SetupDlgProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) {
switch( message ) {
case WM_INITDIALOG:
{
RECT rc;
GetWindowRect( hwnd, &rc );
SetWindowPos( hwnd, NULL
, (GetSystemMetrics( SM_CXSCREEN ) - (rc.right - rc.left)) / 2
, (GetSystemMetrics( SM_CYSCREEN ) - (rc.bottom - rc.top)) / 2
, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
}
if( afConfig & FLAG_HOOK_CTRL_XCV ) {
CheckDlgButton( hwnd, IDB_HOOK_CTRL_XCV, TRUE );
}
if( afConfig & FLAG_HOOK_RBUTTON ) {
CheckDlgButton( hwnd, IDB_HOOK_RBUTTON, TRUE );
}
if( afConfig & FLAG_HOOK_LISTBOX_SEARCH ) {
CheckDlgButton( hwnd, IDB_HOOK_LISTBOX_SEARCH, TRUE );
}
return TRUE;
case WM_COMMAND:
if( wParam == IDOK ) {
afConfig = 0;
if( IsDlgButtonChecked( hwnd, IDB_HOOK_CTRL_XCV ) ) {
afConfig |= FLAG_HOOK_CTRL_XCV;
}
if( IsDlgButtonChecked( hwnd, IDB_HOOK_RBUTTON ) ) {
afConfig |= FLAG_HOOK_RBUTTON;
}
if( IsDlgButtonChecked( hwnd, IDB_HOOK_LISTBOX_SEARCH ) ) {
afConfig |= FLAG_HOOK_LISTBOX_SEARCH;
}
char sz[20];
WritePrivateProfileString( szEnv, szHidemizeKey, itoa( afConfig, sz, 10 )
, szHidemaruIni );
EndDialog( hwnd, IDOK );
} else if( wParam == IDCANCEL ) {
EndDialog( hwnd, IDCANCEL );
} else if( wParam == IDB_HELP ) {
static char szEditor[200];
char* pch;
GetProfileString( "Extensions", "txt", "notepad.exe ^", szEditor, sizeof(szEditor) );
pch = strchr( szEditor, '^' );
if( pch != NULL ) *pch = '\0';
GetModuleFileName( hInstance, szEditor + strlen(szEditor), 100 );
strcpy( szEditor + strlen(szEditor) - 3, "TXT" );
WinExec( szEditor, SW_SHOWNORMAL );
}
break;
}
return 0;
}
static void near SetupDialog( void ) {
DialogBox( hInstance, "SETUP", hwndClient
, (DLGPROC)SetupDlgProc );
}
extern "C" LONG CALLBACK _export ClientWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) {
switch( message ) {
case WM_CREATE:
{
HMENU hmenu = GetSystemMenu( hwnd, FALSE );
ModifyMenu( hmenu, SC_RESTORE, MF_BYCOMMAND | MF_STRING | MF_ENABLED
, SC_RESTORE, "設定(&S)..." );
DeleteMenu( hmenu, SC_SIZE, MF_BYCOMMAND);
DeleteMenu( hmenu, SC_MINIMIZE, MF_BYCOMMAND);
DeleteMenu( hmenu, SC_MAXIMIZE, MF_BYCOMMAND);
}
return TRUE;
case WM_SYSCOMMAND:
if( wParam == CMD_SETUP ) {
SetupDialog();
} else if( wParam == SC_RESTORE || wParam == SC_MAXIMIZE ) {
PostMessage( hwnd, WM_SYSCOMMAND, CMD_SETUP, 0L );
} else {
return DefWindowProc( hwnd, WM_SYSCOMMAND, wParam, lParam );
}
break;
case WM_QUERYOPEN:
PostMessage( hwnd, WM_SYSCOMMAND, CMD_SETUP, 0L );
return 0L;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
case WM_USER:
EditHookRButtonDown( (HWND)wParam );
break;
default:
return DefWindowProc( hwnd, message, wParam, lParam );
}
return 0L;
}
extern "C" LRESULT CALLBACK _export SysMsgProc( int code, WPARAM wParam, LPARAM lParam ) {
MSG FAR* pmsg;
if( code == MSGF_DIALOGBOX ) {
pmsg = (MSG FAR*)lParam;
if( pmsg->message == WM_SYSKEYDOWN ) {
if( pmsg->wParam == VK_F10 ) {
pmsg->message = WM_KEYDOWN;
}
} else if( pmsg->message == WM_CHAR ) {
if( pmsg->wParam < ' ' ) {
int cmd = GetCommand( pmsg->wParam + '@' );
if( cmd == CMD_RETURN ) {
pmsg->message = WM_KEYDOWN;
pmsg->wParam = VK_RETURN;
}
}
}
if( IsWindow( pmsg->hwnd ) ) {
char szClassName[20];
GetClassName( pmsg->hwnd, szClassName, sizeof(szClassName) );
hwndTarget = pmsg->hwnd;
if( strcmp( szClassName, szEdit ) == 0 ) {
wndclass = CLASS_EDIT;
if( EditHookProc( pmsg->hwnd, pmsg->message, pmsg->wParam, pmsg->lParam ) ) return 1;
} else if( strcmp( szClassName, szListBox ) == 0 ) {
wndclass = CLASS_LISTBOX;
if( ListBoxHookProc( pmsg->hwnd, pmsg->message, pmsg->wParam, pmsg->lParam ) ) return 1;
} else if( strcmp( szClassName, szComboBox ) == 0 ) {
wndclass = CLASS_COMBOBOX;
if( ComboBoxHookProc( pmsg->hwnd, pmsg->message, pmsg->wParam, pmsg->lParam ) ) return 1;
}
}
} else if( code == MSGF_MENU ) {
pmsg = (MSG FAR*)lParam;
if( pmsg->message == WM_CHAR ) {
if( pmsg->wParam < ' ' ) {
int cmd = GetCommand( pmsg->wParam + '@' );
if( cmd == CMD_RETURN ) {
pmsg->message = WM_KEYDOWN;
pmsg->wParam = VK_RETURN;
} else if( cmd == CMD_CURSOR_UP ) {
pmsg->message = WM_KEYDOWN;
pmsg->wParam = VK_UP;
} else if( cmd == CMD_CURSOR_DOWN ) {
pmsg->message = WM_KEYDOWN;
pmsg->wParam = VK_DOWN;
} else if( cmd == CMD_CURSOR_RIGHT ) {
pmsg->message = WM_KEYDOWN;
pmsg->wParam = VK_RIGHT;
} else if( cmd == CMD_CURSOR_LEFT ) {
pmsg->message = WM_KEYDOWN;
pmsg->wParam = VK_LEFT;
}
}
}
}
return CallNextHookEx( hhookSysMsg, code, wParam, lParam );
}
static BOOL near LoadHidemaruLib( void ) {
hmodHidemaruLib = LoadLibrary( "HIDEMSUB.DLL" );
if( hmodHidemaruLib == NULL ) {
MessageBox( NULL, "HIDEMSUB.DLL not found."
, NULL, MB_OK | MB_ICONHAND );
return FALSE;
}
PGETHIDEMARUSHAREMEM pfunc = (PGETHIDEMARUSHAREMEM)GetProcAddress( hmodHidemaruLib, "GETHIDEMARUSHAREDMEM" );
pshare = pfunc();
return TRUE;
}
int PASCAL WinMain( HANDLE hInstanceIn, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {
MSG msg;
WNDCLASS wc;
hInstance = hInstanceIn;
if( (hwndClient = FindWindow( szAppName, NULL )) != NULL) {
BringWindowToTop( hwndClient );
return 1;
}
if( !LoadHidemaruLib() ) {
return FALSE;
}
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)ClientWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_HIDEMIZE ) );
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;
if( !RegisterClass( &wc ) ) {
return FALSE;
}
hwndClient = CreateWindow( szAppName, szTitle
, WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0
, HWND_DESKTOP
, NULL, hInstance, NULL );
if( hwndClient == NULL ) {
return FALSE;
}
ShowWindow( hwndClient, SW_SHOWMINNOACTIVE );
UpdateWindow( hwndClient );
afConfig = GetPrivateProfileInt( szEnv, szHidemizeKey
, FLAG_HOOK_CTRL_XCV | FLAG_HOOK_RBUTTON | FLAG_HOOK_LISTBOX_SEARCH
, szHidemaruIni );
hhookSysMsg = SetWindowsHookEx( WH_SYSMSGFILTER, (HOOKPROC)SysMsgProc, hInstance, NULL );
while( GetMessage( &msg, NULL, 0, 0 ) ) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
UnhookWindowsHookEx( hhookSysMsg );
FreeLibrary( hmodHidemaruLib );
return TRUE;
}