📄 xtractor.c
字号:
/*
* xtractor.c - Copyright (C) 1999,2000 Jay A. Key
*
* Main file for CD-DA X-Tractor, a CD audio extaction tool for 32-bit
* windows platforms.
*
**********************************************************************
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <windows.h>
#include <wingdi.h>
#include <commctrl.h>
#include <math.h>
#include "akrip/akrip32.h"
#include "resources.h"
#include "trackwnd.h"
#include "globals.h"
#include "id3.h"
#include "riptracks.h"
#include "statusbar.h"
#include "cddbdlg.h"
#include "config.h"
#if (__IBMC__) /* BWT (20000127) */
WINCOMMCTRLAPI void WINAPI InitCommonControls(void); /* BWT (20000127) */
#endif /* BWT (20000127) */
void logMessage( int which, UINT uMsg, WPARAM wParam, LPARAM lParam );
LRESULT CALLBACK Edit0Proc( HWND, UINT, WPARAM, LPARAM );
LRESULT CALLBACK Edit1Proc( HWND, UINT, WPARAM, LPARAM );
LRESULT CALLBACK Edit2Proc( HWND, UINT, WPARAM, LPARAM );
LRESULT CALLBACK akripWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
HWND createToolbar( HWND hWnd, HINSTANCE hInst );
HWND createHeader( HWND hWnd, HINSTANCE hInst );
void doPaint( HWND hWnd );
void ComputeHeaderPos( HWND hParent );
void handleToolbarNotify( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
int WindowHeight( HWND hWnd );
void RefreshTrackList( void );
int DoConfig( HWND hParent, HINSTANCE hInst, UINT uiStartPage );
void InitAKRip( void );
void DeinitAKRip( void );
void MSB2DWORD( DWORD *d, BYTE *b );
int readRegSZ( HKEY hKey, LPCTSTR lpszValue, LPSTR lpszData, DWORD dwDataLen );
int readRegDWORD( HKEY hKey, LPCTSTR lpszValue, DWORD *pdw );
int doTrackContextMenu( HWND hParent, HWND hChild, LPARAM lParam );
BOOL InitGauge( HINSTANCE hInst );
BOOL RipTrackDlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
BOOL loadBladeEnc( void );
void disableAutoPlay( void );
void restoreAutoPlay( void );
void GetEditItemText( int iCtlId, HWND hCtl );
BOOL CALLBACK ID3InfoDlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
void SetEditItemText( int iCtlId, char *s );
void CheckEnableID3MenuItem( HWND hWnd );
void CheckEnableCDDBMenuItem( HWND hWnd );
void CheckEnableHiColorMenuItem( HWND hWnd );
BOOL CALLBACK AboutDialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
void InitBmpPanel( void );
void DynamicAboutDialog( HWND hParent );
void ShowHelpFile( HWND hWnd, int topic );
void DiffTimeToString( double d, char *buf );
static void GetLineFromBuf( char *tgt, char **src, int len );
void DoCDDBQuery( HWND hWnd );
void SetTrackText( char *buf, int i );
DWORD DoCDDBQueryThread( LPVOID lpParam );
HCDROM findAvailableCD( void );
BOOL RipTrackSegment( HWND hParent, HWND hTrckWnd );
BOOL CALLBACK CDPropertiesDlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
void dbprintf( char *fmt, ... );
DWORD GetDllVersion( LPCTSTR lpszDllName );
LRESULT CALLBACK SubToolbarProc( HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam );
HIMAGELIST CreateToolbarImageList( HWND hWnd, HINSTANCE hInst, int idResource );
int AddToolbarImages( HINSTANCE hInst, HWND hWnd, BOOL bSysColorChange, BOOL bToggleHiColor );
BOOL DisplayIsHiColor( void );
char szClassName[] = "xtractor";
static int iStatusHeight = 0;
static int iToolbarHeight;
HWND hStatus = NULL;
HWND hTrackWnd = NULL;
static HWND hToolbar = NULL;
static HWND hEditArtist, hEditAlbum;
static HIMAGELIST hImgLists[3] = { NULL, NULL, NULL };
static WNDPROC lpfnToolbarProc = NULL;
static char regKeyName[] = "SOFTWARE\\AKSoft\\X-Tractor";
static unsigned long ulOldAutorun = (unsigned long)0x95;
static char szOldAutoPlay[256] = "Play";
static char regAutoPlay[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer";
static char regAutoAudioCD[] = "AudioCD\\Shell";
/*
* Global variables
*/
int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszCmdLine,
int nCmdShow )
{
WNDCLASSEX wc;
HWND hWnd;
MSG msg;
RECT rc;
static int aStatusWidths[3] = {40, 290,-1};
INITCOMMONCONTROLSEX ic;
ic.dwSize = sizeof(ic);
ic.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&ic);
ghInstance = hInst;
hPrevInst = hPrevInst;
lpszCmdLine = lpszCmdLine;
InitTrackWnd( hInst );
InitAKRip( );
InitGauge( hInst );
bMP3 = loadBladeEnc();
InitBmpPanel();
ZeroMemory( &wc, sizeof(wc) );
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)akripWndProc;
wc.hInstance = hInst;
wc.hIcon = LoadIcon( hInst, "ALTRIP3" );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = szClassName;
wc.lpszMenuName = "akripMenu";
wc.hIconSm = LoadIcon( hInst, "ALTRIP3" );
if ( !RegisterClassEx( &wc ) )
return FALSE;
hWnd = CreateWindowEx( WS_EX_APPWINDOW, szClassName, "CD-DA X-Tractor",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
540, 400,
NULL, NULL, hInst, NULL );
if ( !hWnd )
return FALSE;
hToolbar = createToolbar( hWnd, hInst );
iToolbarHeight = WindowHeight( hToolbar );
hStatus = CreateStatusWindow( WS_VISIBLE | WS_CHILD | SBARS_SIZEGRIP,
"", hWnd, IDM_STATUSBAR );
SendMessage( hStatus, SB_SETPARTS, 3, (LPARAM)aStatusWidths );
iStatusHeight = WindowHeight( hStatus );
GetClientRect( hWnd, &rc );
rc.top += iToolbarHeight;
rc.bottom -= iStatusHeight;
hTrackWnd = createTrackWnd( hWnd, hInst, IDM_TRACKWND, &rc );
if ( bAutoTOC )
{
SendMessage( hWnd, WM_COMMAND, MAKEWPARAM( IDM_REFRESH, BN_CLICKED ), 0L );
if ( bAutoCheck )
SendMessage( hTrackWnd, WM_CHECKTRACK, (WPARAM)ALLTRACKS, (LPARAM)TRUE );
}
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
disableAutoPlay();
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
restoreAutoPlay();
if ( hImgLists[0] ) ImageList_Destroy( hImgLists[0] );
if ( hImgLists[1] ) ImageList_Destroy( hImgLists[1] );
if ( hImgLists[2] ) ImageList_Destroy( hImgLists[2] );
return msg.wParam;
}
LRESULT CALLBACK akripWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
RECT rc;
switch( uMsg )
{
case WM_CREATE:
CheckEnableID3MenuItem( hWnd );
CheckEnableCDDBMenuItem( hWnd );
if ( GetDllVersion( "comctl32.dll" ) < MAKELONG(4,71) )
{
// disallow switching between 8- and 24-bit bitmaps in the toolbar
bHiColor = FALSE;
EnableMenuItem( GetMenu( hWnd ), IDM_HICOLOR, MF_BYCOMMAND | MF_GRAYED );
}
CheckEnableHiColorMenuItem( hWnd );
break;
case WM_COMMAND:
switch( LOWORD( wParam ) )
{
case IDM_EXIT:
DestroyWindow( hWnd );
break;
case IDM_REFRESH:
if ( !bInCDDBQuery )
{
RefreshTrackList( );
asSetID3Info( ID3_ERASE, NULL, 0 );
SetEditItemText( IDE_ARTIST, "" );
SetEditItemText( IDE_ALBUM, "" );
if ( bAutoCheck )
SendMessage( hTrackWnd, WM_CHECKTRACK, (WPARAM)ALLTRACKS, (LPARAM)TRUE );
if ( bCDDB )
DoCDDBQuery( hWnd );
}
break;
case IDM_RIP:
DialogBoxParam( ghInstance, "RipTrackDialog", hWnd, (DLGPROC)RipTrackDlgProc, (LPARAM)hTrackWnd );
break;
case IDM_ID3:
case IDM_ID3TAGEDIT:
DialogBox( ghInstance, "ID3InfoDialog", hWnd, (DLGPROC)ID3InfoDlgProc );
break;
case IDM_CDPARMS:
DialogBox( ghInstance, "CDPropertiesDialog", hWnd, (DLGPROC)CDPropertiesDlgProc );
break;
case IDM_CDSETTINGS:
case IDM_OPTIONS:
DoConfig( hWnd, ghInstance, 0 );
break;
case IDM_DIRSETTINGS:
DoConfig( hWnd, ghInstance, 1 );
break;
case IDM_MP3SETTINGS:
DoConfig( hWnd, ghInstance, 2 );
break;
case IDM_CDDBSETTINGS:
DoConfig( hWnd, ghInstance, 3 );
break;
case IDM_CHECKALL:
SendMessage( hTrackWnd, WM_CHECKTRACK, ALLTRACKS, (LPARAM)TRUE );
break;
case IDM_INVERT:
SendMessage( hTrackWnd, WM_INVERTCHECK, ALLTRACKS, 0L );
break;
case IDM_RENAME:
SendMessage( hTrackWnd, WM_RENSELTRACK, 0, 0L );
break;
case IDE_ARTIST:
case IDE_ALBUM:
if ( (int)HIWORD( wParam ) == EN_CHANGE )
GetEditItemText( (int)LOWORD( wParam ), (HWND)lParam );
break;
case IDM_ENABLEID3:
bID3 = !bID3;
CheckEnableID3MenuItem( hWnd );
break;
case IDM_ENABLECDDB:
bCDDB = !bCDDB;
CheckEnableCDDBMenuItem( hWnd );
break;
case IDM_HICOLOR:
bHiColor = !bHiColor;
CheckEnableHiColorMenuItem( hWnd );
AddToolbarImages( ghInstance, hToolbar, FALSE, TRUE );
break;
case IDM_ABOUT:
DynamicAboutDialog( hWnd );
break;
case IDM_HELPTOPICS:
ShowHelpFile( hWnd, IDM_HELPTOPICS );
break;
case IDM_RIPSEGMENT:
RipTrackSegment( hWnd, hTrackWnd );
break;
}
break;
case WM_DESTROY:
DeinitAKRip( );
PostQuitMessage( 0 );
break;
case WM_NOTIFY:
switch( wParam )
{
case IDM_TOOLBAR:
handleToolbarNotify( hWnd, uMsg, wParam, lParam );
break;
}
break;
case WM_SYSCOLORCHANGE:
SendMessage( hToolbar, uMsg, wParam, lParam );
SendMessage( hTrackWnd, uMsg, wParam, lParam );
break;
case WM_PAINT:
doPaint( hWnd );
break;
case WM_SIZE:
SendMessage( hToolbar, TB_AUTOSIZE, 0, 0L );
GetClientRect( hWnd, &rc );
MoveWindow( hStatus, 0, rc.bottom - iStatusHeight, rc.right - rc.left, rc.bottom, TRUE );
rc.top += iToolbarHeight;
rc.bottom -= iStatusHeight;
MoveWindow( hTrackWnd, 0, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE );
break;
default:
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
return 0L;
}
/*
* Subclass wndproc for Toolbar. Handles the WM_SYSCOLORCHANGE and
* also the tooltip messages
*/
#define WM_SETSUBCLASSPROC (WM_USER+999)
LRESULT CALLBACK SubToolbarProc( HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam )
{
LPTOOLTIPTEXT lpt = (LPTOOLTIPTEXT)lParam;
if ( uMsg == WM_SETSUBCLASSPROC )
{
lpfnToolbarProc = (WNDPROC)GetWindowLong( hWnd, GWL_WNDPROC );
SetWindowLong( hWnd, GWL_WNDPROC, (LONG)SubToolbarProc );
return 0L;
}
switch( uMsg )
{
case WM_SYSCOLORCHANGE:
AddToolbarImages( ghInstance, hWnd, TRUE, FALSE );
return CallWindowProc( lpfnToolbarProc, hWnd, uMsg, wParam, lParam );
case WM_NOTIFY:
if ( lpt->hdr.code == TTN_GETDISPINFOA || lpt->hdr.code == TTN_GETDISPINFOW )
{
lpt->hinst = ghInstance;
lpt->lpszText = MAKEINTRESOURCE(lpt->hdr.idFrom);
return 0L;
}
break;
default:
break;
}
return CallWindowProc( lpfnToolbarProc, hWnd, uMsg, wParam, lParam );
}
HIMAGELIST CreateToolbarImageList( HWND hWnd, HINSTANCE hInst, int idResource )
{
HIMAGELIST retVal;
HBITMAP hBmp;
retVal = ImageList_Create( 50, 50, ILC_COLOR24 | ILC_MASK, 5, 0 );
hBmp = LoadBitmap( hInst, MAKEINTRESOURCE(idResource) );
ImageList_AddMasked( retVal, hBmp, RGB(192,192,192) );
DeleteObject( hBmp );
return retVal;
}
int AddToolbarImages( HINSTANCE hInst, HWND hWnd, BOOL bSysColorChange,
BOOL bToggleHiColor )
{
TBADDBITMAP tbBitmaps;
HIMAGELIST hOldImageList[3] = { NULL, NULL, NULL };
int iBmp, iHotBmp, iOldBmp;
if ( bHiColor )
{
iBmp = idToolbar24Bmp;
iOldBmp = idToolbarBmp;
iHotBmp = idToolbarHot24Bmp;
}
else
{
iBmp = idToolbarBmp;
iOldBmp = idToolbar24Bmp;
iHotBmp = idToolbarHotBmp;
}
// check if we can use the flat toolbar with "hot" buttons
if ( GetDllVersion( "comctl32.dll" ) < MAKELONG(4,71) )
{
/*
* Only add the bitmap on initial creation when using older version
* of comctl32.dll. Otherwise we ignore the call.
*/
if ( !bSysColorChange && !bToggleHiColor )
{
// use old style
tbBitmaps.hInst = NULL;
tbBitmaps.nID = (UINT)LoadBitmap( hInst, MAKEINTRESOURCE( iBmp ) );
SendMessage( hWnd, TB_ADDBITMAP, 5, (LPARAM)&tbBitmaps );
}
}
else
{
/*
* We'll actually change imagelists for v4.71+ of comctl32.dll.
*/
if ( bSysColorChange || bToggleHiColor )
{
hOldImageList[0] = hImgLists[0];
hOldImageList[1] = hImgLists[1];
hOldImageList[2] = hImgLists[2];
}
// create image lists
hImgLists[0] = CreateToolbarImageList( hWnd, hInst, iBmp );
SendMessage( hWnd, TB_SETIMAGELIST, 0, (LPARAM)hImgLists[0] );
#if _CONFIG_FLAT_TOOLBAR
hImgLists[1] = CreateToolbarImageList( hWnd, hInst, iHotBmp );
SendMessage( hWnd, TB_SETHOTIMAGELIST, 0, (LPARAM)hImgLists[1] );
#endif
}
if ( hOldImageList[0] ) ImageList_Destroy( hOldImageList[0] );
if ( hOldImageList[1] ) ImageList_Destroy( hOldImageList[1] );
if ( hOldImageList[2] ) ImageList_Destroy( hOldImageList[2] );
return 0;
}
/*
* Creates the toolbar, loads bitmap resources, etc. InitCommonControls()
* must be called prior to calling this function
*/
HWND createToolbar( HWND hWnd, HINSTANCE hInst )
{
HWND hRet;
TBBUTTON tb[4];
int idx = 0;
RECT rc;
DWORD dwToolbarStyle = WS_CHILD | WS_BORDER | WS_VISIBLE | TBSTYLE_TOOLTIPS;
memset( tb, 0, sizeof(TBBUTTON[4]) );
tb[idx].iBitmap = 0;
tb[idx].idCommand = IDM_REFRESH;
tb[idx].fsState = TBSTATE_ENABLED;
tb[idx].fsStyle = TBSTYLE_BUTTON;
tb[idx].dwData = 0;
tb[idx++].iString = -1;
tb[idx].iBitmap = 2;
tb[idx].idCommand = IDM_RIP;
tb[idx].fsState = TBSTATE_ENABLED;
tb[idx].fsStyle = TBSTYLE_BUTTON;
tb[idx].dwData = 0;
tb[idx++].iString = -1;
#if 0
tb[idx].iBitmap = 1;
tb[idx].idCommand = IDM_MP3;
tb[idx].fsState = TBSTATE_ENABLED;
tb[idx].fsStyle = TBSTYLE_CHECK;
tb[idx].dwData = 0;
tb[idx++].iString = -1;
#endif
tb[idx].iBitmap = 3;
tb[idx].idCommand = IDM_OPTIONS;
tb[idx].fsState = TBSTATE_ENABLED;
tb[idx].fsStyle = TBSTYLE_BUTTON;
tb[idx].dwData = 0;
tb[idx++].iString = -1;
tb[idx].iBitmap = 4;
tb[idx].idCommand = IDM_ID3;
tb[idx].fsState = TBSTATE_ENABLED;
tb[idx].fsStyle = TBSTYLE_BUTTON;
tb[idx].dwData = 0;
tb[idx++].iString = -1;
hRet = CreateWindowEx( WS_EX_TOOLWINDOW, TOOLBARCLASSNAME, "",
dwToolbarStyle,
0, 0, 100, 64,
hWnd, (HMENU)IDM_TOOLBAR, hInst, NULL );
#if _CONFIG_FLAT_TOOLBAR
dwToolbarStyle = (DWORD)SendMessage( hRet, TB_GETSTYLE, 0, 0L );
dwToolbarStyle |= TBSTYLE_FLAT;
SendMessage( hRet, TB_SETSTYLE, 0, (LPARAM)dwToolbarStyle );
#endif
SendMessage( hRet, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0L );
SendMessage( hRet, TB_SETBITMAPSIZE, 0, MAKELONG( 50, 46 ) );
SendMessage( hRet, TB_SETBUTTONSIZE, 0, MAKELONG( 58, 53 ) );
SendMessage( hRet, TB_AUTOSIZE, 0, 0L );
AddToolbarImages( hInst, hRet, FALSE, FALSE );
SendMessage( hRet, TB_ADDBUTTONS, idx, (LPARAM)&tb );
SubToolbarProc( hRet, WM_SETSUBCLASSPROC, 0, 0L );
SendMessage( hRet, TB_GETITEMRECT, (WPARAM)(idx-1), (LPARAM)&rc );
CreateWindowEx( 0L, "STATIC", "Artist: ",
SS_RIGHT | WS_CHILD | WS_VISIBLE,
rc.right + 10, rc.top + 6, 60, 20, hRet,
(HMENU)NULL, hInst, NULL );
CreateWindowEx( 0L, "STATIC", "Album: ",
SS_RIGHT | WS_CHILD | WS_VISIBLE,
rc.right + 10, rc.top + 32, 60, 20, hRet,
(HMENU)NULL, hInst, NULL );
hEditArtist = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", "",
ES_LEFT | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL
| WS_BORDER | WS_TABSTOP | WS_GROUP ,
rc.right + 72, rc.top + 2, 210, 24, hRet,
(HMENU)IDE_ARTIST, hInst, NULL );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -