📄 main.c
字号:
/*
* function: Main control program for aacDECdrop
*
* This program is distributed under the GNU General Public License, version 2.
* A copy of this license is included with this source.
*
* Copyright (C) 2002 John Edwards
*
* last mod: aacDECdrop decoder last updated 2002-03-14
*/
#include <windows.h>
#include <shellapi.h>
#include <string.h>
#include <stdio.h>
#include <commctrl.h>
#include "resource.h"
#include "decthread.h"
#include "decode.h"
#include "misc.h"
#define LOSHORT(l) ((SHORT)(l))
#define HISHORT(l) ((SHORT)(((DWORD)(l) >> 16) & 0xFFFF))
#define INI_FILE "aacDECdrop.ini"
#define CREATEFONT(sz) \
CreateFont((sz), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
VARIABLE_PITCH | FF_SWISS, "")
HANDLE event = NULL;
int width = 130, height = 130;
RECT bar1, bar2, vbrBR;
int prog1 = 0, prog2 = 0;
int moving = 0;
POINT pt;
HINSTANCE hinst;
int frame = 0;
HBITMAP hbm[12], temp;
HMENU menu;
int decoding_done = 0;
int stop_decoding = 0;
double file_complete;
int totalfiles;
int numfiles;
HWND g_hwnd;
HWND qcwnd;
HFONT font2;
char *fileName;
SettingsAAC iniSettings; // iniSettings holds the parameters for the aacDECdrop configuration
int animate = 0;
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK QCProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) ;
/*
* Write the .ini file using the current aacDECdrop settings
*/
int
WriteIniFile ( const char* Filename )
{
FILE* fp;
if ( (fp = fopen (Filename, "w")) == NULL )
return EOF; // could not open file
fprintf (fp, "[aacDECdrop]\n");
fprintf (fp, "Window_X=%i\n" , iniSettings.window_x );
fprintf (fp, "Window_Y=%i\n" , iniSettings.window_y );
fprintf (fp, "Always_on_top=%i\n" , iniSettings.always_on_top);
fprintf (fp, "Logerr=%i\n" , iniSettings.logerr );
fprintf (fp, "DecodeMode=%i\n" , iniSettings.decode_mode );
fprintf (fp, "OutputFormat=%i\n" , iniSettings.outputFormat );
fprintf (fp, "FileType=%i\n" , iniSettings.fileType );
fprintf (fp, "ObjectType=%i\n" , iniSettings.object_type );
return fclose (fp);
}
/*
* Read the .ini file and set the aacDECdrop settings
*/
int
ReadIniFile ( FILE* fp )
{
char buff [256];
int val;
rewind ( fp );
fgets ( buff, sizeof buff, fp );
if ( 0 != memcmp ( buff, "[aacDECdrop]", 12 ) )
return EOF;
while ( fgets ( buff, sizeof buff, fp ) != NULL ) {
if ( 1 == sscanf ( buff, "Window_X=%d" , &val ) ) iniSettings.window_x = val;
else if ( 1 == sscanf ( buff, "Window_Y=%d" , &val ) ) iniSettings.window_y = val;
else if ( 1 == sscanf ( buff, "Always_on_top=%d", &val ) ) iniSettings.always_on_top = val;
else if ( 1 == sscanf ( buff, "Logerr=%d" , &val ) ) iniSettings.logerr = val;
else if ( 1 == sscanf ( buff, "DecodeMode=%d" , &val ) ) iniSettings.decode_mode = val;
else if ( 1 == sscanf ( buff, "OutputFormat=%d" , &val ) ) iniSettings.outputFormat = val;
else if ( 1 == sscanf ( buff, "FileType=%d" , &val ) ) iniSettings.fileType = val;
else if ( 1 == sscanf ( buff, "ObjectType=%d" , &val ) ) iniSettings.object_type = val;
}
return 0;
}
/*
* Get aacDECdrop settings at startup, writes .ini file, if not present
*/
void
GetAACdecSettings ( void )
{
FILE* fp = NULL;
char PathAndName [] = {INI_FILE};
// set default values
iniSettings.window_x = 64; // default box position (x co-ord)
iniSettings.window_y = 64; // default box position (y co-ord)
iniSettings.always_on_top = 8; // default = on
iniSettings.logerr = 0; // default = off
iniSettings.decode_mode = 1; // default = 1 (decode to file)
iniSettings.outputFormat = 1; // default = 1 (16 bit PCM)
iniSettings.fileType = 1; // default = 1 (Microsoft WAV)
iniSettings.object_type = 1; // default = 1 (Low Complexity)
// Read INI_FILE
if ( (fp = fopen (PathAndName, "r")) == NULL ) { // file does not exist: write it!
WriteIniFile ( PathAndName );
}
else { // file does exist: read it!
ReadIniFile (fp);
fclose (fp);
}
return;
}
void set_always_on_top(HWND hwnd, int v)
{
CheckMenuItem(menu, IDM_ONTOP, v ? MF_CHECKED : MF_UNCHECKED);
SetWindowPos(hwnd, v ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOMOVE);
iniSettings.always_on_top = v;
}
void set_logerr(HWND hwnd, int v)
{
CheckMenuItem(menu, IDM_LOGERR, v ? MF_CHECKED : MF_UNCHECKED);
iniSettings.logerr = v;
set_use_dialogs(v);
}
void set_decode_mode(int v)
{
decthread_set_decode_mode(v);
iniSettings.decode_mode = v;
}
void set_outputFormat(int v)
{
decthread_set_outputFormat(v);
iniSettings.outputFormat = v;
}
void set_fileType(int v)
{
decthread_set_fileType(v);
iniSettings.fileType = v;
}
void set_object_type(int v)
{
decthread_set_object_type(v);
iniSettings.object_type = v;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static char szAppName[] = "aacDECdrop";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
const int width = 130;
const int height = 130;
int x;
int y;
hinst = hInstance;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_ICON1));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
RegisterClass(&wndclass);
GetAACdecSettings();
x = max(min(iniSettings.window_x, GetSystemMetrics(SM_CXSCREEN) - width), 0);
y = max(min(iniSettings.window_y, GetSystemMetrics(SM_CYSCREEN) - height), 0);
hwnd = CreateWindow(szAppName, "aacDECdrop", WS_POPUP | WS_DLGFRAME, x, y,
width, height, NULL, NULL, hInstance, NULL);
g_hwnd = hwnd;
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
font2 = CREATEFONT(10);
SetTimer(hwnd, 1, 80, NULL);
set_always_on_top(hwnd, iniSettings.always_on_top);
set_logerr(hwnd, iniSettings.logerr);
set_decode_mode(iniSettings.decode_mode);
set_outputFormat(iniSettings.outputFormat);
set_fileType(iniSettings.fileType);
set_object_type(iniSettings.object_type);
for (frame = 0; frame < 8; frame++)
hbm[frame] = LoadImage(hinst, MAKEINTRESOURCE(IDB_TF01 + frame), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
frame = 0;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
for (frame = 0; frame < 8; frame++)
DeleteObject(hbm[frame]);
return msg.wParam;
}
void HandleDrag(HWND hwnd, HDROP hDrop)
{
int cFiles, i;
char szFile[MAX_PATH];
char *ext;
int flag = 0;
cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
for (i = 0; i < cFiles; i++)
{
DragQueryFile(hDrop, i, szFile, sizeof(szFile));
if (ext = strrchr(szFile, '.'))
{
if (stricmp(ext, ".aac") == 0 || stricmp(ext, ".mp4") == 0)
{
flag = 1;
decthread_addfile(szFile);
stop_decoding = 0;
}
}
}
DragFinish(hDrop);
if (flag)
SetEvent(event);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc, hmem;
static HDC offscreen;
PAINTSTRUCT ps;
RECT rect, rect2;
BITMAP bm;
POINT point;
static POINT start;
static int dragging = 0;
HDC desktop;
HBITMAP hbitmap;
HANDLE hdrop;
HFONT dfltFont;
int dfltBGMode;
double percomp;
switch (message)
{
case WM_CREATE:
menu = LoadMenu(hinst, MAKEINTRESOURCE(IDR_MENU1));
menu = GetSubMenu(menu, 0);
offscreen = CreateCompatibleDC(NULL);
desktop = GetDC(GetDesktopWindow());
hbitmap = CreateCompatibleBitmap(desktop, 200, 200);
ReleaseDC(GetDesktopWindow(), desktop);
SelectObject(offscreen, hbitmap);
// Start the engines
decthread_init();
// We accept drag&drop
DragAcceptFiles(hwnd, TRUE);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
width = rect.right + 1;
height = rect.bottom + 1;
FillRect(offscreen, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
DrawText(offscreen, "Drop Files Here", -1, &rect, DT_SINGLELINE | DT_CENTER);
SetRect(&rect2, 0, height - 110, width, height - 25);
DrawText(offscreen, "For Decoding", -1, &rect2, DT_SINGLELINE | DT_CENTER);
hmem = CreateCompatibleDC(offscreen);
SelectObject(hmem, hbm[frame]);
GetObject(hbm[frame], sizeof(BITMAP), &bm);
BitBlt(offscreen, width / 2 - 33, height / 2 - 31, bm.bmWidth, bm.bmHeight, hmem, 0, 0, SRCCOPY);
DeleteDC(hmem);
percomp = ((double)(totalfiles - numfiles) + 1 - (1 - file_complete)) / (double)totalfiles;
SetRect(&vbrBR, 0, height - 35, width, height - 19);
dfltBGMode = SetBkMode(offscreen, TRANSPARENT);
dfltFont = SelectObject(offscreen, font2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -