home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1996 November
/
VPR9611A.ISO
/
ols
/
win31
/
hmize120
/
hmize120.lzh
/
SOURCE.LZH
/
LISTHOOK.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-14
|
6KB
|
290 lines
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include "global.h"
#include "hidemize.h"
#include "listhook.h"
#include "..\hidemaru\menu.h"
static BOOL fComboBox;
static char szSearch[100];
static HWND hwndSearch;
static char chSearch;
int CALLBACK _export SearchDlgProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) {
switch( message ) {
case WM_INITDIALOG:
{
RECT rc;
GetWindowRect( hwndSearch, &rc);
SetWindowPos( hwnd, NULL, rc.left, rc.top, 0, 0
, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
}
SendDlgItemMessage( hwnd, IDE_SEARCH, EM_LIMITTEXT, (WPARAM)(sizeof(szSearch)-1), 0L );
SetFocus( GetDlgItem( hwnd, IDE_SEARCH ) );
if( chSearch != '\0' ) {
SendDlgItemMessage( hwnd, IDE_SEARCH, WM_CHAR, chSearch, 1L );
}
return FALSE;
case WM_COMMAND:
if( wParam == IDOK ) {
GetDlgItemText( hwnd, IDE_SEARCH, szSearch, sizeof(szSearch) );
EndDialog( hwnd, IDOK );
} else if( wParam == IDCANCEL ) {
EndDialog( hwnd, IDCANCEL );
}
break;
}
return 0;
}
static void ToUpper( char* psz ) {
while( *psz != '\0' ) {
if( *psz >= 'a' && *psz <= 'z' ) {
*psz = *psz - 'a' + 'A';
}
psz ++;
}
}
static BOOL IsSearchAble( void ) {
if( fComboBox ) {
return FALSE;
}
DWORD dwStyle = GetWindowLong( hwndSearch, GWL_STYLE );
if( dwStyle & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE) ) {
if( (dwStyle & LBS_HASSTRINGS) == 0 ) {
return FALSE;
}
}
return TRUE;
}
static void SearchDown( void ) {
if( !IsSearchAble()
|| szSearch[0] == '\0' ) {
MessageBeep(0);
return;
}
int i = (int)SendMessage( hwndSearch, LB_GETCURSEL, 0, 0L );
if( i < 0 ) {
i = 0;
} else {
i ++;
}
for(;;) {
char sz[200];
int cch;
cch = (int)SendMessage( hwndSearch, LB_GETTEXTLEN, (WPARAM)i, 0L );
if( cch < 0 ) {
MessageBeep(0);
return;
}
if( cch < sizeof(sz) - 1 ) {
SendMessage( hwndSearch, LB_GETTEXT, (WPARAM)i, (LPARAM)(LPSTR)sz );
ToUpper( sz );
if( strstr( sz, szSearch ) != NULL ) {
SendMessage( hwndSearch, LB_SETCURSEL, (WPARAM)i, 0L );
SendMessage( GetParent( hwndSearch ), WM_COMMAND
, GetWindowWord( hwndSearch, GWW_ID )
, MAKELONG( hwndSearch, LBN_SELCHANGE ) );
break;
}
}
i ++;
}
}
static void SearchUp( void ) {
if( !IsSearchAble()
|| szSearch[0] == '\0' ) {
MessageBeep(0);
return;
}
int i = (int)SendMessage( hwndSearch, LB_GETCURSEL, 0, 0L );
if( i < 0 ) {
i = (int)SendMessage( hwndSearch, LB_GETCOUNT, 0, 0L ) - 1;
} else {
i --;
}
for(;;) {
char sz[200];
int cch;
if( i < 0 ) {
MessageBeep(0);
return;
}
cch = (int)SendMessage( hwndSearch, LB_GETTEXTLEN, (WPARAM)i, 0L );
if( cch < 0 ) {
MessageBeep(0);
return;
}
if( cch < sizeof(sz) - 1 ) {
SendMessage( hwndSearch, LB_GETTEXT, (WPARAM)i, (LPARAM)(LPSTR)sz );
ToUpper( sz );
if( strstr( sz, szSearch ) != NULL ) {
SendMessage( hwndSearch, LB_SETCURSEL, (WPARAM)i, 0L );
SendMessage( GetParent( hwndSearch ), WM_COMMAND
, GetWindowWord( hwndSearch, GWW_ID )
, MAKELONG( hwndSearch, LBN_SELCHANGE ) );
break;
}
}
i --;
}
}
static BOOL Search( char chSearchIn = '\0' ) {
chSearch = chSearchIn;
hwndSearch = hwndTarget;
if( !IsSearchAble() ) {
DebugOut( "IsSearchAble() returns FALSE.\x0d\x0a" );
return FALSE;
}
if( DialogBox( hInstance, "SEARCH", NULL, (DLGPROC)SearchDlgProc ) == IDOK ) {
ToUpper( szSearch );
SearchDown();
}
return TRUE;
}
BOOL ProcessListBoxCommand( int cmd ) {
DebugOut( "ListBoxCommand: " );
{
char sz[20];
itoa( cmd, sz, 10 );
DebugOut( sz );
DebugOut( "\x0d\x0a" );
}
switch( cmd ) {
case CMD_CURSOR_UP:
case CMD_FAST_UP:
SendVKey( VK_UP );
break;
case CMD_CURSOR_DOWN:
case CMD_FAST_DOWN:
SendVKey( VK_DOWN );
break;
case CMD_CURSOR_RIGHT:
SendVKey( VK_RIGHT );
break;
case CMD_CURSOR_LEFT:
SendVKey( VK_LEFT );
break;
case CMD_GO_LINE_TOP:
case CMD_GO_LINE_TOP2:
case CMD_GO_FILE_TOP:
SendVKey( VK_HOME );
break;
case CMD_GO_LINE_END:
case CMD_GO_LINE_END2:
case CMD_GO_FILE_END:
SendVKey( VK_END );
break;
case CMD_NEXT_PAGE:
case CMD_HALF_NEXT_PAGE:
SendVKey( VK_NEXT );
break;
case CMD_PREV_PAGE:
case CMD_HALF_PREV_PAGE:
SendVKey( VK_PRIOR );
break;
case CMD_FIND:
case CMD_FIND_DEFAULT_UP:
if( !Search() ) {
MessageBeep(0);
}
break;
case CMD_FIND_UP:
SearchUp();
break;
case CMD_FIND_DOWN:
SearchDown();
break;
default:
if( cmd >= CMD_MENU_1 && cmd <= CMD_MENU_8 ) {
CommandKeyMenu( cmd );
break;
}
MessageBeep(0);
return FALSE;
}
return TRUE;
}
BOOL ListBoxHookProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) {
static int cmd;
fComboBox = FALSE;
switch( message ) {
case WM_KEYDOWN:
if( wParam >= VK_F1 ) {
cmd = GetCommand( wParam );
if( cmd != 0 ) {
if( ProcessListBoxCommand( cmd ) ) {
return TRUE;
}
}
}
break;
case WM_CHAR:
if( wParam < ' ' ) {
cmd = GetCommand( wParam + '@' );
if( cmd != 0 ) {
if( ProcessListBoxCommand( cmd ) ) {
return TRUE;
}
}
} else if( wParam > ' ' && (afConfig & FLAG_HOOK_LISTBOX_SEARCH) != 0 ) {
DebugOut( "ListBox: search\x0d\x0a" );
if( Search( wParam ) ) {
return TRUE;
}
}
break;
}
return FALSE;
}
BOOL ComboBoxHookProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) {
static int cmd;
fComboBox = TRUE;
switch( message ) {
case WM_KEYDOWN:
if( wParam >= VK_F1 ) {
cmd = GetCommand( wParam );
if( cmd != 0 ) {
if( ProcessListBoxCommand( cmd ) ) {
return TRUE;
}
}
}
break;
case WM_CHAR:
if( wParam < ' ' ) {
cmd = GetCommand( wParam + '@' );
if( cmd != 0 ) {
if( ProcessListBoxCommand( cmd ) ) {
return TRUE;
}
}
}
break;
}
return FALSE;
}