main_init.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "Main.h"
  9. #include "menuv5.h"
  10. #include "resource.h"
  11. extern "C"
  12. {
  13. int g_main_created = 0;
  14. }
  15. static INT_PTR CALLBACK tmpProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  16. {
  17. return 0;
  18. }
  19. BOOL InitApplication(HINSTANCE hInstance) // register Winamp's window class, returns TRUE on success
  20. {
  21. HICON hIcon;
  22. WNDCLASSW wc = {0, };
  23. wc.style = CS_DBLCLKS;
  24. wc.hInstance = hInstance;
  25. hIcon = wc.hIcon = LoadIconW(hInstance, MAKEINTRESOURCE(ICON_XP));
  26. wc.hCursor = NULL;
  27. //wc.lpfnWndProc = Main_WndProc;
  28. //wc.lpszClassName = L"Winamp";;
  29. //if (!RegisterClassW( &wc ))
  30. // return 0;
  31. wc.lpfnWndProc = VIS_WndProc;
  32. wc.lpszClassName = L"WinampVis";
  33. if (!RegisterClassW(&wc))
  34. return 0;
  35. wc.lpfnWndProc = video_WndProc;
  36. wc.lpszClassName = L"Winamp Video";
  37. if (!RegisterClassW(&wc))
  38. return 0;
  39. #ifdef WA2
  40. #ifndef NETSCAPE
  41. wc.style = CS_DBLCLKS;
  42. wc.lpfnWndProc = MB_WndProc;
  43. wc.lpszClassName = "Winamp MB";
  44. if (!RegisterClassW(&wc))
  45. return 0;
  46. #endif
  47. #endif
  48. /* now register unicode windows */
  49. WNDCLASSW wcW = {0, };
  50. wcW.style = CS_DBLCLKS;
  51. wcW.hInstance = hInstance;
  52. hIcon = wcW.hIcon = LoadIconW(hInstance, MAKEINTRESOURCE(ICON_XP));
  53. wcW.hCursor = NULL;
  54. wcW.lpfnWndProc = emb_WndProc;
  55. wcW.lpszClassName = L"Winamp Gen";
  56. if (!RegisterClassW(&wcW))
  57. return 0;
  58. wcW.style |= CS_VREDRAW | CS_HREDRAW;
  59. wcW.lpfnWndProc = EQ_WndProc;
  60. wcW.lpszClassName = L"Winamp EQ";
  61. if (!RegisterClassW(&wcW))
  62. return 0;
  63. wcW.lpfnWndProc = PE_WndProc;
  64. wcW.lpszClassName = L"Winamp PE";
  65. if (!RegisterClassW(&wcW))
  66. return 0;
  67. // make other people's dialogs show the winamp icon
  68. HWND h = CreateDialogW(hMainInstance, MAKEINTRESOURCE(IDD_OPENLOC), NULL, tmpProc);
  69. SetClassLongPtrW(h, GCLP_HICON, (LONG_PTR)hIcon);
  70. DestroyWindow(h);
  71. return 1;
  72. }
  73. void ConvertRatingMenuStar(HMENU menu, UINT menu_id)
  74. {
  75. MENUITEMINFOW mi = {sizeof(mi), MIIM_DATA | MIIM_TYPE, MFT_STRING};
  76. wchar_t rateBuf[32], *rateStr = rateBuf;
  77. mi.dwTypeData = rateBuf;
  78. mi.cch = 32;
  79. if(GetMenuItemInfoW(menu, menu_id, FALSE, &mi))
  80. {
  81. while(rateStr && *rateStr)
  82. {
  83. if(*rateStr == L'*') *rateStr = L'\u2605';
  84. rateStr=CharNextW(rateStr);
  85. }
  86. SetMenuItemInfoW(menu, menu_id, FALSE, &mi);
  87. }
  88. }
  89. void main_Create()
  90. {
  91. static int t = 0;
  92. g_main_created = 1;
  93. SetWindowTextW(hMainWindow, caption);
  94. hVisWindow = CreateWindowExW(0, L"WinampVis", L"", WS_CHILD, 0, 0, 0, 0,
  95. hMainWindow, NULL, hMainInstance, NULL);
  96. ShowWindow(hVisWindow, SW_SHOWNA);
  97. SetWindowLong(hMainWindow, GWLP_USERDATA, (config_keeponscreen&2) ? 0x49474541 : 0);
  98. hTooltipWindow = CreateWindowW(TOOLTIPS_CLASSW, (LPCWSTR)NULL, TTS_ALWAYSTIP | TTS_NOPREFIX,
  99. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  100. hMainWindow, NULL, hMainInstance, NULL);
  101. SendMessageW(hTooltipWindow, TTM_SETDELAYTIME, TTDT_INITIAL, 375);
  102. SendMessageW(hTooltipWindow, TTM_SETDELAYTIME, TTDT_AUTOPOP, 2000);
  103. SendMessageW(hTooltipWindow, TTM_SETDELAYTIME, TTDT_RESHOW, 1000);
  104. hEQTooltipWindow = CreateWindowW(TOOLTIPS_CLASSW, (LPCWSTR)NULL, TTS_ALWAYSTIP | TTS_NOPREFIX,
  105. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  106. hEQWindow, NULL, hMainInstance, NULL);
  107. SendMessageW(hEQTooltipWindow, TTM_SETDELAYTIME, TTDT_INITIAL, 125);
  108. SendMessageW(hEQTooltipWindow, TTM_SETDELAYTIME, TTDT_AUTOPOP, 2000);
  109. SendMessageW(hEQTooltipWindow, TTM_SETDELAYTIME, TTDT_RESHOW, 1000);
  110. hVideoTooltipWindow = CreateWindowW(TOOLTIPS_CLASSW, (LPCWSTR)NULL, TTS_ALWAYSTIP | TTS_NOPREFIX,
  111. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  112. hVideoWindow, NULL, hMainInstance, NULL);
  113. SendMessageW(hVideoTooltipWindow, TTM_SETDELAYTIME, TTDT_INITIAL, 125);
  114. SendMessageW(hVideoTooltipWindow, TTM_SETDELAYTIME, TTDT_AUTOPOP, 2000);
  115. SendMessageW(hVideoTooltipWindow, TTM_SETDELAYTIME, TTDT_RESHOW, 1000);
  116. hPLTooltipWindow = CreateWindowW(TOOLTIPS_CLASSW, (LPCWSTR)NULL, TTS_ALWAYSTIP | TTS_NOPREFIX,
  117. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  118. hPLWindow, NULL, hMainInstance, NULL);
  119. SendMessageW(hPLTooltipWindow, TTM_SETDELAYTIME, TTDT_INITIAL, 125);
  120. SendMessageW(hPLTooltipWindow, TTM_SETDELAYTIME, TTDT_AUTOPOP, 2000);
  121. SendMessageW(hPLTooltipWindow, TTM_SETDELAYTIME, TTDT_RESHOW, 1000);
  122. /*hPL2TooltipWindow = CreateWindowW(TOOLTIPS_CLASSW, (LPCWSTR)NULL, TTS_ALWAYSTIP | TTS_NOPREFIX,
  123. 0, 0, 0, 0, hPLWindow, NULL, hMainInstance, NULL);*/
  124. // TODO attempt to make this more like the listview timings
  125. /*SendMessageW(hPL2TooltipWindow, TTM_SETDELAYTIME, TTDT_INITIAL, 125);
  126. SendMessageW(hPL2TooltipWindow, TTM_SETDELAYTIME, TTDT_AUTOPOP, 2000);
  127. SendMessageW(hPL2TooltipWindow, TTM_SETDELAYTIME, TTDT_RESHOW, 1000);*/
  128. SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
  129. top_menu = LPLoadMenu(WINAMP_MAIN);
  130. #ifdef NETSCAPE
  131. EnableMenuItem(top_menu, WINAMP_OPTIONS_MINIBROWSER, MF_BYCOMMAND | MF_GRAYED);
  132. #endif
  133. main_menu = GetSubMenu(top_menu, 0);
  134. g_submenus_play = GetSubMenu(main_menu, 2);
  135. g_submenus_bookmarks1 = GetSubMenu(main_menu, 4);
  136. g_submenus_bookmarks2 = GetSubMenu(GetSubMenu(main_menu, 2), 4 + (g_audiocdletters ? g_audiocdletters + 1 : 0));
  137. g_submenus_skins1 = GetSubMenu(main_menu, MAINMENU_OPTIONS_BASE + 3);
  138. g_submenus_skins2 = GetSubMenu(GetSubMenu(main_menu, MAINMENU_OPTIONS_BASE), 1);
  139. g_submenus_vis = GetSubMenu(main_menu, MAINMENU_OPTIONS_BASE + 2);
  140. g_submenus_options = GetSubMenu(main_menu, MAINMENU_OPTIONS_BASE);
  141. if (config_wlz_menu)
  142. {
  143. MENUITEMINFOW mii = {sizeof(mii), MIIM_SUBMENU | MIIM_TYPE | MIIM_ID, MFT_STRING, };
  144. mii.hSubMenu = g_submenus_lang = CreatePopupMenu();
  145. mii.dwTypeData = getStringW(IDS_LANGUAGEPACKS_MENU, NULL, 0);
  146. mii.cch = (UINT)wcslen(mii.dwTypeData);
  147. g_submenus_lang_id = mii.wID = unique_loword_command++;
  148. InsertMenuItemW(main_menu, MAINMENU_OPTIONS_BASE+4, TRUE, &mii);
  149. }
  150. HMENU rating_menu = GetSubMenu(GetSubMenu(GetSubMenu(top_menu,2),5),10);
  151. ConvertRatingMenuStar(rating_menu, ID_PL_RATING5);
  152. ConvertRatingMenuStar(rating_menu, ID_PL_RATING4);
  153. ConvertRatingMenuStar(rating_menu, ID_PL_RATING3);
  154. ConvertRatingMenuStar(rating_menu, ID_PL_RATING2);
  155. ConvertRatingMenuStar(rating_menu, ID_PL_RATING1);
  156. rating_menu = GetSubMenu(GetSubMenu(GetSubMenu(top_menu,3),0),5);
  157. ConvertRatingMenuStar(rating_menu, ID_RATING5);
  158. ConvertRatingMenuStar(rating_menu, ID_RATING4);
  159. ConvertRatingMenuStar(rating_menu, ID_RATING3);
  160. ConvertRatingMenuStar(rating_menu, ID_RATING2);
  161. ConvertRatingMenuStar(rating_menu, ID_RATING1);
  162. Skin_Random();
  163. Skin_Load();
  164. g_skinloadedmanually = 0;
  165. set_aot(0);
  166. set_taskbar();
  167. CheckMenuItem(main_menu, WINAMP_OPTIONS_EASYMOVE, config_easymove ? MF_CHECKED : MF_UNCHECKED);
  168. CheckMenuItem(main_menu, WINAMP_FILE_SHUFFLE, config_shuffle ? MF_CHECKED : MF_UNCHECKED);
  169. CheckMenuItem(main_menu, WINAMP_FILE_REPEAT, config_repeat ? MF_CHECKED : MF_UNCHECKED);
  170. CheckMenuItem(GetSubMenu(GetSubMenu(top_menu, 3), 13), ID_VIDEOWND_VERTICALLYFLIP, (config_video_fliprgb ? MF_CHECKED: MF_UNCHECKED));
  171. if (!config_timeleftmode)
  172. CheckMenuItem(main_menu, WINAMP_OPTIONS_ELAPSED, MF_CHECKED);
  173. else
  174. CheckMenuItem(main_menu, WINAMP_OPTIONS_REMAINING, MF_CHECKED);
  175. draw_setnoupdate(1);
  176. draw_init();
  177. draw_shuffle(config_shuffle, 0);
  178. draw_eqplbut(config_eq_open, 0, config_pe_open, 0);
  179. draw_repeat(config_repeat, 0);
  180. draw_eject(0);
  181. draw_buttonbar( -1);
  182. draw_volumebar(config_volume, 0);
  183. draw_panbar(config_pan, 0);
  184. draw_songname(L"", &t, 0);
  185. draw_playicon(2);
  186. draw_clutterbar(0);
  187. draw_monostereo(0);
  188. draw_tbar(1, config_windowshade, 0);
  189. draw_setnoupdate(0);
  190. InsertMenuW(GetSystemMenu(hMainWindow, FALSE), 0, MF_POPUP | MF_BYPOSITION, (UINT_PTR) main_menu, L"Winamp");
  191. InsertMenu(GetSystemMenu(hMainWindow, FALSE), 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
  192. if (config_autoscrollname) SetTimer(hMainWindow, UPDATE_DISPLAY_TIMER + 1, 200, NULL);
  193. if (config_shuffle) PlayList_randpos( -BIGINT);
  194. dsp_init();
  195. newversioncheck();
  196. SetTimer(hMainWindow, STATS_TIMER, 1000, NULL);
  197. }
  198. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) // create the main Winamp window
  199. {
  200. int sc = config_minimized; // config_minimized gets trashed in WM_CREATE
  201. deferring_show = 1;
  202. main_Create();
  203. out_setwnd();
  204. if (!CreateWindowExW(0, L"Winamp EQ", getStringW(IDS_EQCAPTION, NULL, 0), WS_OVERLAPPED,
  205. config_eq_wx, config_eq_wy, 0, 0, // WM_CREATE will size it
  206. hMainWindow, NULL, hInstance, NULL)) return FALSE;
  207. if (!CreateWindowExW(WS_EX_ACCEPTFILES, L"Winamp PE", getStringW(IDS_PECAPTION, NULL, 0), WS_OVERLAPPED,
  208. config_pe_wx, config_pe_wy, 0, 0, // WM_CREATE will size it
  209. hMainWindow, NULL, hInstance, NULL)) return FALSE;
  210. if (!video_Create())
  211. return FALSE;
  212. hPLVisWindow = CreateWindowExW(0, L"WinampVis", L"", WS_CHILD,
  213. 0, 0, 0, 0,
  214. hPLWindow, NULL, hMainInstance, NULL);
  215. ShowWindow(hPLVisWindow, SW_SHOWNA);
  216. eq_startuphack = pe_startuphack = 1;
  217. if (config_eq_open)
  218. {
  219. config_eq_open = 0;
  220. eq_dialog(hMainWindow,sc);
  221. }
  222. // MessageBox(NULL,"p4","0",0);
  223. if (config_pe_open)
  224. {
  225. config_pe_open = 0;
  226. pleditDlg(hMainWindow,sc);
  227. }
  228. if (config_video_open)
  229. {
  230. config_video_open = 0;
  231. ShowVideoWindow(sc);
  232. }
  233. // MessageBox(NULL,"p5","0",0);
  234. if (!config_mw_open)
  235. {
  236. MoveOffscreen(hMainWindow);
  237. Ipc_WindowToggle(IPC_CB_WND_MAIN, config_mw_open);
  238. //config_mw_open=1;
  239. //SendMessageW(hMainWindow,WM_COMMAND,WINAMP_MAIN_WINDOW,0);
  240. }
  241. else
  242. CheckMenuItem(main_menu, WINAMP_MAIN_WINDOW, MF_CHECKED);
  243. eq_startuphack = pe_startuphack = 0;
  244. /*
  245. Browser_init();
  246. if (config_si_open)
  247. OpenBrowser();
  248. */
  249. if (sc)
  250. g_showcode = SW_SHOWMINIMIZED;
  251. else if (nCmdShow == SW_SHOWMAXIMIZED || nCmdShow == SW_MAXIMIZE)
  252. g_showcode = SW_SHOWNORMAL;
  253. else
  254. g_showcode = nCmdShow;
  255. v5_top_menu = LPLoadMenu(WINAMP5_MENUBAR);
  256. if (config_wlz_menu)
  257. {
  258. MENUITEMINFOW mii = {sizeof(mii), MIIM_SUBMENU | MIIM_TYPE | MIIM_ID, MFT_STRING, };
  259. mii.hSubMenu = g_submenus_lang;
  260. mii.dwTypeData = getStringW(IDS_LANGUAGEPACKS_MENU, NULL, 0);
  261. mii.cch = (UINT)wcslen(mii.dwTypeData);
  262. mii.wID = g_submenus_lang_id;
  263. InsertMenuItemW(GetSubMenu(v5_top_menu, 2), 1, TRUE, &mii);
  264. g_mm_ffoptionsbase_adj++;
  265. }
  266. SetTimer(hMainWindow, 200, 5, NULL); // defer main window showing
  267. BeginFullscreenAppMonitor();
  268. return TRUE;
  269. }