📄 lmidialog.cpp
字号:
case WM_CTLCOLORSTATIC:
//
// This makes the subcaption blue like other settings pages.
//
if ( LABEL_CAPTION == GetWindowLong( (HWND)lParam, GWL_ID ) )
SetTextColor( (HDC)wParam, RGB(0,0,255) );
return (BOOL)GetStockObject( WHITE_BRUSH );
case WM_DESTROY:
DeleteObject( pli->hfontCaption );
LocalFree( pli );
return TRUE;
case WM_CLOSE:
EndDialog( hDlg, 0 );
return FALSE;
case WM_COMMAND:
switch( LOWORD(wParam) )
{
case CONTROL_DOODLER:
if ( DIN_READY != HIWORD(wParam) )
return FALSE;
switch( pli->state )
{
case lmistate_get_access:
{
LONG lCompareFailed;
void* pEnteredDoodle;
void* pSecurityDoodle;
//
// User is submiting a response for security validation. Validate
// the doodle and figure out what to do next.
//
SendMessage( pli->hwndDoodler, DIM_CLEAR, 0, 0 ); // Don't let the doodle hang around.
//
// Get the doodle that was entered.
//
pEnteredDoodle = (void*)SendMessage( pli->hwndDoodler, DIM_GETDATA, 0, 0 );
//
// If no doodle was entered, keep ask for one.
//
if ( !pEnteredDoodle )
return FALSE;
//
// See if it's the same as the current security code.
//
pSecurityDoodle = LmiDialog_GetSecurity();
lCompareFailed = SendMessage( pli->hwndDoodler, DIM_COMPARE,
(WPARAM)pEnteredDoodle, (LPARAM)pSecurityDoodle );
LocalFree( pEnteredDoodle );
#ifdef DEBUG
//
// While debugging, don't lock the developer out if there isn't
// a security doodle for some reason.
//
if ( !pSecurityDoodle )
lCompareFailed = FALSE;
#endif
LocalFree( pSecurityDoodle );
//
// If the doodle is incorrect, alert the user and ask for another.
//
if ( lCompareFailed )
{
if ( pli->fPowerOn )
MessageBeep((UINT)-1);
else
MessageBox( hDlg, TEXT("Sorry. Your doodle is incorrect. Try again."),
g_pszAppletCaption, MB_OK|MB_ICONEXCLAMATION );
return FALSE;
}
//
// Power-on security validated
//
if ( pli->fPowerOn /* && !lCompareFailed */ )
return EndDialog( hDlg, 1 ), FALSE;
//
// If the user is requesting to disable security...
//
if ( BST_CHECKED == SendDlgItemMessage( hDlg, CHECKBOX_DISABLE, BM_GETCHECK, 0, 0 ) )
{
if ( LmiDialog_ClearSecurity() )
{
MessageBox( hDlg,
TEXT("Security is now disabled."),
g_pszAppletCaption,
MB_OK|MB_ICONINFORMATION );
}
else
{
MessageBox( hDlg,
TEXT("Security couldn't be disabled."),
g_pszAppletCaption,
MB_OK|MB_ICONINFORMATION );
}
EndDialog( hDlg, 1 );
return FALSE;
}
//
// User wants to enter new security info...
//
ShowWindow( GetDlgItem( hDlg, CHECKBOX_DISABLE ), SW_HIDE );
SendMessage( pli->hwndDoodler, DIM_SECURE, 0, 0 ); // Enable doodle feedback.
SetDlgItemText( hDlg, LABEL_PROMPT, TEXT("Enter new doodle:") );
//
// Next step is to get a new doodle
//
pli->state = lmistate_get_new;
return FALSE;
}
case lmistate_get_new:
//
// Remember new doodle
//
pli->pNewDoodle = (void*)SendMessage( pli->hwndDoodler, DIM_GETDATA, 0, 0 );
//
// Let the user see the resulting doodle geometry for a moment.
//
if ( pli->pNewDoodle )
Sleep( 1000 );
SendMessage( pli->hwndDoodler, DIM_CLEAR, 0, 0 );
//
// If there wasn't a valid doodle, keep trying.
//
if ( !pli->pNewDoodle )
return FALSE;
//
// To make sure that's what they wanted, ask them for that doodle again.
//
SetDlgItemText( hDlg, LABEL_PROMPT, TEXT("Repeat new doodle:") );
pli->state = lmistate_repeat_new;
return FALSE;
case lmistate_repeat_new:
{
LONG lCompareFailed;
//
// Remember repeat doodle
//
pli->pRepeatDoodle = (void*)SendMessage( pli->hwndDoodler, DIM_GETDATA, 0, 0 );
//
// Let the user see the resulting doodle geometry for a moment.
//
if ( pli->pRepeatDoodle )
Sleep( 1000 );
SendMessage( pli->hwndDoodler, DIM_CLEAR, 0, 0 );
//
// If there wasn't a valid doodle, keep trying.
//
if ( !pli->pRepeatDoodle )
return FALSE;
lCompareFailed = SendMessage( pli->hwndDoodler, DIM_COMPARE,
(WPARAM)pli->pNewDoodle, (LPARAM)pli->pRepeatDoodle );
//
// If the two doodles are the same, enable the security.
//
if ( (!lCompareFailed) &&
LmiDialog_EnableSecurity( hDlg, (BYTE*)pli->pNewDoodle,
SendMessage( pli->hwndDoodler, DIM_GETDATALEN, 0, 0 ) ) )
{
MessageBox( hDlg,
TEXT("Security is now enabled."),
g_pszAppletCaption,
MB_OK|MB_ICONINFORMATION );
}
LocalFree( pli->pNewDoodle );
LocalFree( pli->pRepeatDoodle );
//
// If the two doodles are different, go ask for a new doodle again.
//
if ( lCompareFailed )
{
MessageBox( hDlg,
TEXT("Oops! Your new doodles don't match. Try again."),
g_pszAppletCaption,
MB_OK|MB_ICONEXCLAMATION );
SetDlgItemText( hDlg, LABEL_PROMPT, TEXT("Enter new doodle:") );
pli->state = lmistate_get_new;
return FALSE;
}
return EndDialog( hDlg, 1 ), FALSE;
}
}
return FALSE;
case IDCANCEL:
try
{
#ifndef DEBUG
if ( pli->fPowerOn ) // You can't cancel out of
return FALSE; // power-on mode unless you're debugging.
#endif
LmiDialog_ClearSecurity();
}
catch(...)
{
}
return EndDialog( hDlg, 0 ), FALSE;
}
break;
}
return FALSE;
}
//
// Create a parent for the dialog.
//
HWND LmiDialog_CreateObjectWindow()
{
static BOOL fInitialized = FALSE;
if ( !fInitialized )
{
WNDCLASS wc;
memset( &wc, 0, sizeof(wc) );
wc.hInstance = g_hInstance;
wc.lpfnWndProc = DefWindowProc;
wc.lpszClassName = TEXT("CPL_LetMeIn");
RegisterClass( &wc );
}
return CreateWindowEx( 0, l_pszObjectClassName, TEXT(""), WS_VISIBLE, 0, 0, 0, 0, (HWND)0, (HMENU)0, g_hInstance, 0 );
}
//
// Show the dialog.
//
void LmiDialog_DoModal( HWND hwndParent, BOOL fPowerUp )
{
HWND hwndObject = (HWND)0;
HWND hwndPrevious;
hwndPrevious = FindWindow( l_pszObjectClassName, 0 );
if ( !fPowerUp ) // Update mode = control panel
{
if ( hwndPrevious )
{
SetForegroundWindow( hwndPrevious );
return;
}
if ( !LmiDialog_HaveControl( (HWND)0 ) )
return;
//
// The object window is necessary because we don't want our modal dialog to be a child
// of the Today window, otherwise the user can't see the Today window unless they
// close the applet.
//
hwndObject = LmiDialog_CreateObjectWindow();
}
else // Power-on
hwndObject = hwndParent; // Use whatever parent window startui gives us.
//
// Initialize the doodle control class.
//
LmiDoodler_Init( g_hInstance );
//
// Do the work.
//
DialogBoxParam( g_hInstance, MAKEINTRESOURCE(DIALOG_LETMEIN), hwndObject,
LmiDialog_DlgProc, (LPARAM)fPowerUp );
DestroyWindow( hwndObject );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -