📄 main.c
字号:
break;
case ID_LOADSKIN:
{
if (globals.main_bool_skin_next_is_default == TRUE)
options.use_default_skin = TRUE;
else
options.use_default_skin = FALSE;
if (options.use_default_skin == FALSE) {
char skinpathje[MAX_PATH];
strcpy(skinpathje, options.main_skin_file);
if (main_skin_open(options.main_skin_file) == FALSE)
main_set_default_skin();
else {
main_skin_add_to_menu(skinpathje);
main_skin_select_menu(skinpathje);
}
} else
main_set_default_skin();
if(options.scroll_track_title)
SetTimer(hWnd, CPC_TIMERID_SCROLLTITLETEXT, 50, NULL);
else
KillTimer(hWnd, CPC_TIMERID_SCROLLTITLETEXT);
main_reset_window(hWnd);
main_add_tooltips(hWnd, TRUE);
break;
}
default:
return -1;
}
return 0;
}
void cmdline_usage(void)
{
HRSRC resource;
HGLOBAL globaldata;
resource = FindResource(NULL, // module handle
MAKEINTRESOURCE(IDR_USAGE), // pointer to resource name
"raw"); // pointer to resource type
globaldata = LoadResource(NULL, // resource-module handle
resource);
MessageBox(NULL, (LPCTSTR) LockResource(globaldata),
"CoolPlayer command line options", 0); // text to set
PostQuitMessage(0);
}
int *cmdline_get_argument(char *arg)
{
if (_stricmp(arg, "help") == 0 || arg[0] == '?'
|| ((arg[0] == 'h' || arg[0] == 'H') && arg[1] == '\0'))
cmdline_usage();
if (_stricmp(arg, "add") == 0 || (GetTickCount() - globals.playlist_last_add_time) < 1000)
globals.playlist_bool_addsong = TRUE;
else
globals.playlist_bool_addsong = FALSE;
if (_stricmp(arg, "top") == 0)
return &options.always_on_top;
if (_stricmp(arg, "exit") == 0)
return &options.auto_exit_after_playing;
if (_stricmp(arg, "exitnow") == 0)
PostQuitMessage(0);
if (_stricmp(arg, "icon") == 0)
return &options.rotate_systray_icon;
if (_stricmp(arg, "scroll") == 0)
return &options.scroll_track_title;
if (_stricmp(arg, "time") == 0)
return &options.show_remaining_time;
if (_stricmp(arg, "tag") == 0)
return &options.read_id3_tag;
if (_stricmp(arg, "easy") == 0)
return &options.easy_move;
if (_stricmp(arg, "playlist") == 0)
return &options.remember_playlist;
if (_stricmp(arg, "played") == 0)
return &options.remember_last_played_track;
if (_stricmp(arg, "eq") == 0)
return &options.equalizer;
if (_stricmp(arg, "shuffle") == 0)
return &options.shuffle_play;
if (_stricmp(arg, "repeat") == 0)
return &options.repeat_playlist;
if (_stricmp(arg, "autoplay") == 0)
return &options.auto_play_when_started;
if (_stricmp(arg, "output") == 0)
return &options.decoder_output_mode;
if (_stricmp(arg, "skin") == 0)
return &options.use_default_skin;
if (_stricmp(arg, "showplaylist") == 0)
return &options.show_playlist;
if (_stricmp(arg, "minimized") == 0)
return &globals.main_int_show_minimized;
if (_stricmp(arg, "fileonce") == 0)
return &options.allow_file_once_in_playlist;
if (_stricmp(arg, "taskbar") == 0)
return &options.show_on_taskbar;
if (_stricmp(arg, "multipleinstances") == 0)
return &options.allow_multiple_instances;
return NULL;
}
int cmdline_parse_options(int argc,char **argv)
{
// char *token;
// char commandline[MAX_PATH];
int i;
int *value;
for(i=1;i<argc;i++)
{
char *arg=argv[i];
if (arg[0] == '-') {
if (value = cmdline_get_argument(arg+1)) *value = FALSE;
if (value == &options.use_default_skin) {
i++;
if (stricmp(argv[i], "default") == 0) *value = TRUE;
else strcpy(options.main_skin_file, argv[i]);
}
if (value == &globals.main_int_show_minimized) {
if (options.show_on_taskbar)
globals.main_int_show_minimized = SW_MINIMIZE;
else
globals.main_int_show_minimized = SW_HIDE;
}
}else if (arg[0] == '+') {
if (value = cmdline_get_argument(arg + 1))
*value = TRUE;
}
}
return 1;
}
//
//
//
BOOL cmdline_parse_argument(char *token)
{
char buffie[MAX_PATH] = "";
char expath[MAX_PATH];
strcpy(buffie, token);
path_unquote(buffie);
if (buffie[0] == '\0')
return FALSE;
if (path_is_relative(buffie))
{
char exepath[MAX_PATH];
main_get_program_path(GetModuleHandle(NULL), exepath, MAX_PATH);
sprintf(expath, "%s%s", exepath, buffie);
}
else
strcpy(expath, buffie);
if (_access(expath, 0) != -1)
{
if (globals.playlist_bool_addsong == FALSE
&& globals.cmdline_bool_clear_playlist_first == TRUE)
{
CPL_Empty(globals.m_hPlaylist);
globals.cmdline_bool_clear_playlist_first = FALSE;
}
CPL_SyncLoadNextFile(globals.m_hPlaylist);
if(path_is_directory(expath) == TRUE)
CPL_AddDirectory_Recurse(globals.m_hPlaylist, expath);
else
CPL_AddFile(globals.m_hPlaylist, expath);
return TRUE;
}
return FALSE;
}
//
//
//
char *str_delete_substr(char *strbuf, char *strtodel)
{
char *offset=NULL;
while (*strbuf) {
offset = strstr(strbuf, strtodel);
if (offset)
strcpy(offset, (offset + strlen(strtodel)));
else
break;
}
return strbuf;
}
int cmdline_parse_files(int argc,char **argv)
{
BOOL wegotsome = FALSE;
int i;
globals.cmdline_bool_clear_playlist_first = TRUE;
for(i=1;i<argc;i++)
{
char *arg=argv[i];
if (arg[0] != '-' && arg[0] != '+') {
if (cmdline_parse_argument(arg))
wegotsome = TRUE;
}
}
return wegotsome;
}
int APIENTRY
WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wc;
HWND hWnd;
MSG msg;
HRGN winregion;
INITCOMMONCONTROLSEX controls;
HMENU hpopup;
BOOL bAlreadyRuning;
HANDLE hMutexOneInstance;
// Ensure that this system is audio capable
if(waveOutGetNumDevs() < 1)
{
MessageBox(GetDesktopWindow(), "No audio devices in this system", "CoolPlayer", MB_ICONSTOP | MB_OK);
return -1;
}
options_read();
hMutexOneInstance = CreateMutex(NULL, FALSE, "COOLPLAYER-045FA840-B10D-2G3-3436-006067709674");
bAlreadyRuning = (GetLastError() == ERROR_ALREADY_EXISTS
|| GetLastError() == ERROR_ACCESS_DENIED);
// The call fails with ERROR_ACCESS_DENIED if the Mutex was
// created in a different users session because of passing
// NULL for the SECURITY_ATTRIBUTES on Mutex creation);
if(bAlreadyRuning)
{
// Find the other coolplayer instance
HWND hWndCoolPlayer = FindWindow(CLC_COOLPLAYER_WINDOWCLASSNAME, NULL);
if(hWndCoolPlayer != NULL)
{
if(lpCmdLine[0] != '\0')
{
int i;
int size=0;
COPYDATASTRUCT cds;
for(i=0;i<__argc;i++)
size+=strlen(__argv[i])+1;
// cds.cbData = strlen(lpCmdLine) + 1;
// cds.dwData = strlen(lpCmdLine) + 1;
// cds.lpData = lpCmdLine;
cds.cbData = size;
cds.dwData = __argc;
cds.lpData = __argv[0];
SendMessage(hWndCoolPlayer, WM_COPYDATA, (WPARAM)hWndCoolPlayer, (LPARAM)&cds);
}
else
{
SetForegroundWindow(hWndCoolPlayer);
ShowWindow(hWndCoolPlayer, SW_RESTORE);
}
}
if(!options.allow_multiple_instances)
return FALSE; // terminates the creation
}
/* kill this */
controls.dwSize = sizeof(INITCOMMONCONTROLSEX);
controls.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx(&controls);
// options.shuffle_play = FALSE;
// options.repeat_playlist = FALSE;
// options.equalizer = FALSE;
globals.main_bool_slider_keep_focus = FALSE;
globals.main_int_skin_last_number = 5001;
windows.m_hWndFindDialog = NULL;
globals.playlist_int_last_searched_track = 0;
globals.m_iLastPlaylistSortColoumn = -1;
globals.m_bQuickFindWindowPos_Valid = FALSE;
globals.m_hPlaylist = CPL_CreatePlaylist();
globals.m_hhkListView_Posted = NULL;
globals.playlist_bool_addsong = FALSE;
globals.playlist_last_add_time = 0;
globals.m_hSysIcon = NULL;
CPSK_Initialise();
hpopup = LoadMenu(NULL, MAKEINTRESOURCE(IDR_MENU1));
globals.main_menu_popup = GetSubMenu(hpopup, 0);
globals.m_hPlaylistImages = ImageList_LoadBitmap( hInstance,
MAKEINTRESOURCE(IDB_PLAYLIST_CURRENTTRACK),
12,
1,
RGB(0xFF, 0x00, 0xFF));
if (!options.show_on_taskbar)
switch (nCmdShow) {
case SW_MINIMIZE:
case SW_SHOWMINIMIZED:
case SW_SHOWMINNOACTIVE:
nCmdShow = SW_HIDE;
}
globals.main_int_show_minimized = nCmdShow;
cmdline_parse_options(__argc,__argv);
if (*options.main_skin_file && options.use_default_skin == FALSE) {
char lastskinfile[MAX_PATH];
strcpy(lastskinfile, options.main_skin_file);
if (main_skin_open(options.main_skin_file) == FALSE) {
main_set_default_skin();
} else {
main_skin_add_to_menu(lastskinfile);
main_skin_select_menu(lastskinfile);
}
} else {
main_set_default_skin();
}
globals.main_bool_wavwrite_dir_already_known = FALSE;
globals.main_int_track_position = 0;
globals.m_enPlayerState = cppsStopped;
srand((unsigned int) time(NULL));
if (graphics.bmp_main_up) {
HDC hRefDC = GetDC(NULL);
ZeroMemory(&wc, sizeof(wc));
wc.style = CS_OWNDC;
//wc.style = CS_PARENTDC;
wc.lpszClassName = CLC_COOLPLAYER_WINDOWCLASSNAME;
wc.lpfnWndProc = (WNDPROC) main_windowproc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = NULL;
graphics.pal_main = CreateHalftonePalette(hRefDC);
ReleaseDC(NULL, hRefDC);
if (RegisterClass(&wc)) {
BITMAP bm;
GetObject(graphics.bmp_main_up, sizeof(bm), &bm);
globals.m_hPlayer = NULL;
hWnd =
CreateWindowEx(WS_EX_ACCEPTFILES | WS_EX_TOOLWINDOW,
CLC_COOLPLAYER_WINDOWCLASSNAME, "CoolPlayer",
WS_POPUP | WS_CLIPSIBLINGS,
options.main_window_pos.x,
options.main_window_pos.y, bm.bmWidth,
bm.bmHeight, NULL, NULL, hInstance, NULL);
SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)LoadIcon(hInstance, MAKEINTRESOURCE(APP_ICON)));
SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)LoadIcon(hInstance, MAKEINTRESOUR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -