main.c
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:70k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. // Windows Header Files:
  2. #include "stdafx.h"
  3. #include "globals.h"
  4. #include "WindowsOS.h"
  5. #include "CPI_Player.h"
  6. #include "CPI_Playlist.h"
  7. #include "CPI_PlaylistItem.h"
  8. #include "DLG_Find.h"
  9. #include "CPI_PlaylistWindow.h"
  10. #include "RotatingIcon.h"
  11. #include "CPI_Indicators.h"
  12. void    main_skin_select_menu(char *name)
  13. {
  14.     int     teller;
  15.     char    skinstring[MAX_PATH];
  16.     HMENU   popje = GetSubMenu(globals.main_menu_popup, 4);
  17.     int     itemcounter =
  18.         GetMenuItemCount(GetSubMenu(globals.main_menu_popup, 4));
  19.     for (teller = 0; teller < itemcounter; teller++) {
  20.         GetMenuString(popje, teller, skinstring, MAX_PATH, MF_BYPOSITION);
  21.         if (strcmp(name, skinstring) == 0) {
  22.             CheckMenuRadioItem(popje, 0, itemcounter, teller,
  23.                                MF_BYPOSITION);
  24.         }
  25.     }
  26. }
  27. void    main_reset_window(HWND hWnd)
  28. {
  29.     HRGN    winregion;
  30.     BITMAP  bm;
  31.     GetObject(graphics.bmp_main_up, sizeof(bm), &bm);
  32.     winregion =
  33.         main_bitmap_to_region(graphics.bmp_main_up, Skin.transparentcolor);
  34.     SetWindowPos(hWnd, // handle to window
  35.                  HWND_NOTOPMOST, // placement-order handle
  36.                  0, // horizontal position
  37.                  0, // vertical position
  38.                  bm.bmWidth, // width
  39.                  bm.bmHeight, // height
  40.                  SWP_NOMOVE | SWP_NOZORDER // window-positioning flags
  41.                 );
  42.     SetWindowRgn(hWnd, winregion, TRUE);
  43.     CPI_Player__SetPositionRange(globals.m_hPlayer,
  44.                                  Skin.Object[PositionSlider].maxw ? Skin.Object[PositionSlider].h : Skin.Object[PositionSlider].w);
  45.     RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE);
  46. }
  47. void    main_skin_add_to_menu(char *name)
  48. {
  49.     MENUITEMINFO menuinfo;
  50.     int     itemcounter =
  51.         GetMenuItemCount(GetSubMenu(globals.main_menu_popup, 4));
  52.     int     teller;
  53.     for (teller = 0; teller < itemcounter; teller++) {
  54.         char    skinstring[MAX_PATH];
  55.         GetMenuString(GetSubMenu(globals.main_menu_popup, 4), teller,
  56.                       skinstring, MAX_PATH, MF_BYPOSITION);
  57.         if (strcmp(name, skinstring) == 0)
  58.             return;
  59.     }
  60.     menuinfo.cbSize = sizeof(MENUITEMINFO);
  61.     menuinfo.fMask = MIIM_TYPE | MIIM_ID;
  62.     menuinfo.fType = MFT_STRING | MFT_RADIOCHECK;
  63.     menuinfo.fState;
  64.     if (globals.main_int_skin_last_number ==
  65.             5001 +
  66.             options.remember_skin_count) globals.main_int_skin_last_number =
  67.                     5001;
  68.     menuinfo.wID = globals.main_int_skin_last_number++;
  69.     menuinfo.hSubMenu;
  70.     menuinfo.hbmpChecked;
  71.     menuinfo.hbmpUnchecked;
  72.     menuinfo.dwItemData;
  73.     menuinfo.cch = sizeof(menuinfo.dwTypeData);
  74.     menuinfo.dwTypeData = name;
  75.     InsertMenuItem(globals.main_menu_popup, MENU_SKIN_DEFAULT, FALSE,
  76.                    &menuinfo);
  77.     if (itemcounter > options.remember_skin_count) {
  78.         RemoveMenu(GetSubMenu(globals.main_menu_popup, 4), 0,
  79.                    MF_BYPOSITION);
  80.     }
  81. }
  82. char   *str_trim(char *string)
  83. {
  84.     int     i = strlen(string) - 1;
  85.     while (i >= 0 && string[i] == ' ')
  86.         string[i--] = 0;
  87.     while (*string == ' ')
  88.         string++;
  89.     return string;
  90. }
  91. DWORD   main_get_program_path(HINSTANCE hInst, LPTSTR pszBuffer,
  92.                               DWORD dwSize)
  93. //
  94. //      Return the size of the path in bytes.
  95. {
  96.     DWORD   dwLength = GetModuleFileName(hInst, pszBuffer, dwSize);
  97.     if (dwLength) {
  98.         while (dwLength && pszBuffer[dwLength] != '\') {
  99.             dwLength--;
  100.         }
  101.         if (dwLength)
  102.             pszBuffer[dwLength + 1] = '';
  103.     }
  104.     return dwLength;
  105. }
  106. //
  107. //
  108. //
  109. int playlist_write()
  110. {
  111.     OPENFILENAME fn;
  112.     BOOL bResult;
  113.     char pcOutputName[MAX_PATH] = "";
  114.     // Get filename to save
  115.     fn.lStructSize = sizeof(OPENFILENAME);
  116.     fn.hwndOwner = windows.m_hWndPlaylist;
  117.     fn.hInstance = NULL;
  118.     fn.lpstrFilter = "M3U Playlist Files (*.m3u)*.m3uPLS Playlist files (*.pls)*.pls";
  119.     fn.lpstrCustomFilter = NULL;
  120.     fn.nMaxCustFilter = 0;
  121.     fn.nFilterIndex = 0;
  122.     fn.lpstrFile = pcOutputName;
  123.     fn.nMaxFile = MAX_PATH;
  124.     fn.lpstrFileTitle = NULL;
  125.     fn.nMaxFileTitle = 0;
  126.     fn.lpstrInitialDir = options.last_used_directory;
  127.     fn.lpstrTitle = NULL;
  128.     fn.Flags = OFN_HIDEREADONLY
  129.                | OFN_EXPLORER
  130.                | OFN_OVERWRITEPROMPT
  131.                | OFN_PATHMUSTEXIST
  132.                | OFN_ENABLESIZING;
  133.     fn.nFileOffset = 0;
  134.     fn.nFileExtension = 0;
  135.     fn.lpstrDefExt = "m3u";
  136.     fn.lCustData = 0;
  137.     fn.lpfnHook = NULL;
  138.     fn.lpTemplateName = NULL;
  139.     bResult = GetSaveFileName(&fn);
  140.     if(bResult == FALSE)
  141.         return FALSE;
  142.     CPL_ExportPlaylist(globals.m_hPlaylist, pcOutputName);
  143.     return TRUE;
  144. }
  145. //
  146. //
  147. //
  148. void main_update_title_text()
  149. {
  150.     int     teller;
  151.     HBITMAP h, h2;
  152.     HPALETTE oldpal;
  153.     const char* pcText;
  154.     int     stringlen;
  155.     int     width;
  156.     CP_HPLAYLISTITEM hItem_Current;
  157.     HDC SongtitleDc;
  158.     int iG;
  159.     iG = Skin.Object[SongtitleText].w;
  160.     hItem_Current = CPL_GetActiveItem(globals.m_hPlaylist);
  161.     if(hItem_Current)
  162.         pcText = CPLI_GetTrackName(hItem_Current);
  163.     else
  164.         pcText = "CoolPlayer";
  165.     stringlen = strlen(pcText);
  166.     width = ((stringlen + 4) * Skin.Object[SongtitleText].w);
  167.     if(stringlen > Skin.Object[SongtitleText].maxw)
  168.         globals.mail_int_title_scroll_max_position = width;
  169.     else
  170.         globals.mail_int_title_scroll_max_position = 0;
  171.     globals.main_int_title_scroll_position = 0;
  172.     SongtitleDc = CreateCompatibleDC(drawables.dc_main);
  173.     DeleteObject(graphics.bmp_main_title_area);
  174.     graphics.bmp_main_title_area =
  175.         CreateCompatibleBitmap(drawables.dc_main, width * 2,
  176.                                Skin.Object[SongtitleText].h);
  177.     h2 = SelectObject(SongtitleDc, graphics.bmp_main_title_area);
  178.     oldpal = SelectPalette(SongtitleDc, graphics.pal_main, FALSE);
  179.     RealizePalette(SongtitleDc);
  180.     h = (HBITMAP) SelectObject(drawables.dc_memory, graphics.bmp_main_up);
  181.     BitBlt(SongtitleDc, 0, 0,
  182.            (Skin.Object[SongtitleText].maxw +
  183.             1) * Skin.Object[SongtitleText].w,
  184.            Skin.Object[SongtitleText].h, drawables.dc_memory,
  185.            Skin.Object[SongtitleText].x, Skin.Object[SongtitleText].y,
  186.            SRCCOPY);
  187.     BitBlt(SongtitleDc, Skin.Object[SongtitleText].w * stringlen, 0,
  188.            (Skin.Object[SongtitleText].maxw +
  189.             1) * Skin.Object[SongtitleText].w,
  190.            Skin.Object[SongtitleText].h, drawables.dc_memory,
  191.            Skin.Object[SongtitleText].x, Skin.Object[SongtitleText].y,
  192.            SRCCOPY);
  193.     SelectObject(drawables.dc_memory, graphics.bmp_main_title_font);
  194.     for (teller = 0; teller < stringlen; teller++) {
  195.         BitBlt(SongtitleDc, (teller * Skin.Object[SongtitleText].w),
  196.                0, Skin.Object[SongtitleText].w,
  197.                Skin.Object[SongtitleText].h, drawables.dc_memory,
  198.                Skin.Object[SongtitleText].w * (pcText[teller] - 32), 0,
  199.                SRCCOPY);
  200.         if (stringlen > Skin.Object[SongtitleText].maxw)
  201.             BitBlt(SongtitleDc, width + (teller * Skin.Object[SongtitleText].w), 0,
  202.                    Skin.Object[SongtitleText].w,
  203.                    Skin.Object[SongtitleText].h, drawables.dc_memory,
  204.                    Skin.Object[SongtitleText].w * (pcText[teller] - 32), 0,
  205.                    SRCCOPY);
  206.     }
  207.     //     TextOut(SongtitleDc,0,0,text,stringlen);
  208.     SelectPalette(SongtitleDc, oldpal, FALSE);
  209.     SelectObject(drawables.dc_memory, h);
  210.     SelectObject(SongtitleDc, h2);
  211.     DeleteDC(SongtitleDc);
  212.     // Setup systray text
  213.     if(globals.m_hSysIcon && hItem_Current)
  214.     {
  215.         // If there is a track name and artist name - set the format %artist% - %track%
  216.         if(CPLI_GetTrackName(hItem_Current) && CPLI_GetArtist(hItem_Current))
  217.         {
  218.             char cBuffer[2060];
  219.             sprintf(cBuffer, "%.1024s - %.1024s", CPLI_GetArtist(hItem_Current), CPLI_GetTrackName(hItem_Current));
  220.             CPSYSICON_SetTipText(globals.m_hSysIcon, cBuffer);
  221.         }
  222.         else
  223.             CPSYSICON_SetTipText(globals.m_hSysIcon, pcText);
  224.     }
  225. }
  226. //
  227. //
  228. //
  229. void    main_draw_title(HWND hWnd)
  230. {
  231.     int     left = Skin.Object[SongtitleText].x;
  232.     int     top = Skin.Object[SongtitleText].y;
  233.     window_bmp_blt(hWnd, graphics.bmp_main_title_area,
  234.                    Skin.Object[SongtitleText].x,
  235.                    Skin.Object[SongtitleText].y,
  236.                    (Skin.Object[SongtitleText].maxw +
  237.                     1) * Skin.Object[SongtitleText].w,
  238.                    Skin.Object[SongtitleText].h,
  239.                    0 + globals.main_int_title_scroll_position, 0);
  240. }
  241. void    main_draw_bitrate(HWND hWnd)
  242. {
  243.     int     left = Skin.Object[BitrateText].x;
  244.     int     top = Skin.Object[BitrateText].y;
  245.     if (left) {
  246.         int     teller;
  247.         window_bmp_blt(hWnd, graphics.bmp_main_up, left, top,
  248.                        3 * Skin.Object[SongtitleText].w,
  249.                        Skin.Object[SongtitleText].h, left, top);
  250.         for (teller = 0; globals.main_text_bitrate[teller]; teller++)
  251.             window_bmp_blt(hWnd, graphics.bmp_main_title_font,
  252.                            left + (teller * Skin.Object[SongtitleText].w),
  253.                            top, Skin.Object[SongtitleText].w,
  254.                            Skin.Object[SongtitleText].h,
  255.                            Skin.Object[SongtitleText].w *
  256.                            ((globals.main_text_bitrate[teller]) - 32), 0);
  257.     }
  258. }
  259. void    main_draw_frequency(HWND hWnd)
  260. {
  261.     int     left = Skin.Object[FreqText].x;
  262.     int     top = Skin.Object[FreqText].y;
  263.     if (left) {
  264.         int     teller;
  265.         window_bmp_blt(hWnd, graphics.bmp_main_up, left, top,
  266.                        2 * Skin.Object[SongtitleText].w,
  267.                        Skin.Object[SongtitleText].h, left, top);
  268.         for (teller = 0; globals.main_text_frequency[teller]; teller++)
  269.             window_bmp_blt(hWnd, graphics.bmp_main_title_font,
  270.                            left + (teller * Skin.Object[SongtitleText].w),
  271.                            top, Skin.Object[SongtitleText].w,
  272.                            Skin.Object[SongtitleText].h,
  273.                            Skin.Object[SongtitleText].w *
  274.                            ((globals.main_text_frequency[teller]) - 32),
  275.                            0);
  276.     }
  277. }
  278. void    main_set_eq(void)
  279. {
  280.     CPI_Player__SetEQ(globals.m_hPlayer, options.equalizer, options.eq_settings);
  281. }
  282. void    main_draw_time(HWND hWnd)
  283. {
  284.     int     top = Skin.Object[TimeText].y;
  285.     int     left = Skin.Object[TimeText].x;
  286.     int     height = Skin.Object[TimeText].h;
  287.     int     width = Skin.Object[TimeText].w;
  288.     unsigned long hrs, minutes, seconds;
  289.     unsigned long ss = globals.main_int_track_total_seconds;
  290.     if (left) {
  291.         if (options.show_remaining_time == TRUE)
  292.             ss = (globals.main_long_track_duration - ss);
  293.         seconds = ss % 60;
  294.         ss /= 60;
  295.         minutes = ss % 60;
  296.         ss /= 60;
  297.         hrs = ss;
  298.         // hours
  299.         window_bmp_blt(hWnd, graphics.bmp_main_time_font, left + width,
  300.                        top, width, height, width * hrs, 0);
  301.         // Separator
  302.         window_bmp_blt(hWnd, graphics.bmp_main_time_font,
  303.                        left + (2 * width), top, width, height, width * 10,
  304.                        0);
  305.         // minutes
  306.         window_bmp_blt(hWnd, graphics.bmp_main_time_font,
  307.                        left + (3 * width), top, width, height,
  308.                        width * (minutes / 10), 0);
  309.         window_bmp_blt(hWnd, graphics.bmp_main_time_font,
  310.                        left + (4 * width), top, width, height,
  311.                        width * (minutes % 10), 0);
  312.         // Separator
  313.         window_bmp_blt(hWnd, graphics.bmp_main_time_font,
  314.                        left + (5 * width), top, width, height, width * 10,
  315.                        0);
  316.         // seconds
  317.         window_bmp_blt(hWnd, graphics.bmp_main_time_font,
  318.                        left + (6 * width), top, width, height,
  319.                        width * (seconds / 10), 0);
  320.         window_bmp_blt(hWnd, graphics.bmp_main_time_font,
  321.                        left + (7 * width), top, width, height,
  322.                        width * (seconds % 10), 0);
  323.         if (options.show_remaining_time == TRUE)
  324.             window_bmp_blt(hWnd, graphics.bmp_main_time_font, left, top,
  325.                            width, height, width * 11, 0);
  326.         else
  327.             window_bmp_blt(hWnd, graphics.bmp_main_up, left, top, width,
  328.                            height, left, top);
  329.     }
  330. }
  331. void    main_draw_tracknr(HWND hWnd)
  332. {
  333.     int     top = Skin.Object[TrackText].y;
  334.     int     left = Skin.Object[TrackText].x;
  335.     int     width = Skin.Object[TrackText].w;
  336.     int     height = Skin.Object[TrackText].h;
  337.     int     nummertje;
  338.     int     tracknr = 0;//globals.main_int_playlist_track_number;
  339.     CP_HPLAYLISTITEM hCursor;
  340.     for(hCursor= CPL_GetActiveItem(globals.m_hPlaylist); hCursor; hCursor = CPLI_Prev(hCursor))
  341.         tracknr++;
  342.     if (left) {
  343.         nummertje = tracknr % 10;
  344.         window_bmp_blt(hWnd, graphics.bmp_main_track_font,
  345.                        left + (2 * width), top, width, height,
  346.                        width * (nummertje), 0);
  347.         nummertje = ((tracknr - nummertje) % 100);
  348.         window_bmp_blt(hWnd, graphics.bmp_main_track_font, left + width,
  349.                        top, width, height, width * (nummertje / 10), 0);
  350.         nummertje = ((tracknr - nummertje) % 1000);
  351.         window_bmp_blt(hWnd, graphics.bmp_main_track_font, left, top,
  352.                        width, height, width * (nummertje / 100), 0);
  353.     }
  354. }
  355. BOOL    path_is_directory(char *filename)
  356. {
  357.     DWORD   attribs = GetFileAttributes(filename);
  358.     if (attribs & FILE_ATTRIBUTE_DIRECTORY)
  359.         return TRUE;
  360.     else
  361.         return FALSE;
  362. }
  363. int     playlist_open_file(BOOL clearlist)
  364. {
  365.     OPENFILENAME fn;
  366.     char    filefilter[] =
  367.         "All Supported files*.mp1;*.mp2;*.mp3;*.m3u;*.pls;*.wav;*.ogg"
  368.         "MPEG audio files (*.mp1;*.mp2;*.mp3)*.mp1;*.mp2;*.mp3"
  369.         "Vorbis files (*.ogg)*.ogg"
  370.         "Playlist files (*.m3u;*.pls)*.m3u;*.pls"
  371.         "WAV files (*.wav)*.wav"
  372.         "All Files (*.*)*.*";
  373.     BOOL    returnval;
  374.     char    initialfilename[MAX_PATH * 200] = "";
  375.     fn.lStructSize = sizeof(OPENFILENAME);
  376.     fn.hwndOwner = (HWND) GetWindowLong(windows.wnd_main, DWL_USER);
  377.     fn.hInstance = NULL;
  378.     fn.lpstrFilter = filefilter;
  379.     fn.lpstrCustomFilter = NULL;
  380.     fn.nMaxCustFilter = 0;
  381.     fn.nFilterIndex = 0;
  382.     fn.lpstrFile = initialfilename;
  383.     fn.nMaxFile = MAX_PATH * 200;
  384.     fn.lpstrFileTitle = NULL;
  385.     fn.nMaxFileTitle = 0;
  386.     fn.lpstrInitialDir = options.last_used_directory;
  387.     fn.lpstrTitle = NULL;
  388.     fn.Flags =
  389.         OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY | OFN_EXPLORER |
  390.         OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_ENABLESIZING;
  391.     fn.nFileOffset = 0;
  392.     fn.nFileExtension = 0;
  393.     fn.lpstrDefExt = NULL;
  394.     fn.lCustData = 0;
  395.     fn.lpfnHook = NULL;
  396.     fn.lpTemplateName = NULL;
  397.     returnval = GetOpenFileName(&fn);
  398.     if (returnval != FALSE) {
  399.         char   *newfilename;
  400.         char    path_buffer[_MAX_PATH];
  401.         char    path_buffer2[_MAX_PATH];
  402.         if (clearlist)
  403.             CPL_Empty(globals.m_hPlaylist);
  404.         strcpy(path_buffer, fn.lpstrFile);
  405.         if (path_is_directory(fn.lpstrFile) == TRUE) {
  406.             path_add_backslash(path_buffer);
  407.         } else {
  408.             path_remove_filespec(path_buffer);
  409.         }
  410.         strcpy(options.last_used_directory, path_buffer);
  411.         newfilename = fn.lpstrFile + fn.nFileOffset;
  412.         while (newfilename[0] != 0) {
  413.             strcpy(path_buffer2, path_buffer);
  414.             strcat(path_buffer2, newfilename);
  415.             CPL_SyncLoadNextFile(globals.m_hPlaylist);
  416.             CPL_AddFile(globals.m_hPlaylist, path_buffer2);
  417.             newfilename = newfilename + strlen(newfilename) + 1;
  418.         }
  419.         return 1;
  420.     }
  421.     return 0;
  422. }
  423. void    main_draw_vu_from_mouse(HWND hWnd, int vunummer, int vuwaarde)
  424. {
  425.     if (Skin.Object[vunummer].maxw == 1) // Vertical Slider
  426.     {
  427.         if (Skin.Object[vunummer].x2 != 0) {
  428.             window_bmp_blt(hWnd, graphics.bmp_main_up,
  429.                            Skin.Object[vunummer].x,
  430.                            Skin.Object[vunummer].y,
  431.                            Skin.Object[vunummer].w,
  432.                            Skin.Object[vunummer].h +
  433.                            Skin.Object[vunummer].h2,
  434.                            Skin.Object[vunummer].x,
  435.                            Skin.Object[vunummer].y);
  436.             window_bmp_blt(hWnd, graphics.bmp_main_down,
  437.                            Skin.Object[vunummer].x,
  438.                            vuwaarde,
  439.                            Skin.Object[vunummer].w2,
  440.                            Skin.Object[vunummer].h2,
  441.                            Skin.Object[vunummer].x2,
  442.                            Skin.Object[vunummer].y2);
  443.             return;
  444.         }
  445.         window_bmp_blt(hWnd, graphics.bmp_main_up,
  446.                        Skin.Object[vunummer].x,
  447.                        vuwaarde,
  448.                        Skin.Object[vunummer].w,
  449.                        Skin.Object[vunummer].h - (vuwaarde -
  450.                                                   Skin.Object[vunummer].y),
  451.                        Skin.Object[vunummer].x, vuwaarde);
  452.         window_bmp_blt(hWnd, graphics.bmp_main_down,
  453.                        Skin.Object[vunummer].x,
  454.                        Skin.Object[vunummer].y,
  455.                        Skin.Object[vunummer].w,
  456.                        vuwaarde - Skin.Object[vunummer].y,
  457.                        Skin.Object[vunummer].x, Skin.Object[vunummer].y);
  458.     } else // Horizontal Slider
  459.     {
  460.         if (Skin.Object[vunummer].x2 != 0) {
  461.             window_bmp_blt(hWnd, graphics.bmp_main_up,
  462.                            Skin.Object[vunummer].x,
  463.                            Skin.Object[vunummer].y,
  464.                            Skin.Object[vunummer].w +
  465.                            Skin.Object[vunummer].w2,
  466.                            Skin.Object[vunummer].h,
  467.                            Skin.Object[vunummer].x,
  468.                            Skin.Object[vunummer].y);
  469.             window_bmp_blt(hWnd, graphics.bmp_main_down,
  470.                            vuwaarde,
  471.                            Skin.Object[vunummer].y,
  472.                            Skin.Object[vunummer].w2,
  473.                            Skin.Object[vunummer].h2,
  474.                            Skin.Object[vunummer].x2,
  475.                            Skin.Object[vunummer].y2);
  476.             return;
  477.         }
  478.         window_bmp_blt(hWnd, graphics.bmp_main_up,
  479.                        Skin.Object[vunummer].x,
  480.                        Skin.Object[vunummer].y,
  481.                        vuwaarde - Skin.Object[vunummer].x,
  482.                        Skin.Object[vunummer].h,
  483.                        Skin.Object[vunummer].x, Skin.Object[vunummer].y);
  484.         window_bmp_blt(hWnd, graphics.bmp_main_down,
  485.                        vuwaarde,
  486.                        Skin.Object[vunummer].y,
  487.                        Skin.Object[vunummer].w - (vuwaarde -
  488.                                                   Skin.Object[vunummer].x),
  489.                        Skin.Object[vunummer].h, vuwaarde,
  490.                        Skin.Object[vunummer].y);
  491.     }
  492. }
  493. void    main_draw_vu_from_value(HWND hWnd, int vunummer, int vuwaarde)
  494. {
  495.     int     positionwaarde;
  496.     if (Skin.Object[vunummer].maxw == 1) // Vertical slider
  497.     {
  498.         switch (vunummer) {
  499.         case VolumeSlider:
  500.             positionwaarde =
  501.                 (int) ((float) Skin.Object[vunummer].y +
  502.                        Skin.Object[vunummer].h -
  503.                        (((float) vuwaarde / (float) 100.0f) *
  504.                         (float) Skin.Object[vunummer].h));
  505.             break;
  506.         case PositionSlider:
  507.             positionwaarde =
  508.                 (int) (Skin.Object[PositionSlider].y +
  509.                        Skin.Object[PositionSlider].h) - vuwaarde;
  510.             if (vuwaarde > Skin.Object[PositionSlider].h)
  511.                 positionwaarde = Skin.Object[PositionSlider].y;
  512.             break;
  513.         default: // so it's a eq
  514.             positionwaarde =
  515.                 (int) ((float) Skin.Object[vunummer].y +
  516.                        Skin.Object[vunummer].h -
  517.                        (
  518.                            ((float) (vuwaarde + 128.0f) /
  519.                             (float) 255.0f) * (float) Skin.Object[vunummer].h));
  520.         }
  521.         main_draw_vu_from_mouse(hWnd, vunummer, positionwaarde);
  522.     } else // Horizontal Slider
  523.     {
  524.         switch (vunummer) {
  525.         case VolumeSlider:
  526.             positionwaarde =
  527.                 (int) ((float) Skin.Object[vunummer].x +
  528.                        (((float) vuwaarde / (float) 100.0f) *
  529.                         (float) Skin.Object[vunummer].w));
  530.             break;
  531.         case PositionSlider:
  532.             positionwaarde =
  533.                 (int) vuwaarde + Skin.Object[PositionSlider].x;
  534.             if (vuwaarde > Skin.Object[PositionSlider].w)
  535.                 positionwaarde =
  536.                     Skin.Object[PositionSlider].w +
  537.                     Skin.Object[PositionSlider].x;
  538.             break;
  539.         default: // so it's a eq
  540.             positionwaarde =
  541.                 (int) ((float) Skin.Object[vunummer].x +
  542.                        (
  543.                            ((float) (vuwaarde + 128.0) /
  544.                             (float) 255.0f) * (float) Skin.Object[vunummer].w));
  545.         }
  546.         main_draw_vu_from_mouse(hWnd, vunummer, positionwaarde);
  547.     }
  548. }
  549. BOOL    main_draw_vu_all(HWND hWnd, WPARAM wParam, LPARAM lParam,
  550.                          BOOL rememberlastval)
  551. {
  552.     POINTS  cursorpos;
  553.     int     teller;
  554.     int     moveit = TRUE;
  555.     cursorpos = MAKEPOINTS(lParam);
  556.     for (teller = VolumeSlider; teller <= Eq8; teller++) {
  557.         int knobx=0,knoby=0;
  558.         int addx=0,addy=0;
  559.         if (Skin.Object[teller].maxw == 0) { // we have  a horizontal one
  560.             knobx=Skin.Object[teller].w2/2;
  561.             addx=1;
  562.         }
  563.         else { // we have  a vertical one
  564.             knoby=Skin.Object[teller].h2/2;
  565.             addy=1;
  566.         }
  567.         if (cursorpos.x >= Skin.Object[teller].x + knobx - addx
  568.                 && cursorpos.y >= Skin.Object[teller].y + knoby - addy
  569.                 && cursorpos.x <=
  570.                 Skin.Object[teller].x + Skin.Object[teller].w + (knobx*2) + addx
  571.                 && cursorpos.y <=
  572.                 Skin.Object[teller].y + Skin.Object[teller].h + (knoby*2) + addy) {
  573.             int waarde=0;
  574.             if (Skin.Object[teller].maxw == 0)
  575.                 cursorpos.x-=knobx;
  576.             else
  577.                 cursorpos.y-=knoby;
  578.             moveit = FALSE;
  579.             switch (teller) {
  580.             case Eq1:
  581.             case Eq2:
  582.             case Eq3:
  583.             case Eq4:
  584.             case Eq5:
  585.             case Eq6:
  586.             case Eq7:
  587.             case Eq8:
  588.                 if (globals.main_bool_slider_keep_focus == FALSE) {
  589.                     if (Skin.Object[teller].maxw == 1)
  590.                         options.eq_settings[(teller - Eq1) + 1] =
  591.                             (int) (
  592.                                 ((Skin.Object
  593.                                   [teller].y +
  594.                                   Skin.Object[teller].h) -
  595.                                  cursorpos.y) * (255 /
  596.                                                  (float)
  597.                                                  Skin.Object[teller].
  598.                                                  h)) - 128;
  599.                     else
  600.                         options.eq_settings[(teller - Eq1) + 1] =
  601.                             (int) ((cursorpos.x - Skin.Object[teller].x) *
  602.                                    (255 / (float) Skin.Object[teller].w)) -
  603.                             128;
  604.                     if(options.eq_settings[(teller - Eq1) + 1]>127) options.eq_settings[(teller - Eq1) + 1]=127;
  605.                     if(options.eq_settings[(teller - Eq1) + 1]<-128)   options.eq_settings[(teller - Eq1) + 1]=-128;
  606.                     waarde=options.eq_settings[(teller - Eq1) + 1];
  607.                     main_set_eq();
  608.                 }
  609.                 break;
  610.             case VolumeSlider:
  611.                 {
  612.                     globals.main_bool_slider_keep_focus = TRUE;
  613.                     if (Skin.Object[teller].maxw == 1) // we have  a vertical one
  614.                     {
  615.                         globals.m_iVolume = (int) (((100.0f / (float)
  616.                                                      Skin.Object[teller].h) *
  617.                                                     ( (Skin.Object[teller].y +
  618.                                                        Skin.Object[teller].h) -
  619.                                                       cursorpos.y)));
  620.                     }
  621.                     else
  622.                     {
  623.                         globals.m_iVolume =
  624.                             (int) ((cursorpos.x - Skin.Object[teller].x) *
  625.                                    (100 / (float) Skin.Object[teller].w));
  626.                     }
  627.                     if(globals.m_iVolume>100) globals.m_iVolume=100;
  628.                     if(globals.m_iVolume<0) globals.m_iVolume=0;
  629.                     // CP_TRACE1("level=%d",globals.m_iVolume);
  630.                     CPI_Player__SetVolume(globals.m_hPlayer, globals.m_iVolume);
  631.                     waarde=globals.m_iVolume;
  632.                     break;
  633.                 }
  634.             case PositionSlider:
  635.                 if(globals.m_bStreaming == TRUE)
  636.                 {
  637.                     waarde = globals.m_iStreamingPortion;
  638.                 }
  639.                 else if(globals.main_bool_slider_keep_focus == FALSE)
  640.                 {
  641.                     if (Skin.Object[teller].maxw == 0)
  642.                     {
  643.                         globals.main_int_track_position = cursorpos.x - Skin.Object[teller].x;
  644.                         CPI_Player__Seek(globals.m_hPlayer, globals.main_int_track_position, Skin.Object[teller].w);
  645.                     }
  646.                     else
  647.                     {
  648.                         globals.main_int_track_position = ((Skin.Object[teller].y + Skin.Object[teller].h) - cursorpos.y);
  649.                         CPI_Player__Seek(globals.m_hPlayer, globals.main_int_track_position, Skin.Object[teller].h);
  650.                     }
  651.                     waarde=globals.main_int_track_position;
  652.                 }
  653.                 break;
  654.             }
  655.             // main_draw_vu_from_mouse(hWnd, teller, Skin.Object[teller].maxw ? cursorpos.y : cursorpos.x);
  656.             main_draw_vu_from_value(hWnd, teller, waarde);
  657.         }
  658.     }
  659.     return moveit;
  660. }
  661. int window_bmp_blt(HWND hWnd, HBITMAP SrcBmp, int srcx, int srcy, int srcw, int srch, int dstx, int dsty)
  662. {
  663.     if (srcw && srch) {
  664.         HBITMAP h = (HBITMAP) SelectObject(drawables.dc_memory, SrcBmp);
  665.         int     retval = BitBlt(drawables.dc_main, srcx, srcy, srcw, srch,
  666.                                 drawables.dc_memory, dstx, dsty,
  667.                                 SRCCOPY);
  668.         SelectObject(drawables.dc_memory, h);
  669.         return retval;
  670.     }
  671.     return FALSE;
  672. }
  673. void    main_draw_controls_all(HWND hWnd)
  674. {
  675.     int     teller;
  676.     for (teller = PlaySwitch; teller <= ExitButton; teller++) {
  677.         window_bmp_blt(hWnd, graphics.bmp_main_up, Skin.Object[teller].x,
  678.                        Skin.Object[teller].y, Skin.Object[teller].w,
  679.                        Skin.Object[teller].h, Skin.Object[teller].x,
  680.                        Skin.Object[teller].y);
  681.         window_bmp_blt(hWnd, graphics.bmp_main_up, Skin.Object[teller].x2,
  682.                        Skin.Object[teller].y2, Skin.Object[teller].w2,
  683.                        Skin.Object[teller].h2, Skin.Object[teller].x2,
  684.                        Skin.Object[teller].y2);
  685.         switch (teller) {
  686.         case RepeatSwitch:
  687.             if (options.repeat_playlist)
  688.                 window_bmp_blt(hWnd, graphics.bmp_main_switch,
  689.                                Skin.Object[RepeatSwitch].x2,
  690.                                Skin.Object[RepeatSwitch].y2,
  691.                                Skin.Object[RepeatSwitch].w2,
  692.                                Skin.Object[RepeatSwitch].h2,
  693.                                Skin.Object[RepeatSwitch].x2,
  694.                                Skin.Object[RepeatSwitch].y2);
  695.             break;
  696.         case ShuffleSwitch:
  697.             if (options.shuffle_play)
  698.                 window_bmp_blt(hWnd, graphics.bmp_main_switch,
  699.                                Skin.Object[ShuffleSwitch].x2,
  700.                                Skin.Object[ShuffleSwitch].y2,
  701.                                Skin.Object[ShuffleSwitch].w2,
  702.                                Skin.Object[ShuffleSwitch].h2,
  703.                                Skin.Object[ShuffleSwitch].x2,
  704.                                Skin.Object[ShuffleSwitch].y2);
  705.             break;
  706.         case EqSwitch:
  707.             if (options.equalizer)
  708.                 window_bmp_blt(hWnd, graphics.bmp_main_switch,
  709.                                Skin.Object[EqSwitch].x2,
  710.                                Skin.Object[EqSwitch].y2,
  711.                                Skin.Object[EqSwitch].w2,
  712.                                Skin.Object[EqSwitch].h2,
  713.                                Skin.Object[EqSwitch].x2,
  714.                                Skin.Object[EqSwitch].y2);
  715.             break;
  716.         case PlaySwitch:
  717.             if(globals.m_enPlayerState == cppsPlaying)
  718.                 window_bmp_blt(hWnd, graphics.bmp_main_switch,
  719.                                Skin.Object[teller].x2,
  720.                                Skin.Object[teller].y2,
  721.                                Skin.Object[teller].w2,
  722.                                Skin.Object[teller].h2,
  723.                                Skin.Object[teller].x2,
  724.                                Skin.Object[teller].y2);
  725.             break;
  726.         case PauseSwitch:
  727.             if(globals.m_enPlayerState == cppsPaused)
  728.                 window_bmp_blt(hWnd, graphics.bmp_main_switch,
  729.                                Skin.Object[teller].x2,
  730.                                Skin.Object[teller].y2,
  731.                                Skin.Object[teller].w2,
  732.                                Skin.Object[teller].h2,
  733.                                Skin.Object[teller].x2,
  734.                                Skin.Object[teller].y2);
  735.             break;
  736.         case StopSwitch:
  737.             if(globals.m_enPlayerState == cppsStopped)
  738.                 window_bmp_blt(hWnd, graphics.bmp_main_switch,
  739.                                Skin.Object[teller].x2,
  740.                                Skin.Object[teller].y2,
  741.                                Skin.Object[teller].w2,
  742.                                Skin.Object[teller].h2,
  743.                                Skin.Object[teller].x2,
  744.                                Skin.Object[teller].y2);
  745.             break;
  746.         }
  747.     }
  748. }
  749. void    options_create(HWND hWnd)
  750. {
  751.     windows.dlg_options = CreateDialog(GetModuleHandle(NULL), // handle to application instance
  752.                                        MAKEINTRESOURCE(IDD_OPTIONS), // identifies dialog box template
  753.                                        hWnd, // handle to owner window
  754.                                        options_windowproc); // pointer to dialog box procedure
  755.     ShowWindow(windows.dlg_options, SW_SHOWNORMAL);
  756. }
  757. void    url_create(HWND hWnd)
  758. {
  759.     DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_URL),
  760.               hWnd, url_windowproc);
  761. }
  762. void    main_menuproc(HWND hWnd, LPPOINT points)
  763. {
  764.     int     retval;
  765.     /* SetForegroundWindow and the ensuing null PostMessage is a
  766.        workaround for a Windows 95 bug (see MSKB article Q135788,
  767.        http://www.microsoft.com/kb/articles/q135/7/88.htm, I think).
  768.        In typical Microsoft style this bug is listed as "by design".
  769.        SetForegroundWindow also causes our MessageBox to pop up in front
  770.        of any other application's windows. */
  771.     SetForegroundWindow(hWnd);
  772.     /* We specifiy TPM_RETURNCMD, so TrackPopupMenu returns the menu
  773.        selection instead of returning immediately and our getting a
  774.        WM_COMMAND with the selection. You don't have to do it this way.
  775.      */
  776.     switch (retval =
  777.                 TrackPopupMenu(globals.main_menu_popup,
  778.                                TPM_RETURNCMD | TPM_RIGHTBUTTON, points->x,
  779.                                points->y, 0, hWnd, NULL)) // LPRECT user can click in
  780.         // without dismissing menu
  781.     {
  782.     case MENU_EXIT:
  783.         DestroyWindow(hWnd);
  784.         break;
  785.     case MENU_PLAYLIST:
  786.         CPVERB_TogglePlaylistWindow(vaDoVerb, hWnd);
  787.         break;
  788.     case MENU_OPENFILE:
  789.         main_play_control(ID_LOAD, hWnd);
  790.         break;
  791.     case MENU_ABOUT:
  792.         about_create(hWnd);
  793.         break;
  794.     case MENU_OPENLOC:
  795.         url_create(hWnd);
  796.         break;
  797.     case MENU_OPTIONS:
  798.         options_create(hWnd);
  799.         break;
  800.     case MENU_SKIN_DEFAULT:
  801.         {
  802.             options.use_default_skin = TRUE;
  803.             globals.main_bool_skin_next_is_default = TRUE;
  804.             main_play_control(ID_LOADSKIN, hWnd);
  805.             break;
  806.         }
  807.     default:
  808.         {
  809.             if (main_play_control((WORD) retval, hWnd) != -1)
  810.                 break;
  811.             if (GetMenuString
  812.                     (globals.main_menu_popup, retval, NULL, 0, MF_BYCOMMAND)) {
  813.                 GetMenuString(globals.main_menu_popup, retval,
  814.                               options.main_skin_file, MAX_PATH,
  815.                               MF_BYCOMMAND);
  816.                 main_skin_select_menu(options.main_skin_file);
  817.                 options.use_default_skin = FALSE;
  818.                 globals.main_bool_skin_next_is_default = FALSE;
  819.                 main_play_control(ID_LOADSKIN, hWnd);
  820.             }
  821.             break;
  822.         }
  823.     }
  824.     PostMessage(hWnd, 0, 0, 0); // see above
  825. }
  826. LRESULT CALLBACK
  827. main_windowproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  828. {
  829.     // Give the player a crack at the messages - it needs these so that it can call the notification callbacks
  830.     if(globals.m_hPlayer)
  831.     {
  832.         LRESULT lResult;
  833.         const BOOL bHandled = CPI_Player__HandleNotifyMessages(globals.m_hPlayer, message, wParam, lParam, &lResult);
  834.         if(bHandled == TRUE)
  835.             return lResult;
  836.     }
  837.     switch (message) {
  838.         POINTS  cursorpos;
  839.     case WM_TIMER:
  840.         if (wParam == CPC_TIMERID_SCROLLTITLETEXT) {
  841.             main_draw_title(hWnd);
  842.             if(globals.mail_int_title_scroll_max_position == 0)
  843.                 globals.main_int_title_scroll_position = 0;
  844.             else
  845.             {
  846.                 globals.main_int_title_scroll_position++;
  847.                 if(globals.main_int_title_scroll_position > globals.mail_int_title_scroll_max_position)
  848.                     globals.main_int_title_scroll_position -= globals.mail_int_title_scroll_max_position;
  849.             }
  850.         }
  851.         else if(wParam == CPC_TIMERID_INTERTRACKDELAY)
  852.         {
  853.             KillTimer(hWnd, CPC_TIMERID_INTERTRACKDELAY);
  854.             CPL_PlayItem(globals.m_hPlaylist, FALSE, pmNextItem);
  855.         }
  856.         else if(wParam == CPC_TIMERID_ROTATINGSMILY)
  857.         {
  858.             CPSYSICON_AdvanceFrame(globals.m_hSysIcon);
  859.         }
  860.         break;
  861.     case WM_MOUSEWHEEL:
  862.         {
  863.             short zDelta = (short) HIWORD(wParam);
  864.             if (zDelta < 0)
  865.                 globals.m_iVolume -= 5;
  866.             else
  867.                 globals.m_iVolume += 5;
  868.             if (globals.m_iVolume > 100)
  869.                 globals.m_iVolume = 100;
  870.             if (globals.m_iVolume < 0)
  871.                 globals.m_iVolume = 0;
  872.             main_draw_vu_from_value(hWnd, VolumeSlider, globals.m_iVolume);
  873.             CPI_Player__SetVolume(globals.m_hPlayer, globals.m_iVolume);
  874.             return 0;
  875.         }
  876.     case WM_COPYDATA:
  877.         {
  878.             PCOPYDATASTRUCT copydata = (PCOPYDATASTRUCT) lParam;
  879.             int i=0,count=0;
  880.             BOOL    wegotsome;
  881.             char *string=copydata->lpData;
  882.             int argc = copydata->dwData;
  883.             char *argv[255]={0};
  884.             while(count<argc)
  885.             {
  886.                 argv[count++]=string;
  887.                 string+=strlen(string)+1;
  888.             }
  889.             cmdline_parse_options(argc,argv);
  890.             wegotsome = cmdline_parse_files(argc,argv);
  891.             if (globals.playlist_bool_addsong == FALSE
  892.                     && wegotsome == TRUE) {
  893.                 CPL_PlayItem(globals.m_hPlaylist, TRUE, pmCurrentItem);
  894.             }
  895.             main_draw_controls_all(hWnd);
  896.             main_set_eq();
  897.             globals.playlist_bool_addsong = FALSE;
  898.             globals.playlist_last_add_time = GetTickCount();
  899.             break;
  900.         }
  901.     case WM_NOTIFYICON:
  902.         switch (lParam) {
  903.         case WM_RBUTTONUP:
  904.             {
  905.                 POINT   pt;
  906.                 GetCursorPos(&pt);
  907.                 main_menuproc(hWnd, &pt);
  908.             }
  909.             break;
  910.         case WM_MBUTTONUP:
  911.             if(globals.m_enPlayerState == cppsPlaying || globals.m_enPlayerState == cppsPaused)
  912.                 CPVERB_Pause(vaDoVerb, hWnd);
  913.             break;
  914.         case WM_LBUTTONUP:
  915.             {
  916.                 RECT    rcClip;
  917.                 RECT    rcClient;
  918.                 int     Result;
  919.                 GetClientRect(hWnd, &rcClient);
  920.                 Result = GetClipBox(drawables.dc_main, &rcClip);
  921.                 if (Result == COMPLEXREGION
  922.                         && EqualRect(&rcClip, &rcClient)) {
  923.                     if (options.show_on_taskbar)
  924.                         ShowWindow(hWnd, SW_MINIMIZE);
  925.                     else
  926.                         ShowWindow(hWnd, SW_HIDE);
  927.                 } else {
  928.                     ShowWindow(hWnd, SW_RESTORE);
  929.                 }
  930.             }
  931.             BringWindowToTop(hWnd);
  932.             SetForegroundWindow(hWnd);
  933.             break;
  934.         }
  935.         break;
  936.     case WM_CREATE:
  937.         if(options.scroll_track_title)
  938.             SetTimer(hWnd, CPC_TIMERID_SCROLLTITLETEXT, 50, NULL);
  939.         else
  940.             KillTimer(hWnd, CPC_TIMERID_SCROLLTITLETEXT);
  941.         SetTimer(hWnd, CPC_TIMERID_ROTATINGSMILY, 100, NULL);
  942.         break;
  943.     case WM_RBUTTONDOWN:
  944.         {
  945.             POINT   points;
  946.             GetCursorPos(&points);
  947.             main_menuproc(hWnd, &points);
  948.             break;
  949.         }
  950.     case WM_CAPTURECHANGED:
  951.         ReleaseCapture();
  952.         break;
  953.     case WM_LBUTTONDOWN:
  954.         {
  955.             int     teller;
  956.             BOOL    moveit = TRUE;
  957.             SetCapture(hWnd);
  958.             cursorpos = MAKEPOINTS(lParam);
  959.             for (teller = 0; teller <= ExitButton; teller++) {
  960.                 if (cursorpos.x >= Skin.Object[teller].x
  961.                         && cursorpos.y >= Skin.Object[teller].y
  962.                         && cursorpos.x <=
  963.                         Skin.Object[teller].x + Skin.Object[teller].w
  964.                         && cursorpos.y <=
  965.                         Skin.Object[teller].y + Skin.Object[teller].h) {
  966.                     window_bmp_blt(hWnd, graphics.bmp_main_down,
  967.                                    Skin.Object[teller].x,
  968.                                    Skin.Object[teller].y,
  969.                                    Skin.Object[teller].w,
  970.                                    Skin.Object[teller].h,
  971.                                    Skin.Object[teller].x,
  972.                                    Skin.Object[teller].y);
  973.                     moveit = FALSE;
  974.                     return 0;
  975.                 }
  976.             }
  977.             if (cursorpos.x >= Skin.Object[TimeText].x
  978.                     && cursorpos.y >= Skin.Object[TimeText].y
  979.                     && cursorpos.x <=
  980.                     Skin.Object[TimeText].x + (Skin.Object[TimeText].w * 8)
  981.                     && cursorpos.y <=
  982.                     Skin.Object[TimeText].y + Skin.Object[TimeText].h) {
  983.                 moveit = FALSE;
  984.             }
  985.             // id3tag editor
  986.             if (cursorpos.x >= Skin.Object[SongtitleText].x
  987.                     && cursorpos.y >= Skin.Object[SongtitleText].y
  988.                     && cursorpos.x <=
  989.                     Skin.Object[SongtitleText].x +
  990.                     (Skin.Object[SongtitleText].w *
  991.                      Skin.Object[SongtitleText].maxw)
  992.                     && cursorpos.y <=
  993.                     Skin.Object[SongtitleText].y +
  994.                     Skin.Object[SongtitleText].h) {
  995.                 moveit = FALSE;
  996.             }
  997.             // VU & volume
  998.             if (main_draw_vu_all(hWnd, wParam, lParam, TRUE) == FALSE)
  999.                 moveit = FALSE;
  1000.             // Move Window
  1001.             if (cursorpos.x >= Skin.Object[MoveArea].x
  1002.                     && cursorpos.y >= Skin.Object[MoveArea].y
  1003.                     && cursorpos.x <=
  1004.                     Skin.Object[MoveArea].x + Skin.Object[MoveArea].w
  1005.                     && cursorpos.y <=
  1006.                     Skin.Object[MoveArea].y + Skin.Object[MoveArea].h
  1007.                     || (moveit == TRUE && options.easy_move == TRUE)) {
  1008.                 ReleaseCapture();
  1009.                 SendMessage(hWnd, WM_SYSCOMMAND, SC_MOVE | HTCLIENT, 0);
  1010.             }
  1011.             break;
  1012.         }
  1013.     case WM_MOUSEMOVE:
  1014.         {
  1015.             MSG     msg;
  1016.             if (wParam == MK_LBUTTON)
  1017.                 main_draw_vu_all(hWnd, wParam, lParam, FALSE);
  1018.             msg.lParam = lParam;
  1019.             msg.wParam = wParam;
  1020.             msg.message = message;
  1021.             msg.hwnd = hWnd;
  1022.             SendMessage(windows.wnd_tooltip, TTM_RELAYEVENT, 0,
  1023.                         (LPARAM) (LPMSG) & msg);
  1024.         }
  1025.         break;
  1026.     case WM_CANCELMODE:
  1027.         ReleaseCapture();
  1028.         break;
  1029.     case WM_LBUTTONUP:
  1030.         {
  1031.             int     teller;
  1032.             ReleaseCapture();
  1033.             globals.main_bool_slider_keep_focus = FALSE;
  1034.             cursorpos = MAKEPOINTS(lParam);
  1035.             for (teller = PlaySwitch; teller <= ExitButton; teller++) {
  1036.                 if (cursorpos.x >= Skin.Object[teller].x
  1037.                         && cursorpos.y >= Skin.Object[teller].y
  1038.                         && cursorpos.x <=
  1039.                         Skin.Object[teller].x + Skin.Object[teller].w
  1040.                         && cursorpos.y <=
  1041.                         Skin.Object[teller].y + Skin.Object[teller].h) {
  1042.                     switch (teller) {
  1043.                     case PlaySwitch:
  1044.                         main_play_control(ID_PLAY, hWnd);
  1045.                         break;
  1046.                     case PauseSwitch:
  1047.                         main_play_control(ID_PAUSE, hWnd);
  1048.                         break;
  1049.                     case StopSwitch:
  1050.                         main_play_control(ID_STOP, hWnd);
  1051.                         break;
  1052.                     case RepeatSwitch:
  1053.                         main_play_control(ID_REPEAT, hWnd);
  1054.                         break;
  1055.                     case ShuffleSwitch:
  1056.                         main_play_control(ID_SHUFFLE, hWnd);
  1057.                         break;
  1058.                     case EqSwitch:
  1059.                         main_play_control(ID_EQUALIZER, hWnd);
  1060.                         break;
  1061.                     case PlaylistButton:
  1062.                         main_play_control(ID_PLAYLIST, hWnd);
  1063.                         break;
  1064.                     case NextButton:
  1065.                         main_play_control(ID_NEXT, hWnd);
  1066.                         break;
  1067.                     case PrevButton:
  1068.                         main_play_control(ID_PREVIOUS, hWnd);
  1069.                         break;
  1070.                     case MinimizeButton:
  1071.                         if (options.show_on_taskbar)
  1072.                             ShowWindow(hWnd, SW_MINIMIZE);
  1073.                         else
  1074.                             ShowWindow(hWnd, SW_HIDE);
  1075.                         break;
  1076.                     case NextSkinButton:
  1077.                         main_play_control(ID_LOADSKIN, hWnd);
  1078.                         break;
  1079.                     case ExitButton:
  1080.                         DestroyWindow(hWnd);
  1081.                         break;
  1082.                     case EjectButton:
  1083.                         main_play_control(ID_LOAD, hWnd);
  1084.                         break;
  1085.                     }
  1086.                 }
  1087.             }
  1088.             // options.show_remaining_time time
  1089.             if (cursorpos.x >= Skin.Object[TimeText].x
  1090.                     && cursorpos.y >= Skin.Object[TimeText].y
  1091.                     && cursorpos.x <=
  1092.                     (Skin.Object[TimeText].x + (Skin.Object[TimeText].w * 8))
  1093.                     && cursorpos.y <=
  1094.                     (Skin.Object[TimeText].y + Skin.Object[TimeText].h)) {
  1095.                 options.show_remaining_time = !options.show_remaining_time;
  1096.                 main_draw_time(hWnd);
  1097.                 break;
  1098.             }
  1099.             main_draw_controls_all(hWnd);
  1100.             break;
  1101.         }
  1102.     case WM_PAINT:
  1103.         {
  1104.             PAINTSTRUCT ps;
  1105.             HDC     winhdc = BeginPaint(hWnd, &ps);
  1106.             if (graphics.bmp_main_up) {
  1107.                 BITMAP  bm;
  1108.                 int     teller, teller2 = 1;
  1109.                 HPALETTE oldpal;
  1110.                 oldpal =
  1111.                     SelectPalette(drawables.dc_main, graphics.pal_main,
  1112.                                   FALSE);
  1113.                 RealizePalette(drawables.dc_main);
  1114.                 GetObject(graphics.bmp_main_up, sizeof(bm), &bm);
  1115.                 window_bmp_blt(hWnd, graphics.bmp_main_up, ps.rcPaint.left,
  1116.                                ps.rcPaint.top, ps.rcPaint.right,
  1117.                                ps.rcPaint.bottom, ps.rcPaint.left,
  1118.                                ps.rcPaint.top);
  1119.                 for (teller = Eq1; teller <= Eq8; teller++)
  1120.                     main_draw_vu_from_value(hWnd, teller,
  1121.                                             options.eq_settings
  1122.                                             [teller2++]);
  1123.                 main_draw_vu_from_value(hWnd, VolumeSlider, globals.m_iVolume);
  1124.                 if(globals.m_bStreaming == TRUE)
  1125.                     main_draw_vu_from_value(windows.wnd_main, PositionSlider, globals.m_iStreamingPortion);
  1126.                 else
  1127.                     main_draw_vu_from_value(windows.wnd_main, PositionSlider, globals.main_int_track_position);
  1128.                 main_draw_tracknr(hWnd);
  1129.                 main_draw_title(hWnd);
  1130.                 main_draw_time(hWnd);
  1131.                 main_draw_bitrate(hWnd);
  1132.                 main_draw_frequency(hWnd);
  1133.                 main_draw_controls_all(hWnd);
  1134.                 SelectPalette(drawables.dc_main, oldpal, FALSE);
  1135.             }
  1136.             EndPaint(hWnd, &ps);
  1137.             return 0;
  1138.         }
  1139.     case WM_MOVE:
  1140.         options.main_window_pos.x = (int) (short) LOWORD(lParam); // horizontal position
  1141.         options.main_window_pos.y = (int) (short) HIWORD(lParam); // vertical position
  1142.         return 0;
  1143.     case WM_SYSKEYDOWN:
  1144.     case WM_KEYDOWN:
  1145.         {
  1146.             const BOOL bAltIsDown = (GetAsyncKeyState(VK_MENU)  & 0x8000) ? TRUE : FALSE;
  1147.             const BOOL bCtrlIsDown = (GetAsyncKeyState(VK_CONTROL)  & 0x8000) ? TRUE : FALSE;
  1148.             const BOOL bShiftIsDown = (GetAsyncKeyState(VK_SHIFT)  & 0x8000) ? TRUE : FALSE;
  1149.             CP_HandleKeyPress_Player(hWnd, (int)wParam, bAltIsDown, bCtrlIsDown, bShiftIsDown);
  1150.         }
  1151.         return 0;
  1152.     case WM_DESTROY:
  1153.         if (options.remember_playlist == TRUE)
  1154.             playlist_write_default();
  1155.         CPlaylistWindow_Destroy();
  1156.         // CPlayerWindow_Destroy();
  1157.         options_write();
  1158.         CPL_DestroyPlaylist(globals.m_hPlaylist);
  1159.         CPI_Player__Destroy(globals.m_hPlayer);
  1160.         CPIC_FreeIndicators();
  1161. #if _DEBUG
  1162.         globals.m_hPlaylist = NULL;
  1163.         globals.m_hPlayer = NULL;
  1164. #endif
  1165.         PostQuitMessage(0);
  1166.         break;
  1167.     case WM_COMMAND:
  1168.         {
  1169.             int     accelreturn = main_play_control(LOWORD(wParam), hWnd);
  1170.             main_draw_controls_all(hWnd);
  1171.             return accelreturn;
  1172.         }
  1173.         // Set the global window handle and handle normally
  1174.     case WM_NCCREATE:
  1175.         windows.wnd_main = hWnd;
  1176.         return DefWindowProc(hWnd, message, wParam, lParam);
  1177.         break;
  1178.     case WM_DROPFILES:
  1179.         {
  1180.             const BOOL bCtrlIsDown = (GetAsyncKeyState(VK_CONTROL)  & 0x8000) ? TRUE : FALSE;
  1181.             HDROP hDrop = (HDROP)wParam;
  1182.             // Replace the current list by default - append if CTRL is down
  1183.             CPL_SyncLoadNextFile(globals.m_hPlaylist);
  1184.             if(bCtrlIsDown == FALSE)
  1185.             {
  1186.                 CPL_Empty(globals.m_hPlaylist);
  1187.                 globals.m_enPlayerState = cppsStopped;
  1188.                 CPL_AddDroppedFiles(globals.m_hPlaylist, hDrop);
  1189.                 CPL_PlayItem(globals.m_hPlaylist, TRUE, pmCurrentItem);
  1190.             }
  1191.             else
  1192.                 CPL_AddDroppedFiles(globals.m_hPlaylist, hDrop);
  1193.         }
  1194.     case WM_HOTKEY:
  1195.         {
  1196.             const int iIDHotKey = (int)wParam;
  1197.             if(iIDHotKey == CP_HOTKEY_NEXT)
  1198.                 CPVERB_NextTrack(vaDoVerb, hWnd);
  1199.             if(iIDHotKey == CP_HOTKEY_PREV)
  1200.                 CPVERB_PrevTrack(vaDoVerb, hWnd);
  1201.             if(iIDHotKey == CP_HOTKEY_STOP)
  1202.                 CPVERB_Stop(vaDoVerb, hWnd);
  1203.             if(iIDHotKey == CP_HOTKEY_PLAY0 || iIDHotKey == CP_HOTKEY_PLAY1)
  1204.             {
  1205.                 if(globals.m_enPlayerState == cppsPlaying)
  1206.                     CPVERB_Pause(vaDoVerb, hWnd);
  1207.                 else
  1208.                     CPVERB_Play(vaDoVerb, hWnd);
  1209.             }
  1210.         }
  1211.     default:
  1212.         return DefWindowProc(hWnd, message, wParam, lParam);
  1213.     }
  1214.     return (0);
  1215. }
  1216. int     main_play_control(WORD wParam, HWND hWnd)
  1217. {
  1218.     switch (wParam)
  1219.     {
  1220.     case ID_PLAYLIST:
  1221.         CPVERB_TogglePlaylistWindow(vaDoVerb, hWnd);
  1222.         return !options.show_playlist;
  1223.         break;
  1224.     case ID_REPEAT:
  1225.         CPVERB_ToggleRepeat(vaDoVerb, hWnd);
  1226.         return !options.shuffle_play;
  1227.     case ID_EXIT:
  1228.         CPVERB_Exit(vaDoVerb, hWnd);
  1229.         break;
  1230.     case ID_SHUFFLE:
  1231.         CPVERB_ToggleShuffle(vaDoVerb, hWnd);
  1232.         return !options.shuffle_play;
  1233.     case ID_EQUALIZER:
  1234.         CPVERB_ToggleEqualiser(vaDoVerb, hWnd);
  1235.         return !options.equalizer;
  1236.     case ID_STOP:
  1237.         CPVERB_Stop(vaDoVerb, hWnd);
  1238.         break;
  1239.     case ID_PLAY:
  1240.         CPVERB_Play(vaDoVerb, hWnd);
  1241.         break;
  1242.     case ID_PAUSE:
  1243.         CPVERB_Pause(vaDoVerb, hWnd);
  1244.         return 0;
  1245.     case ID_NEXT:
  1246.         CPVERB_NextTrack(vaDoVerb, hWnd);
  1247.         break;
  1248.     case ID_PREVIOUS:
  1249.         CPVERB_PrevTrack(vaDoVerb, hWnd);
  1250.         break;
  1251.     case ID_LOAD:
  1252.         CPVERB_OpenFile(vaDoVerb, hWnd);
  1253.         break;
  1254.     case ID_VOLUMEUP:
  1255.         CPVERB_VolumeUp(vaDoVerb, hWnd);
  1256.         break;
  1257.     case ID_VOLUMEDOWN:
  1258.         CPVERB_VolumeDown(vaDoVerb, hWnd);
  1259.         break;
  1260.     case ID_SEEKFORWARD:
  1261.         CPVERB_SkipForwards(vaDoVerb, hWnd);
  1262.         break;
  1263.     case ID_SEEKBACKWARD:
  1264.         CPVERB_SkipBackwards(vaDoVerb, hWnd);
  1265.         break;
  1266.     case ID_ABOUT:
  1267.         CPVERB_About(vaDoVerb, hWnd);
  1268.         break;
  1269.     case ID_DRAWSKINLINES:
  1270.         {
  1271.             int     teller;
  1272.             HDC     windc = GetDC(hWnd);
  1273.             HPEN    pen = CreatePen(PS_NULL, 0, 0);
  1274.             HPEN    oldpen = SelectObject(windc, pen);
  1275.             for (teller = PlaySwitch; teller < Lastone; teller++) {
  1276.                 HBRUSH  brush =
  1277.                     CreateSolidBrush(RGB(255 * rand(), 255 * rand(),
  1278.                                          255 * rand()));
  1279.                 HBRUSH  oldbrush = SelectObject(windc, brush);
  1280.                 Rectangle(windc, Skin.Object[teller].x,
  1281.                           Skin.Object[teller].y,
  1282.                           Skin.Object[teller].x +
  1283.                           Skin.Object[teller].w + 2,
  1284.                           Skin.Object[teller].y + Skin.Object[teller].h +
  1285.                           2);
  1286.                 SelectObject(windc, oldbrush);
  1287.                 DeleteObject(brush);
  1288.             }
  1289.             SelectObject(windc, oldpen);
  1290.             DeleteObject(pen);
  1291.             ReleaseDC(hWnd, windc);
  1292.         }
  1293.         break;
  1294.     case ID_LOADSKIN:
  1295.         {
  1296.             if (globals.main_bool_skin_next_is_default == TRUE)
  1297.                 options.use_default_skin = TRUE;
  1298.             else
  1299.                 options.use_default_skin = FALSE;
  1300.             if (options.use_default_skin == FALSE) {
  1301.                 char    skinpathje[MAX_PATH];
  1302.                 strcpy(skinpathje, options.main_skin_file);
  1303.                 if (main_skin_open(options.main_skin_file) == FALSE)
  1304.                     main_set_default_skin();
  1305.                 else {
  1306.                     main_skin_add_to_menu(skinpathje);
  1307.                     main_skin_select_menu(skinpathje);
  1308.                 }
  1309.             } else
  1310.                 main_set_default_skin();
  1311.             if(options.scroll_track_title)
  1312.                 SetTimer(hWnd, CPC_TIMERID_SCROLLTITLETEXT, 50, NULL);
  1313.             else
  1314.                 KillTimer(hWnd, CPC_TIMERID_SCROLLTITLETEXT);
  1315.             main_reset_window(hWnd);
  1316.             main_add_tooltips(hWnd, TRUE);
  1317.             break;
  1318.         }
  1319.     default:
  1320.         return -1;
  1321.     }
  1322.     return 0;
  1323. }
  1324. void    cmdline_usage(void)
  1325. {
  1326.     HRSRC   resource;
  1327.     HGLOBAL globaldata;
  1328.     resource = FindResource(NULL, // module handle
  1329.                             MAKEINTRESOURCE(IDR_USAGE), // pointer to resource name
  1330.                             "raw"); // pointer to resource type
  1331.     globaldata = LoadResource(NULL, // resource-module handle
  1332.                               resource);
  1333.     MessageBox(NULL, (LPCTSTR) LockResource(globaldata),
  1334.                "CoolPlayer command line options", 0); // text to set
  1335.     PostQuitMessage(0);
  1336. }
  1337. int    *cmdline_get_argument(char *arg)
  1338. {
  1339.     if (_stricmp(arg, "help") == 0 || arg[0] == '?'
  1340.             || ((arg[0] == 'h' || arg[0] == 'H') && arg[1] == ''))
  1341.         cmdline_usage();
  1342.     if (_stricmp(arg, "add") == 0 || (GetTickCount() - globals.playlist_last_add_time) < 1000)
  1343.         globals.playlist_bool_addsong = TRUE;
  1344.     else
  1345.         globals.playlist_bool_addsong = FALSE;
  1346.     if (_stricmp(arg, "top") == 0)
  1347.         return &options.always_on_top;
  1348.     if (_stricmp(arg, "exit") == 0)
  1349.         return &options.auto_exit_after_playing;
  1350.     if (_stricmp(arg, "exitnow") == 0)
  1351.         PostQuitMessage(0);
  1352.     if (_stricmp(arg, "icon") == 0)
  1353.         return &options.rotate_systray_icon;
  1354.     if (_stricmp(arg, "scroll") == 0)
  1355.         return &options.scroll_track_title;
  1356.     if (_stricmp(arg, "time") == 0)
  1357.         return &options.show_remaining_time;
  1358.     if (_stricmp(arg, "tag") == 0)
  1359.         return &options.read_id3_tag;
  1360.     if (_stricmp(arg, "easy") == 0)
  1361.         return &options.easy_move;
  1362.     if (_stricmp(arg, "playlist") == 0)
  1363.         return &options.remember_playlist;
  1364.     if (_stricmp(arg, "played") == 0)
  1365.         return &options.remember_last_played_track;
  1366.     if (_stricmp(arg, "eq") == 0)
  1367.         return &options.equalizer;
  1368.     if (_stricmp(arg, "shuffle") == 0)
  1369.         return &options.shuffle_play;
  1370.     if (_stricmp(arg, "repeat") == 0)
  1371.         return &options.repeat_playlist;
  1372.     if (_stricmp(arg, "autoplay") == 0)
  1373.         return &options.auto_play_when_started;
  1374.     if (_stricmp(arg, "output") == 0)
  1375.         return &options.decoder_output_mode;
  1376.     if (_stricmp(arg, "skin") == 0)
  1377.         return &options.use_default_skin;
  1378.     if (_stricmp(arg, "showplaylist") == 0)
  1379.         return &options.show_playlist;
  1380.     if (_stricmp(arg, "minimized") == 0)
  1381.         return &globals.main_int_show_minimized;
  1382.     if (_stricmp(arg, "fileonce") == 0)
  1383.         return &options.allow_file_once_in_playlist;
  1384.     if (_stricmp(arg, "taskbar") == 0)
  1385.         return &options.show_on_taskbar;
  1386.     if (_stricmp(arg, "multipleinstances") == 0)
  1387.         return &options.allow_multiple_instances;
  1388.     return NULL;
  1389. }
  1390. int     cmdline_parse_options(int argc,char **argv)
  1391. {
  1392.     //    char   *token;
  1393.     //   char    commandline[MAX_PATH];
  1394.     int i;
  1395.     int    *value;
  1396.     for(i=1;i<argc;i++)
  1397.     {
  1398.         char *arg=argv[i];
  1399.         if (arg[0] == '-') {
  1400.             if (value = cmdline_get_argument(arg+1)) *value = FALSE;
  1401.             if (value == &options.use_default_skin) {
  1402.                 i++;
  1403.                 if (stricmp(argv[i], "default") == 0)  *value = TRUE;
  1404.                 else strcpy(options.main_skin_file, argv[i]);
  1405.             }
  1406.             if (value == &globals.main_int_show_minimized) {
  1407.                 if (options.show_on_taskbar)
  1408.                     globals.main_int_show_minimized = SW_MINIMIZE;
  1409.                 else
  1410.                     globals.main_int_show_minimized = SW_HIDE;
  1411.             }
  1412.         }else if (arg[0] == '+') {
  1413.             if (value = cmdline_get_argument(arg + 1))
  1414.                 *value = TRUE;
  1415.         }
  1416.     }
  1417.     return 1;
  1418. }
  1419. //
  1420. //
  1421. //
  1422. BOOL cmdline_parse_argument(char *token)
  1423. {
  1424.     char    buffie[MAX_PATH] = "";
  1425.     char    expath[MAX_PATH];
  1426.     strcpy(buffie, token);
  1427.     path_unquote(buffie);
  1428.     if (buffie[0] == '')
  1429.         return FALSE;
  1430.     if (path_is_relative(buffie))
  1431.     {
  1432.         char    exepath[MAX_PATH];
  1433.         main_get_program_path(GetModuleHandle(NULL), exepath, MAX_PATH);
  1434.         sprintf(expath, "%s%s", exepath, buffie);
  1435.     }
  1436.     else
  1437.         strcpy(expath, buffie);
  1438.     if (_access(expath, 0) != -1)
  1439.     {
  1440.         if (globals.playlist_bool_addsong == FALSE
  1441.                 && globals.cmdline_bool_clear_playlist_first == TRUE)
  1442.         {
  1443.             CPL_Empty(globals.m_hPlaylist);
  1444.             globals.cmdline_bool_clear_playlist_first = FALSE;
  1445.         }
  1446.         CPL_SyncLoadNextFile(globals.m_hPlaylist);
  1447.         if(path_is_directory(expath) == TRUE)
  1448.             CPL_AddDirectory_Recurse(globals.m_hPlaylist, expath);
  1449.         else
  1450.             CPL_AddFile(globals.m_hPlaylist, expath);
  1451.         return TRUE;
  1452.     }
  1453.     return FALSE;
  1454. }
  1455. //
  1456. //
  1457. //
  1458. char   *str_delete_substr(char *strbuf, char *strtodel)
  1459. {
  1460.     char   *offset=NULL;
  1461.     while (*strbuf) {
  1462.         offset = strstr(strbuf, strtodel);
  1463.         if (offset)
  1464.             strcpy(offset, (offset + strlen(strtodel)));
  1465.         else
  1466.             break;
  1467.     }
  1468.     return strbuf;
  1469. }
  1470. int     cmdline_parse_files(int argc,char **argv)
  1471. {
  1472.     BOOL    wegotsome = FALSE;
  1473.     int i;
  1474.     globals.cmdline_bool_clear_playlist_first = TRUE;
  1475.     for(i=1;i<argc;i++)
  1476.     {
  1477.         char *arg=argv[i];
  1478.         if (arg[0] != '-' && arg[0] != '+') {
  1479.             if (cmdline_parse_argument(arg))
  1480.                 wegotsome = TRUE;
  1481.         }
  1482.     }
  1483.     return wegotsome;
  1484. }
  1485. int     APIENTRY
  1486. WinMain(HINSTANCE hInstance,
  1487.         HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  1488. {
  1489.     WNDCLASS wc;
  1490.     HWND    hWnd;
  1491.     MSG     msg;
  1492.     HRGN    winregion;
  1493.     INITCOMMONCONTROLSEX controls;
  1494.     HMENU   hpopup;
  1495.     BOOL    bAlreadyRuning;
  1496.     HANDLE  hMutexOneInstance;
  1497.     // Ensure that this system is audio capable
  1498.     if(waveOutGetNumDevs() < 1)
  1499.     {
  1500.         MessageBox(GetDesktopWindow(), "No audio devices in this system", "CoolPlayer", MB_ICONSTOP | MB_OK);
  1501.         return -1;
  1502.     }
  1503.     options_read();
  1504.     hMutexOneInstance = CreateMutex(NULL, FALSE, "COOLPLAYER-045FA840-B10D-2G3-3436-006067709674");
  1505.     bAlreadyRuning = (GetLastError() == ERROR_ALREADY_EXISTS
  1506.                       || GetLastError() == ERROR_ACCESS_DENIED);
  1507.     // The call fails with ERROR_ACCESS_DENIED if the Mutex was
  1508.     // created in a different users session because of passing
  1509.     // NULL for the SECURITY_ATTRIBUTES on Mutex creation);
  1510.     if(bAlreadyRuning)
  1511.     {
  1512.         // Find the other coolplayer instance
  1513.         HWND hWndCoolPlayer = FindWindow(CLC_COOLPLAYER_WINDOWCLASSNAME, NULL);
  1514.         if(hWndCoolPlayer != NULL)
  1515.         {
  1516.             if(lpCmdLine[0] != '')
  1517.             {
  1518.                 int i;
  1519.                 int size=0;
  1520.                 COPYDATASTRUCT cds;
  1521.                 for(i=0;i<__argc;i++)
  1522.                     size+=strlen(__argv[i])+1;
  1523.                 // cds.cbData = strlen(lpCmdLine) + 1;
  1524.                 // cds.dwData = strlen(lpCmdLine) + 1;
  1525.                 // cds.lpData = lpCmdLine;
  1526.                 cds.cbData = size;
  1527.                 cds.dwData = __argc;
  1528.                 cds.lpData = __argv[0];
  1529.                 SendMessage(hWndCoolPlayer, WM_COPYDATA, (WPARAM)hWndCoolPlayer, (LPARAM)&cds);
  1530.             }
  1531.             else
  1532.             {
  1533.                 SetForegroundWindow(hWndCoolPlayer);
  1534.                 ShowWindow(hWndCoolPlayer, SW_RESTORE);
  1535.             }
  1536.         }
  1537.         if(!options.allow_multiple_instances)
  1538.             return FALSE; // terminates the creation
  1539.     }
  1540.     /* kill this */
  1541.     controls.dwSize = sizeof(INITCOMMONCONTROLSEX);
  1542.     controls.dwICC = ICC_BAR_CLASSES;
  1543.     InitCommonControlsEx(&controls);
  1544.     //    options.shuffle_play = FALSE;
  1545.     //  options.repeat_playlist = FALSE;
  1546.     //    options.equalizer = FALSE;
  1547.     globals.main_bool_slider_keep_focus = FALSE;
  1548.     globals.main_int_skin_last_number = 5001;
  1549.     windows.m_hWndFindDialog = NULL;
  1550.     globals.playlist_int_last_searched_track = 0;
  1551.     globals.m_iLastPlaylistSortColoumn = -1;
  1552.     globals.m_bQuickFindWindowPos_Valid = FALSE;
  1553.     globals.m_hPlaylist = CPL_CreatePlaylist();
  1554.     globals.m_hhkListView_Posted = NULL;
  1555.     globals.playlist_bool_addsong = FALSE;
  1556.     globals.playlist_last_add_time = 0;
  1557.     globals.m_hSysIcon = NULL;
  1558.     CPSK_Initialise();
  1559.     hpopup = LoadMenu(NULL, MAKEINTRESOURCE(IDR_MENU1));
  1560.     globals.main_menu_popup = GetSubMenu(hpopup, 0);
  1561.     globals.m_hPlaylistImages = ImageList_LoadBitmap( hInstance,
  1562.                                 MAKEINTRESOURCE(IDB_PLAYLIST_CURRENTTRACK),
  1563.                                 12,
  1564.                                 1,
  1565.                                 RGB(0xFF, 0x00, 0xFF));
  1566.     if (!options.show_on_taskbar)
  1567.         switch (nCmdShow) {
  1568.         case SW_MINIMIZE:
  1569.         case SW_SHOWMINIMIZED:
  1570.         case SW_SHOWMINNOACTIVE:
  1571.             nCmdShow = SW_HIDE;
  1572.         }
  1573.     globals.main_int_show_minimized = nCmdShow;
  1574.     cmdline_parse_options(__argc,__argv);
  1575.     if (*options.main_skin_file && options.use_default_skin == FALSE) {
  1576.         char    lastskinfile[MAX_PATH];
  1577.         strcpy(lastskinfile, options.main_skin_file);
  1578.         if (main_skin_open(options.main_skin_file) == FALSE) {
  1579.             main_set_default_skin();
  1580.         } else {
  1581.             main_skin_add_to_menu(lastskinfile);
  1582.             main_skin_select_menu(lastskinfile);
  1583.         }
  1584.     } else {
  1585.         main_set_default_skin();
  1586.     }
  1587.     globals.main_bool_wavwrite_dir_already_known = FALSE;
  1588.     globals.main_int_track_position = 0;
  1589.     globals.m_enPlayerState = cppsStopped;
  1590.     srand((unsigned int) time(NULL));
  1591.     if (graphics.bmp_main_up) {
  1592.         HDC     hRefDC = GetDC(NULL);
  1593.         ZeroMemory(&wc, sizeof(wc));
  1594.         wc.style         = CS_OWNDC;
  1595.         //wc.style = CS_PARENTDC;
  1596.         wc.lpszClassName = CLC_COOLPLAYER_WINDOWCLASSNAME;
  1597.         wc.lpfnWndProc = (WNDPROC) main_windowproc;
  1598.         wc.hInstance = hInstance;
  1599.         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  1600.         wc.hIcon = NULL;
  1601.         graphics.pal_main = CreateHalftonePalette(hRefDC);
  1602.         ReleaseDC(NULL, hRefDC);
  1603.         if (RegisterClass(&wc)) {
  1604.             BITMAP  bm;
  1605.             GetObject(graphics.bmp_main_up, sizeof(bm), &bm);
  1606.             globals.m_hPlayer = NULL;
  1607.             hWnd =
  1608.                 CreateWindowEx(WS_EX_ACCEPTFILES | WS_EX_TOOLWINDOW,
  1609.                                CLC_COOLPLAYER_WINDOWCLASSNAME, "CoolPlayer",
  1610.                                WS_POPUP | WS_CLIPSIBLINGS,
  1611.                                options.main_window_pos.x,
  1612.                                options.main_window_pos.y, bm.bmWidth,
  1613.                                bm.bmHeight, NULL, NULL, hInstance, NULL);
  1614.             SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)LoadIcon(hInstance, MAKEINTRESOURCE(APP_ICON)));
  1615.             SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)LoadIcon(hInstance, MAKEINTRESOURCE(APP_ICON)));
  1616.             // Register hotkey
  1617.             RegisterHotKey(hWnd, CP_HOTKEY_NEXT, 0L, VK_MEDIA_NEXT_TRACK);
  1618.             RegisterHotKey(hWnd, CP_HOTKEY_PREV, 0L, VK_MEDIA_PREV_TRACK);
  1619.             RegisterHotKey(hWnd, CP_HOTKEY_STOP, 0L, VK_MEDIA_STOP);
  1620.             RegisterHotKey(hWnd, CP_HOTKEY_PLAY0, 0L, VK_MEDIA_PLAY_PAUSE);
  1621.             RegisterHotKey(hWnd, CP_HOTKEY_PLAY1, 0L, VK_PAUSE);
  1622.             if (hWnd) {
  1623.                 if (options.show_on_taskbar) {
  1624.                     SetWindowLong(hWnd, GWL_EXSTYLE,
  1625.                                   GetWindowLong(hWnd,
  1626.                                                 GWL_EXSTYLE) &
  1627.                                   ~WS_EX_TOOLWINDOW);
  1628.                     SetWindowLong(hWnd, GWL_STYLE,
  1629.                                   GetWindowLong(hWnd,
  1630.                                                 GWL_STYLE) | WS_SYSMENU);
  1631.                 }
  1632.                 drawables.dc_main = GetDC(hWnd);
  1633.                 drawables.dc_memory =
  1634.                     CreateCompatibleDC(drawables.dc_main);
  1635.                 // Create player instance
  1636.                 globals.m_hPlayer = CPI_Player__Create(hWnd);
  1637.                 globals.m_iVolume = CPI_Player__GetVolume(globals.m_hPlayer);
  1638.                 winregion =
  1639.                     main_bitmap_to_region(graphics.bmp_main_up, Skin.transparentcolor);
  1640.                 SetWindowRgn(hWnd, winregion, TRUE);
  1641.                 ShowWindow(hWnd, globals.main_int_show_minimized);
  1642.                 globals.m_hSysIcon = CPSYSICON_Create(hWnd);
  1643.                 CPI_Player__SetPositionRange(globals.m_hPlayer,
  1644.                                              Skin.Object[PositionSlider].maxw ? Skin.Object[PositionSlider].h : Skin.Object[PositionSlider].w);
  1645.                 CP_InitWindowsRoutines();
  1646.                 IF_ProcessInit();
  1647.                 // CPlayerWindow_Create();
  1648.                 CPlaylistWindow_Create();
  1649.                 window_set_always_on_top(hWnd, options.always_on_top);
  1650.                 main_set_eq();
  1651.                 globals.m_enPlayerState = cppsStopped;
  1652.                 globals.m_bStreaming = FALSE;
  1653.                 globals.m_iStreamingPortion = 0;
  1654.                 {
  1655.                     BOOL wegotsome;
  1656.                     wegotsome = cmdline_parse_files(__argc,__argv);
  1657.                     if (!wegotsome || globals.playlist_bool_addsong == TRUE)
  1658.                     {
  1659.                         if ( (CPL_GetFirstItem(globals.m_hPlaylist)
  1660.                                 && globals.playlist_bool_addsong == TRUE
  1661.                                 && options.remember_playlist == TRUE)
  1662.                                 || (options.remember_playlist == TRUE
  1663.                                     && CPL_GetFirstItem(globals.m_hPlaylist) == NULL) )
  1664.                         {
  1665.                             char pcPlaylistFilename[MAX_PATH];
  1666.                             main_get_program_path(GetModuleHandle(NULL), pcPlaylistFilename, MAX_PATH);
  1667.                             strcat(pcPlaylistFilename, "default.m3u");
  1668.                             CPL_SyncLoadNextFile(globals.m_hPlaylist);
  1669.                             CPL_SetAutoActivateInitial(globals.m_hPlaylist, TRUE);
  1670.                             CPL_AddFile(globals.m_hPlaylist, pcPlaylistFilename);
  1671.                             CPL_SetAutoActivateInitial(globals.m_hPlaylist, FALSE);
  1672.                         }
  1673.                         else if(*options.initial_file)
  1674.                         {
  1675.                             CPL_SyncLoadNextFile(globals.m_hPlaylist);
  1676.                             CPL_AddSingleFile(globals.m_hPlaylist, options.initial_file, NULL);
  1677.                         }
  1678.                     }
  1679.                     // Start playing
  1680.                     if(wegotsome || options.auto_play_when_started)
  1681.                         CPL_PlayItem(globals.m_hPlaylist, TRUE, pmCurrentItem);
  1682.                 }
  1683.                 windows.wnd_tooltip =
  1684.                     CreateWindow(TOOLTIPS_CLASS, (LPSTR) NULL,
  1685.                                  TTS_ALWAYSTIP, CW_USEDEFAULT,
  1686.                                  CW_USEDEFAULT, CW_USEDEFAULT,
  1687.                                  CW_USEDEFAULT, hWnd, (HMENU) NULL,
  1688.                                  hInstance, NULL);
  1689.                 main_add_tooltips(hWnd, FALSE);
  1690.                 while(GetMessage(&msg, NULL, 0, 0))
  1691.                 {
  1692.                     if(msg.message == CPPLNM_TAGREAD)
  1693.                     {
  1694.                         CPL_HandleAsyncNotify(globals.m_hPlaylist, msg.wParam, msg.lParam);
  1695.                         continue;
  1696.                     }
  1697.                     if(msg.message == CPPLNM_SYNCSHUFFLE)
  1698.                     {
  1699.                         CPL_Stack_Shuffle(globals.m_hPlaylist, TRUE);
  1700.                         continue;
  1701.                     }
  1702.                     if(msg.message == CPPLNM_SYNCSETACTIVE)
  1703.                     {
  1704.                         CPL_SetActiveItem(globals.m_hPlaylist, (CP_HPLAYLISTITEM)msg.wParam);
  1705.                         continue;
  1706.                     }
  1707.                     if(windows.m_hWndFindDialog && IsDialogMessage(windows.m_hWndFindDialog, &msg))
  1708.                         continue;
  1709.                     TranslateMessage(&msg);
  1710.                     DispatchMessage(&msg);
  1711.                 }
  1712.                 // Clean up
  1713.                 DestroyMenu(globals.main_menu_popup);
  1714.                 DestroyMenu(hpopup);
  1715.                 CPSYSICON_Destroy(globals.m_hSysIcon);
  1716.                 DeleteDC(drawables.dc_memory);
  1717.                 ReleaseDC(hWnd, drawables.dc_main);
  1718.                 DeleteObject(graphics.bmp_main_title_area);
  1719.                 ImageList_Destroy(globals.m_hPlaylistImages);
  1720.                 CPSK_Uninitialise();
  1721.                 IF_ProcessDeInit();
  1722.                 return (msg.wParam);
  1723.             }
  1724.         }
  1725.     }
  1726.     return -1;
  1727. }
  1728. //
  1729. //
  1730. //