📄 smbrdr.c
字号:
// SMBRDR.C
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <shellapi.h>
#include <stdlib.h>
#include "srfunc.h"
#include "resource.h"
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
);
INT_PTR CALLBACK SmbRdrDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK ProviderDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK StatisticsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
#define APP_TITLE TEXT("SMB MiniRDR")
#define INSTALL_NOTICE TEXT("Mini Redirector is not completely installed.\n") \
TEXT("Do you wish to complete this now?")
#define INSTALL_REPLY TEXT("Sorry, the install must finish before using the SMB MiniRDR.")
#define INSTALL_FAIL APP_TITLE TEXT(" installation failed to complete.")
#define INSTALL_FILES APP_TITLE TEXT(" necessary files aren't present.")
#define INSTALL_OTHER APP_TITLE TEXT(" not properly installed.")
#define NOSTATS TEXT("Statistics display is unimplemented at this time.\n") \
TEXT("Please check back with the next version.")
#define OPERROR TEXT("Error attempting operation.")
#define TASK_TIP APP_TITLE TEXT(" Control")
#define WM_SHNOTIFY WM_USER + 100
#define WM_RDRSTATECHANGE WM_USER + 200
#define TIMER_ID 54321
typedef struct _DLGDATASTRUCT
{
HWND hDlg;
ULONG_PTR RdrState;
HBRUSH hRedBrush;
HBRUSH hGrnBrush;
HBRUSH hBluBrush;
HBRUSH hWhtBrush;
HBRUSH hYelBrush;
HINSTANCE hInstance;
ULONG_PTR ElapsedStartTime;
ULONG_PTR Action;
HANDLE hActionThread;
HANDLE hBusyThread;
HANDLE hBusySignal;
} DLGDATASTRUCT, *PDLGDATASTRUCT;
VOID InitiateAction( PDLGDATASTRUCT pdds );
DWORD ActionProc( PDLGDATASTRUCT pdds );
VOID IndicateWait( PDLGDATASTRUCT pdds );
VOID UnindicateWait( PDLGDATASTRUCT pdds );
DWORD BusyProc( PDLGDATASTRUCT pdds );
#define GetDDS( _x_ ) (PDLGDATASTRUCT) GetWindowLongPtr( _x_, DWLP_USER )
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HANDLE hSingleInstance;
msg.wParam = 1;
hSingleInstance = CreateMutex( NULL, 0, APP_TITLE TEXT(" MUTEX") );
if ( GetLastError( ) != ERROR_ALREADY_EXISTS )
{
BOOL RdrIsInstalled;
ULONG_PTR SetupStatus;
SetupStatus = RdrInstallCheck( );
RdrIsInstalled = ( SetupStatus == SETUP_COMPLETE );
if ( !RdrIsInstalled )
{
int answer;
if ( SetupStatus == SETUP_INCOMPLETE )
{
answer = MessageBox( NULL, INSTALL_NOTICE, APP_TITLE, MB_YESNOCANCEL | MB_DEFBUTTON1 | MB_ICONEXCLAMATION );
if ( answer == IDYES )
{
if ( !( RdrIsInstalled = RdrCompleteSetup( ) ) )
{
MessageBox( NULL, INSTALL_FAIL, APP_TITLE, MB_OK | MB_ICONERROR );
}
}
else if ( answer == IDNO )
{
MessageBox( NULL, INSTALL_REPLY, APP_TITLE, MB_OK | MB_ICONINFORMATION );
}
}
else if ( SetupStatus == SETUP_MISSING_FILE )
{
MessageBox( NULL, INSTALL_FILES, APP_TITLE, MB_OK | MB_ICONERROR );
}
else
{
MessageBox( NULL, INSTALL_OTHER, APP_TITLE, MB_OK | MB_ICONERROR );
}
}
if ( RdrIsInstalled )
{
HWND hDlg;
DLGDATASTRUCT dds;
dds.hRedBrush = CreateSolidBrush( RGB( 255, 0, 0 ) );
dds.hGrnBrush = CreateSolidBrush( RGB( 0, 255, 0 ) );
dds.hBluBrush = CreateSolidBrush( RGB( 0, 0, 255 ) );
dds.hWhtBrush = CreateSolidBrush( RGB( 255, 255, 255 ) );
dds.hYelBrush = CreateSolidBrush( RGB( 255, 255, 127 ) );
dds.hInstance = hInstance;
dds.ElapsedStartTime = 0;
dds.Action = 0;
dds.hActionThread = NULL;
dds.hBusyThread = NULL;
dds.hBusySignal = NULL;
dds.hDlg = NULL;
dds.RdrState = RDR_NULL_STATE;
hDlg = CreateDialogParam( hInstance, MAKEINTRESOURCE(IDD_SMBRDR), NULL, SmbRdrDlgProc, (LPARAM) &dds );
if ( hDlg )
{
NOTIFYICONDATA nid;
dds.hDlg = hDlg;
nid.cbSize = sizeof( NOTIFYICONDATA );
nid.hWnd = hDlg;
nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
nid.uID = IDI_SMBRDR;
nid.uCallbackMessage = WM_SHNOTIFY;
nid.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE(IDI_SMBRDR ) );
lstrcpy( nid.szTip, TASK_TIP );
Shell_NotifyIcon( NIM_ADD, &nid );
PostMessage( hDlg, WM_SETICON, ICON_SMALL, (LPARAM) nid.hIcon );
PostMessage( hDlg, WM_SETICON, ICON_BIG, (LPARAM) nid.hIcon );
while ( GetMessage( &msg, NULL, 0, 0 ) )
{
if ( !IsWindow( hDlg ) || !IsDialogMessage( hDlg, &msg ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
Shell_NotifyIcon( NIM_DELETE, &nid );
if ( nid.hIcon )
{
DestroyIcon( nid.hIcon );
}
}
DeleteObject( dds.hRedBrush );
DeleteObject( dds.hGrnBrush );
DeleteObject( dds.hBluBrush );
DeleteObject( dds.hWhtBrush );
DeleteObject( dds.hYelBrush );
if ( dds.hActionThread )
{
WaitForSingleObject( dds.hActionThread, INFINITE );
CloseHandle( dds.hActionThread );
dds.hActionThread = NULL;
}
}
}
else
{
HWND hDlg = FindWindow( NULL, APP_TITLE );
SetForegroundWindow( hDlg );
if ( !IsWindowVisible( hDlg ) )
{
ShowWindow( hDlg, SW_SHOWNORMAL );
}
}
CloseHandle( hSingleInstance );
return (int) msg.wParam;
}
INT_PTR CALLBACK SmbRdrDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch ( message )
{
case WM_INITDIALOG:
{
PDLGDATASTRUCT pdds = (PDLGDATASTRUCT) lParam;
RECT rect;
ULONG_PTR CurrentState;
SetWindowLongPtr(hDlg, DWLP_USER, lParam);
CurrentState = RdrGetInitialState( );
CheckRadioButton( hDlg, IDC_DRVLOAD, IDC_DRVUNLOAD,
CurrentState > RDR_UNLOADING ? IDC_DRVLOAD : IDC_DRVUNLOAD );
CheckRadioButton( hDlg, IDC_RDRSTART, IDC_RDRSTOP,
CurrentState > RDR_STOPPING ? IDC_RDRSTART : IDC_RDRSTOP );
pdds->Action = ACTION_NONE;
PostMessage( hDlg, WM_RDRSTATECHANGE, 0, CurrentState );
SetDlgItemText( hDlg, IDC_STARTTIME, TEXT( "00:00" ) );
SetTimer( hDlg, TIMER_ID, 1000, NULL );
GetWindowRect( hDlg, &rect );
rect.right -= rect.left;
rect.bottom -= rect.top;
rect.left = ( GetSystemMetrics( SM_CXSCREEN ) - rect.right ) / 2;
rect.top = ( GetSystemMetrics( SM_CYSCREEN ) - rect.bottom ) / 3;
MoveWindow( hDlg,
rect.left,
rect.top,
rect.right,
rect.bottom,
FALSE );
}
break;
case WM_COMMAND:
{
PDLGDATASTRUCT pdds = GetDDS( hDlg );
switch ( LOWORD( wParam ) )
{
case IDC_DRVLOAD:
case IDC_DRVUNLOAD:
{
if ( HIWORD( wParam ) == BN_CLICKED )
{
ULONG_PTR NewState, action;
action = ( IsDlgButtonChecked( hDlg, IDC_DRVLOAD ) == BST_CHECKED ) ?
ACTION_LOAD : ACTION_UNLOAD;
NewState = RdrGetNextState( action, pdds->RdrState );
if ( NewState != RDR_NULL_STATE )
{
pdds->Action = action;
PostMessage( hDlg, WM_RDRSTATECHANGE, 0, NewState );
}
}
}
break;
case IDC_RDRSTART:
case IDC_RDRSTOP:
{
if ( HIWORD( wParam ) == BN_CLICKED )
{
ULONG_PTR NewState, action;
action = ( IsDlgButtonChecked( hDlg, IDC_RDRSTART ) == BST_CHECKED ) ?
ACTION_START : ACTION_STOP;
NewState = RdrGetNextState( action, pdds->RdrState );
if ( NewState != RDR_NULL_STATE )
{
pdds->Action = action;
PostMessage( hDlg, WM_RDRSTATECHANGE, 0, NewState );
}
}
}
break;
case IDC_STATISTICS:
MessageBox( hDlg, NOSTATS, APP_TITLE, MB_OK | MB_ICONINFORMATION );
//DialogBox( pdds->hInstance, MAKEINTRESOURCE(IDD_STATISTICS), hDlg, StatisticsDlgProc );
break;
case IDC_PROVIDER:
DialogBox( pdds->hInstance, MAKEINTRESOURCE(IDD_PROVIDER), hDlg, ProviderDlgProc );
break;
case IDC_HIDE:
{
PostMessage( hDlg, WM_SYSCOMMAND, SC_MINIMIZE, -1 );
}
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -