1
0

wnd.cpp 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005 Nullsoft, Inc.
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. * Neither the name of Nullsoft nor the names of its contributors may be used to
  14. endorse or promote products derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #include <stdio.h>
  25. #include <windows.h>
  26. #include <windowsx.h>
  27. #include "vis.h"
  28. #include "draw.h"
  29. #include "wnd.h"
  30. #include "cfgwnd.h"
  31. #include "r_defs.h"
  32. #include "resource.h"
  33. #include "render.h"
  34. #include "undo.h"
  35. #include <multimon.h>
  36. #include "avs_eelif.h"
  37. #define WINAMP_NEXT_WINDOW 40063
  38. #include "wa_ipc.h"
  39. #include "ff_ipc.h"
  40. #include "../Agave/Language/api_language.h"
  41. #ifndef WS_EX_LAYERED
  42. #define WS_EX_LAYERED 0x80000
  43. #endif
  44. #ifndef LWA_ALPHA
  45. #define LWA_ALPHA 2
  46. #endif
  47. #define ID_VIS_NEXT 40382
  48. #define ID_VIS_PREV 40383
  49. #define ID_VIS_RANDOM 40384
  50. struct winampVisModule *g_mod;
  51. extern volatile int g_ThreadQuit;
  52. extern int /*g_preset_dirty,*/ config_prompt_save_preset, config_reuseonresize;
  53. int g_saved_preset_dirty;
  54. extern int cfg_cancelfs_on_deactivate;
  55. extern char g_noeffectstr[];
  56. #ifndef WA2_EMBED
  57. static int cfg_x=100, cfg_y=100, cfg_w=400, cfg_h=300;
  58. #endif
  59. #ifndef WA2_EMBED
  60. static HDC hFrameDC;
  61. static HBITMAP hFrameBitmap, hFrameBitmap_old;
  62. #else
  63. embedWindowState myWindowState;
  64. HWND g_hWA2ParentWindow;
  65. #endif
  66. int g_reset_vars_on_recompile=1; // fucko: add config for this
  67. // Wharf integration
  68. int inWharf=0;
  69. int need_redock=0;
  70. extern int cfg_fs_use_overlay;
  71. extern int g_config_seh;
  72. void toggleWharfAmpDock(HWND hwnd);
  73. //-
  74. int g_in_destroy=0,g_minimized=0,g_fakeinit=0;
  75. int g_rnd_cnt;
  76. char g_skin_name[MAX_PATH];
  77. int debug_reg[8];
  78. void GetClientRect_adj(HWND hwnd, RECT *r)
  79. {
  80. GetClientRect(hwnd,r);
  81. #ifndef WA2_EMBED
  82. if (!inWharf)
  83. {
  84. r->right-=7+6;
  85. r->bottom-=15+5;
  86. }
  87. #endif
  88. }
  89. HWND g_hwnd;
  90. HWND hwnd_WinampParent;
  91. extern HWND g_hwndDlg;
  92. extern char last_preset[2048];
  93. char *scanstr_back(char *str, char *toscan, char *defval)
  94. {
  95. char *s=str+strlen(str)-1;
  96. if (strlen(str) < 1) return defval;
  97. if (strlen(toscan) < 1) return defval;
  98. while (1)
  99. {
  100. char *t=toscan;
  101. while (*t)
  102. if (*t++ == *s) return s;
  103. t=CharPrev(str,s);
  104. if (t==s) return defval;
  105. s=t;
  106. }
  107. }
  108. int LoadPreset(int preset)
  109. {
  110. char temp[MAX_PATH];
  111. wsprintf(temp,"%s\\PRESET%02d.APH",g_path,preset);
  112. if (g_render_transition->LoadPreset(temp,1))
  113. return 0;
  114. if (preset < 12) wsprintf(last_preset,"\\F%d.aph",preset+1);
  115. else if (preset < 22) wsprintf(last_preset,"\\%d.aph",preset-12);
  116. else if (preset < 32) wsprintf(last_preset,"\\Shift-%d.aph",preset-22);
  117. return 1;
  118. }
  119. void WritePreset(int preset)
  120. {
  121. char temp[MAX_PATH];
  122. wsprintf(temp,"%s\\PRESET%02d.APH",g_path,preset);
  123. g_render_effects->__SavePreset(temp);
  124. }
  125. void my_getViewport( RECT *r, RECT *sr )
  126. {
  127. if ( sr )
  128. {
  129. HINSTANCE h = LoadLibraryW( L"user32.dll" );
  130. if ( h )
  131. {
  132. HMONITOR( WINAPI * Mfr )( LPCRECT lpcr, DWORD dwFlags ) = ( HMONITOR( WINAPI * )( LPCRECT, DWORD ) ) GetProcAddress( h, "MonitorFromRect" );
  133. BOOL( WINAPI * Gmi )( HMONITOR mon, LPMONITORINFO lpmi ) = ( BOOL( WINAPI * )( HMONITOR, LPMONITORINFO ) ) GetProcAddress( h, "GetMonitorInfoW" );
  134. if ( Mfr && Gmi )
  135. {
  136. HMONITOR hm;
  137. hm = Mfr( sr, MONITOR_DEFAULTTONULL );
  138. if ( hm )
  139. {
  140. MONITORINFOEXW mi;
  141. memset( &mi, 0, sizeof( mi ) );
  142. mi.cbSize = sizeof( mi );
  143. if ( Gmi( hm, &mi ) )
  144. {
  145. *r = mi.rcWork;
  146. return;
  147. }
  148. }
  149. }
  150. FreeLibrary( h );
  151. }
  152. }
  153. SystemParametersInfoW( SPI_GETWORKAREA, 0, r, 0 );
  154. }
  155. void SetTransparency(HWND hWnd, int enable, int amount)
  156. {
  157. #ifdef WA2_EMBED
  158. // disable transparency if hosted in gen_ff
  159. HWND w = myWindowState.me;
  160. while (GetWindowLong(w, GWL_STYLE) & WS_CHILD) w = GetParent(w);
  161. char classname[256];
  162. GetClassName(w, classname, 255); classname[255] = 0;
  163. if (!stricmp(classname, "BaseWindow_RootWnd")) return;
  164. // --
  165. #endif
  166. DWORD dwLong;
  167. HINSTANCE h;
  168. void (__stdcall *a)(HWND h, int a, int b, int c);
  169. hWnd=GetParent(hWnd);
  170. dwLong = GetWindowLong(hWnd, GWL_EXSTYLE);
  171. if(amount==255||!enable) {
  172. if(dwLong&WS_EX_LAYERED)
  173. SetWindowLong(hWnd, GWL_EXSTYLE, dwLong & ~WS_EX_LAYERED);
  174. } else {
  175. if(!(dwLong&WS_EX_LAYERED))
  176. SetWindowLong(hWnd, GWL_EXSTYLE, dwLong | WS_EX_LAYERED);
  177. h=LoadLibrary("USER32.DLL");
  178. if(h!=NULL) {
  179. a=(void (__stdcall *)(HWND,int,int,int))GetProcAddress(h,"SetLayeredWindowAttributes");
  180. if(a!=NULL)
  181. a(hWnd, RGB(0,0,0), amount, LWA_ALPHA);
  182. FreeLibrary(h);
  183. }
  184. }
  185. }
  186. int readyToLoadPreset(HWND parent, int isnew)
  187. {
  188. if (config_prompt_save_preset && C_UndoStack::isdirty())
  189. {
  190. static int here;
  191. if (here) return 0;
  192. here=1;
  193. // strange bugfix, ick
  194. void Wnd_GoWindowed(HWND hwnd);
  195. if (DDraw_IsFullScreen()) Wnd_GoWindowed(g_hwnd);
  196. char title[48];
  197. int ret=MessageBox(parent,
  198. WASABI_API_LNGSTRING(!isnew?IDS_CURRENT_PRESET_EDITED_SAVE_BEFORE_LOAD:
  199. IDS_CURRENT_PRESET_EDITED_SAVE_BEFORE_NEW),
  200. WASABI_API_LNGSTRING_BUF(IDS_AVS_PRESET_MODIFIED,title,48),MB_YESNOCANCEL);
  201. here=0;
  202. if (ret == IDCANCEL)
  203. {
  204. return 0;
  205. }
  206. if (ret == IDYES)
  207. {
  208. int dosavePreset(HWND hwndDlg);
  209. int r=1;
  210. // if (last_preset[0])
  211. // r=g_render_effects->SavePreset(last_preset);
  212. if (r)
  213. {
  214. if (dosavePreset(parent)) return 0;
  215. }
  216. }
  217. }
  218. //C_UndoStack::clear();
  219. // g_preset_dirty=0;
  220. return 1;
  221. }
  222. char *extension(char *fn)
  223. {
  224. char *s = fn + strlen(fn);
  225. while (s >= fn && *s != '.' && *s != '\\') s--;
  226. if (s < fn) return fn;
  227. if (*s == '\\') return fn;
  228. return (s+1);
  229. }
  230. static int last_windowed_w, last_windowed_h;
  231. void Wnd_GoWindowed(HWND hwnd)
  232. {
  233. if (DDraw_IsFullScreen())
  234. {
  235. #ifdef WA2_EMBED
  236. SendMessage(g_mod->hwndParent,WM_WA_IPC,0,IPC_SET_VIS_FS_FLAG);
  237. #endif
  238. #if !defined(WA2_EMBED)
  239. DDraw_SetFullScreen(0,cfg_w-7-6,cfg_h-15-5,cfg_fs_d&2,0);
  240. #else
  241. SetParent(hwnd,myWindowState.me);
  242. SetWindowLong(hwnd,GWL_STYLE,WS_VISIBLE|WS_CHILDWINDOW|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_OVERLAPPED);
  243. DDraw_SetFullScreen(0,last_windowed_w,last_windowed_h,cfg_fs_d&2,0);
  244. HWND w = myWindowState.me;
  245. while (GetWindowLong(w, GWL_STYLE) & WS_CHILD) w = GetParent(w);
  246. ShowWindow(w,SW_SHOWNA);
  247. #endif
  248. if (cfg_cancelfs_on_deactivate) ShowCursor(TRUE);
  249. int tm=(GetWindowLong(g_mod->hwndParent,GWL_EXSTYLE)&WS_EX_TOPMOST)==WS_EX_TOPMOST;
  250. #if !defined(WA2_EMBED)
  251. SetWindowPos(hwnd,tm?HWND_TOPMOST:HWND_NOTOPMOST,cfg_x,cfg_y,cfg_w,cfg_h,SWP_NOACTIVATE);
  252. #else
  253. PostMessage(GetParent(hwnd),WM_SIZE,0,0);
  254. #endif
  255. SetTransparency(hwnd,cfg_trans,cfg_trans_amount);
  256. SetTimer(hwnd,88,100,NULL);
  257. }
  258. }
  259. void Wnd_GoFullScreen(HWND hwnd)
  260. {
  261. if (!DDraw_IsFullScreen())
  262. {
  263. #if 1
  264. #ifdef WA2_EMBED
  265. if (SendMessage(g_mod->hwndParent,WM_WA_IPC,0,IPC_IS_PLAYING_VIDEO)>1)
  266. {
  267. PostMessage(hwnd,WM_USER+1667,1,2);
  268. return;
  269. }
  270. #endif
  271. #endif
  272. extern int cfg_fs_use_overlay;
  273. #ifdef WA2_EMBED
  274. RECT r;
  275. GetClientRect(hwnd,&r);
  276. last_windowed_w=r.right;
  277. last_windowed_h=r.bottom;
  278. #endif
  279. if (!DDraw_IsMode(cfg_fs_w,cfg_fs_h,cfg_fs_bpp))
  280. {
  281. int DDraw_PickMode(int *w, int *h, int *bpp);
  282. if (!DDraw_PickMode(&cfg_fs_w,&cfg_fs_h,&cfg_fs_bpp))
  283. return;
  284. }
  285. {
  286. #ifdef WA2_EMBED
  287. SendMessage(g_mod->hwndParent,WM_WA_IPC,1,IPC_SET_VIS_FS_FLAG);
  288. #endif
  289. RECT tr;
  290. if (inWharf)
  291. {
  292. need_redock=1;
  293. toggleWharfAmpDock(hwnd);
  294. }
  295. SetTransparency(hwnd,0,0);
  296. if (cfg_cancelfs_on_deactivate) ShowCursor(FALSE);
  297. GetWindowRect(hwnd,&tr);
  298. if (cfg_cfgwnd_open) ShowWindow(g_hwndDlg,SW_HIDE);
  299. if (!cfg_fs_use_overlay)
  300. {
  301. #if defined(WA2_EMBED)
  302. SetWindowLong(hwnd,GWL_STYLE,WS_VISIBLE);
  303. SetParent(hwnd,NULL);
  304. HWND w = myWindowState.me;
  305. while (GetWindowLong(w, GWL_STYLE) & WS_CHILD) w = GetParent(w);
  306. ShowWindow(w,SW_HIDE);
  307. #endif
  308. DDraw_SetFullScreen(1,cfg_fs_w,cfg_fs_h,cfg_fs_d&1,cfg_fs_bpp);
  309. RECT r;
  310. my_getViewport(&r,&tr);
  311. SetWindowPos(hwnd,HWND_TOPMOST,r.left,r.top,cfg_fs_w,cfg_fs_h,0);
  312. SetForegroundWindow(hwnd);
  313. }
  314. else
  315. {
  316. #if defined(WA2_EMBED)
  317. SetWindowLong(hwnd,GWL_STYLE,WS_VISIBLE);
  318. SetParent(hwnd,NULL);
  319. HWND w = myWindowState.me;
  320. while (GetWindowLong(w, GWL_STYLE) & WS_CHILD) w = GetParent(w);
  321. ShowWindow(w,SW_HIDE);
  322. #endif
  323. DDraw_SetFullScreen(1,cfg_fs_w,cfg_fs_h,cfg_fs_d&1,0);
  324. }
  325. }
  326. #if 0
  327. else
  328. {
  329. if (!cfg_cfgwnd_open)
  330. {
  331. ShowWindow(g_hwndDlg,SW_SHOWNA);
  332. CfgWnd_RePopIfNeeded();
  333. cfg_cfgwnd_open=1;
  334. }
  335. SendMessage(g_hwndDlg,WM_COMMAND,IDM_FULLSCREEN,0);
  336. }
  337. #endif
  338. }
  339. }
  340. int g_config_smp_mt=2,g_config_smp=0;
  341. static char *INI_FILE;
  342. static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  343. int cfg_fs_dblclk=1;
  344. int Wnd_Init(struct winampVisModule *this_mod)
  345. {
  346. WNDCLASS wc={0,};
  347. g_mod=this_mod;
  348. wc.style = CS_DBLCLKS|CS_VREDRAW|CS_HREDRAW;
  349. wc.lpfnWndProc = WndProc;
  350. wc.hInstance = this_mod->hDllInstance;
  351. wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
  352. wc.lpszClassName = "avswnd";
  353. wc.hCursor=LoadCursor(NULL,IDC_ARROW);
  354. hwnd_WinampParent=this_mod->hwndParent;
  355. if (!RegisterClass(&wc))
  356. {
  357. // MessageBox(this_mod->hwndParent,"Error registering window class","Error",MB_OK);
  358. // return 1;
  359. }
  360. {
  361. #ifndef REAPLAY_PLUGIN
  362. INI_FILE = (char*)SendMessage(this_mod->hwndParent,WM_WA_IPC,0,IPC_GETINIFILE);
  363. #else
  364. extern const char *(*get_ini_file)();
  365. INI_FILE = (char *)get_ini_file();
  366. #endif
  367. #define AVS_SECTION "AVS"
  368. #ifdef LASER
  369. #undef AVS_SECTION
  370. #define AVS_SECTION "AVS_L"
  371. extern int g_laser_nomessage,g_laser_zones;
  372. g_laser_nomessage=GetPrivateProfileInt(AVS_SECTION,"laser_nomessage",0,INI_FILE);
  373. g_laser_zones=GetPrivateProfileInt(AVS_SECTION,"laser_zones",1,INI_FILE);
  374. #else
  375. g_config_smp=GetPrivateProfileInt(AVS_SECTION,"smp",0,INI_FILE);
  376. g_config_smp_mt=GetPrivateProfileInt(AVS_SECTION,"smp_mt",2,INI_FILE);
  377. #endif
  378. need_redock=GetPrivateProfileInt(AVS_SECTION,"cfg_docked",0,INI_FILE);
  379. cfg_cfgwnd_x=GetPrivateProfileInt(AVS_SECTION,"cfg_cfgwnd_x",cfg_cfgwnd_x,INI_FILE);
  380. cfg_cfgwnd_y=GetPrivateProfileInt(AVS_SECTION,"cfg_cfgwnd_y",cfg_cfgwnd_y,INI_FILE);
  381. cfg_cfgwnd_open=GetPrivateProfileInt(AVS_SECTION,"cfg_cfgwnd_open",cfg_cfgwnd_open,INI_FILE);
  382. cfg_fs_w=GetPrivateProfileInt(AVS_SECTION,"cfg_fs_w",cfg_fs_w,INI_FILE);
  383. cfg_fs_h=GetPrivateProfileInt(AVS_SECTION,"cfg_fs_h",cfg_fs_h,INI_FILE);
  384. cfg_fs_bpp=GetPrivateProfileInt(AVS_SECTION,"cfg_fs_bpp",cfg_fs_bpp,INI_FILE);
  385. cfg_fs_d=GetPrivateProfileInt(AVS_SECTION,"cfg_fs_d",cfg_fs_d,INI_FILE);
  386. cfg_fs_fps=GetPrivateProfileInt(AVS_SECTION,"cfg_fs_fps",6,INI_FILE);
  387. cfg_fs_rnd=GetPrivateProfileInt(AVS_SECTION,"cfg_fs_rnd",cfg_fs_rnd,INI_FILE);
  388. cfg_fs_rnd_time=GetPrivateProfileInt(AVS_SECTION,"cfg_fs_rnd_time",cfg_fs_rnd_time,INI_FILE);
  389. cfg_fs_dblclk=GetPrivateProfileInt(AVS_SECTION,"cfg_fs_dblclk",cfg_fs_dblclk,INI_FILE);
  390. cfg_fs_flip=GetPrivateProfileInt(AVS_SECTION,"cfg_fs_flip",cfg_fs_flip,INI_FILE);
  391. cfg_fs_height=GetPrivateProfileInt(AVS_SECTION,"cfg_fs_height",cfg_fs_height,INI_FILE);
  392. cfg_fs_use_overlay=GetPrivateProfileInt(AVS_SECTION,"cfg_fs_use_overlay",cfg_fs_use_overlay,INI_FILE);
  393. cfg_cancelfs_on_deactivate=GetPrivateProfileInt(AVS_SECTION,"cfg_fs_cancelondeactivate",cfg_cancelfs_on_deactivate,INI_FILE);
  394. cfg_speed=GetPrivateProfileInt(AVS_SECTION,"cfg_speed",cfg_speed,INI_FILE);
  395. cfg_trans=GetPrivateProfileInt(AVS_SECTION,"cfg_trans",cfg_trans,INI_FILE);
  396. cfg_dont_min_avs=GetPrivateProfileInt(AVS_SECTION,"cfg_dont_min_avs",cfg_dont_min_avs,INI_FILE);
  397. cfg_smartbeat=GetPrivateProfileInt(AVS_SECTION,"cfg_smartbeat",cfg_smartbeat,INI_FILE);
  398. cfg_smartbeatsticky=GetPrivateProfileInt(AVS_SECTION,"cfg_smartbeatsticky",cfg_smartbeatsticky,INI_FILE);
  399. cfg_smartbeatresetnewsong=GetPrivateProfileInt(AVS_SECTION,"cfg_smartbeatresetnewsong",cfg_smartbeatresetnewsong,INI_FILE);
  400. cfg_smartbeatonlysticky=GetPrivateProfileInt(AVS_SECTION,"cfg_smartbeatonlysticky",cfg_smartbeatonlysticky,INI_FILE);
  401. GetPrivateProfileString( AVS_SECTION,"config_pres_subdir","",config_pres_subdir,sizeof(config_pres_subdir),INI_FILE);
  402. GetPrivateProfileString( AVS_SECTION,"last_preset_name","",last_preset,sizeof(last_preset),INI_FILE);
  403. cfg_transitions=GetPrivateProfileInt(AVS_SECTION,"cfg_transitions_en",cfg_transitions,INI_FILE);
  404. cfg_transitions2=GetPrivateProfileInt(AVS_SECTION,"cfg_transitions_preinit",cfg_transitions2,INI_FILE);
  405. cfg_transitions_speed=GetPrivateProfileInt(AVS_SECTION,"cfg_transitions_speed",cfg_transitions_speed,INI_FILE);
  406. cfg_transition_mode=GetPrivateProfileInt(AVS_SECTION,"cfg_transitions_mode",cfg_transition_mode,INI_FILE);
  407. cfg_bkgnd_render=GetPrivateProfileInt(AVS_SECTION,"cfg_bkgnd_render",cfg_bkgnd_render,INI_FILE);
  408. cfg_bkgnd_render_color=GetPrivateProfileInt(AVS_SECTION,"cfg_bkgnd_render_color",cfg_bkgnd_render_color,INI_FILE);
  409. cfg_render_prio=GetPrivateProfileInt(AVS_SECTION,"cfg_render_prio",cfg_render_prio,INI_FILE);
  410. g_saved_preset_dirty=GetPrivateProfileInt(AVS_SECTION,"g_preset_dirty",C_UndoStack::isdirty(),INI_FILE);
  411. config_prompt_save_preset=GetPrivateProfileInt(AVS_SECTION,"cfg_prompt_save_preset",config_prompt_save_preset,INI_FILE);
  412. config_reuseonresize=GetPrivateProfileInt(AVS_SECTION,"cfg_reuseonresize",config_reuseonresize,INI_FILE);
  413. g_log_errors=GetPrivateProfileInt(AVS_SECTION,"cfg_log_errors",g_log_errors,INI_FILE);
  414. g_reset_vars_on_recompile=GetPrivateProfileInt(AVS_SECTION,"cfg_reset_vars",g_reset_vars_on_recompile,INI_FILE);
  415. g_config_seh=GetPrivateProfileInt(AVS_SECTION,"cfg_seh",g_config_seh,INI_FILE);
  416. #ifdef WA2_EMBED
  417. memset(&myWindowState,0,sizeof(myWindowState));
  418. myWindowState.r.left=GetPrivateProfileInt(AVS_SECTION,"wx",32,INI_FILE);
  419. myWindowState.r.top=GetPrivateProfileInt(AVS_SECTION,"wy",32,INI_FILE);
  420. myWindowState.r.right = GetPrivateProfileInt(AVS_SECTION,"ww",320,INI_FILE)+myWindowState.r.left;
  421. myWindowState.r.bottom = GetPrivateProfileInt(AVS_SECTION,"wh",240,INI_FILE)+myWindowState.r.top;
  422. #else
  423. cfg_x=GetPrivateProfileInt(AVS_SECTION,"cfg_x",cfg_x,INI_FILE);
  424. cfg_y=GetPrivateProfileInt(AVS_SECTION,"cfg_y",cfg_y,INI_FILE);
  425. cfg_w=GetPrivateProfileInt(AVS_SECTION,"cfg_w",cfg_w,INI_FILE);
  426. cfg_h=GetPrivateProfileInt(AVS_SECTION,"cfg_h",cfg_h,INI_FILE);
  427. #endif
  428. int x;
  429. for (x = 0; x < 8; x ++)
  430. {
  431. char debugreg[32];
  432. wsprintf(debugreg,"debugreg_%d",x);
  433. debug_reg[x]=GetPrivateProfileInt(AVS_SECTION,debugreg,x,INI_FILE);
  434. }
  435. }
  436. #ifdef LASER
  437. cfg_transitions=0;
  438. cfg_transition_mode=0;
  439. cfg_transitions2=0;
  440. #endif
  441. g_in_destroy=0;
  442. #ifndef WA2_EMBED
  443. {
  444. RECT ir={cfg_x,cfg_y,cfg_w+cfg_x,cfg_y+cfg_h};
  445. RECT or;
  446. my_getViewport(&or,&ir);
  447. if (cfg_x < or.left) cfg_x=or.left;
  448. if (cfg_y < or.top) cfg_y=or.top;
  449. if (cfg_x > or.right-16) cfg_x=or.right-16;
  450. if (cfg_y > or.bottom-16) cfg_y=or.bottom-16;
  451. // determine bounding rectangle for window
  452. }
  453. #endif
  454. #ifndef WA2_EMBED
  455. int styles=WS_VISIBLE;
  456. HWND par = g_minimized?NULL:this_mod->hwndParent;
  457. #else
  458. int styles=WS_CHILDWINDOW|WS_OVERLAPPED|WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
  459. HWND (*e)(embedWindowState *v) = NULL;
  460. #ifndef REAPLAY_PLUGIN
  461. *(void**)&e = (void *)SendMessage(this_mod->hwndParent,WM_WA_IPC,(LPARAM)0,IPC_GET_EMBEDIF);
  462. HWND par=0;
  463. if (e) par=e(&myWindowState);
  464. if (par) SetWindowText(par,"AVS");
  465. #else
  466. HWND par = this_mod->hwndParent;
  467. #endif
  468. g_hWA2ParentWindow=par;
  469. #endif
  470. #ifndef WA2_EMBED
  471. CreateWindowEx(WS_EX_ACCEPTFILES,"avswnd","Winamp AVS Display",
  472. styles,cfg_x,cfg_y,cfg_w,cfg_h,par,NULL,
  473. this_mod->hDllInstance,0);
  474. #else
  475. CreateWindowEx(WS_EX_ACCEPTFILES,"avswnd","avs",
  476. styles,0,0,100,100,par,NULL, this_mod->hDllInstance,0);
  477. SendMessage(this_mod->hwndParent, WM_WA_IPC, (int)g_hwnd, IPC_SETVISWND);
  478. #endif
  479. if (!g_hwnd)
  480. {
  481. char title[32];
  482. MessageBox(this_mod->hwndParent,WASABI_API_LNGSTRING(IDS_ERROR_CREATING_WINDOW),
  483. WASABI_API_LNGSTRING_BUF(IDS_AVS_ERROR,title,32),MB_OK);
  484. return 1;
  485. }
  486. #ifndef REAPLAY_PLUGIN
  487. #ifdef WA2_EMBED
  488. ShowWindow(g_hwnd,SW_SHOWNA);
  489. ShowWindow(par,SW_SHOWNA);
  490. #endif
  491. #endif
  492. SetTransparency(g_hwnd,cfg_trans,cfg_trans_amount);
  493. return 0;
  494. }
  495. static void WriteInt(char *name, int value)
  496. {
  497. char str[128];
  498. wsprintf(str,"%d",value);
  499. WritePrivateProfileString(AVS_SECTION,name,str,INI_FILE);
  500. }
  501. void Wnd_Quit(void)
  502. {
  503. extern HWND g_hwndDlg;
  504. g_in_destroy=1;
  505. #ifdef WA2_EMBED
  506. SendMessage(g_mod->hwndParent, WM_WA_IPC, 0, IPC_SETVISWND);
  507. if (myWindowState.me)
  508. {
  509. SetForegroundWindow(g_mod->hwndParent);
  510. DestroyWindow(myWindowState.me);
  511. }
  512. else
  513. #endif
  514. if (g_hwnd && IsWindow(g_hwnd)) DestroyWindow(g_hwnd);
  515. g_hwnd=NULL;
  516. UnregisterClass("avswnd",g_mod->hDllInstance);
  517. {
  518. #ifdef LASER
  519. extern int g_laser_zones,g_laser_nomessage;
  520. wsprintf(str,"%d",g_laser_zones);
  521. WriteInt("laser_zones",g_laser_zones);
  522. WriteInt("laser_nomessage",g_laser_nomessage);
  523. #else
  524. WriteInt("smp",g_config_smp);
  525. WriteInt("smp_mt",g_config_smp_mt);
  526. #endif
  527. #ifdef WA2_EMBED
  528. WriteInt("wx",myWindowState.r.left);
  529. WriteInt("wy",myWindowState.r.top);
  530. WriteInt("ww",myWindowState.r.right-myWindowState.r.left);
  531. WriteInt("wh",myWindowState.r.bottom-myWindowState.r.top);
  532. #else
  533. WriteInt("cfg_x",cfg_x);
  534. WriteInt("cfg_y",cfg_y);
  535. WriteInt("cfg_w",cfg_w);
  536. WriteInt("cfg_h",cfg_h);
  537. #endif
  538. WritePrivateProfileString(AVS_SECTION,"config_pres_subdir",config_pres_subdir,INI_FILE);
  539. WriteInt("cfg_docked",inWharf?1:0);
  540. WriteInt("cfg_cfgwnd_open",cfg_cfgwnd_open);
  541. WriteInt("cfg_cfgwnd_x",cfg_cfgwnd_x);
  542. WriteInt("cfg_cfgwnd_y",cfg_cfgwnd_y);
  543. WriteInt("cfg_fs_w",cfg_fs_w);
  544. WriteInt("cfg_fs_h",cfg_fs_h);
  545. WriteInt("cfg_fs_d",cfg_fs_d);
  546. WriteInt("cfg_fs_bpp",cfg_fs_bpp);
  547. WriteInt("cfg_fs_fps",cfg_fs_fps);
  548. WriteInt("cfg_fs_rnd",cfg_fs_rnd);
  549. WriteInt("cfg_fs_rnd_time",cfg_fs_rnd_time);
  550. WriteInt("cfg_fs_dblclk",cfg_fs_dblclk);
  551. WriteInt("cfg_fs_flip",cfg_fs_flip);
  552. WriteInt("cfg_fs_height",cfg_fs_height);
  553. WriteInt("cfg_fs_use_overlay",cfg_fs_use_overlay);
  554. WriteInt("cfg_fs_cancelondeactivate",cfg_cancelfs_on_deactivate);
  555. WriteInt("cfg_speed",cfg_speed);
  556. WriteInt("cfg_trans",cfg_trans);
  557. WriteInt("cfg_dont_min_avs",cfg_dont_min_avs);
  558. WriteInt("cfg_smartbeat",cfg_smartbeat);
  559. WriteInt("cfg_smartbeatsticky",cfg_smartbeatsticky);
  560. WriteInt("cfg_smartbeatresetnewsong",cfg_smartbeatresetnewsong);
  561. WriteInt("cfg_smartbeatonlysticky",cfg_smartbeatonlysticky);
  562. WriteInt("cfg_transitions_en",cfg_transitions);
  563. WriteInt("cfg_transitions_preinit",cfg_transitions2);
  564. WriteInt("cfg_transitions_speed",cfg_transitions_speed);
  565. WriteInt("cfg_transitions_mode",cfg_transition_mode);
  566. WriteInt("cfg_bkgnd_render",cfg_bkgnd_render);
  567. WriteInt("cfg_bkgnd_render_color",cfg_bkgnd_render_color);
  568. WriteInt("cfg_render_prio",cfg_render_prio);
  569. WriteInt("g_preset_dirty",C_UndoStack::isdirty());
  570. WriteInt("cfg_prompt_save_preset",config_prompt_save_preset);
  571. WritePrivateProfileString(AVS_SECTION,"last_preset_name",last_preset,INI_FILE);
  572. WriteInt("cfg_reuseonresize",config_reuseonresize);
  573. WriteInt("cfg_log_errors",g_log_errors);
  574. WriteInt("cfg_reset_vars",g_reset_vars_on_recompile);
  575. WriteInt("cfg_seh",g_config_seh);
  576. int x;
  577. for (x = 0; x < 8; x ++)
  578. {
  579. char debugreg[32];
  580. wsprintf(debugreg,"debugreg_%d",x);
  581. WriteInt(debugreg,debug_reg[x]);
  582. }
  583. }
  584. }
  585. void toggleWharfAmpDock(HWND hwnd)
  586. {
  587. if (DDraw_IsFullScreen()) return;
  588. HWND Wharf=g_hwndDlg?GetDlgItem(g_hwndDlg,IDC_RRECT):NULL;
  589. if (!Wharf) return;
  590. if (!inWharf)
  591. {
  592. RECT r,r2;
  593. // show IDC_RRECT, resize IDC_TREE1 down
  594. GetWindowRect(GetDlgItem(g_hwndDlg,IDC_RRECT),&r);
  595. GetWindowRect(GetDlgItem(g_hwndDlg,IDC_TREE1),&r2);
  596. SetWindowPos(GetDlgItem(g_hwndDlg,IDC_TREE1),NULL,0,0,r2.right-r2.left,r.top - 4 - r2.top,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
  597. ShowWindow(GetDlgItem(g_hwndDlg,IDC_RRECT),SW_SHOWNA);
  598. #ifdef WA2_EMBED
  599. GetClientRect(hwnd,&r);
  600. last_windowed_w=r.right;
  601. last_windowed_h=r.bottom;
  602. #endif
  603. inWharf=1;
  604. GetWindowRect(Wharf, &r);
  605. SetParent(hwnd, Wharf);
  606. #ifndef WA2_EMBED
  607. SetWindowLong(hwnd, GWL_STYLE, (GetWindowLong(hwnd,GWL_STYLE)&(~WS_POPUP))|WS_CHILD);
  608. #else
  609. HWND w = g_hWA2ParentWindow;
  610. while (GetWindowLong(w, GWL_STYLE) & WS_CHILD)
  611. {
  612. w = GetParent(w);
  613. }
  614. if (!SendMessage(g_mod->hwndParent, WM_WA_IPC, (int)w, IPC_FF_ISMAINWND)) ShowWindow(w,SW_HIDE);
  615. else ShowWindow(g_hWA2ParentWindow,SW_HIDE);
  616. #endif
  617. SetWindowPos(hwnd, NULL, 0, 0, r.right-r.left, r.bottom-r.top, SWP_NOZORDER|SWP_NOACTIVATE);
  618. DDraw_Resize(r.right-r.left, r.bottom-r.top,cfg_fs_d&2);
  619. }
  620. else
  621. {
  622. RECT r,r2;
  623. // hide IDC_RRECT, resize IDC_TREE1 up
  624. GetWindowRect(GetDlgItem(g_hwndDlg,IDC_RRECT),&r);
  625. GetWindowRect(GetDlgItem(g_hwndDlg,IDC_TREE1),&r2);
  626. ShowWindow(GetDlgItem(g_hwndDlg,IDC_RRECT),SW_HIDE);
  627. SetWindowPos(GetDlgItem(g_hwndDlg,IDC_TREE1),NULL,0,0,r2.right-r2.left,r.bottom - r2.top - 2,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
  628. #ifndef WA2_EMBED
  629. SetWindowLong(hwnd, GWL_STYLE, (GetWindowLong(hwnd,GWL_STYLE)&(~(WS_CHILD|WS_VISIBLE)))|WS_POPUP);
  630. SetParent(hwnd, NULL);
  631. SetWindowPos(hwnd, NULL, cfg_x, cfg_y, cfg_w,cfg_h, SWP_NOZORDER|SWP_NOACTIVATE);
  632. DDraw_Resize(cfg_w-7-6,cfg_h-15-5,cfg_fs_d&2);
  633. ShowWindow(hwnd,SW_SHOWNA);
  634. #else
  635. SetParent(hwnd, g_hWA2ParentWindow);
  636. DDraw_Resize(last_windowed_w,last_windowed_h,cfg_fs_d&2);
  637. HWND w = g_hWA2ParentWindow;
  638. while (GetWindowLong(w, GWL_STYLE) & WS_CHILD)
  639. {
  640. w = GetParent(w);
  641. }
  642. if (SendMessage(g_mod->hwndParent, WM_WA_IPC, (int)w, IPC_FF_ISMAINWND))
  643. w=g_hWA2ParentWindow;
  644. PostMessage(GetParent(hwnd),WM_SIZE,0,0);
  645. ShowWindow(w,SW_SHOWNA);
  646. //SetWindowPos(hwnd,0,0,0,cfg_w,cfg_h,SWP_NOACTIVATE|SWP_NOZORDER);
  647. //SetTimer(hwnd,66,500,NULL);
  648. #endif
  649. InvalidateRect(Wharf,NULL,TRUE);
  650. inWharf=0;
  651. }
  652. }
  653. int findInMenu(HMENU parent, HMENU sub, UINT id, char *buf, int buf_len)
  654. {
  655. int x,l=GetMenuItemCount(parent);
  656. char *bufadd=buf+strlen(buf);
  657. bufadd[0]='\\';
  658. for (x = 0; x < l; x ++)
  659. {
  660. MENUITEMINFO mi={sizeof(mi),MIIM_SUBMENU|MIIM_TYPE|MIIM_ID,};
  661. mi.dwTypeData=bufadd+1;
  662. mi.cch=buf_len - (bufadd-buf+2);
  663. GetMenuItemInfo(parent,x,TRUE,&mi);
  664. if (mi.hSubMenu)
  665. {
  666. if (sub && mi.hSubMenu == sub)
  667. return 1;
  668. if (findInMenu(mi.hSubMenu,sub,id,buf,buf_len))
  669. return 1;
  670. }
  671. else
  672. {
  673. if (!sub && id && mi.wID == id)
  674. return 1;
  675. }
  676. }
  677. bufadd[0]=0;
  678. return 0;
  679. }
  680. static int find_preset(char *parent_path, int dir, char *lastpreset, char *newpreset, int *state)
  681. {
  682. HANDLE h;
  683. WIN32_FIND_DATA d;
  684. char dirmask[4096];
  685. wsprintf(dirmask,"%s\\*.avs",parent_path);
  686. h = FindFirstFile(dirmask,&d);
  687. if (h != INVALID_HANDLE_VALUE)
  688. {
  689. do
  690. {
  691. if (!(d.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
  692. {
  693. wsprintf(dirmask,"%s\\%s",parent_path,d.cFileName);
  694. if (lastpreset)
  695. {
  696. if (*state)
  697. {
  698. strcpy(newpreset,dirmask);
  699. FindClose(h);
  700. return 1;
  701. }
  702. if (dir > 0)
  703. {
  704. if (!newpreset[0]) // save the first one we find, in case we fail (wrap)
  705. strcpy(newpreset,dirmask);
  706. if (!stricmp(dirmask,lastpreset)) *state=1;
  707. }
  708. if (dir < 0)
  709. {
  710. if (!stricmp(dirmask,lastpreset))
  711. {
  712. if (newpreset[0]) { // if we find it first, skip it so we can go to the end :)
  713. FindClose(h);
  714. return 1;
  715. }
  716. }
  717. strcpy(newpreset,dirmask);
  718. }
  719. }
  720. else
  721. {
  722. int cnt=++(*state);
  723. if (cnt < 1) cnt=1;
  724. int r=((rand()&1023)<<10)|(rand()&1023);
  725. if (r < (1024*1024)/cnt)
  726. {
  727. strcpy(newpreset,dirmask);
  728. }
  729. }
  730. }
  731. } while (FindNextFile(h,&d));
  732. FindClose(h);
  733. }
  734. wsprintf(dirmask,"%s\\*.*",parent_path);
  735. h = FindFirstFile(dirmask,&d);
  736. if (h != INVALID_HANDLE_VALUE)
  737. {
  738. do
  739. {
  740. if (d.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && d.cFileName[0] != '.')
  741. {
  742. wsprintf(dirmask,"%s\\%s",parent_path,d.cFileName);
  743. if (find_preset(dirmask,dir,lastpreset,newpreset,state)) {
  744. FindClose(h);
  745. return 1;
  746. }
  747. }
  748. } while (FindNextFile(h,&d));
  749. FindClose(h);
  750. }
  751. return 0;
  752. }
  753. void next_preset(HWND hwnd) {
  754. g_rnd_cnt=0;
  755. if (readyToLoadPreset(hwnd,0))
  756. {
  757. char dirmask[2048];
  758. char i_path[1024];
  759. if (config_pres_subdir[0]) wsprintf(i_path,"%s\\%s",g_path,config_pres_subdir);
  760. else strcpy(i_path,g_path);
  761. dirmask[0]=0;
  762. int state=0;
  763. find_preset(i_path,1,last_preset,dirmask,&state);
  764. if (dirmask[0] && stricmp(last_preset,dirmask))
  765. {
  766. if (g_render_transition->LoadPreset(dirmask,2) != 2)
  767. lstrcpyn(last_preset,dirmask,sizeof(last_preset));
  768. }
  769. }
  770. }
  771. void random_preset(HWND hwnd) {
  772. g_rnd_cnt=0;
  773. if (readyToLoadPreset(hwnd,0))
  774. {
  775. char dirmask[2048];
  776. char i_path[1024];
  777. if (config_pres_subdir[0]) wsprintf(i_path,"%s\\%s",g_path,config_pres_subdir);
  778. else strcpy(i_path,g_path);
  779. dirmask[0]=0;
  780. int state=0;
  781. find_preset(i_path,0,NULL,dirmask,&state);
  782. if (dirmask[0])
  783. {
  784. if (g_render_transition->LoadPreset(dirmask,4) != 2)
  785. lstrcpyn(last_preset,dirmask,sizeof(last_preset));
  786. }
  787. }
  788. }
  789. void previous_preset(HWND hwnd) {
  790. g_rnd_cnt=0;
  791. if (readyToLoadPreset(hwnd,0))
  792. {
  793. char dirmask[2048];
  794. char i_path[1024];
  795. if (config_pres_subdir[0]) wsprintf(i_path,"%s\\%s",g_path,config_pres_subdir);
  796. else strcpy(i_path,g_path);
  797. dirmask[0]=0;
  798. int state=0;
  799. find_preset(i_path,-1,last_preset,dirmask,&state);
  800. if (dirmask[0] && stricmp(last_preset,dirmask))
  801. {
  802. if (g_render_transition->LoadPreset(dirmask,2) != 2)
  803. lstrcpyn(last_preset,dirmask,sizeof(last_preset));
  804. }
  805. }
  806. }
  807. static HMENU presetTreeMenu;
  808. static int presetTreeCount;
  809. void DoPopupMenu() {
  810. // Winamp3 Bug#331: Don't let the popupmenu pop when in fullscreen.
  811. if (!DDraw_IsFullScreen())
  812. {
  813. void DDraw_NoUpdateScreen(int r);
  814. HANDLE h;
  815. WIN32_FIND_DATA d;
  816. char dirmask[1024];
  817. if (presetTreeMenu) DestroyMenu(presetTreeMenu);
  818. POINT p;
  819. int x;
  820. int insert_pos=0, directory_pos=0;
  821. presetTreeMenu=CreatePopupMenu();
  822. {
  823. MENUITEMINFO i={sizeof(i),};
  824. i.fMask=MIIM_TYPE|MIIM_DATA|MIIM_ID;
  825. i.fType=MFT_STRING;
  826. i.dwItemData=0;
  827. i.wID = 1024;
  828. i.dwTypeData=WASABI_API_LNGSTRING(IDS_FULLSCREEN);
  829. i.cch=strlen(i.dwTypeData);
  830. InsertMenuItem(presetTreeMenu,insert_pos++,TRUE,&i);
  831. if (!inWharf)
  832. {
  833. i.wID = 256;
  834. i.dwTypeData=WASABI_API_LNGSTRING(IDS_AVS_EDITOR);
  835. i.cch=strlen(i.dwTypeData);
  836. InsertMenuItem(presetTreeMenu,insert_pos++,TRUE,&i);
  837. }
  838. if (!DDraw_IsFullScreen())
  839. {
  840. i.wID = 512;
  841. i.dwTypeData=WASABI_API_LNGSTRING(IDS_DOCK_IN_AVS_EDITOR);
  842. i.cch=strlen(i.dwTypeData);
  843. InsertMenuItem(presetTreeMenu,insert_pos++,TRUE,&i);
  844. }
  845. i.wID=0;
  846. i.fType=MFT_SEPARATOR;
  847. InsertMenuItem(presetTreeMenu,insert_pos++,TRUE,&i);
  848. }
  849. GetCursorPos(&p);
  850. if (DDraw_IsFullScreen())
  851. {
  852. CheckMenuItem(presetTreeMenu,1024,MF_CHECKED);
  853. }
  854. if (IsWindowVisible(g_hwndDlg)) CheckMenuItem(presetTreeMenu,256,MF_CHECKED);
  855. if (inWharf) CheckMenuItem(presetTreeMenu,512,MF_CHECKED);
  856. wsprintf(dirmask,"%s\\*.*",g_path);
  857. directory_pos=insert_pos;
  858. presetTreeCount=1025;
  859. h = FindFirstFile(dirmask,&d);
  860. if (h != INVALID_HANDLE_VALUE)
  861. {
  862. do
  863. {
  864. if (d.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && d.cFileName[0] != '.')
  865. {
  866. MENUITEMINFO mi={sizeof(mi),MIIM_SUBMENU|MIIM_TYPE,MFT_STRING,MFS_DEFAULT
  867. };
  868. mi.hSubMenu=CreatePopupMenu();
  869. mi.dwTypeData=d.cFileName;
  870. mi.cch = strlen(d.cFileName);
  871. InsertMenuItem(presetTreeMenu,directory_pos++,TRUE,&mi);
  872. insert_pos++;
  873. }
  874. else if (!stricmp(extension(d.cFileName),"avs"))
  875. {
  876. extension(d.cFileName)[-1]=0;
  877. MENUITEMINFO i={sizeof(i),MIIM_TYPE|MIIM_ID,MFT_STRING,MFS_DEFAULT };
  878. i.dwTypeData = d.cFileName;
  879. i.cch = strlen(d.cFileName);
  880. i.wID=presetTreeCount++;
  881. InsertMenuItem(presetTreeMenu,insert_pos++,TRUE,&i);
  882. }
  883. } while (FindNextFile(h,&d));
  884. FindClose(h);
  885. }
  886. x=TrackPopupMenu(presetTreeMenu,TPM_LEFTALIGN|TPM_TOPALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON|TPM_LEFTBUTTON,p.x,p.y,0,g_hwnd,NULL);
  887. if (x == 1024)
  888. {
  889. if (DDraw_IsFullScreen())
  890. {
  891. if (!cfg_fs_use_overlay) Wnd_GoWindowed(g_hwnd);
  892. }
  893. else
  894. Wnd_GoFullScreen(g_hwnd);
  895. }
  896. else if (x == 512)
  897. {
  898. if (!inWharf && !cfg_cfgwnd_open)
  899. {
  900. cfg_cfgwnd_open=1;
  901. ShowWindow(g_hwndDlg,SW_SHOWNA);
  902. CfgWnd_RePopIfNeeded();
  903. }
  904. toggleWharfAmpDock(g_hwnd);
  905. }
  906. else if (x == 256)
  907. {
  908. SendMessage(g_hwnd,WM_USER+33,0,0);
  909. }
  910. else if (x >= 1025)
  911. {
  912. char buf[2048];
  913. buf[0]=0;
  914. if (readyToLoadPreset(g_hwnd,0))
  915. {
  916. if (findInMenu(presetTreeMenu,0,x,buf,2048))
  917. {
  918. char temp[4096];
  919. wsprintf(temp,"%s%s.avs",g_path,buf);
  920. if (g_render_transition->LoadPreset(temp,1) != 2)
  921. lstrcpyn(last_preset,temp,sizeof(last_preset));
  922. }
  923. else
  924. {
  925. // g_render_transition->LoadPreset
  926. // wsprintf(temp,"%s\\%s",g_path,curfilename);
  927. }
  928. }
  929. }
  930. DestroyMenu(presetTreeMenu);
  931. presetTreeMenu=0;
  932. }
  933. }
  934. static LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
  935. {
  936. if ( DDraw_IsFullScreen() &&
  937. !cfg_fs_use_overlay &&
  938. ( ( message == WM_KEYDOWN && wParam == VK_ESCAPE ) ||
  939. message == WM_LBUTTONUP ||
  940. ( message == WM_NCACTIVATE && !wParam ) ||
  941. message == WM_KILLFOCUS
  942. )
  943. )
  944. {
  945. Wnd_GoWindowed( hwnd );
  946. return 0;
  947. }
  948. else if ( message == WM_LBUTTONUP )
  949. {
  950. if ( !DDraw_IsFullScreen() )
  951. {
  952. #ifndef WA2_EMBED
  953. int x = GET_X_LPARAM( lParam );
  954. int y = GET_Y_LPARAM( lParam );
  955. RECT r;
  956. GetClientRect( hwnd, &r );
  957. if ( x > r.right - 12 && x < r.right - 3 && y > r.top + 3 && y < r.top + 13 )
  958. {
  959. g_in_destroy = 1;
  960. DestroyWindow( hwnd );
  961. }
  962. #endif
  963. /*
  964. else
  965. {
  966. static int lastdblclk;
  967. if (lastdblclk && GetTickCount()-lastdblclk > 1000 && !inWharf)
  968. DDraw_SetStatusText("double-click for configuration",600);
  969. lastdblclk=GetTickCount();
  970. }
  971. */
  972. }
  973. }
  974. if ( message == WM_LBUTTONDOWN )
  975. {
  976. SetFocus( g_hwnd );
  977. if ( inWharf ) SetFocus( hwnd );
  978. SetCapture( hwnd );
  979. return 0;
  980. }
  981. if ( message == WM_LBUTTONUP )
  982. {
  983. POINT p;
  984. RECT r;
  985. p.x = GET_X_LPARAM( lParam );
  986. p.y = GET_Y_LPARAM( lParam );
  987. ClientToScreen( hwnd, &p );
  988. if ( inWharf )
  989. {
  990. GetWindowRect( g_hwndDlg, &r );
  991. if ( !PtInRect( &r, p ) )
  992. {
  993. toggleWharfAmpDock( hwnd );
  994. }
  995. }
  996. else
  997. {
  998. RECT r2;
  999. GetWindowRect( GetDlgItem( g_hwndDlg, IDC_TREE1 ), &r );
  1000. GetWindowRect( hwnd, &r2 );
  1001. if ( PtInRect( &r, p ) && cfg_cfgwnd_open && !PtInRect( &r2, p ) )
  1002. {
  1003. toggleWharfAmpDock( hwnd );
  1004. }
  1005. }
  1006. ReleaseCapture();
  1007. return 0;
  1008. }
  1009. if ( message == WM_LBUTTONDBLCLK && !DDraw_IsFullScreen() )
  1010. {
  1011. if ( cfg_fs_dblclk )
  1012. {
  1013. if ( DDraw_IsFullScreen() )
  1014. {
  1015. if ( !cfg_fs_use_overlay ) Wnd_GoWindowed( hwnd );
  1016. }
  1017. else
  1018. Wnd_GoFullScreen( hwnd );
  1019. }
  1020. else
  1021. {
  1022. if ( inWharf )
  1023. {
  1024. toggleWharfAmpDock( hwnd );
  1025. }
  1026. else if ( IsWindowVisible( g_hwndDlg ) )
  1027. {
  1028. cfg_cfgwnd_open = 0;
  1029. ShowWindow( g_hwndDlg, SW_HIDE );
  1030. }
  1031. else
  1032. {
  1033. cfg_cfgwnd_open = 1;
  1034. ShowWindow( g_hwndDlg, SW_SHOWNA );
  1035. CfgWnd_RePopIfNeeded();
  1036. }
  1037. }
  1038. return 0;
  1039. }
  1040. switch ( message )
  1041. {
  1042. case WM_USER + 1667:
  1043. if ( wParam == 1 && lParam == 2 )
  1044. {
  1045. char title[ 32 ];
  1046. MessageBox( hwnd, WASABI_API_LNGSTRING( IDS_CANNOT_GO_FULLSCREEN_WHEN_VIDEO_PLAYING ),
  1047. WASABI_API_LNGSTRING_BUF( IDS_AVS_FULLSCREEN, title, 32 ),
  1048. MB_OK | MB_ICONINFORMATION );
  1049. }
  1050. return 0;
  1051. case WM_USER + 1666:
  1052. if ( wParam == 1 && lParam == 15 )
  1053. {
  1054. if ( DDraw_IsFullScreen() )
  1055. {
  1056. if ( cfg_fs_use_overlay ) SetFocus( hwnd ); // kill overlay window
  1057. else Wnd_GoWindowed( hwnd );
  1058. }
  1059. }
  1060. return 0;
  1061. case WM_INITMENUPOPUP:
  1062. if ( HIWORD( lParam ) == 0 && presetTreeMenu && !GetMenuItemCount( (HMENU) wParam ) )
  1063. {
  1064. char buf[ 2048 ];
  1065. buf[ 0 ] = 0;
  1066. if ( findInMenu( presetTreeMenu, (HMENU) wParam, 0, buf, 2048 ) )
  1067. {
  1068. HANDLE h;
  1069. WIN32_FIND_DATA d;
  1070. char dirmask[ 4096 ];
  1071. wsprintf( dirmask, "%s%s\\*.*", g_path, buf );
  1072. int directory_pos = 0, insert_pos = 0;
  1073. // build menu
  1074. h = FindFirstFile( dirmask, &d );
  1075. if ( h != INVALID_HANDLE_VALUE )
  1076. {
  1077. do
  1078. {
  1079. if ( d.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && d.cFileName[ 0 ] != '.' )
  1080. {
  1081. MENUITEMINFO mi = { sizeof( mi ),MIIM_SUBMENU | MIIM_TYPE,MFT_STRING,MFS_DEFAULT };
  1082. mi.hSubMenu = CreatePopupMenu();
  1083. mi.dwTypeData = d.cFileName;
  1084. mi.cch = strlen( d.cFileName );
  1085. InsertMenuItem( (HMENU) wParam, directory_pos++, TRUE, &mi );
  1086. insert_pos++;
  1087. }
  1088. else if ( !stricmp( extension( d.cFileName ), "avs" ) )
  1089. {
  1090. extension( d.cFileName )[ -1 ] = 0;
  1091. MENUITEMINFO i = { sizeof( i ),MIIM_TYPE | MIIM_ID,MFT_STRING,MFS_DEFAULT };
  1092. i.dwTypeData = d.cFileName;
  1093. i.cch = strlen( d.cFileName );
  1094. i.wID = presetTreeCount++;
  1095. InsertMenuItem( (HMENU) wParam, insert_pos++, TRUE, &i );
  1096. }
  1097. } while ( FindNextFile( h, &d ) );
  1098. FindClose( h );
  1099. }
  1100. }
  1101. }
  1102. return 0;
  1103. case WM_RBUTTONUP:
  1104. DoPopupMenu();
  1105. return 0;
  1106. case WM_USER + 33:
  1107. DDraw_SetStatusText( "", 100 );
  1108. if ( inWharf )
  1109. {
  1110. toggleWharfAmpDock( hwnd );
  1111. }
  1112. else if ( IsWindowVisible( g_hwndDlg ) )
  1113. {
  1114. cfg_cfgwnd_open = 0;
  1115. ShowWindow( g_hwndDlg, SW_HIDE );
  1116. }
  1117. else
  1118. {
  1119. cfg_cfgwnd_open = 1;
  1120. ShowWindow( g_hwndDlg, SW_SHOWNA );
  1121. CfgWnd_RePopIfNeeded();
  1122. }
  1123. return 0;
  1124. case WM_USER + 32:
  1125. Wnd_GoFullScreen( hwnd );
  1126. return 0;
  1127. case WM_SYSKEYDOWN:
  1128. case WM_KEYDOWN:
  1129. if ( ( GetAsyncKeyState( VK_CONTROL ) & 0x8000 ) && wParam == VK_F4 )
  1130. {
  1131. SendMessage( hwnd, WM_CLOSE, 0, 0 );
  1132. return 0;
  1133. }
  1134. if ( ( GetAsyncKeyState( VK_MENU ) & 0x8000 ) && wParam == VK_F4 )
  1135. {
  1136. PostMessage( hwnd_WinampParent, message, wParam, lParam );
  1137. break;
  1138. }
  1139. if ( wParam == VK_SPACE )
  1140. {
  1141. do_random:
  1142. random_preset( hwnd );
  1143. }
  1144. else if ( wParam == 0x55 )
  1145. {
  1146. next_preset( hwnd );
  1147. }
  1148. else if ( wParam == 0x59 )
  1149. {
  1150. previous_preset( hwnd );
  1151. }
  1152. else if ( wParam == VK_RETURN )
  1153. {
  1154. if ( GetAsyncKeyState( VK_MENU ) & 0x8000 )
  1155. {
  1156. if ( DDraw_IsFullScreen() )
  1157. {
  1158. if ( !cfg_fs_use_overlay ) Wnd_GoWindowed( hwnd );
  1159. }
  1160. else
  1161. Wnd_GoFullScreen( hwnd );
  1162. }
  1163. }
  1164. else if ( wParam == /* VK_T */ 0x54 )
  1165. {
  1166. extern int draw_title_p;
  1167. draw_title_p = 2;
  1168. }
  1169. else if ( wParam == /* VK_F */ 0x52 + 'F' - 'R' )
  1170. {
  1171. cfg_fs_fps ^= 1;
  1172. DDraw_SetStatusText( WASABI_API_LNGSTRING( cfg_fs_fps & 1 ? IDS_FULLSCREEN_FPS_ON : IDS_FULLSCREEN_FPS_OFF ) );
  1173. }
  1174. else if ( wParam == /* VK_R */ 0x52 )
  1175. {
  1176. cfg_fs_rnd = !cfg_fs_rnd;
  1177. g_rnd_cnt = 0;
  1178. DDraw_SetStatusText( WASABI_API_LNGSTRING( cfg_fs_rnd ? IDS_RANDOM_PRESETS_ON : IDS_RANDOM_PRESETS_OFF ) );
  1179. }
  1180. else if ( wParam >= VK_F1 && wParam <= VK_F12 )
  1181. {
  1182. char s[ 128 ], *st, stBuf[ 48 ];
  1183. if ( GetAsyncKeyState( VK_CONTROL ) & ( 1 << 15 ) )
  1184. {
  1185. st = WASABI_API_LNGSTRING_BUF( IDS_SAVED_TO, stBuf, 48 );
  1186. WritePreset( wParam - VK_F1 );
  1187. }
  1188. else
  1189. {
  1190. if ( !readyToLoadPreset( hwnd, 0 ) ) return 0;
  1191. if ( LoadPreset( wParam - VK_F1 ) ) st = WASABI_API_LNGSTRING_BUF( IDS_LOADED_FROM, stBuf, 48 );
  1192. else st = WASABI_API_LNGSTRING_BUF( IDS_ERROR_LOADING_FROM, stBuf, 48 );
  1193. }
  1194. wsprintf( s, "%s F%d", st, wParam - VK_F1 + 1 );
  1195. DDraw_SetStatusText( s );
  1196. }
  1197. else if ( wParam >= '0' && wParam <= '9' )
  1198. {
  1199. int n = 0;
  1200. char s[ 128 ], *st, stBuf[ 48 ];
  1201. if ( GetAsyncKeyState( VK_SHIFT ) & ( 1 << 15 ) )
  1202. n = 10;
  1203. if ( GetAsyncKeyState( VK_CONTROL ) & ( 1 << 15 ) )
  1204. {
  1205. st = WASABI_API_LNGSTRING_BUF( IDS_SAVED_TO, stBuf, 48 );
  1206. WritePreset( wParam - '0' + 12 + n );
  1207. }
  1208. else
  1209. {
  1210. if ( !readyToLoadPreset( hwnd, 0 ) ) return 0;
  1211. if ( LoadPreset( wParam - '0' + 12 + n ) ) st = WASABI_API_LNGSTRING_BUF( IDS_LOADED_FROM, stBuf, 48 );
  1212. else st = WASABI_API_LNGSTRING_BUF( IDS_ERROR_LOADING_FROM, stBuf, 48 );
  1213. }
  1214. wsprintf( s, "%s %s%d", st, n ? WASABI_API_LNGSTRING( IDS_SHIFT_ ) : "", wParam - '0' );
  1215. DDraw_SetStatusText( s );
  1216. }
  1217. else
  1218. {
  1219. if ( wParam == 0x4B && DDraw_IsFullScreen() )
  1220. {
  1221. if ( !cfg_fs_use_overlay ) Wnd_GoWindowed( hwnd );
  1222. }
  1223. else PostMessage( hwnd_WinampParent, message, wParam, lParam );
  1224. }
  1225. return 0;
  1226. case WM_TIMER:
  1227. #ifndef WA2_EMBED
  1228. if ( wParam == 66 )
  1229. {
  1230. KillTimer( hwnd, 66 );
  1231. SetWindowPos( hwnd, 0, 0, 0, cfg_w, cfg_h, SWP_NOACTIVATE | SWP_NOZORDER );
  1232. }
  1233. #endif
  1234. if ( wParam == 88 )
  1235. {
  1236. KillTimer( hwnd, 88 );
  1237. if ( cfg_cfgwnd_open )
  1238. {
  1239. ShowWindow( g_hwndDlg, SW_SHOWNA );
  1240. UpdateWindow( g_hwndDlg );
  1241. CfgWnd_RePopIfNeeded();
  1242. }
  1243. if ( need_redock && g_hwndDlg )
  1244. {
  1245. need_redock = 0;
  1246. toggleWharfAmpDock( hwnd );
  1247. }
  1248. }
  1249. if ( wParam == 32 )
  1250. {
  1251. DWORD a;
  1252. #ifndef REAPLAY_PLUGIN
  1253. if ( SendMessageTimeout( hwnd_WinampParent, WM_USER, (WPARAM) 0, 201, SMTO_BLOCK, 1000, &a ) && a )
  1254. {
  1255. if ( strcmp( g_skin_name, (char *) a ) )
  1256. {
  1257. lstrcpyn( g_skin_name, (char *) a, sizeof( g_skin_name ) );
  1258. PostMessage( hwnd, WM_DISPLAYCHANGE, 0, 0 );
  1259. }
  1260. }
  1261. #endif
  1262. if ( g_rnd_cnt >= 0 && g_rnd_cnt++ >= max( cfg_fs_rnd_time, 1 ) )
  1263. {
  1264. g_rnd_cnt = 0;
  1265. if ( ( !IsWindowVisible( g_hwndDlg ) || DDraw_IsFullScreen() ) && cfg_fs_rnd )
  1266. goto do_random;
  1267. }
  1268. }
  1269. if ( wParam == 30 )
  1270. {
  1271. KillTimer( hwnd, 30 );
  1272. if ( !DDraw_IsFullScreen() && !inWharf )
  1273. {
  1274. InvalidateRect( hwnd, NULL, FALSE );
  1275. int tm = ( GetWindowLong( g_mod->hwndParent, GWL_EXSTYLE ) & WS_EX_TOPMOST ) == WS_EX_TOPMOST;
  1276. SetWindowPos( hwnd, tm ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
  1277. RECT r;
  1278. GetClientRect_adj( hwnd, &r );
  1279. DDraw_Resize( r.right - r.left, r.bottom - r.top, cfg_fs_d & 2 );
  1280. }
  1281. }
  1282. #ifndef WA2_EMBED
  1283. if ( wParam == 29 )
  1284. {
  1285. if ( !IsIconic( hwnd_WinampParent ) )
  1286. {
  1287. KillTimer( hwnd, 29 );
  1288. g_mod->Quit( g_mod );
  1289. g_minimized = 0;
  1290. g_fakeinit = 1;
  1291. g_mod->Init( g_mod );
  1292. g_fakeinit = 0;
  1293. SetActiveWindow( g_mod->hwndParent );
  1294. }
  1295. }
  1296. #endif
  1297. return 0;
  1298. case WM_DROPFILES:
  1299. {
  1300. char temp[ MAX_PATH ];
  1301. HDROP hdrop = (HDROP) wParam;
  1302. DragQueryFile( hdrop, 0, temp, sizeof( temp ) );
  1303. if ( readyToLoadPreset( hwnd, 0 ) )
  1304. {
  1305. if ( !stricmp( extension( temp ), "avs" ) )
  1306. {
  1307. if ( g_render_transition->LoadPreset( temp, 1 ) != 2 )
  1308. lstrcpyn( last_preset, temp, sizeof( last_preset ) );
  1309. }
  1310. }
  1311. DragFinish( hdrop );
  1312. }
  1313. return 0;
  1314. case WM_DISPLAYCHANGE:
  1315. #ifndef WA2_EMBED
  1316. SelectObject( hFrameDC, hFrameBitmap_old );
  1317. DeleteObject( hFrameBitmap );
  1318. hFrameBitmap = NULL;
  1319. {
  1320. char buf[ MAX_PATH ];
  1321. if ( SendMessage( hwnd_WinampParent, WM_USER, (WPARAM) buf, 201 ) )
  1322. {
  1323. strcat( buf, "\\avs.bmp" );
  1324. hFrameBitmap = (HBITMAP) LoadImage( g_hInstance, buf, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
  1325. }
  1326. if ( !hFrameBitmap )
  1327. hFrameBitmap = (HBITMAP) LoadImage( g_hInstance, MAKEINTRESOURCE( IDB_BITMAP1 ), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
  1328. }
  1329. hFrameBitmap_old = (HBITMAP) SelectObject( hFrameDC, hFrameBitmap );
  1330. #endif
  1331. InvalidateRect( hwnd, NULL, FALSE );
  1332. return 0;
  1333. case WM_CREATE:
  1334. g_hwnd = hwnd;
  1335. if ( DDraw_Init() )
  1336. {
  1337. return 1;
  1338. }
  1339. #ifndef WA2_EMBED
  1340. {
  1341. char buf[ MAX_PATH ];
  1342. int a;
  1343. if ( ( a = SendMessage( hwnd_WinampParent, WM_USER, (WPARAM) buf, 201 ) ) )
  1344. {
  1345. lstrcpyn( g_skin_name, (char *) a, sizeof( g_skin_name ) );
  1346. strcat( buf, "\\avs.bmp" );
  1347. hFrameBitmap = (HBITMAP) LoadImage( g_hInstance, buf, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
  1348. }
  1349. if ( !hFrameBitmap )
  1350. hFrameBitmap = (HBITMAP) LoadImage( g_hInstance, MAKEINTRESOURCE( IDB_BITMAP1 ), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
  1351. }
  1352. hFrameDC = (HDC) CreateCompatibleDC( NULL );
  1353. hFrameBitmap_old = (HBITMAP) SelectObject( hFrameDC, hFrameBitmap );
  1354. #endif
  1355. //FG> This totally fucks up a child layered window painting in wa3, i'm not even sure that's a good thing for wa2... basically the child window gets excluded from the layered update and ends up updating behind the layer, on top of the desktop
  1356. #ifndef WA2_EMBED
  1357. SetWindowLong( hwnd, GWL_STYLE, 0 );
  1358. SetWindowPos( hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_DRAWFRAME | SWP_NOACTIVATE );
  1359. #endif
  1360. SetTimer( hwnd, 32, 1000, NULL );
  1361. return 0;
  1362. #ifndef WA2_EMBED
  1363. case WM_NCHITTEST:
  1364. {
  1365. int x = GET_X_LPARAM( lParam );
  1366. int y = GET_Y_LPARAM( lParam );
  1367. RECT r;
  1368. GetWindowRect( hwnd, &r );
  1369. if ( inWharf )
  1370. return HTCLIENT;
  1371. if ( DDraw_IsFullScreen() || ( x > r.right - 12 && x < r.right - 3 && y > r.top + 3 && y < r.top + 13 ) )
  1372. return HTCLIENT;
  1373. if ( x < r.left + 6 && y > r.bottom - 6 ) return HTBOTTOMLEFT;
  1374. if ( x > r.right - 6 && y > r.bottom - 6 ) return HTBOTTOMRIGHT;
  1375. if ( x < r.left + 6 && y < r.top + 6 ) return HTTOPLEFT;
  1376. if ( x > r.right - 6 && y < r.top + 6 ) return HTTOPRIGHT;
  1377. if ( y < r.top + 6 ) return HTTOP;
  1378. if ( y > r.bottom - 6 ) return HTBOTTOM;
  1379. if ( x < r.left + 6 ) return HTLEFT;
  1380. if ( x > r.right - 6 ) return HTRIGHT;
  1381. if ( y < r.top + 15 ) return HTCAPTION;
  1382. }
  1383. return HTCLIENT;
  1384. #endif
  1385. case WM_CLOSE:
  1386. #ifndef WA2_EMBED
  1387. g_in_destroy = 1;
  1388. DestroyWindow( hwnd );
  1389. #else
  1390. g_in_destroy = 1;
  1391. SetForegroundWindow( g_mod->hwndParent );
  1392. DestroyWindow( myWindowState.me );
  1393. #endif
  1394. return 0;
  1395. case WM_DESTROY:
  1396. #ifndef WA2_EMBED
  1397. SelectObject( hFrameDC, hFrameBitmap_old );
  1398. DeleteObject( hFrameDC );
  1399. DeleteObject( hFrameBitmap );
  1400. #endif
  1401. g_ThreadQuit = 1;
  1402. if ( !g_minimized )
  1403. {
  1404. PostQuitMessage( 0 );
  1405. }
  1406. return 0;
  1407. case WM_MOVE:
  1408. if ( !DDraw_IsFullScreen() && !inWharf )
  1409. {
  1410. #ifndef WA2_EMBED
  1411. int w;
  1412. RECT r;
  1413. RECT r2;
  1414. int xPos, yPos, f = 0;
  1415. xPos = (int) (short) LOWORD( lParam ); // horizontal position
  1416. yPos = (int) (short) HIWORD( lParam ); // vertical position
  1417. GetClientRect( hwnd, &r2 );
  1418. for ( w = 0; w < 5; w++ )
  1419. {
  1420. HWND hw;
  1421. if ( w == 0 )
  1422. {
  1423. RECT r2;
  1424. GetWindowRect( hwnd, &r2 );
  1425. my_getViewport( &r, &r2 );
  1426. }
  1427. else if ( w == 1 && IsWindowVisible( hwnd_WinampParent ) )
  1428. GetWindowRect( hwnd_WinampParent, &r );
  1429. else if ( w == 2 && ( hw = FindWindowEx( NULL, NULL, "Winamp EQ", NULL ) )
  1430. && IsWindowVisible( hw ) )
  1431. GetWindowRect( hw, &r );
  1432. else if ( w == 3 && ( hw = FindWindowEx( NULL, NULL, "Winamp PE", NULL ) )
  1433. && IsWindowVisible( hw ) )
  1434. GetWindowRect( hw, &r );
  1435. else if ( w == 4 && ( hw = FindWindowEx( NULL, NULL, "Winamp MB", NULL ) )
  1436. && IsWindowVisible( hw ) )
  1437. GetWindowRect( hw, &r );
  1438. else continue;
  1439. #define intersect(x1,x2,y1,y2) \
  1440. (((x1)>(y1)&&(x1)<(y2))||((x2)>(y1)&&(x2)<(y2))||((y1)>(x1)&&(y1)<(x2))||((y2)>(x1)&&(y2)<(x2)))
  1441. if ( xPos > r.left - 10 && xPos < r.left + 10 && intersect( yPos, yPos + r2.bottom, r.top, r.bottom ) )
  1442. {
  1443. xPos = r.left;
  1444. f++;
  1445. }
  1446. if ( yPos > r.top - 10 && yPos < r.top + 10 && intersect( xPos, xPos + r2.right, r.left, r.right ) )
  1447. {
  1448. yPos = r.top;
  1449. f++;
  1450. }
  1451. if ( xPos + r2.right > r.right - 10 && xPos + r2.right < r.right + 10 && intersect( yPos, yPos + r2.bottom, r.top, r.bottom ) )
  1452. {
  1453. xPos = r.right - r2.right;
  1454. f++;
  1455. }
  1456. if ( yPos + r2.bottom > r.bottom - 10 && yPos + r2.bottom < r.bottom + 10 && intersect( xPos, xPos + r2.right, r.left, r.right ) )
  1457. {
  1458. yPos = r.bottom - r2.bottom;
  1459. f++;
  1460. }
  1461. if ( xPos + r2.right > r.left - 10 && xPos + r2.right < r.left + 10 && intersect( yPos, yPos + r2.bottom, r.top, r.bottom ) )
  1462. {
  1463. xPos = r.left - r2.right;
  1464. f++;
  1465. }
  1466. if ( yPos + r2.bottom > r.top - 10 && yPos + r2.bottom < r.top + 10 && intersect( xPos, xPos + r2.right, r.left, r.right ) )
  1467. {
  1468. yPos = r.top - r2.bottom;
  1469. f++;
  1470. }
  1471. if ( xPos > r.right - 10 && xPos < r.right + 10 && intersect( yPos, yPos + r2.bottom, r.top, r.bottom ) )
  1472. {
  1473. xPos = r.right;
  1474. f++;
  1475. }
  1476. if ( yPos > r.bottom - 10 && yPos < r.bottom + 10 && intersect( xPos, xPos + r2.right, r.left, r.right ) )
  1477. {
  1478. yPos = r.bottom;
  1479. f++;
  1480. }
  1481. }
  1482. if ( f )
  1483. {
  1484. SetWindowPos( hwnd, NULL, xPos, yPos, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
  1485. }
  1486. {
  1487. RECT r;
  1488. GetWindowRect( hwnd, &r );
  1489. cfg_x = r.left;
  1490. cfg_y = r.top;
  1491. cfg_w = r.right - r.left;
  1492. cfg_h = r.bottom - r.top;
  1493. }
  1494. #endif
  1495. }
  1496. return 0;
  1497. case WM_GETMINMAXINFO:
  1498. {
  1499. LPMINMAXINFO mmi = (LPMINMAXINFO) lParam;
  1500. mmi->ptMinTrackSize.x = 80;
  1501. mmi->ptMinTrackSize.y = 40;
  1502. }
  1503. return 0;
  1504. case WM_SETCURSOR:
  1505. if ( DDraw_IsFullScreen() )
  1506. {
  1507. SetCursor( NULL );
  1508. return TRUE;
  1509. }
  1510. break;
  1511. case WM_SIZE:
  1512. if ( wParam != SIZE_MINIMIZED )
  1513. {
  1514. if ( !DDraw_IsFullScreen() )
  1515. {
  1516. if ( !inWharf )
  1517. {
  1518. #ifndef WA2_EMBED
  1519. RECT r;
  1520. GetWindowRect( hwnd, &r );
  1521. cfg_x = r.left;
  1522. cfg_y = r.top;
  1523. cfg_w = r.right - r.left;
  1524. cfg_h = r.bottom - r.top;
  1525. #endif
  1526. DDraw_BeginResize();
  1527. KillTimer( hwnd, 30 );
  1528. SetTimer( hwnd, 30, 33, NULL );
  1529. }
  1530. }
  1531. }
  1532. break;
  1533. case WM_WINDOWPOSCHANGING:
  1534. {
  1535. LPWINDOWPOS lpwp = (LPWINDOWPOS) lParam;
  1536. if ( cfg_dont_min_avs && !g_in_destroy && lpwp->flags & SWP_HIDEWINDOW && !g_minimized && !inWharf )
  1537. {
  1538. #ifndef WA2_EMBED
  1539. g_minimized = 1;
  1540. g_mod->Quit( g_mod );
  1541. g_fakeinit = 1;
  1542. g_mod->Init( g_mod );
  1543. g_fakeinit = 0;
  1544. if ( ( GetWindowLong( g_mod->hwndParent, GWL_EXSTYLE ) & WS_EX_TOPMOST ) == WS_EX_TOPMOST )
  1545. SetWindowPos( g_hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
  1546. SetTimer( g_hwnd, 29, 500, NULL );
  1547. #endif
  1548. }
  1549. }
  1550. return 0;
  1551. case WM_PAINT:
  1552. if ( !DDraw_IsFullScreen() )
  1553. {
  1554. PAINTSTRUCT ps;
  1555. HDC hdc = BeginPaint( hwnd, &ps );
  1556. #ifndef WA2_EMBED
  1557. RECT r;
  1558. HDC tempdc = CreateCompatibleDC( hdc );
  1559. GetClientRect( hwnd, &r );
  1560. HBITMAP oldbm, tempbm = CreateCompatibleBitmap( hdc, 7, r.bottom - 20 );
  1561. oldbm = (HBITMAP) SelectObject( tempdc, tempbm );
  1562. if ( !inWharf )
  1563. { // draw window frame
  1564. SetStretchBltMode( hdc, COLORONCOLOR );
  1565. SetStretchBltMode( tempdc, COLORONCOLOR );
  1566. BitBlt( hdc, 0, 0, 50, 15, hFrameDC, 15, 0, SRCCOPY ); // top left
  1567. StretchBlt( hdc, 50, 0, r.right - 50 - 16, 15, hFrameDC, 66, 0, 14, 15, SRCCOPY ); // top middle
  1568. BitBlt( hdc, r.right - 16, 0, 16, 15, hFrameDC, 81, 0, SRCCOPY ); // top right
  1569. StretchBlt( tempdc, 0, 0, 7, r.bottom - 15 - 5, hFrameDC, 0, 16, 7, 172, SRCCOPY ); // left middle
  1570. BitBlt( hdc, 0, 15, 7, r.bottom - 15 - 5, tempdc, 0, 0, SRCCOPY );
  1571. StretchBlt( tempdc, 0, 0, 6, r.bottom - 15 - 5, hFrameDC, 8, 16, 6, 172, SRCCOPY ); // right middle
  1572. BitBlt( hdc, r.right - 6, 15, 6, r.bottom - 15 - 5, tempdc, 0, 0, SRCCOPY );
  1573. BitBlt( hdc, 0, r.bottom - 5, 50, 15, hFrameDC, 15, 16, SRCCOPY ); // bottom left
  1574. StretchBlt( hdc, 50, r.bottom - 5, r.right - 50 - 16, 5, hFrameDC, 66, 16, 14, 5, SRCCOPY ); // bottom middle
  1575. BitBlt( hdc, r.right - 16, r.bottom - 5, 16, 5, hFrameDC, 81, 16, SRCCOPY ); // bottom right
  1576. }
  1577. SelectObject( tempdc, oldbm );
  1578. DeleteObject( tempbm );
  1579. DeleteObject( tempdc );
  1580. #endif
  1581. EndPaint( hwnd, &ps );
  1582. return 0;
  1583. }
  1584. break;
  1585. #ifdef WA2_EMBED
  1586. case WM_COMMAND:
  1587. {
  1588. int id = LOWORD( wParam );
  1589. switch ( id )
  1590. {
  1591. case ID_VIS_NEXT: next_preset( hwnd ); break;
  1592. case ID_VIS_PREV: previous_preset( hwnd ); break;
  1593. case ID_VIS_RANDOM:
  1594. {
  1595. int v = HIWORD( wParam ) ? 1 : 0;
  1596. if ( wParam >> 16 == 0xFFFF )
  1597. {
  1598. SendMessage( g_mod->hwndParent, WM_WA_IPC, cfg_fs_rnd, IPC_CB_VISRANDOM );
  1599. break;
  1600. }
  1601. cfg_fs_rnd = v;
  1602. if ( cfg_fs_rnd ) random_preset( hwnd );
  1603. DDraw_SetStatusText( WASABI_API_LNGSTRING( cfg_fs_rnd ? IDS_RANDOM_PRESETS_ON : IDS_RANDOM_PRESETS_OFF ) );
  1604. break;
  1605. }
  1606. case ID_VIS_FS: Wnd_GoFullScreen( hwnd ); break;
  1607. case ID_VIS_CFG: SendMessage( hwnd, WM_USER + 33, 0, 0 ); break;
  1608. case ID_VIS_MENU: DoPopupMenu(); break;
  1609. }
  1610. break;
  1611. }
  1612. #endif
  1613. }
  1614. return DefWindowProc( hwnd, message, wParam, lParam );
  1615. }