Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

663 lines
18 KiB

  1. //**************************************************************************
  2. // wusercli.c :
  3. // Contains all functions that execute USER32 client code on 16bitside.
  4. // Most of these functions don't exist on x86 builds. So any changes
  5. // to these files must be reflected in wow16\user\usercli.asm
  6. //
  7. // - nanduri
  8. //**************************************************************************
  9. #include "precomp.h"
  10. #pragma hdrstop
  11. MODNAME(wusercli.c);
  12. //**************************************************************************
  13. // WU32ClientToScreen -
  14. //
  15. //**************************************************************************
  16. ULONG FASTCALL WU32ClientToScreen(PVDMFRAME pFrame)
  17. {
  18. POINT t2;
  19. register PCLIENTTOSCREEN16 parg16;
  20. GETARGPTR(pFrame, sizeof(CLIENTTOSCREEN16), parg16);
  21. GETPOINT16(parg16->f2, &t2);
  22. ClientToScreen( HWND32(parg16->f1), &t2 );
  23. PUTPOINT16(parg16->f2, &t2);
  24. FREEARGPTR(parg16);
  25. RETURN(0);
  26. }
  27. //**************************************************************************
  28. // WU32GetClientRect -
  29. //
  30. //**************************************************************************
  31. ULONG FASTCALL WU32GetClientRect(PVDMFRAME pFrame)
  32. {
  33. RECT t2;
  34. register PGETCLIENTRECT16 parg16;
  35. GETARGPTR(pFrame, sizeof(GETCLIENTRECT16), parg16);
  36. /*
  37. * Home Design Gold 2.0
  38. *
  39. * If the call fails, don't overwrite the passed-in
  40. * rect.
  41. */
  42. if (GetClientRect(HWND32(parg16->hwnd), &t2)) {
  43. PUTRECT16(parg16->vpRect, &t2);
  44. }
  45. FREEARGPTR(parg16);
  46. RETURN(0);
  47. }
  48. //**************************************************************************
  49. // WU32GetCursorPos -
  50. //
  51. //**************************************************************************
  52. ULONG FASTCALL WU32GetCursorPos(PVDMFRAME pFrame)
  53. {
  54. POINT t1;
  55. register PGETCURSORPOS16 parg16;
  56. GETARGPTR(pFrame, sizeof(GETCURSORPOS16), parg16);
  57. GetCursorPos( &t1 );
  58. PUTPOINT16(parg16->f1, &t1);
  59. FREEARGPTR(parg16);
  60. RETURN(0);
  61. }
  62. //**************************************************************************
  63. // WU32GetDesktopWindow -
  64. //
  65. //**************************************************************************
  66. ULONG FASTCALL WU32GetDesktopWindow(PVDMFRAME pFrame)
  67. {
  68. ULONG ul;
  69. UNREFERENCED_PARAMETER(pFrame);
  70. ul = GETHWND16(GetDesktopWindow());
  71. RETURN(ul);
  72. }
  73. //**************************************************************************
  74. // WU32GetDlgItem -
  75. //
  76. //**************************************************************************
  77. ULONG FASTCALL WU32GetDlgItem(PVDMFRAME pFrame)
  78. {
  79. ULONG ul;
  80. register PGETDLGITEM16 parg16;
  81. //
  82. // pass the child ID zero-extended. this ID is the hMenu param to
  83. // CreateWindow, so USER gets this ID with hiword = 0.
  84. // Visual Basic relies on this.
  85. //
  86. GETARGPTR(pFrame, sizeof(GETDLGITEM16), parg16);
  87. ul = GETHWND16(GetDlgItem(HWND32(parg16->f1),WORD32(parg16->f2)));
  88. if (CURRENTPTD()->dwWOWCompatFlags & WOWCF_DBASEHANDLEBUG) {
  89. ((PTDB)SEGPTR(pFrame->wTDB,0))->TDB_CompatHandle = (USHORT) ul;
  90. }
  91. FREEARGPTR(parg16);
  92. RETURN(ul);
  93. }
  94. //**************************************************************************
  95. // WU32GetMenu -
  96. //
  97. //**************************************************************************
  98. ULONG FASTCALL WU32GetMenu(PVDMFRAME pFrame)
  99. {
  100. ULONG ul;
  101. register PGETMENU16 parg16;
  102. GETARGPTR(pFrame, sizeof(GETMENU16), parg16);
  103. ul = GETHMENU16(GetMenu(HWND32(parg16->f1)));
  104. FREEARGPTR(parg16);
  105. RETURN(ul);
  106. }
  107. //**************************************************************************
  108. // WU32GetMenuItemCount -
  109. //
  110. //**************************************************************************
  111. ULONG FASTCALL WU32GetMenuItemCount(PVDMFRAME pFrame)
  112. {
  113. ULONG ul;
  114. register PGETMENUITEMCOUNT16 parg16;
  115. GETARGPTR(pFrame, sizeof(GETMENUITEMCOUNT16), parg16);
  116. ul = GETWORD16(GetMenuItemCount( HMENU32(parg16->f1) ));
  117. FREEARGPTR(parg16);
  118. RETURN(ul);
  119. }
  120. //**************************************************************************
  121. // WU32GetSysColor -
  122. //
  123. //**************************************************************************
  124. ULONG FASTCALL WU32GetSysColor(PVDMFRAME pFrame)
  125. {
  126. ULONG ul;
  127. register PGETSYSCOLOR16 parg16;
  128. GETARGPTR(pFrame, sizeof(GETSYSCOLOR16), parg16);
  129. ul = GETDWORD16(GetSysColor( INT32(parg16->f1) ));
  130. FREEARGPTR(parg16);
  131. RETURN(ul);
  132. }
  133. //**************************************************************************
  134. // WU32GetSystemMetrics -
  135. //
  136. //**************************************************************************
  137. ULONG FASTCALL WU32GetSystemMetrics(PVDMFRAME pFrame)
  138. {
  139. ULONG ul;
  140. register PGETSYSTEMMETRICS16 parg16;
  141. int sm;
  142. GETARGPTR(pFrame, sizeof(GETSYSTEMMETRICS16), parg16);
  143. sm = INT32(parg16->f1);
  144. ul = GETINT16(GetSystemMetrics(sm) );
  145. FREEARGPTR(parg16);
  146. RETURN(ul);
  147. }
  148. //**************************************************************************
  149. // WU32GetTopWindow -
  150. //
  151. //**************************************************************************
  152. ULONG FASTCALL WU32GetTopWindow(PVDMFRAME pFrame)
  153. {
  154. ULONG ul;
  155. register PGETTOPWINDOW16 parg16;
  156. GETARGPTR(pFrame, sizeof(GETTOPWINDOW16), parg16);
  157. ul = GETHWND16(GetTopWindow(HWND32(parg16->f1)));
  158. FREEARGPTR(parg16);
  159. RETURN(ul);
  160. }
  161. char szTrayWnd[] = "Shell_TrayWnd";
  162. //**************************************************************************
  163. // WU32GetWindowRect -
  164. //
  165. //**************************************************************************
  166. ULONG FASTCALL WU32GetWindowRect(PVDMFRAME pFrame)
  167. {
  168. RECT t2;
  169. register PGETWINDOWRECT16 parg16;
  170. GETARGPTR(pFrame, sizeof(GETWINDOWRECT16), parg16);
  171. /*
  172. * Home Design Gold 2.0
  173. *
  174. * If the call fails, don't overwrite the passed-in
  175. * rect.
  176. */
  177. if (GetWindowRect(HWND32(parg16->f1), &t2)) {
  178. // Sierra on-line setup hack (expects tray rect to be Classic style)
  179. // See bug #425058
  180. // Unfortunately we can't cache the tray hwnd because if explorer dies
  181. // while the VDM is still running, explorer will get a new hwnd when it
  182. // is restarted that won't match our cached one.
  183. // IMHO this could be a general fix and not under an app compat flag
  184. // in BlackComb.
  185. if(CURRENTPTD()->dwWOWCompatFlags2 & WOWCF2_FIXLUNATRAYRECT) {
  186. char szClassName[20];
  187. if(GetClassName((HWND)parg16->f1,
  188. szClassName,
  189. sizeof(szClassName))) {
  190. if(!lstrcmp(szClassName, szTrayWnd)) {
  191. // these will only be 0 for the Luna theme
  192. if((t2.left == 0) || (t2.top == 0)) {
  193. // Find tray position on desktop. Leave the border that
  194. // is actually in the desktop alone so that the apps can
  195. // calculate their windows accurately.
  196. /*******************************************************
  197. * Note: IMHO the code that is commented out below could
  198. * be uncommented for BlackComb as it more acurr-
  199. * ately resembles what would be returned in
  200. * Classic view. Instead, since we are late in the
  201. * cycle for Whistler (RC2), we adjust the bare
  202. * minimum required to fix the known Sierra cases.
  203. *
  204. * // if tray is at the BOTTOM of the desktop window
  205. * if(t2.top > 0) {
  206. * t2.left--;
  207. * t2.right++;
  208. * t2.bottom++;
  209. *
  210. * // else if the tray is at the RIGHT of desktop window
  211. * } else if(t2.left > 0) {
  212. * t2.top--;
  213. * t2.right++;
  214. * t2.bottom++;
  215. *
  216. * // else if the tray is at the TOP of desktop window
  217. * } else if(t2.right > t2.bottom) {
  218. * t2.top--;
  219. * t2.left--;
  220. * t2.right++;
  221. *
  222. * // else the tray must be at the LEFT of desktop window
  223. * } else {
  224. * t2.top--;
  225. * t2.left--;
  226. * t2.bottom++;
  227. * }
  228. *******************************************************/
  229. // if tray is at the BOTTOM of the desktop window
  230. if(t2.top > 0)
  231. t2.bottom++;
  232. // else if the tray is at the TOP of the desktop window
  233. else if(t2.right > t2.bottom)
  234. t2.top--;
  235. }
  236. }
  237. }
  238. }
  239. PUTRECT16(parg16->f2, &t2);
  240. }
  241. FREEARGPTR(parg16);
  242. RETURN(0);
  243. }
  244. //**************************************************************************
  245. // WU32IsWindow -
  246. //
  247. //**************************************************************************
  248. ULONG FASTCALL WU32IsWindow(PVDMFRAME pFrame)
  249. {
  250. ULONG ul;
  251. HWND hWnd;
  252. register PISWINDOW16 parg16;
  253. GETARGPTR(pFrame, sizeof(ISWINDOW16), parg16);
  254. hWnd = HWND32(parg16->f1);
  255. ul = GETBOOL16(IsWindow(hWnd));
  256. // For apps that get burned by recycled handles -- ie. the old handle they
  257. // had has been destroyed & realloc'd to a different window -- not the one
  258. // they were expecting. This needs to be handled on an app by app basis.
  259. if(ul && (CURRENTPTD()->dwWOWCompatFlagsEx & WOWCFEX_FAKENOTAWINDOW)) {
  260. // NetScape 4.0x install (the bug is in InstallShield)
  261. // Test the offset portion of the 16:16 return address to this call.
  262. // Bug #132616 et al
  263. switch(pFrame->vpCSIP & 0x0000FFFF) {
  264. case 0x4880: // (InstallShield 3.00.104.0)
  265. case 0x44E4: // (InstallShield 3.00.091.0)
  266. {
  267. ULONG result;
  268. LPVOID lp;
  269. // we only want this to fail for calls during Int.Shld cleanup
  270. // we probably shouldn't fail it if was created by a WOW process
  271. result = GetWindowLong(hWnd, GWL_WNDPROC);
  272. if(!IsWOWProc(result)) {
  273. goto IW_HACK;
  274. }
  275. // extra sanity check: InstallSheild calls GetWindowLong & uses
  276. // the returned value as a 16:16 ptr
  277. result = GetWindowLong(hWnd, DWL_MSGRESULT);
  278. GETVDMPTR(result, sizeof(VPVOID), lp);
  279. if(!lp) {
  280. goto IW_HACK;
  281. }
  282. break;
  283. }
  284. }
  285. }
  286. FREEARGPTR(parg16);
  287. RETURN(ul);
  288. IW_HACK:
  289. WOW32WARNMSG((0),"WOW32::IsWindow hack hit!\n");
  290. RETURN(0);
  291. }
  292. //**************************************************************************
  293. // WU32ScreenToClient -
  294. //
  295. //**************************************************************************
  296. ULONG FASTCALL WU32ScreenToClient(PVDMFRAME pFrame)
  297. {
  298. POINT t2;
  299. register PSCREENTOCLIENT16 parg16;
  300. GETARGPTR(pFrame, sizeof(SCREENTOCLIENT16), parg16);
  301. GETPOINT16(parg16->f2, &t2);
  302. ScreenToClient( HWND32(parg16->f1), &t2 );
  303. PUTPOINT16(parg16->f2, &t2);
  304. FREEARGPTR(parg16);
  305. RETURN(0);
  306. }
  307. //**************************************************************************
  308. // WU32IsChild -
  309. //
  310. //**************************************************************************
  311. ULONG FASTCALL WU32IsChild(PVDMFRAME pFrame)
  312. {
  313. ULONG ul;
  314. register PISCHILD16 parg16;
  315. GETARGPTR(pFrame, sizeof(ISCHILD16), parg16);
  316. ul = GETBOOL16(IsChild( HWND32(parg16->f1), HWND32(parg16->f2) ));
  317. FREEARGPTR(parg16);
  318. RETURN(ul);
  319. }
  320. //**************************************************************************
  321. // WU32IsIconic -
  322. //
  323. //**************************************************************************
  324. ULONG FASTCALL WU32IsIconic(PVDMFRAME pFrame)
  325. {
  326. ULONG ul;
  327. register PISICONIC16 parg16;
  328. GETARGPTR(pFrame, sizeof(ISICONIC16), parg16);
  329. ul = GETBOOL16(IsIconic( HWND32(parg16->f1) ));
  330. FREEARGPTR(parg16);
  331. RETURN(ul);
  332. }
  333. //**************************************************************************
  334. // WU32IsWindowEnabled -
  335. //
  336. //**************************************************************************
  337. ULONG FASTCALL WU32IsWindowEnabled(PVDMFRAME pFrame)
  338. {
  339. ULONG ul;
  340. register PISWINDOWENABLED16 parg16;
  341. GETARGPTR(pFrame, sizeof(ISWINDOWENABLED16), parg16);
  342. ul = GETBOOL16(IsWindowEnabled( HWND32(parg16->f1) ));
  343. FREEARGPTR(parg16);
  344. RETURN(ul);
  345. }
  346. //**************************************************************************
  347. // WU32IsWindowVisible -
  348. //
  349. //**************************************************************************
  350. ULONG FASTCALL WU32IsWindowVisible(PVDMFRAME pFrame)
  351. {
  352. ULONG ul;
  353. register PISWINDOWVISIBLE16 parg16;
  354. GETARGPTR(pFrame, sizeof(ISWINDOWVISIBLE16), parg16);
  355. ul = GETBOOL16(IsWindowVisible( HWND32(parg16->f1) ));
  356. FREEARGPTR(parg16);
  357. RETURN(ul);
  358. }
  359. //**************************************************************************
  360. // WU32IsZoomed -
  361. //
  362. //**************************************************************************
  363. ULONG FASTCALL WU32IsZoomed(PVDMFRAME pFrame)
  364. {
  365. ULONG ul;
  366. register PISZOOMED16 parg16;
  367. GETARGPTR(pFrame, sizeof(ISZOOMED16), parg16);
  368. ul = GETBOOL16(IsZoomed( HWND32(parg16->f1) ));
  369. FREEARGPTR(parg16);
  370. RETURN(ul);
  371. }
  372. //**************************************************************************
  373. // WU32GetTickCount -
  374. //
  375. //**************************************************************************
  376. ULONG FASTCALL WU32GetTickCount(PVDMFRAME pFrame)
  377. {
  378. ULONG ul;
  379. UNREFERENCED_PARAMETER(pFrame);
  380. ul = (ULONG)GetTickCount();
  381. if (CURRENTPTD()->dwWOWCompatFlags & WOWCF_GRAINYTICS) {
  382. //
  383. // round down to the nearest 55ms this is for RelayGold, which
  384. // spins calling this API until consecutive calls return a delta
  385. // greater than 52.
  386. //
  387. ul = ul - (ul % 55);
  388. }
  389. RETURN(ul);
  390. }
  391. //**************************************************************************
  392. // On I386 all these functions her handled on clientside. But conditionally
  393. // they may endup doing the actual work via these thunks.
  394. //
  395. // So any changes here like 'win31 compatiblity code' may have to be added
  396. // in mvdm\wow16\user\usercli.asm too.
  397. //
  398. // - nanduri
  399. //**************************************************************************
  400. //**************************************************************************
  401. // WU32DefHookProc -
  402. //
  403. //**************************************************************************
  404. ULONG FASTCALL WU32DefHookProc(PVDMFRAME pFrame)
  405. {
  406. ULONG ul = 0;
  407. register PDEFHOOKPROC16 parg16;
  408. HOOKSTATEDATA HkData;
  409. ULONG hHook16;
  410. INT iHookCode;
  411. INT nCode;
  412. LONG wParam;
  413. LONG lParam;
  414. LPINT lpiFunc;
  415. GETARGPTR(pFrame, sizeof(DEFHOOKPROC16), parg16);
  416. nCode = INT32(parg16->f1);
  417. wParam = WORD32(parg16->f2);
  418. lParam = DWORD32(parg16->f3);
  419. GETMISCPTR(parg16->f4, lpiFunc);
  420. hHook16 = FETCHDWORD(*lpiFunc);
  421. FREEVDMPTR(lpiFunc);
  422. if (ISVALIDHHOOK(hHook16)) {
  423. iHookCode = GETHHOOKINDEX(hHook16);
  424. HkData.iIndex = (BYTE)iHookCode;
  425. if ( W32GetHookStateData( &HkData ) ) {
  426. ul = (ULONG)WU32StdDefHookProc(nCode, wParam, lParam, iHookCode);
  427. }
  428. }
  429. FREEARGPTR(parg16);
  430. RETURN(ul);
  431. }
  432. //**************************************************************************
  433. // WU32GetKeyState -
  434. //
  435. //**************************************************************************
  436. ULONG FASTCALL WU32GetKeyState(PVDMFRAME pFrame)
  437. {
  438. ULONG ul;
  439. SHORT sTmp;
  440. register PGETKEYSTATE16 parg16;
  441. GETARGPTR(pFrame, sizeof(GETKEYSTATE16), parg16);
  442. sTmp = GetKeyState(INT32(parg16->f1));
  443. // compatiblity:
  444. // MSTEST (testdrvr.exe) tests the bit 0x80 for checking the
  445. // shift key state. This works in win31 because the keystate in win31 is
  446. // one byte long and because of similar code below
  447. //
  448. // win31 code is similar to:
  449. // mov al, byte ptr keystate
  450. // cbw
  451. // ret
  452. //
  453. // if 'al' is 0x80, cbw will make ax = 0xff80 and thus in win31
  454. // (state & 0x8000) and (state & 0x0080) will work and mean the same.
  455. //
  456. ul = (ULONG)((sTmp & 0x8000) ? (sTmp | 0x80) : sTmp);
  457. FREEARGPTR(parg16);
  458. RETURN(ul);
  459. }
  460. //**************************************************************************
  461. // WU32GetKeyboardState -
  462. //
  463. //**************************************************************************
  464. ULONG FASTCALL WU32GetKeyboardState(PVDMFRAME pFrame)
  465. {
  466. PBYTE pb1;
  467. register PGETKEYBOARDSTATE16 parg16;
  468. GETARGPTR(pFrame, sizeof(GETKEYBOARDSTATE16), parg16);
  469. ALLOCVDMPTR(parg16->f1, 256, pb1);
  470. #ifdef HACK32 // bug 5704
  471. if (pb1) {
  472. GetKeyboardState( pb1 );
  473. }
  474. #else
  475. GetKeyboardState( pb1 );
  476. #endif
  477. FLUSHVDMPTR(parg16->f1, 256, pb1);
  478. FREEVDMPTR(pb1);
  479. FREEARGPTR(parg16);
  480. RETURN(0);
  481. }