main_wndproc.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 "../nu/ns_wc.h"
  10. #include "../nu/AutoChar.h"
  11. #include "../nu/AutoWide.h"
  12. #include "../nu/AutoWideFn.h"
  13. #include "./api.h"
  14. #include "resource.h"
  15. #include "wintheme.h"
  16. // WM_CREATE handler
  17. LRESULT Main_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
  18. {
  19. // srand(GetTickCount());
  20. hMainWindow = hwnd;
  21. DisableVistaPreview();
  22. HACCEL hAccel = LoadAcceleratorsW(language_pack_instance, MAKEINTRESOURCEW(IDR_ACCELERATOR_GLOBAL));
  23. if (!hAccel && language_pack_instance != hMainInstance) hAccel = LoadAcceleratorsW(hMainInstance, MAKEINTRESOURCEW(IDR_ACCELERATOR_GLOBAL));
  24. if (hAccel) WASABI_API_APP->app_addAccelerators(hwnd, &hAccel, 1, TRANSLATE_MODE_GLOBAL);
  25. hAccel = LoadAcceleratorsW(language_pack_instance, MAKEINTRESOURCEW(IDR_ACCELERATOR_MAIN));
  26. if (!hAccel && language_pack_instance != hMainInstance) hAccel = LoadAcceleratorsW(hMainInstance, MAKEINTRESOURCEW(IDR_ACCELERATOR_MAIN));
  27. if (hAccel) WASABI_API_APP->app_addAccelerators(hwnd, &hAccel, 1, TRANSLATE_MODE_NORMAL);
  28. WASABI_API_APP->app_registerGlobalWindow(hwnd);
  29. return 1;
  30. } // Main_OnCreate()
  31. // Message sent from system notification area
  32. LRESULT Main_OnWASystray(HWND hwnd, int id)
  33. {
  34. POINT p;
  35. switch (id)
  36. {
  37. case WM_LBUTTONUP:
  38. if (GetAsyncKeyState(VK_CONTROL) & (1 << 15))
  39. SendMessageW(hwnd, WM_COMMAND, WINAMP_FILE_LOC, 0);
  40. else if (GetAsyncKeyState(VK_SHIFT) & (1 << 15))
  41. SendMessageW(hwnd, WM_COMMAND, WINAMP_FILE_PLAY, 0);
  42. else if (!IsWindowVisible(hwnd))
  43. {
  44. ShowWindow(hwnd, SW_RESTORE);
  45. ShowWindow(hwnd, SW_SHOW);
  46. }
  47. else SetForegroundWindow(hwnd);
  48. break;
  49. case WM_RBUTTONUP:
  50. GetCursorPos(&p);
  51. SetForegroundWindow(hwnd);
  52. //DoTrackPopup(main_menu, TPM_RIGHTBUTTON, p.x, p.y, hwnd);
  53. TrackPopupMenu(main_menu, TPM_RIGHTBUTTON, p.x, p.y, 0, hwnd, NULL);
  54. break;
  55. }
  56. return 1;
  57. }
  58. // WM_SIZE handler, to detect minizations.
  59. LRESULT Main_OnSize(HWND hwnd, UINT state, int cx, int cy)
  60. {
  61. if (state == SIZE_MINIMIZED)
  62. {
  63. int q = GetAsyncKeyState(VK_SHIFT) >> 15;
  64. if (config_taskbar || q || minimize_hack_winamp) ShowWindow(hwnd, SW_HIDE);
  65. if (q || minimize_hack_winamp)
  66. {
  67. systray_minimize(caption);
  68. config_minimized = 2;
  69. }
  70. else config_minimized = 1;
  71. if (config_pe_open && hPLWindow){
  72. HWND parent = GetParent(GetParent(hPLWindow));
  73. if(IsWindow(parent) && IsWindowVisible(hPLWindow)){}
  74. else ShowWindow(hPLWindow,SW_HIDE);
  75. }
  76. //if (config_mb_open&&hMBWindow) ShowWindow(hMBWindow,SW_HIDE);
  77. if (config_eq_open && hEQWindow) ShowWindow(hEQWindow,SW_HIDE);
  78. minimize_hack_winamp = 0;
  79. }
  80. else if (state == SIZE_RESTORED)
  81. {
  82. if (config_minimized == 2 && !(config_taskbar == 1 || config_taskbar == 2))
  83. {
  84. systray_restore();
  85. }
  86. if (g_taskbar_dirty)
  87. {
  88. g_taskbar_dirty = 0;
  89. set_taskbar();
  90. }
  91. if (!IsWindowVisible(hwnd) && !deferring_show) ShowWindow(hwnd, SW_SHOWNA);
  92. if (config_minimized) set_aot(0);
  93. if (!config_mw_open) MoveOffscreen(hwnd);
  94. config_minimized = 0;
  95. SendMessageW(hwnd, WM_TIMER, UPDATE_DISPLAY_TIMER + 4, 0);
  96. if (!deferring_show) SetForegroundWindow(hwnd);
  97. if (config_pe_open && hPLWindow) ShowWindow(hPLWindow, SW_SHOWNA);
  98. //if (config_mb_open&&hMBWindow) ShowWindow(hMBWindow,SW_SHOWNA);
  99. if (config_eq_open && hEQWindow) ShowWindow(hEQWindow,SW_SHOWNA);
  100. if (config_video_open && hVideoWindow) ShowWindow(hVideoWindow, SW_SHOWNA);
  101. set_aot(0);
  102. // Browser_toggleVisible(1);
  103. }
  104. return 1;
  105. }
  106. // Sent by decode thread to let the main program know it's done
  107. LRESULT Main_OnWAMPEGEOF(HWND hwnd)
  108. {
  109. return PlayQueue_OnEOF();
  110. }
  111. // Drag&Drop handler
  112. LRESULT Main_OnDropFiles(HWND hwnd, HDROP hdrop)
  113. {
  114. wchar_t temp[MAX_PATH] = {0};
  115. int s = (GetAsyncKeyState(VK_SHIFT) & (1 << 15)) ? 0 : 1;
  116. int y = DragQueryFileW(hdrop, 0xffffffff, temp, MAX_PATH);
  117. if (s)
  118. {
  119. PlayList_delete();
  120. PlayList_randpos(0);
  121. }
  122. for (int x = 0; x < y; x ++)
  123. {
  124. DragQueryFileW(hdrop, x, temp, MAX_PATH);
  125. PlayList_appendthing(temp, 0, 0);
  126. }
  127. if (s)
  128. BeginPlayback();
  129. plEditRefresh();
  130. return 1;
  131. }
  132. LRESULT Main_OnCopyData(HWND sendingHWND, COPYDATASTRUCT *cds)
  133. {
  134. switch (cds->dwData)
  135. {
  136. case IPC_SETSKIN:
  137. if (cds->lpData && lstrlenA((char *)cds->lpData))
  138. {
  139. AutoWide dataW((char*)cds->lpData);
  140. if (_wcsicmp(config_skin, dataW))
  141. {
  142. StringCchCopyW(config_skin, MAX_PATH, dataW);
  143. }
  144. SendMessageW(hMainWindow, WM_COMMAND, WINAMP_REFRESHSKIN, 0);
  145. }
  146. return TRUE;
  147. case IPC_SETSKINW:
  148. if (cds->lpData && lstrlenW((wchar_t*)cds->lpData))
  149. {
  150. if (_wcsicmp(config_skin, (wchar_t*)cds->lpData))
  151. {
  152. StringCchCopyW(config_skin, MAX_PATH, (wchar_t*)cds->lpData);
  153. }
  154. SendMessageW(hMainWindow, WM_COMMAND, WINAMP_REFRESHSKIN, 0);
  155. }
  156. return TRUE;
  157. case IPC_CHDIR:
  158. SetCurrentDirectoryA((char *) cds->lpData);
  159. return TRUE;
  160. case IPC_PLAYFILE:
  161. {
  162. char *filename = (char *)cds->lpData;
  163. PlayList_appendthing(AutoWideFn(filename), 0, 0);
  164. plEditRefresh();
  165. }
  166. return TRUE;
  167. case IPC_PLAYFILEW:
  168. {
  169. wchar_t *filename = (wchar_t *)cds->lpData;
  170. PlayList_appendthing(filename, 0, 0);
  171. plEditRefresh();
  172. }
  173. return TRUE;
  174. case IPC_GETMODULENAME:
  175. {
  176. char b[512] = {0}, b2[512] = {0};
  177. GetModuleFileNameA(hMainInstance, b, sizeof(b));
  178. GetShortPathNameA(b, b2, 511);
  179. GetShortPathNameA((char *)cds->lpData, b, 511);
  180. stat_isit = _stricmp(b, b2);
  181. }
  182. return TRUE;
  183. case IPC_ADDBOOKMARK:
  184. {
  185. wchar_t* file = AutoWide((char *)cds->lpData);
  186. Bookmark_additem(file, PlayList_gettitle(file, 1));
  187. }
  188. return TRUE;
  189. case IPC_ADDBOOKMARKW:
  190. {
  191. Bookmark_additem((wchar_t *)cds->lpData, PlayList_gettitle((const wchar_t *)cds->lpData, 1));
  192. }
  193. return TRUE;
  194. case IPC_GET_EXTENDED_FILE_INFOW_HOOKABLE:
  195. {
  196. wchar_t *filename = (wchar_t *)cds->lpData;
  197. wchar_t *tagname = filename + wcslen(filename) + 1;
  198. extendedFileInfoStructW info;
  199. info.filename = filename;
  200. info.metadata = tagname;
  201. wchar_t ret[1024]=L"";
  202. info.ret = ret;
  203. info.retlen = 1024;
  204. if (0 == SendMessageW(hMainWindow, WM_WA_IPC, (WPARAM)&info, IPC_GET_EXTENDED_FILE_INFOW_HOOKABLE))
  205. ret[0] = L'\0';
  206. COPYDATASTRUCT answer;
  207. answer.lpData = info.ret;
  208. answer.cbData = sizeof(ret);
  209. answer.dwData = IPC_GET_EXTENDED_FILE_INFOW_HOOKABLE;
  210. return SendMessageW(sendingHWND, WM_COPYDATA, (WPARAM)hMainWindow, (LPARAM)&answer);
  211. }
  212. case IPC_GET_PLAYING_FILENAME:
  213. {
  214. COPYDATASTRUCT answer;
  215. answer.lpData = FileName;
  216. answer.cbData = (DWORD)(sizeof(wchar_t) * (wcslen(FileName) + 1));
  217. answer.dwData = IPC_GET_PLAYING_FILENAME;
  218. return SendMessageW(sendingHWND, WM_COPYDATA, (WPARAM)hMainWindow, (LPARAM)&answer);
  219. }
  220. case IPC_OPEN_URL:
  221. {
  222. myOpenURL(hMainWindow, (wchar_t *)cds->lpData);
  223. return TRUE;
  224. }
  225. case IPC_HANDLE_URI:
  226. {
  227. HandleFilename((wchar_t *)cds->lpData);
  228. return TRUE;
  229. }
  230. }
  231. return FALSE;
  232. }