winproc.c 110 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290
  1. /*
  2. * Window procedure callbacks
  3. *
  4. * Copyright 1995 Martin von Loewis
  5. * Copyright 1996 Alexandre Julliard
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include "config.h"
  22. #include "wine/port.h"
  23. #include <stdarg.h>
  24. #include <string.h>
  25. #include "windef.h"
  26. #include "winbase.h"
  27. #include "wingdi.h"
  28. #include "wownt32.h"
  29. #include "wine/winbase16.h"
  30. #include "wine/winuser16.h"
  31. #include "stackframe.h"
  32. #include "controls.h"
  33. #include "win.h"
  34. #include "winproc.h"
  35. #include "message.h"
  36. #include "user_private.h"
  37. #include "thread.h"
  38. #include "dde.h"
  39. #include "winternl.h"
  40. #include "wine/unicode.h"
  41. #include "wine/debug.h"
  42. WINE_DECLARE_DEBUG_CHANNEL(msg);
  43. WINE_DECLARE_DEBUG_CHANNEL(relay);
  44. WINE_DEFAULT_DEBUG_CHANNEL(win);
  45. #ifdef __i386__
  46. #include "pshpack1.h"
  47. /* Window procedure 16-to-32-bit thunk */
  48. typedef struct
  49. {
  50. BYTE popl_eax; /* popl %eax (return address) */
  51. BYTE pushl_func; /* pushl $proc */
  52. WNDPROC proc;
  53. BYTE pushl_eax; /* pushl %eax */
  54. BYTE ljmp; /* ljmp relay*/
  55. DWORD relay_offset; /* __wine_call_wndproc_32A/W */
  56. WORD relay_sel;
  57. } WINPROC_THUNK_FROM16;
  58. /* Window procedure 32-to-16-bit thunk */
  59. typedef struct
  60. {
  61. BYTE popl_eax; /* popl %eax (return address) */
  62. BYTE pushl_func; /* pushl $proc */
  63. WNDPROC16 proc;
  64. BYTE pushl_eax; /* pushl %eax */
  65. BYTE jmp; /* jmp relay (relative jump)*/
  66. void (*relay)(); /* WINPROC_CallProc32ATo16() */
  67. } WINPROC_THUNK_FROM32;
  68. /* Simple jmp to call 32-bit procedure directly */
  69. typedef struct
  70. {
  71. BYTE jmp; /* jmp proc (relative jump) */
  72. WNDPROC proc;
  73. } WINPROC_JUMP;
  74. #include "poppack.h"
  75. #else /* __i386__ */
  76. typedef struct
  77. {
  78. WNDPROC proc;
  79. } WINPROC_THUNK_FROM16;
  80. typedef struct
  81. {
  82. WNDPROC16 proc;
  83. } WINPROC_THUNK_FROM32;
  84. typedef struct
  85. {
  86. WNDPROC proc;
  87. } WINPROC_JUMP;
  88. #endif /* __i386__ */
  89. typedef union
  90. {
  91. WINPROC_THUNK_FROM16 t_from16;
  92. WINPROC_THUNK_FROM32 t_from32;
  93. } WINPROC_THUNK;
  94. typedef struct tagWINDOWPROC
  95. {
  96. WINPROC_THUNK thunk; /* Thunk */
  97. WINPROC_JUMP jmp; /* Jump */
  98. BYTE type; /* Function type */
  99. } WINDOWPROC;
  100. static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
  101. UINT msg, WPARAM wParam,
  102. LPARAM lParam );
  103. static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
  104. UINT msg, WPARAM wParam,
  105. LPARAM lParam );
  106. #define MAX_WINPROCS (0x10000 / sizeof(WINDOWPROC))
  107. static WINDOWPROC winproc_array[MAX_WINPROCS];
  108. static UINT winproc_used;
  109. static CRITICAL_SECTION winproc_cs;
  110. static CRITICAL_SECTION_DEBUG critsect_debug =
  111. {
  112. 0, 0, &winproc_cs,
  113. { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
  114. 0, 0, { 0, (DWORD)(__FILE__ ": winproc_cs") }
  115. };
  116. static CRITICAL_SECTION winproc_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
  117. static BOOL is_valid_winproc( WINDOWPROC *proc )
  118. {
  119. /* check alignment */
  120. if (((BYTE *)proc - (BYTE *)winproc_array) % sizeof(*proc)) return FALSE;
  121. /* check array limits */
  122. if (proc < winproc_array || proc >= winproc_array + winproc_used) return FALSE;
  123. return (proc->type != WIN_PROC_INVALID);
  124. }
  125. /* find an existing winproc for a given function and type */
  126. /* FIXME: probably should do something more clever than a linear search */
  127. static inline WINDOWPROC *find_winproc( WNDPROC func, WINDOWPROCTYPE type )
  128. {
  129. unsigned int i;
  130. if (type == WIN_PROC_16)
  131. {
  132. for (i = 0; i < winproc_used; i++)
  133. {
  134. if (winproc_array[i].type == type &&
  135. winproc_array[i].thunk.t_from32.proc == (WNDPROC16)func)
  136. return &winproc_array[i];
  137. }
  138. }
  139. else
  140. {
  141. for (i = 0; i < winproc_used; i++)
  142. {
  143. if (winproc_array[i].type == type &&
  144. winproc_array[i].thunk.t_from16.proc == func)
  145. return &winproc_array[i];
  146. }
  147. }
  148. return NULL;
  149. }
  150. /* initialize a new winproc */
  151. static inline void set_winproc( WINDOWPROC *proc, WNDPROC func, WINDOWPROCTYPE type )
  152. {
  153. #ifdef __i386__
  154. static FARPROC16 relay_32A, relay_32W;
  155. switch(type)
  156. {
  157. case WIN_PROC_16:
  158. proc->thunk.t_from32.popl_eax = 0x58; /* popl %eax */
  159. proc->thunk.t_from32.pushl_func = 0x68; /* pushl $proc */
  160. proc->thunk.t_from32.proc = (WNDPROC16)func;
  161. proc->thunk.t_from32.pushl_eax = 0x50; /* pushl %eax */
  162. proc->thunk.t_from32.jmp = 0xe9; /* jmp relay*/
  163. proc->thunk.t_from32.relay = /* relative jump */
  164. (void(*)())((DWORD)WINPROC_CallProc32ATo16 -
  165. (DWORD)(&proc->thunk.t_from32.relay + 1));
  166. break;
  167. case WIN_PROC_32A:
  168. if (!relay_32A) relay_32A = GetProcAddress16( GetModuleHandle16("user"),
  169. "__wine_call_wndproc_32A" );
  170. proc->thunk.t_from16.popl_eax = 0x58; /* popl %eax */
  171. proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
  172. proc->thunk.t_from16.proc = func;
  173. proc->thunk.t_from16.pushl_eax = 0x50; /* pushl %eax */
  174. proc->thunk.t_from16.ljmp = 0xea; /* ljmp relay*/
  175. proc->thunk.t_from16.relay_offset = OFFSETOF(relay_32A);
  176. proc->thunk.t_from16.relay_sel = SELECTOROF(relay_32A);
  177. proc->jmp.jmp = 0xe9;
  178. /* Fixup relative jump */
  179. proc->jmp.proc = (WNDPROC)((DWORD)func - (DWORD)(&proc->jmp.proc + 1));
  180. break;
  181. case WIN_PROC_32W:
  182. if (!relay_32W) relay_32W = GetProcAddress16( GetModuleHandle16("user"),
  183. "__wine_call_wndproc_32W" );
  184. proc->thunk.t_from16.popl_eax = 0x58; /* popl %eax */
  185. proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
  186. proc->thunk.t_from16.proc = func;
  187. proc->thunk.t_from16.pushl_eax = 0x50; /* pushl %eax */
  188. proc->thunk.t_from16.ljmp = 0xea; /* ljmp relay*/
  189. proc->thunk.t_from16.relay_offset = OFFSETOF(relay_32W);
  190. proc->thunk.t_from16.relay_sel = SELECTOROF(relay_32W);
  191. proc->jmp.jmp = 0xe9;
  192. /* Fixup relative jump */
  193. proc->jmp.proc = (WNDPROC)((char *)func - (char *)(&proc->jmp.proc + 1));
  194. break;
  195. default:
  196. /* Should not happen */
  197. break;
  198. }
  199. #else /* __i386__ */
  200. switch(type)
  201. {
  202. case WIN_PROC_16:
  203. proc->thunk.t_from32.proc = (WNDPROC16)func;
  204. break;
  205. case WIN_PROC_32A:
  206. case WIN_PROC_32W:
  207. proc->thunk.t_from16.proc = func;
  208. break;
  209. default:
  210. /* Should not happen */
  211. break;
  212. }
  213. #endif /* __i386__ */
  214. proc->type = type;
  215. }
  216. static WORD get_winproc_selector(void)
  217. {
  218. static LONG winproc_selector;
  219. WORD ret;
  220. if (!(ret = winproc_selector))
  221. {
  222. LDT_ENTRY entry;
  223. WORD sel = wine_ldt_alloc_entries(1);
  224. wine_ldt_set_base( &entry, winproc_array );
  225. wine_ldt_set_limit( &entry, sizeof(winproc_array) - 1 );
  226. wine_ldt_set_flags( &entry, WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
  227. wine_ldt_set_entry( sel, &entry );
  228. if (!(ret = InterlockedCompareExchange( &winproc_selector, sel, 0 ))) ret = sel;
  229. else wine_ldt_free_entries( sel, 1 ); /* somebody beat us to it */
  230. }
  231. return ret;
  232. }
  233. #ifdef __i386__
  234. /* Some window procedures modify register they shouldn't, or are not
  235. * properly declared stdcall; so we need a small assembly wrapper to
  236. * call them. */
  237. extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
  238. WPARAM wParam, LPARAM lParam );
  239. __ASM_GLOBAL_FUNC( WINPROC_wrapper,
  240. "pushl %ebp\n\t"
  241. "movl %esp,%ebp\n\t"
  242. "pushl %edi\n\t"
  243. "pushl %esi\n\t"
  244. "pushl %ebx\n\t"
  245. "pushl 24(%ebp)\n\t"
  246. "pushl 20(%ebp)\n\t"
  247. "pushl 16(%ebp)\n\t"
  248. "pushl 12(%ebp)\n\t"
  249. "movl 8(%ebp),%eax\n\t"
  250. "call *%eax\n\t"
  251. "leal -12(%ebp),%esp\n\t"
  252. "popl %ebx\n\t"
  253. "popl %esi\n\t"
  254. "popl %edi\n\t"
  255. "leave\n\t"
  256. "ret" );
  257. #else
  258. static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
  259. WPARAM wParam, LPARAM lParam )
  260. {
  261. return proc( hwnd, msg, wParam, lParam );
  262. }
  263. #endif /* __i386__ */
  264. static void MINMAXINFO32to16( const MINMAXINFO *from, MINMAXINFO16 *to )
  265. {
  266. to->ptReserved.x = from->ptReserved.x;
  267. to->ptReserved.y = from->ptReserved.y;
  268. to->ptMaxSize.x = from->ptMaxSize.x;
  269. to->ptMaxSize.y = from->ptMaxSize.y;
  270. to->ptMaxPosition.x = from->ptMaxPosition.x;
  271. to->ptMaxPosition.y = from->ptMaxPosition.y;
  272. to->ptMinTrackSize.x = from->ptMinTrackSize.x;
  273. to->ptMinTrackSize.y = from->ptMinTrackSize.y;
  274. to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
  275. to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
  276. }
  277. static void MINMAXINFO16to32( const MINMAXINFO16 *from, MINMAXINFO *to )
  278. {
  279. to->ptReserved.x = from->ptReserved.x;
  280. to->ptReserved.y = from->ptReserved.y;
  281. to->ptMaxSize.x = from->ptMaxSize.x;
  282. to->ptMaxSize.y = from->ptMaxSize.y;
  283. to->ptMaxPosition.x = from->ptMaxPosition.x;
  284. to->ptMaxPosition.y = from->ptMaxPosition.y;
  285. to->ptMinTrackSize.x = from->ptMinTrackSize.x;
  286. to->ptMinTrackSize.y = from->ptMinTrackSize.y;
  287. to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
  288. to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
  289. }
  290. static void WINDOWPOS32to16( const WINDOWPOS* from, WINDOWPOS16* to )
  291. {
  292. to->hwnd = HWND_16(from->hwnd);
  293. to->hwndInsertAfter = HWND_16(from->hwndInsertAfter);
  294. to->x = from->x;
  295. to->y = from->y;
  296. to->cx = from->cx;
  297. to->cy = from->cy;
  298. to->flags = from->flags;
  299. }
  300. static void WINDOWPOS16to32( const WINDOWPOS16* from, WINDOWPOS* to )
  301. {
  302. to->hwnd = WIN_Handle32(from->hwnd);
  303. to->hwndInsertAfter = (from->hwndInsertAfter == (HWND16)-1) ?
  304. HWND_TOPMOST : WIN_Handle32(from->hwndInsertAfter);
  305. to->x = from->x;
  306. to->y = from->y;
  307. to->cx = from->cx;
  308. to->cy = from->cy;
  309. to->flags = from->flags;
  310. }
  311. /* The strings are not copied */
  312. static void CREATESTRUCT32Ato16( const CREATESTRUCTA* from, CREATESTRUCT16* to )
  313. {
  314. to->lpCreateParams = (SEGPTR)from->lpCreateParams;
  315. to->hInstance = HINSTANCE_16(from->hInstance);
  316. to->hMenu = HMENU_16(from->hMenu);
  317. to->hwndParent = HWND_16(from->hwndParent);
  318. to->cy = from->cy;
  319. to->cx = from->cx;
  320. to->y = from->y;
  321. to->x = from->x;
  322. to->style = from->style;
  323. to->dwExStyle = from->dwExStyle;
  324. }
  325. static void CREATESTRUCT16to32A( const CREATESTRUCT16* from, CREATESTRUCTA *to )
  326. {
  327. to->lpCreateParams = (LPVOID)from->lpCreateParams;
  328. to->hInstance = HINSTANCE_32(from->hInstance);
  329. to->hMenu = HMENU_32(from->hMenu);
  330. to->hwndParent = WIN_Handle32(from->hwndParent);
  331. to->cy = from->cy;
  332. to->cx = from->cx;
  333. to->y = from->y;
  334. to->x = from->x;
  335. to->style = from->style;
  336. to->dwExStyle = from->dwExStyle;
  337. }
  338. /* The strings are not copied */
  339. static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA* from, MDICREATESTRUCT16* to )
  340. {
  341. to->hOwner = HINSTANCE_16(from->hOwner);
  342. to->x = from->x;
  343. to->y = from->y;
  344. to->cx = from->cx;
  345. to->cy = from->cy;
  346. to->style = from->style;
  347. to->lParam = from->lParam;
  348. }
  349. static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16* from, MDICREATESTRUCTA *to )
  350. {
  351. to->hOwner = HINSTANCE_32(from->hOwner);
  352. to->x = from->x;
  353. to->y = from->y;
  354. to->cx = from->cx;
  355. to->cy = from->cy;
  356. to->style = from->style;
  357. to->lParam = from->lParam;
  358. }
  359. /**********************************************************************
  360. * WINPROC_CallWndProc32
  361. *
  362. * Call a 32-bit WndProc.
  363. */
  364. static LRESULT WINPROC_CallWndProc( WNDPROC proc, HWND hwnd, UINT msg,
  365. WPARAM wParam, LPARAM lParam )
  366. {
  367. LRESULT retvalue;
  368. int iWndsLocks;
  369. hwnd = WIN_GetFullHandle( hwnd );
  370. if (TRACE_ON(relay))
  371. DPRINTF( "%04lx:Call window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
  372. GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam );
  373. /* To avoid any deadlocks, all the locks on the windows structures
  374. must be suspended before the control is passed to the application */
  375. iWndsLocks = WIN_SuspendWndsLock();
  376. retvalue = WINPROC_wrapper( proc, hwnd, msg, wParam, lParam );
  377. WIN_RestoreWndsLock(iWndsLocks);
  378. if (TRACE_ON(relay))
  379. DPRINTF( "%04lx:Ret window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
  380. GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam, retvalue );
  381. return retvalue;
  382. }
  383. /***********************************************************************
  384. * WINPROC_CallWndProc16
  385. *
  386. * Call a 16-bit window procedure
  387. */
  388. static LRESULT WINAPI WINPROC_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
  389. UINT16 msg, WPARAM16 wParam,
  390. LPARAM lParam )
  391. {
  392. CONTEXT86 context;
  393. LRESULT ret;
  394. WORD args[5];
  395. DWORD offset = 0;
  396. TEB *teb = NtCurrentTeb();
  397. int iWndsLocks;
  398. /* Window procedures want ax = hInstance, ds = es = ss */
  399. memset(&context, 0, sizeof(context));
  400. context.SegDs = context.SegEs = SELECTOROF(teb->cur_stack);
  401. context.SegFs = wine_get_fs();
  402. context.SegGs = wine_get_gs();
  403. if (!(context.Eax = GetWindowWord( HWND_32(hwnd), GWLP_HINSTANCE ))) context.Eax = context.SegDs;
  404. context.SegCs = SELECTOROF(proc);
  405. context.Eip = OFFSETOF(proc);
  406. context.Ebp = OFFSETOF(teb->cur_stack)
  407. + (WORD)&((STACK16FRAME*)0)->bp;
  408. if (lParam)
  409. {
  410. /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
  411. work if structures passed in lParam are placed in the stack/data
  412. segment. Programmers easily make the mistake of converting lParam
  413. to a near rather than a far pointer, since Windows apparently
  414. allows this. We copy the structures to the 16 bit stack; this is
  415. ugly but makes these programs work. */
  416. switch (msg)
  417. {
  418. case WM_CREATE:
  419. case WM_NCCREATE:
  420. offset = sizeof(CREATESTRUCT16); break;
  421. case WM_DRAWITEM:
  422. offset = sizeof(DRAWITEMSTRUCT16); break;
  423. case WM_COMPAREITEM:
  424. offset = sizeof(COMPAREITEMSTRUCT16); break;
  425. }
  426. if (offset)
  427. {
  428. void *s = MapSL(lParam);
  429. lParam = stack16_push( offset );
  430. memcpy( MapSL(lParam), s, offset );
  431. }
  432. }
  433. iWndsLocks = WIN_SuspendWndsLock();
  434. args[4] = hwnd;
  435. args[3] = msg;
  436. args[2] = wParam;
  437. args[1] = HIWORD(lParam);
  438. args[0] = LOWORD(lParam);
  439. WOWCallback16Ex( 0, WCB16_REGS, sizeof(args), args, (DWORD *)&context );
  440. ret = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
  441. if (offset) stack16_pop( offset );
  442. WIN_RestoreWndsLock(iWndsLocks);
  443. return ret;
  444. }
  445. /**********************************************************************
  446. * WINPROC_GetPtr
  447. *
  448. * Return a pointer to the win proc.
  449. */
  450. static WINDOWPROC *WINPROC_GetPtr( WNDPROC handle )
  451. {
  452. BYTE *ptr;
  453. WINDOWPROC *proc;
  454. /* ptr cannot be < 64K */
  455. if (!HIWORD(handle)) return NULL;
  456. /* Check for a linear pointer */
  457. ptr = (BYTE *)handle;
  458. /* First check if it is the jmp address */
  459. proc = (WINDOWPROC *)(ptr - FIELD_OFFSET(WINDOWPROC,jmp));
  460. if (is_valid_winproc(proc)) return proc;
  461. /* Now it must be the thunk address */
  462. proc = (WINDOWPROC *)(ptr - FIELD_OFFSET(WINDOWPROC,thunk));
  463. if (is_valid_winproc(proc)) return proc;
  464. /* Check for a segmented pointer */
  465. if (HIWORD(handle) == get_winproc_selector())
  466. {
  467. ptr = (BYTE *)winproc_array + LOWORD(handle);
  468. /* It must be the thunk address */
  469. proc = (WINDOWPROC *)(ptr - FIELD_OFFSET(WINDOWPROC,thunk));
  470. if (is_valid_winproc(proc)) return proc;
  471. }
  472. return NULL;
  473. }
  474. /**********************************************************************
  475. * WINPROC_GetProc
  476. *
  477. * Get a window procedure pointer that can be passed to the Windows program.
  478. */
  479. WNDPROC16 WINPROC_GetProc( WNDPROC proc, WINDOWPROCTYPE type )
  480. {
  481. WINDOWPROC *ptr = (WINDOWPROC *)proc;
  482. if (!proc) return NULL;
  483. if (type == WIN_PROC_16) /* We want a 16:16 address */
  484. {
  485. if (ptr->type == WIN_PROC_16)
  486. return ptr->thunk.t_from32.proc;
  487. else
  488. return (WNDPROC16)MAKESEGPTR( get_winproc_selector(),
  489. (char *)&ptr->thunk - (char *)winproc_array );
  490. }
  491. else /* We want a 32-bit address */
  492. {
  493. if (ptr->type == WIN_PROC_16)
  494. return (WNDPROC16)&ptr->thunk;
  495. else if (type != ptr->type)
  496. /* Have to return the jmp address if types don't match */
  497. return (WNDPROC16)&ptr->jmp;
  498. else
  499. /* Some Win16 programs want to get back the proc they set */
  500. return (WNDPROC16)ptr->thunk.t_from16.proc;
  501. }
  502. }
  503. /**********************************************************************
  504. * WINPROC_AllocProc
  505. *
  506. * Allocate a window procedure for a window or class.
  507. *
  508. * Note that allocated winprocs are never freed; the idea is that even if an app creates a
  509. * lot of windows, it will usually only have a limited number of window procedures, so the
  510. * array won't grow too large, and this way we avoid the need to track allocations per window.
  511. */
  512. WNDPROC WINPROC_AllocProc( WNDPROC func, WINDOWPROCTYPE type )
  513. {
  514. WINDOWPROC *proc;
  515. if (!func) return NULL;
  516. EnterCriticalSection( &winproc_cs );
  517. /* check if the function is already a win proc */
  518. if (!(proc = WINPROC_GetPtr( func )))
  519. {
  520. /* then check if we already have a winproc for that function */
  521. if (!(proc = find_winproc( func, type )))
  522. {
  523. if (winproc_used >= MAX_WINPROCS)
  524. FIXME( "too many winprocs, cannot allocate one for %p/%d\n", func, type );
  525. else
  526. {
  527. proc = &winproc_array[winproc_used++];
  528. set_winproc( proc, func, type );
  529. TRACE( "allocated %p for %p/%d (%d/%d used)\n",
  530. proc, func, type, winproc_used, MAX_WINPROCS );
  531. }
  532. }
  533. else TRACE( "reusing %p for %p/%d\n", proc, func, type );
  534. }
  535. LeaveCriticalSection( &winproc_cs );
  536. return (WNDPROC)proc;
  537. }
  538. /**********************************************************************
  539. * WINPROC_GetProcType
  540. *
  541. * Return the window procedure type.
  542. */
  543. WINDOWPROCTYPE WINPROC_GetProcType( WNDPROC proc )
  544. {
  545. if (!proc) return WIN_PROC_INVALID;
  546. return ((WINDOWPROC *)proc)->type;
  547. }
  548. /**********************************************************************
  549. * WINPROC_TestCBForStr
  550. *
  551. * Return TRUE if the lparam is a string
  552. */
  553. inline static BOOL WINPROC_TestCBForStr( HWND hwnd )
  554. {
  555. DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
  556. return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
  557. }
  558. /**********************************************************************
  559. * WINPROC_TestLBForStr
  560. *
  561. * Return TRUE if the lparam is a string
  562. */
  563. inline static BOOL WINPROC_TestLBForStr( HWND hwnd )
  564. {
  565. DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
  566. return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
  567. }
  568. /**********************************************************************
  569. * WINPROC_MapMsg32ATo32W
  570. *
  571. * Map a message from Ansi to Unicode.
  572. * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
  573. *
  574. * FIXME:
  575. * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
  576. * the first four bytes are the handle of the icon
  577. * when the WM_SETTEXT message has been used to set the icon
  578. */
  579. INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
  580. {
  581. switch(msg)
  582. {
  583. case WM_GETTEXT:
  584. case WM_ASKCBFORMATNAME:
  585. {
  586. LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
  587. *pwparam * sizeof(WCHAR) + sizeof(LPARAM) );
  588. if (!ptr) return -1;
  589. *ptr++ = *plparam; /* Store previous lParam */
  590. *plparam = (LPARAM)ptr;
  591. }
  592. return 1;
  593. /* lparam is string (0-terminated) */
  594. case WM_SETTEXT:
  595. case WM_WININICHANGE:
  596. case WM_DEVMODECHANGE:
  597. case CB_DIR:
  598. case LB_DIR:
  599. case LB_ADDFILE:
  600. case EM_REPLACESEL:
  601. {
  602. DWORD len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*plparam, -1, NULL, 0);
  603. WCHAR *buf = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
  604. len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*plparam, -1, buf, len);
  605. *plparam = (LPARAM)buf;
  606. return (*plparam ? 1 : -1);
  607. }
  608. case WM_GETTEXTLENGTH:
  609. case CB_GETLBTEXTLEN:
  610. case LB_GETTEXTLEN:
  611. return 1; /* need to map result */
  612. case WM_NCCREATE:
  613. case WM_CREATE:
  614. {
  615. UNICODE_STRING usBuffer;
  616. struct s
  617. { CREATESTRUCTW cs; /* new structure */
  618. LPCWSTR lpszName; /* allocated Name */
  619. LPCWSTR lpszClass; /* allocated Class */
  620. };
  621. struct s *xs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct s));
  622. if (!xs) return -1;
  623. xs->cs = *(CREATESTRUCTW *)*plparam;
  624. if (HIWORD(xs->cs.lpszName))
  625. {
  626. RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)xs->cs.lpszName);
  627. xs->lpszName = xs->cs.lpszName = usBuffer.Buffer;
  628. }
  629. if (HIWORD(xs->cs.lpszClass))
  630. {
  631. RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)xs->cs.lpszClass);
  632. xs->lpszClass = xs->cs.lpszClass = usBuffer.Buffer;
  633. }
  634. if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
  635. {
  636. MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)HeapAlloc(GetProcessHeap(), 0,
  637. sizeof(*mdi_cs));
  638. *mdi_cs = *(MDICREATESTRUCTW *)xs->cs.lpCreateParams;
  639. if (HIWORD(mdi_cs->szTitle))
  640. {
  641. RtlCreateUnicodeStringFromAsciiz(&usBuffer, (LPCSTR)mdi_cs->szTitle);
  642. mdi_cs->szTitle = usBuffer.Buffer;
  643. }
  644. if (HIWORD(mdi_cs->szClass))
  645. {
  646. RtlCreateUnicodeStringFromAsciiz(&usBuffer, (LPCSTR)mdi_cs->szClass);
  647. mdi_cs->szClass = usBuffer.Buffer;
  648. }
  649. xs->cs.lpCreateParams = mdi_cs;
  650. }
  651. *plparam = (LPARAM)xs;
  652. }
  653. return 1;
  654. case WM_MDICREATE:
  655. {
  656. MDICREATESTRUCTW *cs =
  657. (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
  658. if (!cs) return -1;
  659. *cs = *(MDICREATESTRUCTW *)*plparam;
  660. if (HIWORD(cs->szClass))
  661. {
  662. UNICODE_STRING usBuffer;
  663. RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)cs->szClass);
  664. cs->szClass = usBuffer.Buffer;
  665. }
  666. if (HIWORD(cs->szTitle))
  667. {
  668. UNICODE_STRING usBuffer;
  669. RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)cs->szTitle);
  670. cs->szTitle = usBuffer.Buffer;
  671. }
  672. *plparam = (LPARAM)cs;
  673. }
  674. return 1;
  675. /* Listbox */
  676. case LB_ADDSTRING:
  677. case LB_INSERTSTRING:
  678. case LB_FINDSTRING:
  679. case LB_FINDSTRINGEXACT:
  680. case LB_SELECTSTRING:
  681. if(!*plparam) return 0;
  682. if ( WINPROC_TestLBForStr( hwnd ))
  683. {
  684. UNICODE_STRING usBuffer;
  685. RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)*plparam);
  686. *plparam = (LPARAM)usBuffer.Buffer;
  687. }
  688. return (*plparam ? 1 : -1);
  689. case LB_GETTEXT: /* FIXME: fixed sized buffer */
  690. { if ( WINPROC_TestLBForStr( hwnd ))
  691. { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
  692. if (!ptr) return -1;
  693. *ptr++ = *plparam; /* Store previous lParam */
  694. *plparam = (LPARAM)ptr;
  695. }
  696. }
  697. return 1;
  698. /* Combobox */
  699. case CB_ADDSTRING:
  700. case CB_INSERTSTRING:
  701. case CB_FINDSTRINGEXACT:
  702. case CB_FINDSTRING:
  703. case CB_SELECTSTRING:
  704. if(!*plparam) return 0;
  705. if ( WINPROC_TestCBForStr( hwnd ))
  706. {
  707. UNICODE_STRING usBuffer;
  708. RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)*plparam);
  709. *plparam = (LPARAM)usBuffer.Buffer;
  710. }
  711. return (*plparam ? 1 : -1);
  712. case CB_GETLBTEXT: /* FIXME: fixed sized buffer */
  713. { if ( WINPROC_TestCBForStr( hwnd ))
  714. { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
  715. if (!ptr) return -1;
  716. *ptr++ = *plparam; /* Store previous lParam */
  717. *plparam = (LPARAM)ptr;
  718. }
  719. }
  720. return 1;
  721. /* Multiline edit */
  722. case EM_GETLINE:
  723. { WORD len = (WORD)*plparam;
  724. LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
  725. if (!ptr) return -1;
  726. *ptr++ = *plparam; /* Store previous lParam */
  727. *((WORD *) ptr) = len; /* Store the length */
  728. *plparam = (LPARAM)ptr;
  729. }
  730. return 1;
  731. case WM_CHARTOITEM:
  732. case WM_MENUCHAR:
  733. case WM_CHAR:
  734. case WM_DEADCHAR:
  735. case WM_SYSCHAR:
  736. case WM_SYSDEADCHAR:
  737. case EM_SETPASSWORDCHAR:
  738. {
  739. BYTE ch = LOWORD(*pwparam);
  740. WCHAR wch;
  741. MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
  742. *pwparam = MAKEWPARAM( wch, HIWORD(*pwparam) );
  743. }
  744. return 0;
  745. case WM_IME_CHAR:
  746. {
  747. BYTE ch[2];
  748. WCHAR wch;
  749. ch[0] = (*pwparam >> 8);
  750. ch[1] = *pwparam & 0xff;
  751. if (ch[0])
  752. MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
  753. else
  754. MultiByteToWideChar(CP_ACP, 0, &ch[1], 1, &wch, 1);
  755. *pwparam = MAKEWPARAM( wch, HIWORD(*pwparam) );
  756. }
  757. return 0;
  758. case WM_PAINTCLIPBOARD:
  759. case WM_SIZECLIPBOARD:
  760. FIXME_(msg)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg, hwnd), msg );
  761. return -1;
  762. default: /* No translation needed */
  763. return 0;
  764. }
  765. }
  766. /**********************************************************************
  767. * WINPROC_UnmapMsg32ATo32W
  768. *
  769. * Unmap a message that was mapped from Ansi to Unicode.
  770. */
  771. LRESULT WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
  772. LRESULT result )
  773. {
  774. switch(msg)
  775. {
  776. case WM_GETTEXT:
  777. case WM_ASKCBFORMATNAME:
  778. {
  779. LPARAM *ptr = (LPARAM *)lParam - 1;
  780. if (!wParam) result = 0;
  781. else if (!(result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
  782. (LPSTR)*ptr, wParam, NULL, NULL )))
  783. {
  784. ((LPSTR)*ptr)[wParam-1] = 0;
  785. result = wParam - 1;
  786. }
  787. else result--; /* do not count terminating null */
  788. HeapFree( GetProcessHeap(), 0, ptr );
  789. }
  790. break;
  791. case WM_GETTEXTLENGTH:
  792. case CB_GETLBTEXTLEN:
  793. case LB_GETTEXTLEN:
  794. /* there may be one DBCS char for each Unicode char */
  795. return result * 2;
  796. case WM_NCCREATE:
  797. case WM_CREATE:
  798. {
  799. struct s
  800. { CREATESTRUCTW cs; /* new structure */
  801. LPWSTR lpszName; /* allocated Name */
  802. LPWSTR lpszClass; /* allocated Class */
  803. };
  804. struct s *xs = (struct s *)lParam;
  805. HeapFree( GetProcessHeap(), 0, xs->lpszName );
  806. HeapFree( GetProcessHeap(), 0, xs->lpszClass );
  807. if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
  808. {
  809. MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)xs->cs.lpCreateParams;
  810. if (HIWORD(mdi_cs->szTitle))
  811. HeapFree(GetProcessHeap(), 0, (LPVOID)mdi_cs->szTitle);
  812. if (HIWORD(mdi_cs->szClass))
  813. HeapFree(GetProcessHeap(), 0, (LPVOID)mdi_cs->szClass);
  814. HeapFree(GetProcessHeap(), 0, mdi_cs);
  815. }
  816. HeapFree( GetProcessHeap(), 0, xs );
  817. }
  818. break;
  819. case WM_MDICREATE:
  820. {
  821. MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
  822. if (HIWORD(cs->szTitle))
  823. HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
  824. if (HIWORD(cs->szClass))
  825. HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
  826. HeapFree( GetProcessHeap(), 0, cs );
  827. }
  828. break;
  829. case WM_SETTEXT:
  830. case WM_WININICHANGE:
  831. case WM_DEVMODECHANGE:
  832. case CB_DIR:
  833. case LB_DIR:
  834. case LB_ADDFILE:
  835. case EM_REPLACESEL:
  836. HeapFree( GetProcessHeap(), 0, (void *)lParam );
  837. break;
  838. /* Listbox */
  839. case LB_ADDSTRING:
  840. case LB_INSERTSTRING:
  841. case LB_FINDSTRING:
  842. case LB_FINDSTRINGEXACT:
  843. case LB_SELECTSTRING:
  844. if ( WINPROC_TestLBForStr( hwnd ))
  845. HeapFree( GetProcessHeap(), 0, (void *)lParam );
  846. break;
  847. case LB_GETTEXT:
  848. if ( WINPROC_TestLBForStr( hwnd ))
  849. {
  850. LPARAM *ptr = (LPARAM *)lParam - 1;
  851. result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
  852. (LPSTR)*ptr, 0x7fffffff, NULL, NULL ) - 1;
  853. HeapFree( GetProcessHeap(), 0, ptr );
  854. }
  855. break;
  856. /* Combobox */
  857. case CB_ADDSTRING:
  858. case CB_INSERTSTRING:
  859. case CB_FINDSTRING:
  860. case CB_FINDSTRINGEXACT:
  861. case CB_SELECTSTRING:
  862. if ( WINPROC_TestCBForStr( hwnd ))
  863. HeapFree( GetProcessHeap(), 0, (void *)lParam );
  864. break;
  865. case CB_GETLBTEXT:
  866. if ( WINPROC_TestCBForStr( hwnd ))
  867. {
  868. LPARAM *ptr = (LPARAM *)lParam - 1;
  869. result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
  870. (LPSTR)*ptr, 0x7fffffff, NULL, NULL ) - 1;
  871. HeapFree( GetProcessHeap(), 0, ptr );
  872. }
  873. break;
  874. /* Multiline edit */
  875. case EM_GETLINE:
  876. {
  877. LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
  878. WORD len = *(WORD *) lParam;
  879. result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, result,
  880. (LPSTR)*ptr, len, NULL, NULL );
  881. if (result < len) ((LPSTR)*ptr)[result] = 0;
  882. HeapFree( GetProcessHeap(), 0, ptr );
  883. }
  884. break;
  885. }
  886. return result;
  887. }
  888. /**********************************************************************
  889. * WINPROC_MapMsg32WTo32A
  890. *
  891. * Map a message from Unicode to Ansi.
  892. * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
  893. */
  894. static INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
  895. {
  896. switch(msg)
  897. {
  898. case WM_GETTEXT:
  899. case WM_ASKCBFORMATNAME:
  900. {
  901. LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
  902. *pwparam + sizeof(LPARAM) );
  903. if (!ptr) return -1;
  904. *ptr++ = *plparam; /* Store previous lParam */
  905. *plparam = (LPARAM)ptr;
  906. }
  907. return 1;
  908. case WM_SETTEXT:
  909. case WM_WININICHANGE:
  910. case WM_DEVMODECHANGE:
  911. case CB_DIR:
  912. case LB_DIR:
  913. case LB_ADDFILE:
  914. case EM_REPLACESEL:
  915. if (*plparam)
  916. {
  917. LPCWSTR str = (LPCWSTR)*plparam;
  918. int len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, 0, 0);
  919. *plparam = (LPARAM)HeapAlloc(GetProcessHeap(), 0, len);
  920. if (!*plparam) return -1;
  921. WideCharToMultiByte(CP_ACP, 0, str, -1, (LPSTR)*plparam, len, 0, 0);
  922. return 1;
  923. }
  924. return 0;
  925. case WM_MDICREATE:
  926. {
  927. MDICREATESTRUCTA *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
  928. if (!cs) return -1;
  929. *cs = *(MDICREATESTRUCTA *)*plparam;
  930. if (HIWORD(cs->szTitle))
  931. {
  932. int len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)cs->szTitle, -1, NULL, 0, 0, 0);
  933. LPSTR buf = HeapAlloc(GetProcessHeap(), 0, len);
  934. if (buf) WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)cs->szTitle, -1, buf, len, 0, 0);
  935. cs->szTitle = buf;
  936. }
  937. if (HIWORD(cs->szClass))
  938. {
  939. int len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)cs->szClass, -1, NULL, 0, 0, 0);
  940. LPSTR buf = HeapAlloc(GetProcessHeap(), 0, len);
  941. if (buf) WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)cs->szClass, -1, buf, len, 0, 0);
  942. cs->szClass = buf;
  943. }
  944. *plparam = (LPARAM)cs;
  945. }
  946. return 1;
  947. /* Listbox */
  948. case LB_ADDSTRING:
  949. case LB_INSERTSTRING:
  950. case LB_FINDSTRING:
  951. case LB_FINDSTRINGEXACT:
  952. case LB_SELECTSTRING:
  953. if(!*plparam) return 0;
  954. if ( WINPROC_TestLBForStr( hwnd ))
  955. {
  956. int len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)*plparam, -1, NULL, 0, 0, 0);
  957. LPSTR buf = HeapAlloc(GetProcessHeap(), 0, len);
  958. if (buf) WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)*plparam, -1, buf, len, 0, 0);
  959. *plparam = (LPARAM)buf;
  960. }
  961. return (*plparam ? 1 : -1);
  962. case LB_GETTEXT: /* FIXME: fixed sized buffer */
  963. { if ( WINPROC_TestLBForStr( hwnd ))
  964. { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
  965. if (!ptr) return -1;
  966. *ptr++ = *plparam; /* Store previous lParam */
  967. *plparam = (LPARAM)ptr;
  968. }
  969. }
  970. return 1;
  971. /* Combobox */
  972. case CB_ADDSTRING:
  973. case CB_INSERTSTRING:
  974. case CB_FINDSTRING:
  975. case CB_FINDSTRINGEXACT:
  976. case CB_SELECTSTRING:
  977. if(!*plparam) return 0;
  978. if ( WINPROC_TestCBForStr( hwnd ))
  979. {
  980. int len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)*plparam, -1, NULL, 0, 0, 0);
  981. LPSTR buf = HeapAlloc(GetProcessHeap(), 0, len);
  982. if (buf) WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)*plparam, -1, buf, len, 0, 0);
  983. *plparam = (LPARAM)buf;
  984. }
  985. return (*plparam ? 1 : -1);
  986. case CB_GETLBTEXT: /* FIXME: fixed sized buffer */
  987. { if ( WINPROC_TestCBForStr( hwnd ))
  988. { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
  989. if (!ptr) return -1;
  990. *ptr++ = *plparam; /* Store previous lParam */
  991. *plparam = (LPARAM)ptr;
  992. }
  993. }
  994. return 1;
  995. /* Multiline edit */
  996. case EM_GETLINE:
  997. { WORD len = (WORD)*plparam;
  998. LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
  999. if (!ptr) return -1;
  1000. *ptr++ = *plparam; /* Store previous lParam */
  1001. *((WORD *) ptr) = len; /* Store the length */
  1002. *plparam = (LPARAM)ptr;
  1003. }
  1004. return 1;
  1005. case WM_CHARTOITEM:
  1006. case WM_MENUCHAR:
  1007. case WM_CHAR:
  1008. case WM_DEADCHAR:
  1009. case WM_SYSCHAR:
  1010. case WM_SYSDEADCHAR:
  1011. case EM_SETPASSWORDCHAR:
  1012. {
  1013. WCHAR wch = LOWORD(*pwparam);
  1014. BYTE ch;
  1015. WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
  1016. *pwparam = MAKEWPARAM( ch, HIWORD(*pwparam) );
  1017. }
  1018. return 0;
  1019. case WM_IME_CHAR:
  1020. {
  1021. WCHAR wch = LOWORD(*pwparam);
  1022. BYTE ch[2];
  1023. if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, ch, 2, NULL, NULL ) == 2)
  1024. *pwparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(*pwparam) );
  1025. else
  1026. *pwparam = MAKEWPARAM( ch[0], HIWORD(*pwparam) );
  1027. }
  1028. return 0;
  1029. case WM_PAINTCLIPBOARD:
  1030. case WM_SIZECLIPBOARD:
  1031. FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg, hwnd),msg );
  1032. return -1;
  1033. default: /* No translation needed */
  1034. return 0;
  1035. }
  1036. }
  1037. /**********************************************************************
  1038. * WINPROC_UnmapMsg32WTo32A
  1039. *
  1040. * Unmap a message that was mapped from Unicode to Ansi.
  1041. */
  1042. static LRESULT WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT result )
  1043. {
  1044. switch(msg)
  1045. {
  1046. case WM_GETTEXT:
  1047. case WM_ASKCBFORMATNAME:
  1048. {
  1049. LPARAM *ptr = (LPARAM *)lParam - 1;
  1050. if (!wParam) result = 0;
  1051. else if (!(result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1,
  1052. (LPWSTR)*ptr, wParam )))
  1053. {
  1054. ((LPWSTR)*ptr)[wParam-1] = 0;
  1055. result = wParam - 1;
  1056. }
  1057. else result--; /* do not count terminating null */
  1058. HeapFree( GetProcessHeap(), 0, ptr );
  1059. }
  1060. break;
  1061. case WM_SETTEXT:
  1062. case WM_WININICHANGE:
  1063. case WM_DEVMODECHANGE:
  1064. case CB_DIR:
  1065. case LB_DIR:
  1066. case LB_ADDFILE:
  1067. case EM_REPLACESEL:
  1068. HeapFree( GetProcessHeap(), 0, (void *)lParam );
  1069. break;
  1070. case WM_MDICREATE:
  1071. {
  1072. MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
  1073. if (HIWORD(cs->szTitle))
  1074. HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
  1075. if (HIWORD(cs->szClass))
  1076. HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
  1077. HeapFree( GetProcessHeap(), 0, cs );
  1078. }
  1079. break;
  1080. /* Listbox */
  1081. case LB_ADDSTRING:
  1082. case LB_INSERTSTRING:
  1083. case LB_FINDSTRING:
  1084. case LB_FINDSTRINGEXACT:
  1085. case LB_SELECTSTRING:
  1086. if ( WINPROC_TestLBForStr( hwnd ))
  1087. HeapFree( GetProcessHeap(), 0, (void *)lParam );
  1088. break;
  1089. case LB_GETTEXT:
  1090. if ( WINPROC_TestLBForStr( hwnd ))
  1091. {
  1092. LPARAM *ptr = (LPARAM *)lParam - 1;
  1093. result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff ) - 1;
  1094. HeapFree( GetProcessHeap(), 0, ptr );
  1095. }
  1096. break;
  1097. /* Combobox */
  1098. case CB_ADDSTRING:
  1099. case CB_INSERTSTRING:
  1100. case CB_FINDSTRING:
  1101. case CB_FINDSTRINGEXACT:
  1102. case CB_SELECTSTRING:
  1103. if ( WINPROC_TestCBForStr( hwnd ))
  1104. HeapFree( GetProcessHeap(), 0, (void *)lParam );
  1105. break;
  1106. case CB_GETLBTEXT:
  1107. if ( WINPROC_TestCBForStr( hwnd ))
  1108. {
  1109. LPARAM *ptr = (LPARAM *)lParam - 1;
  1110. result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff ) - 1;
  1111. HeapFree( GetProcessHeap(), 0, ptr );
  1112. }
  1113. break;
  1114. /* Multiline edit */
  1115. case EM_GETLINE:
  1116. {
  1117. LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lparam */
  1118. WORD len = *(WORD *)ptr;
  1119. if (len)
  1120. {
  1121. result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, result, (LPWSTR)*ptr, len );
  1122. if (result < len) ((LPWSTR)*ptr)[result] = 0;
  1123. }
  1124. HeapFree( GetProcessHeap(), 0, ptr );
  1125. }
  1126. break;
  1127. }
  1128. return result;
  1129. }
  1130. static UINT convert_handle_16_to_32(HANDLE16 src, unsigned int flags)
  1131. {
  1132. HANDLE dst;
  1133. UINT sz = GlobalSize16(src);
  1134. LPSTR ptr16, ptr32;
  1135. if (!(dst = GlobalAlloc(flags, sz)))
  1136. return 0;
  1137. ptr16 = GlobalLock16(src);
  1138. ptr32 = GlobalLock(dst);
  1139. if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr32, ptr16, sz);
  1140. GlobalUnlock16(src);
  1141. GlobalUnlock(dst);
  1142. return (UINT)dst;
  1143. }
  1144. /**********************************************************************
  1145. * WINPROC_MapMsg16To32A
  1146. *
  1147. * Map a message from 16- to 32-bit Ansi.
  1148. * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
  1149. */
  1150. INT WINPROC_MapMsg16To32A( HWND hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
  1151. WPARAM *pwparam32, LPARAM *plparam )
  1152. {
  1153. *pmsg32 = (UINT)msg16;
  1154. *pwparam32 = (WPARAM)wParam16;
  1155. switch(msg16)
  1156. {
  1157. case WM_ACTIVATE:
  1158. case WM_CHARTOITEM:
  1159. case WM_COMMAND:
  1160. case WM_VKEYTOITEM:
  1161. *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
  1162. *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
  1163. return 0;
  1164. case WM_HSCROLL:
  1165. case WM_VSCROLL:
  1166. *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
  1167. *plparam = (LPARAM)WIN_Handle32( HIWORD(*plparam) );
  1168. return 0;
  1169. case WM_CTLCOLOR:
  1170. if ( HIWORD(*plparam) > CTLCOLOR_STATIC ) return -1;
  1171. *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
  1172. *pwparam32 = (WPARAM)HDC_32(wParam16);
  1173. *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
  1174. return 0;
  1175. case WM_COMPAREITEM:
  1176. {
  1177. COMPAREITEMSTRUCT16* cis16 = MapSL(*plparam);
  1178. COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)
  1179. HeapAlloc(GetProcessHeap(), 0, sizeof(*cis));
  1180. if (!cis) return -1;
  1181. cis->CtlType = cis16->CtlType;
  1182. cis->CtlID = cis16->CtlID;
  1183. cis->hwndItem = WIN_Handle32( cis16->hwndItem );
  1184. cis->itemID1 = cis16->itemID1;
  1185. cis->itemData1 = cis16->itemData1;
  1186. cis->itemID2 = cis16->itemID2;
  1187. cis->itemData2 = cis16->itemData2;
  1188. cis->dwLocaleId = 0; /* FIXME */
  1189. *plparam = (LPARAM)cis;
  1190. }
  1191. return 1;
  1192. case WM_DELETEITEM:
  1193. {
  1194. DELETEITEMSTRUCT16* dis16 = MapSL(*plparam);
  1195. DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)
  1196. HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
  1197. if (!dis) return -1;
  1198. dis->CtlType = dis16->CtlType;
  1199. dis->CtlID = dis16->CtlID;
  1200. dis->hwndItem = WIN_Handle32( dis16->hwndItem );
  1201. dis->itemData = dis16->itemData;
  1202. *plparam = (LPARAM)dis;
  1203. }
  1204. return 1;
  1205. case WM_MEASUREITEM:
  1206. {
  1207. MEASUREITEMSTRUCT16* mis16 = MapSL(*plparam);
  1208. MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)
  1209. HeapAlloc(GetProcessHeap(), 0,
  1210. sizeof(*mis) + sizeof(LPARAM));
  1211. if (!mis) return -1;
  1212. mis->CtlType = mis16->CtlType;
  1213. mis->CtlID = mis16->CtlID;
  1214. mis->itemID = mis16->itemID;
  1215. mis->itemWidth = mis16->itemWidth;
  1216. mis->itemHeight = mis16->itemHeight;
  1217. mis->itemData = mis16->itemData;
  1218. *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
  1219. *plparam = (LPARAM)mis;
  1220. }
  1221. return 1;
  1222. case WM_DRAWITEM:
  1223. {
  1224. DRAWITEMSTRUCT16* dis16 = MapSL(*plparam);
  1225. DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT*)HeapAlloc(GetProcessHeap(), 0,
  1226. sizeof(*dis));
  1227. if (!dis) return -1;
  1228. dis->CtlType = dis16->CtlType;
  1229. dis->CtlID = dis16->CtlID;
  1230. dis->itemID = dis16->itemID;
  1231. dis->itemAction = dis16->itemAction;
  1232. dis->itemState = dis16->itemState;
  1233. dis->hwndItem = (dis->CtlType == ODT_MENU) ? (HWND)HMENU_32(dis16->hwndItem)
  1234. : WIN_Handle32( dis16->hwndItem );
  1235. dis->hDC = HDC_32(dis16->hDC);
  1236. dis->itemData = dis16->itemData;
  1237. dis->rcItem.left = dis16->rcItem.left;
  1238. dis->rcItem.top = dis16->rcItem.top;
  1239. dis->rcItem.right = dis16->rcItem.right;
  1240. dis->rcItem.bottom = dis16->rcItem.bottom;
  1241. *plparam = (LPARAM)dis;
  1242. }
  1243. return 1;
  1244. case WM_GETMINMAXINFO:
  1245. {
  1246. MINMAXINFO *mmi = (MINMAXINFO *)HeapAlloc( GetProcessHeap(), 0,
  1247. sizeof(*mmi) + sizeof(LPARAM));
  1248. if (!mmi) return -1;
  1249. MINMAXINFO16to32( MapSL(*plparam), mmi );
  1250. *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
  1251. *plparam = (LPARAM)mmi;
  1252. }
  1253. return 1;
  1254. case WM_GETTEXT:
  1255. case WM_SETTEXT:
  1256. case WM_WININICHANGE:
  1257. case WM_DEVMODECHANGE:
  1258. case WM_ASKCBFORMATNAME:
  1259. *plparam = (LPARAM)MapSL(*plparam);
  1260. return 0;
  1261. case WM_MDICREATE:
  1262. {
  1263. MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
  1264. MDICREATESTRUCTA *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
  1265. if (!cs) return -1;
  1266. MDICREATESTRUCT16to32A( cs16, cs );
  1267. cs->szTitle = MapSL(cs16->szTitle);
  1268. cs->szClass = MapSL(cs16->szClass);
  1269. *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
  1270. *plparam = (LPARAM)cs;
  1271. }
  1272. return 1;
  1273. case WM_MDIGETACTIVE:
  1274. *plparam = (LPARAM)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL) );
  1275. *(BOOL*)(*plparam) = 0;
  1276. return 1;
  1277. case WM_MDISETMENU:
  1278. if(wParam16) *pmsg32=WM_MDIREFRESHMENU;
  1279. *pwparam32 = (WPARAM)HMENU_32(LOWORD(*plparam));
  1280. *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
  1281. return 0;
  1282. case WM_MENUCHAR:
  1283. *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
  1284. *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
  1285. return 0;
  1286. case WM_MENUSELECT:
  1287. if((LOWORD(*plparam) & MF_POPUP) && (LOWORD(*plparam) != 0xFFFF))
  1288. {
  1289. HMENU hmenu=HMENU_32(HIWORD(*plparam));
  1290. UINT Pos=MENU_FindSubMenu( &hmenu, HMENU_32(wParam16));
  1291. if(Pos==0xFFFF) Pos=0; /* NO_SELECTED_ITEM */
  1292. *pwparam32 = MAKEWPARAM( Pos, LOWORD(*plparam) );
  1293. }
  1294. else *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
  1295. *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
  1296. return 0;
  1297. case WM_MDIACTIVATE:
  1298. if( *plparam )
  1299. {
  1300. *pwparam32 = (WPARAM)WIN_Handle32( HIWORD(*plparam) );
  1301. *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
  1302. }
  1303. else /* message sent to MDI client */
  1304. *pwparam32 = wParam16;
  1305. return 0;
  1306. case WM_NCCALCSIZE:
  1307. {
  1308. NCCALCSIZE_PARAMS16 *nc16;
  1309. NCCALCSIZE_PARAMS *nc;
  1310. nc = (NCCALCSIZE_PARAMS *)HeapAlloc( GetProcessHeap(), 0,
  1311. sizeof(*nc) + sizeof(LPARAM) );
  1312. if (!nc) return -1;
  1313. nc16 = MapSL(*plparam);
  1314. nc->rgrc[0].left = nc16->rgrc[0].left;
  1315. nc->rgrc[0].top = nc16->rgrc[0].top;
  1316. nc->rgrc[0].right = nc16->rgrc[0].right;
  1317. nc->rgrc[0].bottom = nc16->rgrc[0].bottom;
  1318. if (wParam16)
  1319. {
  1320. nc->lppos = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
  1321. sizeof(*nc->lppos) );
  1322. nc->rgrc[1].left = nc16->rgrc[1].left;
  1323. nc->rgrc[1].top = nc16->rgrc[1].top;
  1324. nc->rgrc[1].right = nc16->rgrc[1].right;
  1325. nc->rgrc[1].bottom = nc16->rgrc[1].bottom;
  1326. nc->rgrc[2].left = nc16->rgrc[2].left;
  1327. nc->rgrc[2].top = nc16->rgrc[2].top;
  1328. nc->rgrc[2].right = nc16->rgrc[2].right;
  1329. nc->rgrc[2].bottom = nc16->rgrc[2].bottom;
  1330. if (nc->lppos) WINDOWPOS16to32( MapSL(nc16->lppos), nc->lppos );
  1331. }
  1332. *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
  1333. *plparam = (LPARAM)nc;
  1334. }
  1335. return 1;
  1336. case WM_NCCREATE:
  1337. case WM_CREATE:
  1338. {
  1339. CREATESTRUCT16 *cs16 = MapSL(*plparam);
  1340. CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
  1341. sizeof(*cs) + sizeof(LPARAM) );
  1342. if (!cs) return -1;
  1343. CREATESTRUCT16to32A( cs16, cs );
  1344. cs->lpszName = MapSL(cs16->lpszName);
  1345. cs->lpszClass = MapSL(cs16->lpszClass);
  1346. if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
  1347. {
  1348. MDICREATESTRUCT16 *mdi_cs16;
  1349. MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)HeapAlloc(GetProcessHeap(), 0,
  1350. sizeof(*mdi_cs));
  1351. if (!mdi_cs)
  1352. {
  1353. HeapFree(GetProcessHeap(), 0, cs);
  1354. return -1;
  1355. }
  1356. mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs16->lpCreateParams);
  1357. MDICREATESTRUCT16to32A(mdi_cs16, mdi_cs);
  1358. mdi_cs->szTitle = MapSL(mdi_cs16->szTitle);
  1359. mdi_cs->szClass = MapSL(mdi_cs16->szClass);
  1360. cs->lpCreateParams = mdi_cs;
  1361. }
  1362. *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
  1363. *plparam = (LPARAM)cs;
  1364. }
  1365. return 1;
  1366. case WM_PARENTNOTIFY:
  1367. if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
  1368. {
  1369. *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
  1370. *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
  1371. }
  1372. return 0;
  1373. case WM_WINDOWPOSCHANGING:
  1374. case WM_WINDOWPOSCHANGED:
  1375. {
  1376. WINDOWPOS *wp = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
  1377. sizeof(*wp) + sizeof(LPARAM) );
  1378. if (!wp) return -1;
  1379. WINDOWPOS16to32( MapSL(*plparam), wp );
  1380. *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
  1381. *plparam = (LPARAM)wp;
  1382. }
  1383. return 1;
  1384. case WM_GETDLGCODE:
  1385. if (*plparam)
  1386. {
  1387. LPMSG16 msg16 = MapSL(*plparam);
  1388. LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
  1389. if (!msg32) return -1;
  1390. msg32->hwnd = WIN_Handle32( msg16->hwnd );
  1391. msg32->lParam = msg16->lParam;
  1392. msg32->time = msg16->time;
  1393. msg32->pt.x = msg16->pt.x;
  1394. msg32->pt.y = msg16->pt.y;
  1395. /* this is right, right? */
  1396. if (WINPROC_MapMsg16To32A( msg32->hwnd, msg16->message,msg16->wParam,
  1397. &msg32->message,&msg32->wParam,
  1398. &msg32->lParam)<0) {
  1399. HeapFree( GetProcessHeap(), 0, msg32 );
  1400. return -1;
  1401. }
  1402. *plparam = (LPARAM)msg32;
  1403. return 1;
  1404. }
  1405. else return 0;
  1406. case WM_NOTIFY:
  1407. *plparam = (LPARAM)MapSL(*plparam);
  1408. return 0;
  1409. case WM_ACTIVATEAPP:
  1410. /* We need this when SetActiveWindow sends a Sendmessage16() to
  1411. * a 32bit window. Might be superflous with 32bit interprocess
  1412. * message queues. */
  1413. if (*plparam) *plparam = HTASK_32( *plparam );
  1414. return 0;
  1415. case WM_NEXTMENU:
  1416. {
  1417. MDINEXTMENU *next = HeapAlloc( GetProcessHeap(), 0, sizeof(*next) );
  1418. if (!next) return -1;
  1419. next->hmenuIn = (HMENU)*plparam;
  1420. next->hmenuNext = 0;
  1421. next->hwndNext = 0;
  1422. *plparam = (LPARAM)next;
  1423. return 1;
  1424. }
  1425. case WM_PAINTCLIPBOARD:
  1426. case WM_SIZECLIPBOARD:
  1427. FIXME_(msg)("message %04x needs translation\n",msg16 );
  1428. return -1;
  1429. case WM_DDE_INITIATE:
  1430. case WM_DDE_TERMINATE:
  1431. case WM_DDE_UNADVISE:
  1432. case WM_DDE_REQUEST:
  1433. *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
  1434. return 0;
  1435. case WM_DDE_ADVISE:
  1436. case WM_DDE_DATA:
  1437. case WM_DDE_POKE:
  1438. {
  1439. HANDLE16 lo16;
  1440. ATOM hi;
  1441. UINT lo32 = 0;
  1442. *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
  1443. lo16 = LOWORD(*plparam);
  1444. hi = HIWORD(*plparam);
  1445. if (lo16 && !(lo32 = convert_handle_16_to_32(lo16, GMEM_DDESHARE)))
  1446. return -1;
  1447. *plparam = PackDDElParam(msg16, lo32, hi);
  1448. }
  1449. return 0; /* FIXME don't know how to free allocated memory (handle) !! */
  1450. case WM_DDE_ACK:
  1451. {
  1452. UINT lo, hi;
  1453. int flag = 0;
  1454. char buf[2];
  1455. *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
  1456. lo = LOWORD(*plparam);
  1457. hi = HIWORD(*plparam);
  1458. if (GlobalGetAtomNameA(hi, buf, 2) > 0) flag |= 1;
  1459. if (GlobalSize16(hi) != 0) flag |= 2;
  1460. switch (flag)
  1461. {
  1462. case 0:
  1463. if (hi)
  1464. {
  1465. MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
  1466. hi = 0;
  1467. }
  1468. break;
  1469. case 1:
  1470. break; /* atom, nothing to do */
  1471. case 3:
  1472. MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
  1473. /* fall thru */
  1474. case 2:
  1475. hi = convert_handle_16_to_32(hi, GMEM_DDESHARE);
  1476. break;
  1477. }
  1478. *plparam = PackDDElParam(WM_DDE_ACK, lo, hi);
  1479. }
  1480. return 0; /* FIXME don't know how to free allocated memory (handle) !! */
  1481. case WM_DDE_EXECUTE:
  1482. *plparam = convert_handle_16_to_32(*plparam, GMEM_DDESHARE);
  1483. return 0; /* FIXME don't know how to free allocated memory (handle) !! */
  1484. default: /* No translation needed */
  1485. return 0;
  1486. }
  1487. }
  1488. /**********************************************************************
  1489. * WINPROC_UnmapMsg16To32A
  1490. *
  1491. * Unmap a message that was mapped from 16- to 32-bit Ansi.
  1492. */
  1493. LRESULT WINPROC_UnmapMsg16To32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
  1494. LRESULT result )
  1495. {
  1496. switch(msg)
  1497. {
  1498. case WM_COMPAREITEM:
  1499. case WM_DELETEITEM:
  1500. case WM_DRAWITEM:
  1501. HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
  1502. break;
  1503. case WM_MEASUREITEM:
  1504. {
  1505. MEASUREITEMSTRUCT16 *mis16;
  1506. MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam;
  1507. lParam = *(LPARAM *)(mis + 1);
  1508. mis16 = MapSL(lParam);
  1509. mis16->itemWidth = (UINT16)mis->itemWidth;
  1510. mis16->itemHeight = (UINT16)mis->itemHeight;
  1511. HeapFree( GetProcessHeap(), 0, mis );
  1512. }
  1513. break;
  1514. case WM_GETMINMAXINFO:
  1515. {
  1516. MINMAXINFO *mmi = (MINMAXINFO *)lParam;
  1517. lParam = *(LPARAM *)(mmi + 1);
  1518. MINMAXINFO32to16( mmi, MapSL(lParam));
  1519. HeapFree( GetProcessHeap(), 0, mmi );
  1520. }
  1521. break;
  1522. case WM_MDICREATE:
  1523. {
  1524. MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
  1525. lParam = *(LPARAM *)(cs + 1);
  1526. MDICREATESTRUCT32Ato16( cs, MapSL(lParam) );
  1527. HeapFree( GetProcessHeap(), 0, cs );
  1528. }
  1529. break;
  1530. case WM_MDIGETACTIVE:
  1531. result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
  1532. HeapFree( GetProcessHeap(), 0, (BOOL *)lParam );
  1533. break;
  1534. case WM_NCCALCSIZE:
  1535. {
  1536. NCCALCSIZE_PARAMS16 *nc16;
  1537. NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lParam;
  1538. lParam = *(LPARAM *)(nc + 1);
  1539. nc16 = MapSL(lParam);
  1540. nc16->rgrc[0].left = nc->rgrc[0].left;
  1541. nc16->rgrc[0].top = nc->rgrc[0].top;
  1542. nc16->rgrc[0].right = nc->rgrc[0].right;
  1543. nc16->rgrc[0].bottom = nc->rgrc[0].bottom;
  1544. if (wParam)
  1545. {
  1546. nc16->rgrc[1].left = nc->rgrc[1].left;
  1547. nc16->rgrc[1].top = nc->rgrc[1].top;
  1548. nc16->rgrc[1].right = nc->rgrc[1].right;
  1549. nc16->rgrc[1].bottom = nc->rgrc[1].bottom;
  1550. nc16->rgrc[2].left = nc->rgrc[2].left;
  1551. nc16->rgrc[2].top = nc->rgrc[2].top;
  1552. nc16->rgrc[2].right = nc->rgrc[2].right;
  1553. nc16->rgrc[2].bottom = nc->rgrc[2].bottom;
  1554. if (nc->lppos)
  1555. {
  1556. WINDOWPOS32to16( nc->lppos, MapSL(nc16->lppos));
  1557. HeapFree( GetProcessHeap(), 0, nc->lppos );
  1558. }
  1559. }
  1560. HeapFree( GetProcessHeap(), 0, nc );
  1561. }
  1562. break;
  1563. case WM_NCCREATE:
  1564. case WM_CREATE:
  1565. {
  1566. CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
  1567. lParam = *(LPARAM *)(cs + 1);
  1568. CREATESTRUCT32Ato16( cs, MapSL(lParam) );
  1569. if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
  1570. HeapFree(GetProcessHeap(), 0, cs->lpCreateParams);
  1571. HeapFree( GetProcessHeap(), 0, cs );
  1572. }
  1573. break;
  1574. case WM_WINDOWPOSCHANGING:
  1575. case WM_WINDOWPOSCHANGED:
  1576. {
  1577. WINDOWPOS *wp = (WINDOWPOS *)lParam;
  1578. lParam = *(LPARAM *)(wp + 1);
  1579. WINDOWPOS32to16(wp, MapSL(lParam));
  1580. HeapFree( GetProcessHeap(), 0, wp );
  1581. }
  1582. break;
  1583. case WM_GETDLGCODE:
  1584. if (lParam)
  1585. {
  1586. LPMSG msg32 = (LPMSG)lParam;
  1587. WINPROC_UnmapMsg16To32A( hwnd, msg32->message, msg32->wParam, msg32->lParam,
  1588. result);
  1589. HeapFree( GetProcessHeap(), 0, msg32 );
  1590. }
  1591. break;
  1592. case WM_NEXTMENU:
  1593. {
  1594. MDINEXTMENU *next = (MDINEXTMENU *)lParam;
  1595. result = MAKELONG( HMENU_16(next->hmenuNext), HWND_16(next->hwndNext) );
  1596. HeapFree( GetProcessHeap(), 0, next );
  1597. }
  1598. break;
  1599. }
  1600. return result;
  1601. }
  1602. /**********************************************************************
  1603. * WINPROC_MapMsg16To32W
  1604. *
  1605. * Map a message from 16- to 32-bit Unicode.
  1606. * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
  1607. */
  1608. INT WINPROC_MapMsg16To32W( HWND hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
  1609. WPARAM *pwparam32, LPARAM *plparam )
  1610. {
  1611. BYTE ch;
  1612. WCHAR wch;
  1613. *pmsg32=(UINT)msg16;
  1614. *pwparam32 = (WPARAM)wParam16;
  1615. switch(msg16)
  1616. {
  1617. case WM_GETTEXT:
  1618. case WM_SETTEXT:
  1619. case WM_WININICHANGE:
  1620. case WM_DEVMODECHANGE:
  1621. case WM_ASKCBFORMATNAME:
  1622. *plparam = (LPARAM)MapSL(*plparam);
  1623. return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
  1624. case WM_GETTEXTLENGTH:
  1625. case CB_GETLBTEXTLEN:
  1626. case LB_GETTEXTLEN:
  1627. return 1; /* need to map result */
  1628. case WM_NCCREATE:
  1629. case WM_CREATE:
  1630. {
  1631. CREATESTRUCT16 *cs16 = MapSL(*plparam);
  1632. CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
  1633. sizeof(*cs) + sizeof(LPARAM) );
  1634. if (!cs) return -1;
  1635. CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
  1636. cs->lpszName = map_str_16_to_32W(cs16->lpszName);
  1637. cs->lpszClass = map_str_16_to_32W(cs16->lpszClass);
  1638. if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
  1639. {
  1640. MDICREATESTRUCT16 *mdi_cs16;
  1641. MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)HeapAlloc(GetProcessHeap(), 0,
  1642. sizeof(*mdi_cs));
  1643. if (!mdi_cs)
  1644. {
  1645. HeapFree(GetProcessHeap(), 0, cs);
  1646. return -1;
  1647. }
  1648. mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs16->lpCreateParams);
  1649. MDICREATESTRUCT16to32A(mdi_cs16, (MDICREATESTRUCTA *)mdi_cs);
  1650. mdi_cs->szTitle = map_str_16_to_32W(mdi_cs16->szTitle);
  1651. mdi_cs->szClass = map_str_16_to_32W(mdi_cs16->szClass);
  1652. cs->lpCreateParams = mdi_cs;
  1653. }
  1654. *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
  1655. *plparam = (LPARAM)cs;
  1656. }
  1657. return 1;
  1658. case WM_MDICREATE:
  1659. {
  1660. MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
  1661. MDICREATESTRUCTW *cs =
  1662. (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
  1663. sizeof(*cs) + sizeof(LPARAM) );
  1664. if (!cs) return -1;
  1665. MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
  1666. cs->szTitle = map_str_16_to_32W(cs16->szTitle);
  1667. cs->szClass = map_str_16_to_32W(cs16->szClass);
  1668. *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
  1669. *plparam = (LPARAM)cs;
  1670. }
  1671. return 1;
  1672. case WM_GETDLGCODE:
  1673. if (*plparam)
  1674. {
  1675. LPMSG16 msg16 = MapSL(*plparam);
  1676. LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
  1677. if (!msg32) return -1;
  1678. msg32->hwnd = WIN_Handle32( msg16->hwnd );
  1679. msg32->lParam = msg16->lParam;
  1680. msg32->time = msg16->time;
  1681. msg32->pt.x = msg16->pt.x;
  1682. msg32->pt.y = msg16->pt.y;
  1683. /* this is right, right? */
  1684. if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
  1685. &msg32->message,&msg32->wParam,
  1686. &msg32->lParam)<0) {
  1687. HeapFree( GetProcessHeap(), 0, msg32 );
  1688. return -1;
  1689. }
  1690. *plparam = (LPARAM)msg32;
  1691. return 1;
  1692. }
  1693. else return 0;
  1694. case WM_CHARTOITEM:
  1695. ch = wParam16;
  1696. MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
  1697. *pwparam32 = MAKEWPARAM( wch, HIWORD(*plparam) );
  1698. *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
  1699. return 0;
  1700. case WM_MENUCHAR:
  1701. ch = wParam16;
  1702. MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
  1703. *pwparam32 = MAKEWPARAM( wch, LOWORD(*plparam) );
  1704. *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
  1705. return 0;
  1706. case WM_CHAR:
  1707. case WM_DEADCHAR:
  1708. case WM_SYSCHAR:
  1709. case WM_SYSDEADCHAR:
  1710. ch = wParam16;
  1711. MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
  1712. *pwparam32 = wch;
  1713. return 0;
  1714. case WM_IME_CHAR:
  1715. return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
  1716. default: /* No Unicode translation needed */
  1717. return WINPROC_MapMsg16To32A( hwnd, msg16, wParam16, pmsg32,
  1718. pwparam32, plparam );
  1719. }
  1720. }
  1721. /**********************************************************************
  1722. * WINPROC_UnmapMsg16To32W
  1723. *
  1724. * Unmap a message that was mapped from 16- to 32-bit Unicode.
  1725. */
  1726. LRESULT WINPROC_UnmapMsg16To32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
  1727. LRESULT result )
  1728. {
  1729. switch(msg)
  1730. {
  1731. case WM_GETTEXT:
  1732. case WM_SETTEXT:
  1733. case WM_GETTEXTLENGTH:
  1734. case CB_GETLBTEXTLEN:
  1735. case LB_GETTEXTLEN:
  1736. case WM_ASKCBFORMATNAME:
  1737. return WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result );
  1738. case WM_NCCREATE:
  1739. case WM_CREATE:
  1740. {
  1741. CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
  1742. lParam = *(LPARAM *)(cs + 1);
  1743. CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs, MapSL(lParam) );
  1744. unmap_str_16_to_32W( cs->lpszName );
  1745. unmap_str_16_to_32W( cs->lpszClass );
  1746. if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
  1747. {
  1748. MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)cs->lpCreateParams;
  1749. unmap_str_16_to_32W( mdi_cs->szTitle );
  1750. unmap_str_16_to_32W( mdi_cs->szClass );
  1751. HeapFree(GetProcessHeap(), 0, cs->lpCreateParams);
  1752. }
  1753. HeapFree( GetProcessHeap(), 0, cs );
  1754. }
  1755. break;
  1756. case WM_MDICREATE:
  1757. {
  1758. MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
  1759. lParam = *(LPARAM *)(cs + 1);
  1760. MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs, MapSL(lParam) );
  1761. unmap_str_16_to_32W( cs->szTitle );
  1762. unmap_str_16_to_32W( cs->szClass );
  1763. HeapFree( GetProcessHeap(), 0, cs );
  1764. }
  1765. break;
  1766. case WM_GETDLGCODE:
  1767. if (lParam)
  1768. {
  1769. LPMSG msg32 = (LPMSG)lParam;
  1770. WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
  1771. result);
  1772. HeapFree( GetProcessHeap(), 0, msg32 );
  1773. }
  1774. break;
  1775. default:
  1776. return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
  1777. }
  1778. return result;
  1779. }
  1780. static HANDLE16 convert_handle_32_to_16(UINT src, unsigned int flags)
  1781. {
  1782. HANDLE16 dst;
  1783. UINT sz = GlobalSize((HANDLE)src);
  1784. LPSTR ptr16, ptr32;
  1785. if (!(dst = GlobalAlloc16(flags, sz)))
  1786. return 0;
  1787. ptr32 = GlobalLock((HANDLE)src);
  1788. ptr16 = GlobalLock16(dst);
  1789. if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr16, ptr32, sz);
  1790. GlobalUnlock((HANDLE)src);
  1791. GlobalUnlock16(dst);
  1792. return dst;
  1793. }
  1794. /**********************************************************************
  1795. * WINPROC_MapMsg32ATo16
  1796. *
  1797. * Map a message from 32-bit Ansi to 16-bit.
  1798. * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
  1799. */
  1800. INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
  1801. UINT16 *pmsg16, WPARAM16 *pwparam16,
  1802. LPARAM *plparam )
  1803. {
  1804. *pmsg16 = (UINT16)msg32;
  1805. *pwparam16 = (WPARAM16)LOWORD(wParam32);
  1806. switch(msg32)
  1807. {
  1808. case SBM_SETRANGE:
  1809. *pmsg16 = SBM_SETRANGE16;
  1810. *plparam = MAKELPARAM(wParam32, *plparam);
  1811. *pwparam16 = 0;
  1812. return 0;
  1813. case SBM_GETRANGE:
  1814. *pmsg16 = SBM_GETRANGE16;
  1815. return 1;
  1816. case BM_GETCHECK:
  1817. case BM_SETCHECK:
  1818. case BM_GETSTATE:
  1819. case BM_SETSTATE:
  1820. case BM_SETSTYLE:
  1821. *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
  1822. return 0;
  1823. case EM_GETSEL:
  1824. case EM_GETRECT:
  1825. case EM_SETRECT:
  1826. case EM_SETRECTNP:
  1827. case EM_SCROLL:
  1828. case EM_LINESCROLL:
  1829. case EM_SCROLLCARET:
  1830. case EM_GETMODIFY:
  1831. case EM_SETMODIFY:
  1832. case EM_GETLINECOUNT:
  1833. case EM_LINEINDEX:
  1834. case EM_SETHANDLE:
  1835. case EM_GETHANDLE:
  1836. case EM_GETTHUMB:
  1837. case EM_LINELENGTH:
  1838. case EM_REPLACESEL:
  1839. case EM_GETLINE:
  1840. case EM_LIMITTEXT:
  1841. case EM_CANUNDO:
  1842. case EM_UNDO:
  1843. case EM_FMTLINES:
  1844. case EM_LINEFROMCHAR:
  1845. case EM_SETTABSTOPS:
  1846. case EM_SETPASSWORDCHAR:
  1847. case EM_EMPTYUNDOBUFFER:
  1848. case EM_GETFIRSTVISIBLELINE:
  1849. case EM_SETREADONLY:
  1850. case EM_SETWORDBREAKPROC:
  1851. case EM_GETWORDBREAKPROC:
  1852. case EM_GETPASSWORDCHAR:
  1853. *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
  1854. return 0;
  1855. case LB_CARETOFF:
  1856. case LB_CARETON:
  1857. case LB_DELETESTRING:
  1858. case LB_GETANCHORINDEX:
  1859. case LB_GETCARETINDEX:
  1860. case LB_GETCOUNT:
  1861. case LB_GETCURSEL:
  1862. case LB_GETHORIZONTALEXTENT:
  1863. case LB_GETITEMDATA:
  1864. case LB_GETITEMHEIGHT:
  1865. case LB_GETSEL:
  1866. case LB_GETSELCOUNT:
  1867. case LB_GETTEXTLEN:
  1868. case LB_GETTOPINDEX:
  1869. case LB_RESETCONTENT:
  1870. case LB_SELITEMRANGE:
  1871. case LB_SELITEMRANGEEX:
  1872. case LB_SETANCHORINDEX:
  1873. case LB_SETCARETINDEX:
  1874. case LB_SETCOLUMNWIDTH:
  1875. case LB_SETCURSEL:
  1876. case LB_SETHORIZONTALEXTENT:
  1877. case LB_SETITEMDATA:
  1878. case LB_SETITEMHEIGHT:
  1879. case LB_SETSEL:
  1880. case LB_SETTOPINDEX:
  1881. *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
  1882. return 0;
  1883. case CB_DELETESTRING:
  1884. case CB_GETCOUNT:
  1885. case CB_GETLBTEXTLEN:
  1886. case CB_LIMITTEXT:
  1887. case CB_RESETCONTENT:
  1888. case CB_SETEDITSEL:
  1889. case CB_GETCURSEL:
  1890. case CB_SETCURSEL:
  1891. case CB_SHOWDROPDOWN:
  1892. case CB_SETITEMDATA:
  1893. case CB_SETITEMHEIGHT:
  1894. case CB_GETITEMHEIGHT:
  1895. case CB_SETEXTENDEDUI:
  1896. case CB_GETEXTENDEDUI:
  1897. case CB_GETDROPPEDSTATE:
  1898. *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
  1899. return 0;
  1900. case CB_GETEDITSEL:
  1901. *pmsg16 = CB_GETEDITSEL16;
  1902. return 1;
  1903. case LB_ADDSTRING:
  1904. case LB_FINDSTRING:
  1905. case LB_FINDSTRINGEXACT:
  1906. case LB_INSERTSTRING:
  1907. case LB_SELECTSTRING:
  1908. case LB_DIR:
  1909. case LB_ADDFILE:
  1910. *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
  1911. *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
  1912. return 1;
  1913. case CB_ADDSTRING:
  1914. case CB_FINDSTRING:
  1915. case CB_FINDSTRINGEXACT:
  1916. case CB_INSERTSTRING:
  1917. case CB_SELECTSTRING:
  1918. case CB_DIR:
  1919. *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
  1920. *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
  1921. return 1;
  1922. case LB_GETITEMRECT:
  1923. {
  1924. RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
  1925. if (!rect) return -1;
  1926. *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
  1927. *plparam = MapLS( rect );
  1928. }
  1929. *pmsg16 = LB_GETITEMRECT16;
  1930. return 1;
  1931. case LB_GETSELITEMS:
  1932. {
  1933. LPARAM *items; /* old LPARAM first, then *pwparam16 x INT16 entries */
  1934. *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
  1935. if (!(items = HeapAlloc( GetProcessHeap(), 0,
  1936. *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
  1937. *items++ = *plparam; /* Store the previous lParam */
  1938. *plparam = MapLS( items );
  1939. }
  1940. *pmsg16 = LB_GETSELITEMS16;
  1941. return 1;
  1942. case LB_SETTABSTOPS:
  1943. if (wParam32)
  1944. {
  1945. INT i;
  1946. LPINT16 stops;
  1947. *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
  1948. if (!(stops = HeapAlloc( GetProcessHeap(), 0,
  1949. *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
  1950. for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
  1951. *plparam = MapLS( stops );
  1952. return 1;
  1953. }
  1954. *pmsg16 = LB_SETTABSTOPS16;
  1955. return 0;
  1956. case CB_GETDROPPEDCONTROLRECT:
  1957. {
  1958. RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
  1959. if (!rect) return -1;
  1960. *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
  1961. *plparam = (LPARAM)MapLS(rect);
  1962. }
  1963. *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
  1964. return 1;
  1965. case LB_GETTEXT:
  1966. *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
  1967. *pmsg16 = LB_GETTEXT16;
  1968. return 1;
  1969. case CB_GETLBTEXT:
  1970. *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
  1971. *pmsg16 = CB_GETLBTEXT16;
  1972. return 1;
  1973. case EM_SETSEL:
  1974. *pwparam16 = 0;
  1975. *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
  1976. *pmsg16 = EM_SETSEL16;
  1977. return 0;
  1978. case WM_ACTIVATE:
  1979. case WM_CHARTOITEM:
  1980. case WM_COMMAND:
  1981. case WM_VKEYTOITEM:
  1982. *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
  1983. return 0;
  1984. case WM_HSCROLL:
  1985. case WM_VSCROLL:
  1986. *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
  1987. return 0;
  1988. case WM_CTLCOLORMSGBOX:
  1989. case WM_CTLCOLOREDIT:
  1990. case WM_CTLCOLORLISTBOX:
  1991. case WM_CTLCOLORBTN:
  1992. case WM_CTLCOLORDLG:
  1993. case WM_CTLCOLORSCROLLBAR:
  1994. case WM_CTLCOLORSTATIC:
  1995. *pmsg16 = WM_CTLCOLOR;
  1996. *plparam = MAKELPARAM( (HWND16)*plparam,
  1997. (WORD)msg32 - WM_CTLCOLORMSGBOX );
  1998. return 0;
  1999. case WM_COMPAREITEM:
  2000. {
  2001. COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
  2002. COMPAREITEMSTRUCT16 *cis = HeapAlloc( GetProcessHeap(), 0, sizeof(COMPAREITEMSTRUCT16));
  2003. if (!cis) return -1;
  2004. cis->CtlType = (UINT16)cis32->CtlType;
  2005. cis->CtlID = (UINT16)cis32->CtlID;
  2006. cis->hwndItem = HWND_16( cis32->hwndItem );
  2007. cis->itemID1 = (UINT16)cis32->itemID1;
  2008. cis->itemData1 = cis32->itemData1;
  2009. cis->itemID2 = (UINT16)cis32->itemID2;
  2010. cis->itemData2 = cis32->itemData2;
  2011. *plparam = MapLS( cis );
  2012. }
  2013. return 1;
  2014. case WM_DELETEITEM:
  2015. {
  2016. DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
  2017. DELETEITEMSTRUCT16 *dis = HeapAlloc( GetProcessHeap(), 0, sizeof(DELETEITEMSTRUCT16) );
  2018. if (!dis) return -1;
  2019. dis->CtlType = (UINT16)dis32->CtlType;
  2020. dis->CtlID = (UINT16)dis32->CtlID;
  2021. dis->itemID = (UINT16)dis32->itemID;
  2022. dis->hwndItem = (dis->CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
  2023. : HWND_16( dis32->hwndItem );
  2024. dis->itemData = dis32->itemData;
  2025. *plparam = MapLS( dis );
  2026. }
  2027. return 1;
  2028. case WM_DRAWITEM:
  2029. {
  2030. DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
  2031. DRAWITEMSTRUCT16 *dis = HeapAlloc( GetProcessHeap(), 0, sizeof(DRAWITEMSTRUCT16) );
  2032. if (!dis) return -1;
  2033. dis->CtlType = (UINT16)dis32->CtlType;
  2034. dis->CtlID = (UINT16)dis32->CtlID;
  2035. dis->itemID = (UINT16)dis32->itemID;
  2036. dis->itemAction = (UINT16)dis32->itemAction;
  2037. dis->itemState = (UINT16)dis32->itemState;
  2038. dis->hwndItem = HWND_16( dis32->hwndItem );
  2039. dis->hDC = HDC_16(dis32->hDC);
  2040. dis->itemData = dis32->itemData;
  2041. dis->rcItem.left = dis32->rcItem.left;
  2042. dis->rcItem.top = dis32->rcItem.top;
  2043. dis->rcItem.right = dis32->rcItem.right;
  2044. dis->rcItem.bottom = dis32->rcItem.bottom;
  2045. *plparam = MapLS( dis );
  2046. }
  2047. return 1;
  2048. case WM_MEASUREITEM:
  2049. {
  2050. MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
  2051. MEASUREITEMSTRUCT16 *mis = HeapAlloc( GetProcessHeap(), 0, sizeof(*mis)+sizeof(LPARAM));
  2052. if (!mis) return -1;
  2053. mis->CtlType = (UINT16)mis32->CtlType;
  2054. mis->CtlID = (UINT16)mis32->CtlID;
  2055. mis->itemID = (UINT16)mis32->itemID;
  2056. mis->itemWidth = (UINT16)mis32->itemWidth;
  2057. mis->itemHeight = (UINT16)mis32->itemHeight;
  2058. mis->itemData = mis32->itemData;
  2059. *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
  2060. *plparam = MapLS( mis );
  2061. }
  2062. return 1;
  2063. case WM_GETMINMAXINFO:
  2064. {
  2065. MINMAXINFO16 *mmi = HeapAlloc( GetProcessHeap(), 0, sizeof(*mmi) + sizeof(LPARAM) );
  2066. if (!mmi) return -1;
  2067. MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
  2068. *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
  2069. *plparam = MapLS( mmi );
  2070. }
  2071. return 1;
  2072. case WM_GETTEXT:
  2073. case WM_ASKCBFORMATNAME:
  2074. {
  2075. LPARAM *str; /* store LPARAM, then *pwparam16 char space */
  2076. *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
  2077. if (!(str = HeapAlloc( GetProcessHeap(), 0, *pwparam16 + sizeof(LPARAM)))) return -1;
  2078. *str++ = *plparam; /* Store the previous lParam */
  2079. *plparam = MapLS( str );
  2080. }
  2081. return 1;
  2082. case WM_MDICREATE:
  2083. {
  2084. MDICREATESTRUCT16 *cs;
  2085. MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
  2086. if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16) ))) return -1;
  2087. MDICREATESTRUCT32Ato16( cs32, cs );
  2088. cs->szTitle = MapLS( cs32->szTitle );
  2089. cs->szClass = MapLS( cs32->szClass );
  2090. *plparam = MapLS( cs );
  2091. }
  2092. return 1;
  2093. case WM_MDIGETACTIVE:
  2094. return 1;
  2095. case WM_MDISETMENU:
  2096. *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
  2097. (HMENU16)LOWORD(*plparam) );
  2098. *pwparam16 = (*plparam == 0);
  2099. return 0;
  2100. case WM_MENUSELECT:
  2101. if(HIWORD(wParam32) & MF_POPUP)
  2102. {
  2103. HMENU hmenu;
  2104. if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
  2105. {
  2106. if((hmenu = GetSubMenu((HMENU)*plparam, *pwparam16)))
  2107. *pwparam16=HMENU_16(hmenu);
  2108. }
  2109. }
  2110. /* fall through */
  2111. case WM_MENUCHAR:
  2112. *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
  2113. return 0;
  2114. case WM_MDIACTIVATE:
  2115. if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
  2116. {
  2117. *pwparam16 = ((HWND)*plparam == hwnd);
  2118. *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
  2119. (HWND16)LOWORD(wParam32) );
  2120. }
  2121. else
  2122. {
  2123. *pwparam16 = HWND_16( (HWND)wParam32 );
  2124. *plparam = 0;
  2125. }
  2126. return 0;
  2127. case WM_NCCALCSIZE:
  2128. {
  2129. NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
  2130. NCCALCSIZE_PARAMS16 *nc = HeapAlloc( GetProcessHeap(), 0, sizeof(*nc) + sizeof(LPARAM));
  2131. if (!nc) return -1;
  2132. nc->rgrc[0].left = nc32->rgrc[0].left;
  2133. nc->rgrc[0].top = nc32->rgrc[0].top;
  2134. nc->rgrc[0].right = nc32->rgrc[0].right;
  2135. nc->rgrc[0].bottom = nc32->rgrc[0].bottom;
  2136. if (wParam32)
  2137. {
  2138. WINDOWPOS16 *wp;
  2139. nc->rgrc[1].left = nc32->rgrc[1].left;
  2140. nc->rgrc[1].top = nc32->rgrc[1].top;
  2141. nc->rgrc[1].right = nc32->rgrc[1].right;
  2142. nc->rgrc[1].bottom = nc32->rgrc[1].bottom;
  2143. nc->rgrc[2].left = nc32->rgrc[2].left;
  2144. nc->rgrc[2].top = nc32->rgrc[2].top;
  2145. nc->rgrc[2].right = nc32->rgrc[2].right;
  2146. nc->rgrc[2].bottom = nc32->rgrc[2].bottom;
  2147. if (!(wp = HeapAlloc( GetProcessHeap(), 0, sizeof(WINDOWPOS16) )))
  2148. {
  2149. HeapFree( GetProcessHeap(), 0, nc );
  2150. return -1;
  2151. }
  2152. WINDOWPOS32to16( nc32->lppos, wp );
  2153. nc->lppos = MapLS( wp );
  2154. }
  2155. *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
  2156. *plparam = MapLS( nc );
  2157. }
  2158. return 1;
  2159. case WM_NCCREATE:
  2160. case WM_CREATE:
  2161. {
  2162. CREATESTRUCT16 *cs;
  2163. CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
  2164. if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16) ))) return -1;
  2165. CREATESTRUCT32Ato16( cs32, cs );
  2166. cs->lpszName = MapLS( cs32->lpszName );
  2167. cs->lpszClass = MapLS( cs32->lpszClass );
  2168. if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
  2169. {
  2170. MDICREATESTRUCT16 *mdi_cs16;
  2171. MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs32->lpCreateParams;
  2172. mdi_cs16 = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs16));
  2173. if (!mdi_cs16)
  2174. {
  2175. HeapFree(GetProcessHeap(), 0, cs);
  2176. return -1;
  2177. }
  2178. MDICREATESTRUCT32Ato16(mdi_cs, mdi_cs16);
  2179. mdi_cs16->szTitle = MapLS( mdi_cs->szTitle );
  2180. mdi_cs16->szClass = MapLS( mdi_cs->szClass );
  2181. cs->lpCreateParams = MapLS( mdi_cs16 );
  2182. }
  2183. *plparam = MapLS( cs );
  2184. }
  2185. return 1;
  2186. case WM_PARENTNOTIFY:
  2187. if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
  2188. *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
  2189. /* else nothing to do */
  2190. return 0;
  2191. case WM_NOTIFY:
  2192. *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
  2193. return 1;
  2194. case WM_SETTEXT:
  2195. case WM_WININICHANGE:
  2196. case WM_DEVMODECHANGE:
  2197. *plparam = MapLS( (LPSTR)*plparam );
  2198. return 1;
  2199. case WM_WINDOWPOSCHANGING:
  2200. case WM_WINDOWPOSCHANGED:
  2201. {
  2202. WINDOWPOS16 *wp = HeapAlloc( GetProcessHeap(), 0, sizeof(*wp) + sizeof(LPARAM) );
  2203. if (!wp) return -1;
  2204. WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
  2205. *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
  2206. *plparam = MapLS( wp );
  2207. }
  2208. return 1;
  2209. case WM_GETDLGCODE:
  2210. if (*plparam) {
  2211. LPMSG msg32 = (LPMSG) *plparam;
  2212. LPMSG16 msg16 = HeapAlloc( GetProcessHeap(), 0, sizeof(MSG16) );
  2213. if (!msg16) return -1;
  2214. msg16->hwnd = HWND_16( msg32->hwnd );
  2215. msg16->lParam = msg32->lParam;
  2216. msg16->time = msg32->time;
  2217. msg16->pt.x = msg32->pt.x;
  2218. msg16->pt.y = msg32->pt.y;
  2219. /* this is right, right? */
  2220. if (WINPROC_MapMsg32ATo16(msg32->hwnd,msg32->message,msg32->wParam,
  2221. &msg16->message,&msg16->wParam, &msg16->lParam)<0)
  2222. {
  2223. HeapFree( GetProcessHeap(), 0, msg16 );
  2224. return -1;
  2225. }
  2226. *plparam = MapLS( msg16 );
  2227. return 1;
  2228. }
  2229. return 0;
  2230. case WM_ACTIVATEAPP:
  2231. if (*plparam) *plparam = HTASK_16( (HANDLE)*plparam );
  2232. return 0;
  2233. case WM_NEXTMENU:
  2234. {
  2235. MDINEXTMENU *next = (MDINEXTMENU *)*plparam;
  2236. *plparam = (LPARAM)next->hmenuIn;
  2237. return 1;
  2238. }
  2239. case WM_PAINT:
  2240. if (IsIconic( hwnd ) && GetClassLongW( hwnd, GCL_HICON ))
  2241. {
  2242. *pmsg16 = WM_PAINTICON;
  2243. *pwparam16 = 1;
  2244. }
  2245. return 0;
  2246. case WM_ERASEBKGND:
  2247. if (IsIconic( hwnd ) && GetClassLongW( hwnd, GCL_HICON ))
  2248. *pmsg16 = WM_ICONERASEBKGND;
  2249. return 0;
  2250. case WM_PAINTCLIPBOARD:
  2251. case WM_SIZECLIPBOARD:
  2252. FIXME_(msg)("message %04x needs translation\n", msg32 );
  2253. return -1;
  2254. /* following messages should not be sent to 16-bit apps */
  2255. case WM_SIZING:
  2256. case WM_MOVING:
  2257. case WM_CAPTURECHANGED:
  2258. case WM_STYLECHANGING:
  2259. case WM_STYLECHANGED:
  2260. return -1;
  2261. case WM_DDE_INITIATE:
  2262. case WM_DDE_TERMINATE:
  2263. case WM_DDE_UNADVISE:
  2264. case WM_DDE_REQUEST:
  2265. *pwparam16 = HWND_16((HWND)wParam32);
  2266. return 0;
  2267. case WM_DDE_ADVISE:
  2268. case WM_DDE_DATA:
  2269. case WM_DDE_POKE:
  2270. {
  2271. UINT lo32, hi;
  2272. HANDLE16 lo16 = 0;
  2273. *pwparam16 = HWND_16((HWND)wParam32);
  2274. UnpackDDElParam(msg32, *plparam, &lo32, &hi);
  2275. if (lo32 && !(lo16 = convert_handle_32_to_16(lo32, GMEM_DDESHARE)))
  2276. return -1;
  2277. *plparam = MAKELPARAM(lo16, hi);
  2278. }
  2279. return 0; /* FIXME don't know how to free allocated memory (handle) !! */
  2280. case WM_DDE_ACK:
  2281. {
  2282. UINT lo, hi;
  2283. int flag = 0;
  2284. char buf[2];
  2285. *pwparam16 = HWND_16((HWND)wParam32);
  2286. UnpackDDElParam(msg32, *plparam, &lo, &hi);
  2287. if (GlobalGetAtomNameA((ATOM)hi, buf, sizeof(buf)) > 0) flag |= 1;
  2288. if (GlobalSize((HANDLE)hi) != 0) flag |= 2;
  2289. switch (flag)
  2290. {
  2291. case 0:
  2292. if (hi)
  2293. {
  2294. MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
  2295. hi = 0;
  2296. }
  2297. break;
  2298. case 1:
  2299. break; /* atom, nothing to do */
  2300. case 3:
  2301. MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
  2302. /* fall thru */
  2303. case 2:
  2304. hi = convert_handle_32_to_16(hi, GMEM_DDESHARE);
  2305. break;
  2306. }
  2307. *plparam = MAKELPARAM(lo, hi);
  2308. }
  2309. return 0; /* FIXME don't know how to free allocated memory (handle) !! */
  2310. case WM_DDE_EXECUTE:
  2311. *plparam = convert_handle_32_to_16(*plparam, GMEM_DDESHARE);
  2312. return 0; /* FIXME don't know how to free allocated memory (handle) !! */
  2313. default: /* No translation needed */
  2314. return 0;
  2315. }
  2316. }
  2317. /**********************************************************************
  2318. * WINPROC_UnmapMsg32ATo16
  2319. *
  2320. * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
  2321. */
  2322. void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
  2323. MSGPARAM16* p16 )
  2324. {
  2325. switch(msg)
  2326. {
  2327. case SBM_GETRANGE:
  2328. *(LPINT)wParam = LOWORD(p16->lResult);
  2329. *(LPINT)lParam = HIWORD(p16->lResult);
  2330. break;
  2331. case LB_ADDFILE:
  2332. case LB_ADDSTRING:
  2333. case LB_DIR:
  2334. case LB_FINDSTRING:
  2335. case LB_FINDSTRINGEXACT:
  2336. case LB_INSERTSTRING:
  2337. case LB_SELECTSTRING:
  2338. case LB_GETTEXT:
  2339. case CB_ADDSTRING:
  2340. case CB_FINDSTRING:
  2341. case CB_FINDSTRINGEXACT:
  2342. case CB_INSERTSTRING:
  2343. case CB_SELECTSTRING:
  2344. case CB_DIR:
  2345. case CB_GETLBTEXT:
  2346. case WM_SETTEXT:
  2347. case WM_WININICHANGE:
  2348. case WM_DEVMODECHANGE:
  2349. UnMapLS( (SEGPTR)p16->lParam );
  2350. break;
  2351. case LB_SETTABSTOPS:
  2352. case WM_COMPAREITEM:
  2353. case WM_DELETEITEM:
  2354. case WM_DRAWITEM:
  2355. {
  2356. void *ptr = MapSL( p16->lParam );
  2357. UnMapLS( p16->lParam );
  2358. HeapFree( GetProcessHeap(), 0, ptr );
  2359. }
  2360. break;
  2361. case CB_GETDROPPEDCONTROLRECT:
  2362. case LB_GETITEMRECT:
  2363. {
  2364. RECT *r32;
  2365. RECT16 *rect = MapSL(p16->lParam);
  2366. UnMapLS( p16->lParam );
  2367. p16->lParam = *(LPARAM *)(rect + 1);
  2368. r32 = (RECT *)p16->lParam;
  2369. r32->left = rect->left;
  2370. r32->top = rect->top;
  2371. r32->right = rect->right;
  2372. r32->bottom = rect->bottom;
  2373. HeapFree( GetProcessHeap(), 0, rect );
  2374. }
  2375. break;
  2376. case LB_GETSELITEMS:
  2377. {
  2378. INT i;
  2379. LPINT16 items = MapSL(p16->lParam);
  2380. UnMapLS( p16->lParam );
  2381. p16->lParam = *((LPARAM *)items - 1);
  2382. for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
  2383. HeapFree( GetProcessHeap(), 0, (LPARAM *)items - 1 );
  2384. }
  2385. break;
  2386. case CB_GETEDITSEL:
  2387. if( wParam )
  2388. *((PUINT)(wParam)) = LOWORD(p16->lResult);
  2389. if( lParam )
  2390. *((PUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
  2391. break;
  2392. case WM_MEASUREITEM:
  2393. {
  2394. MEASUREITEMSTRUCT16 *mis = MapSL(p16->lParam);
  2395. MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
  2396. mis32->itemWidth = mis->itemWidth;
  2397. mis32->itemHeight = mis->itemHeight;
  2398. UnMapLS( p16->lParam );
  2399. HeapFree( GetProcessHeap(), 0, mis );
  2400. }
  2401. break;
  2402. case WM_GETMINMAXINFO:
  2403. {
  2404. MINMAXINFO16 *mmi = MapSL(p16->lParam);
  2405. UnMapLS( p16->lParam );
  2406. p16->lParam = *(LPARAM *)(mmi + 1);
  2407. MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
  2408. HeapFree( GetProcessHeap(), 0, mmi );
  2409. }
  2410. break;
  2411. case WM_GETTEXT:
  2412. case WM_ASKCBFORMATNAME:
  2413. {
  2414. LPSTR str = MapSL(p16->lParam);
  2415. UnMapLS( p16->lParam );
  2416. p16->lParam = *((LPARAM *)str - 1);
  2417. lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
  2418. HeapFree( GetProcessHeap(), 0, (LPARAM *)str - 1 );
  2419. }
  2420. break;
  2421. case WM_MDICREATE:
  2422. {
  2423. MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
  2424. UnMapLS( cs->szTitle );
  2425. UnMapLS( cs->szClass );
  2426. UnMapLS( p16->lParam );
  2427. HeapFree( GetProcessHeap(), 0, cs );
  2428. }
  2429. break;
  2430. case WM_MDIGETACTIVE:
  2431. if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
  2432. p16->lResult = (LRESULT)WIN_Handle32( LOWORD(p16->lResult) );
  2433. break;
  2434. case WM_NCCALCSIZE:
  2435. {
  2436. NCCALCSIZE_PARAMS *nc32;
  2437. NCCALCSIZE_PARAMS16 *nc = MapSL(p16->lParam);
  2438. UnMapLS( p16->lParam );
  2439. p16->lParam = *(LPARAM *)(nc + 1);
  2440. nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
  2441. nc32->rgrc[0].left = nc->rgrc[0].left;
  2442. nc32->rgrc[0].top = nc->rgrc[0].top;
  2443. nc32->rgrc[0].right = nc->rgrc[0].right;
  2444. nc32->rgrc[0].bottom = nc->rgrc[0].bottom;
  2445. if (p16->wParam)
  2446. {
  2447. WINDOWPOS16 *pos = MapSL(nc->lppos);
  2448. UnMapLS( nc->lppos );
  2449. nc32->rgrc[1].left = nc->rgrc[1].left;
  2450. nc32->rgrc[1].top = nc->rgrc[1].top;
  2451. nc32->rgrc[1].right = nc->rgrc[1].right;
  2452. nc32->rgrc[1].bottom = nc->rgrc[1].bottom;
  2453. nc32->rgrc[2].left = nc->rgrc[2].left;
  2454. nc32->rgrc[2].top = nc->rgrc[2].top;
  2455. nc32->rgrc[2].right = nc->rgrc[2].right;
  2456. nc32->rgrc[2].bottom = nc->rgrc[2].bottom;
  2457. WINDOWPOS16to32( pos, nc32->lppos );
  2458. HeapFree( GetProcessHeap(), 0, pos );
  2459. }
  2460. HeapFree( GetProcessHeap(), 0, nc );
  2461. }
  2462. break;
  2463. case WM_NCCREATE:
  2464. case WM_CREATE:
  2465. {
  2466. CREATESTRUCT16 *cs = MapSL(p16->lParam);
  2467. UnMapLS( p16->lParam );
  2468. UnMapLS( cs->lpszName );
  2469. UnMapLS( cs->lpszClass );
  2470. if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
  2471. {
  2472. MDICREATESTRUCT16 *mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs->lpCreateParams);
  2473. UnMapLS( cs->lpCreateParams );
  2474. UnMapLS( mdi_cs16->szTitle );
  2475. UnMapLS( mdi_cs16->szClass );
  2476. HeapFree(GetProcessHeap(), 0, mdi_cs16);
  2477. }
  2478. HeapFree( GetProcessHeap(), 0, cs );
  2479. }
  2480. break;
  2481. case WM_WINDOWPOSCHANGING:
  2482. case WM_WINDOWPOSCHANGED:
  2483. {
  2484. WINDOWPOS16 *wp = MapSL(p16->lParam);
  2485. UnMapLS( p16->lParam );
  2486. p16->lParam = *(LPARAM *)(wp + 1);
  2487. WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
  2488. HeapFree( GetProcessHeap(), 0, wp );
  2489. }
  2490. break;
  2491. case WM_NOTIFY:
  2492. UnMapLS(p16->lParam);
  2493. break;
  2494. case WM_GETDLGCODE:
  2495. if (p16->lParam)
  2496. {
  2497. LPMSG16 msg16 = MapSL(p16->lParam);
  2498. MSGPARAM16 msgp16;
  2499. UnMapLS( p16->lParam );
  2500. msgp16.wParam=msg16->wParam;
  2501. msgp16.lParam=msg16->lParam;
  2502. WINPROC_UnmapMsg32ATo16(((LPMSG)lParam)->hwnd, ((LPMSG)lParam)->message,
  2503. ((LPMSG)lParam)->wParam, ((LPMSG)lParam)->lParam,
  2504. &msgp16 );
  2505. HeapFree( GetProcessHeap(), 0, msg16 );
  2506. }
  2507. break;
  2508. case WM_NEXTMENU:
  2509. {
  2510. MDINEXTMENU *next = (MDINEXTMENU *)lParam;
  2511. next->hmenuNext = HMENU_32( LOWORD(p16->lResult) );
  2512. next->hwndNext = WIN_Handle32( HIWORD(p16->lResult) );
  2513. p16->lResult = 0;
  2514. }
  2515. break;
  2516. }
  2517. }
  2518. /**********************************************************************
  2519. * WINPROC_MapMsg32WTo16
  2520. *
  2521. * Map a message from 32-bit Unicode to 16-bit.
  2522. * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
  2523. */
  2524. INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
  2525. UINT16 *pmsg16, WPARAM16 *pwparam16,
  2526. LPARAM *plparam )
  2527. {
  2528. BYTE ch;
  2529. WCHAR wch;
  2530. *pmsg16 = LOWORD(msg32);
  2531. *pwparam16 = LOWORD(wParam32);
  2532. switch(msg32)
  2533. {
  2534. case LB_ADDSTRING:
  2535. case LB_FINDSTRING:
  2536. case LB_FINDSTRINGEXACT:
  2537. case LB_INSERTSTRING:
  2538. case LB_SELECTSTRING:
  2539. case LB_DIR:
  2540. case LB_ADDFILE:
  2541. *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
  2542. *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
  2543. return 1;
  2544. case CB_ADDSTRING:
  2545. case CB_FINDSTRING:
  2546. case CB_FINDSTRINGEXACT:
  2547. case CB_INSERTSTRING:
  2548. case CB_SELECTSTRING:
  2549. case CB_DIR:
  2550. *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
  2551. *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
  2552. return 1;
  2553. case WM_NCCREATE:
  2554. case WM_CREATE:
  2555. {
  2556. CREATESTRUCT16 *cs;
  2557. CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
  2558. if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16) ))) return -1;
  2559. CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
  2560. cs->lpszName = map_str_32W_to_16( cs32->lpszName );
  2561. cs->lpszClass = map_str_32W_to_16( cs32->lpszClass );
  2562. if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
  2563. {
  2564. MDICREATESTRUCT16 *mdi_cs16;
  2565. MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)cs32->lpCreateParams;
  2566. mdi_cs16 = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs16));
  2567. if (!mdi_cs16)
  2568. {
  2569. HeapFree(GetProcessHeap(), 0, cs);
  2570. return -1;
  2571. }
  2572. MDICREATESTRUCT32Ato16((MDICREATESTRUCTA *)mdi_cs, mdi_cs16);
  2573. mdi_cs16->szTitle = map_str_32W_to_16(mdi_cs->szTitle);
  2574. mdi_cs16->szClass = map_str_32W_to_16(mdi_cs->szClass);
  2575. cs->lpCreateParams = MapLS(mdi_cs16);
  2576. }
  2577. *plparam = MapLS(cs);
  2578. }
  2579. return 1;
  2580. case WM_MDICREATE:
  2581. {
  2582. MDICREATESTRUCT16 *cs;
  2583. MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
  2584. if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16) ))) return -1;
  2585. MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
  2586. cs->szTitle = map_str_32W_to_16( cs32->szTitle );
  2587. cs->szClass = map_str_32W_to_16( cs32->szClass );
  2588. *plparam = MapLS(cs);
  2589. }
  2590. return 1;
  2591. case WM_SETTEXT:
  2592. case WM_WININICHANGE:
  2593. case WM_DEVMODECHANGE:
  2594. *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
  2595. return 1;
  2596. case LB_GETTEXT:
  2597. if ( WINPROC_TestLBForStr( hwnd ))
  2598. {
  2599. LPSTR str = HeapAlloc( GetProcessHeap(), 0, 256 ); /* FIXME: fixed sized buffer */
  2600. if (!str) return -1;
  2601. *pmsg16 = LB_GETTEXT16;
  2602. *plparam = (LPARAM)MapLS(str);
  2603. }
  2604. return 1;
  2605. case CB_GETLBTEXT:
  2606. if ( WINPROC_TestCBForStr( hwnd ))
  2607. {
  2608. LPSTR str = HeapAlloc( GetProcessHeap(), 0, 256 ); /* FIXME: fixed sized buffer */
  2609. if (!str) return -1;
  2610. *pmsg16 = CB_GETLBTEXT16;
  2611. *plparam = (LPARAM)MapLS(str);
  2612. }
  2613. return 1;
  2614. case WM_CHARTOITEM:
  2615. wch = LOWORD(wParam32);
  2616. WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
  2617. *pwparam16 = ch;
  2618. *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
  2619. return 0;
  2620. case WM_MENUCHAR:
  2621. wch = LOWORD(wParam32);
  2622. WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
  2623. *pwparam16 = ch;
  2624. *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
  2625. return 0;
  2626. case WM_CHAR:
  2627. case WM_DEADCHAR:
  2628. case WM_SYSCHAR:
  2629. case WM_SYSDEADCHAR:
  2630. wch = wParam32;
  2631. WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
  2632. *pwparam16 = ch;
  2633. return 0;
  2634. case WM_IME_CHAR:
  2635. {
  2636. BYTE ch[2];
  2637. wch = wParam32;
  2638. if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, ch, 2, NULL, NULL ) == 2)
  2639. *pwparam16 = (ch[0] << 8) | ch[1];
  2640. else
  2641. *pwparam16 = ch[0];
  2642. }
  2643. return 0;
  2644. default: /* No Unicode translation needed (?) */
  2645. return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
  2646. pwparam16, plparam );
  2647. }
  2648. }
  2649. /**********************************************************************
  2650. * WINPROC_UnmapMsg32WTo16
  2651. *
  2652. * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
  2653. */
  2654. void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
  2655. MSGPARAM16* p16 )
  2656. {
  2657. switch(msg)
  2658. {
  2659. case LB_ADDSTRING:
  2660. case LB_FINDSTRING:
  2661. case LB_FINDSTRINGEXACT:
  2662. case LB_INSERTSTRING:
  2663. case LB_SELECTSTRING:
  2664. case LB_DIR:
  2665. case LB_ADDFILE:
  2666. case CB_ADDSTRING:
  2667. case CB_FINDSTRING:
  2668. case CB_FINDSTRINGEXACT:
  2669. case CB_INSERTSTRING:
  2670. case CB_SELECTSTRING:
  2671. case CB_DIR:
  2672. case WM_SETTEXT:
  2673. case WM_WININICHANGE:
  2674. case WM_DEVMODECHANGE:
  2675. unmap_str_32W_to_16( p16->lParam );
  2676. break;
  2677. case WM_NCCREATE:
  2678. case WM_CREATE:
  2679. {
  2680. CREATESTRUCT16 *cs = MapSL(p16->lParam);
  2681. UnMapLS( p16->lParam );
  2682. unmap_str_32W_to_16( cs->lpszName );
  2683. unmap_str_32W_to_16( cs->lpszClass );
  2684. if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
  2685. {
  2686. MDICREATESTRUCT16 *mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs->lpCreateParams);
  2687. UnMapLS( cs->lpCreateParams );
  2688. unmap_str_32W_to_16(mdi_cs16->szTitle);
  2689. unmap_str_32W_to_16(mdi_cs16->szClass);
  2690. HeapFree(GetProcessHeap(), 0, mdi_cs16);
  2691. }
  2692. HeapFree( GetProcessHeap(), 0, cs );
  2693. }
  2694. break;
  2695. case WM_MDICREATE:
  2696. {
  2697. MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
  2698. UnMapLS( p16->lParam );
  2699. unmap_str_32W_to_16( cs->szTitle );
  2700. unmap_str_32W_to_16( cs->szClass );
  2701. HeapFree( GetProcessHeap(), 0, cs );
  2702. }
  2703. break;
  2704. case WM_GETTEXT:
  2705. case WM_ASKCBFORMATNAME:
  2706. {
  2707. LPSTR str = MapSL(p16->lParam);
  2708. UnMapLS( p16->lParam );
  2709. p16->lParam = *((LPARAM *)str - 1);
  2710. MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)p16->lParam, 0x7fffffff );
  2711. p16->lResult = strlenW( (LPWSTR)p16->lParam );
  2712. HeapFree( GetProcessHeap(), 0, (LPARAM *)str - 1 );
  2713. }
  2714. break;
  2715. case LB_GETTEXT:
  2716. if ( WINPROC_TestLBForStr( hwnd ))
  2717. {
  2718. LPSTR str = MapSL(p16->lParam);
  2719. UnMapLS( p16->lParam );
  2720. p16->lResult = MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff ) - 1;
  2721. HeapFree( GetProcessHeap(), 0, (LPARAM *)str );
  2722. }
  2723. break;
  2724. case CB_GETLBTEXT:
  2725. if ( WINPROC_TestCBForStr( hwnd ))
  2726. {
  2727. LPSTR str = MapSL(p16->lParam);
  2728. UnMapLS( p16->lParam );
  2729. p16->lResult = MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff ) - 1;
  2730. HeapFree( GetProcessHeap(), 0, (LPARAM *)str );
  2731. }
  2732. break;
  2733. default:
  2734. WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
  2735. break;
  2736. }
  2737. }
  2738. /**********************************************************************
  2739. * WINPROC_CallProc32ATo32W
  2740. *
  2741. * Call a window procedure, translating args from Ansi to Unicode.
  2742. */
  2743. static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
  2744. UINT msg, WPARAM wParam,
  2745. LPARAM lParam )
  2746. {
  2747. LRESULT result;
  2748. int unmap;
  2749. TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
  2750. func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
  2751. if( (unmap = WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam )) == -1) {
  2752. ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
  2753. SPY_GetMsgName(msg, hwnd), wParam, lParam );
  2754. return 0;
  2755. }
  2756. result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
  2757. if (unmap) result = WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result );
  2758. return result;
  2759. }
  2760. /**********************************************************************
  2761. * WINPROC_CallProc32WTo32A_fast
  2762. *
  2763. */
  2764. static BOOL WINPROC_CallProc32WTo32A_fast( WNDPROC func, HWND hwnd,
  2765. UINT msg, WPARAM wParam,
  2766. LPARAM lParam, LRESULT *result )
  2767. {
  2768. switch(msg)
  2769. {
  2770. case WM_NCCREATE:
  2771. case WM_CREATE:
  2772. { /* csW->lpszName and csW->lpszClass are NOT supposed to be atoms
  2773. * at this point.
  2774. */
  2775. char buffer[1024];
  2776. char *cls = buffer, *name;
  2777. CREATESTRUCTW *csW = (CREATESTRUCTW *)lParam;
  2778. CREATESTRUCTA csA = *(CREATESTRUCTA *)csW;
  2779. DWORD name_lenA, name_lenW, class_lenA, class_lenW;
  2780. class_lenW = strlenW(csW->lpszClass) * sizeof(WCHAR);
  2781. RtlUnicodeToMultiByteSize(&class_lenA, csW->lpszClass, class_lenW);
  2782. if (csW->lpszName)
  2783. {
  2784. name_lenW = strlenW(csW->lpszName) * sizeof(WCHAR);
  2785. RtlUnicodeToMultiByteSize(&name_lenA, csW->lpszName, name_lenW);
  2786. }
  2787. else
  2788. name_lenW = name_lenA = 0;
  2789. if (class_lenA + name_lenA + 2 > sizeof(buffer))
  2790. {
  2791. cls = HeapAlloc(GetProcessHeap(), 0, class_lenA + name_lenA + 2);
  2792. if (!cls) return FALSE;
  2793. }
  2794. RtlUnicodeToMultiByteN(cls, class_lenA, NULL, csW->lpszClass, class_lenW);
  2795. cls[class_lenA] = 0;
  2796. csA.lpszClass = cls;
  2797. if (csW->lpszName)
  2798. {
  2799. name = cls + class_lenA + 1;
  2800. RtlUnicodeToMultiByteN(name, name_lenA, NULL, csW->lpszName, name_lenW);
  2801. name[name_lenA] = 0;
  2802. csA.lpszName = name;
  2803. }
  2804. if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
  2805. {
  2806. MDICREATESTRUCTA mdi_cs;
  2807. mdi_cs = *(MDICREATESTRUCTA *)csW->lpCreateParams;
  2808. mdi_cs.szTitle = csA.lpszName;
  2809. mdi_cs.szClass = csA.lpszClass;
  2810. csA.lpCreateParams = &mdi_cs;
  2811. }
  2812. lParam = (LPARAM)&csA;
  2813. *result = WINPROC_CallWndProc(func, hwnd, msg, wParam, lParam);
  2814. if (cls != buffer) HeapFree(GetProcessHeap(), 0, cls);
  2815. }
  2816. return TRUE;
  2817. default:
  2818. return FALSE;
  2819. }
  2820. }
  2821. /**********************************************************************
  2822. * WINPROC_CallProc32WTo32A
  2823. *
  2824. * Call a window procedure, translating args from Unicode to Ansi.
  2825. */
  2826. static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
  2827. UINT msg, WPARAM wParam,
  2828. LPARAM lParam )
  2829. {
  2830. LRESULT result;
  2831. int unmap;
  2832. TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
  2833. func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
  2834. if (WINPROC_CallProc32WTo32A_fast( func, hwnd, msg, wParam, lParam, &result ))
  2835. return result;
  2836. if ((unmap = WINPROC_MapMsg32WTo32A( hwnd, msg, &wParam, &lParam )) == -1) {
  2837. ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
  2838. SPY_GetMsgName(msg, hwnd), wParam, lParam );
  2839. return 0;
  2840. }
  2841. result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
  2842. if( unmap ) result = WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam, result );
  2843. return result;
  2844. }
  2845. /**********************************************************************
  2846. * __wine_call_wndproc_32A (USER.1010)
  2847. */
  2848. LRESULT WINAPI __wine_call_wndproc_32A( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
  2849. WNDPROC func )
  2850. {
  2851. LRESULT result;
  2852. UINT msg32;
  2853. WPARAM wParam32;
  2854. HWND hwnd32 = WIN_Handle32( hwnd );
  2855. TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
  2856. func, hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
  2857. if (WINPROC_MapMsg16To32A( hwnd32, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
  2858. return 0;
  2859. result = WINPROC_CallWndProc( func, hwnd32, msg32, wParam32, lParam );
  2860. return WINPROC_UnmapMsg16To32A( hwnd32, msg32, wParam32, lParam, result );
  2861. }
  2862. /**********************************************************************
  2863. * __wine_call_wndproc_32W (USER.1011)
  2864. */
  2865. LRESULT WINAPI __wine_call_wndproc_32W( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
  2866. WNDPROC func )
  2867. {
  2868. LRESULT result;
  2869. UINT msg32;
  2870. WPARAM wParam32;
  2871. HWND hwnd32 = WIN_Handle32( hwnd );
  2872. TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
  2873. func, hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
  2874. if (WINPROC_MapMsg16To32W( hwnd32, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
  2875. return 0;
  2876. result = WINPROC_CallWndProc( func, hwnd32, msg32, wParam32, lParam );
  2877. return WINPROC_UnmapMsg16To32W( hwnd32, msg32, wParam32, lParam, result );
  2878. }
  2879. /**********************************************************************
  2880. * WINPROC_CallProc32ATo16
  2881. *
  2882. * Call a 16-bit window procedure, translating the 32-bit args.
  2883. */
  2884. static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
  2885. UINT msg, WPARAM wParam,
  2886. LPARAM lParam )
  2887. {
  2888. UINT16 msg16;
  2889. MSGPARAM16 mp16;
  2890. TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
  2891. func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
  2892. mp16.lParam = lParam;
  2893. if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam, &msg16, &mp16.wParam, &mp16.lParam ) == -1)
  2894. return 0;
  2895. mp16.lResult = WINPROC_CallWndProc16( func, HWND_16(hwnd), msg16,
  2896. mp16.wParam, mp16.lParam );
  2897. WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
  2898. return mp16.lResult;
  2899. }
  2900. /**********************************************************************
  2901. * WINPROC_CallProc32WTo16
  2902. *
  2903. * Call a 16-bit window procedure, translating the 32-bit args.
  2904. */
  2905. static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
  2906. UINT msg, WPARAM wParam,
  2907. LPARAM lParam )
  2908. {
  2909. UINT16 msg16;
  2910. MSGPARAM16 mp16;
  2911. TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
  2912. func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
  2913. mp16.lParam = lParam;
  2914. if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam,
  2915. &mp16.lParam ) == -1)
  2916. return 0;
  2917. mp16.lResult = WINPROC_CallWndProc16( func, HWND_16(hwnd), msg16,
  2918. mp16.wParam, mp16.lParam );
  2919. WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
  2920. return mp16.lResult;
  2921. }
  2922. /**********************************************************************
  2923. * CallWindowProc (USER.122)
  2924. */
  2925. LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
  2926. WPARAM16 wParam, LPARAM lParam )
  2927. {
  2928. WINDOWPROC *proc;
  2929. if (!func) return 0;
  2930. if (!(proc = WINPROC_GetPtr( (WNDPROC)func )))
  2931. return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
  2932. #if testing
  2933. func = WINPROC_GetProc( (WNDPROC)proc, WIN_PROC_16 );
  2934. return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
  2935. #endif
  2936. switch(proc->type)
  2937. {
  2938. case WIN_PROC_16:
  2939. if (!proc->thunk.t_from32.proc) return 0;
  2940. return WINPROC_CallWndProc16( proc->thunk.t_from32.proc,
  2941. hwnd, msg, wParam, lParam );
  2942. case WIN_PROC_32A:
  2943. if (!proc->thunk.t_from16.proc) return 0;
  2944. return __wine_call_wndproc_32A( hwnd, msg, wParam, lParam, proc->thunk.t_from16.proc );
  2945. case WIN_PROC_32W:
  2946. if (!proc->thunk.t_from16.proc) return 0;
  2947. return __wine_call_wndproc_32W( hwnd, msg, wParam, lParam, proc->thunk.t_from16.proc );
  2948. default:
  2949. WARN_(relay)("Invalid proc %p\n", proc );
  2950. return 0;
  2951. }
  2952. }
  2953. /**********************************************************************
  2954. * CallWindowProcA (USER32.@)
  2955. *
  2956. * The CallWindowProc() function invokes the windows procedure _func_,
  2957. * with _hwnd_ as the target window, the message specified by _msg_, and
  2958. * the message parameters _wParam_ and _lParam_.
  2959. *
  2960. * Some kinds of argument conversion may be done, I'm not sure what.
  2961. *
  2962. * CallWindowProc() may be used for windows subclassing. Use
  2963. * SetWindowLong() to set a new windows procedure for windows of the
  2964. * subclass, and handle subclassed messages in the new windows
  2965. * procedure. The new windows procedure may then use CallWindowProc()
  2966. * with _func_ set to the parent class's windows procedure to dispatch
  2967. * the message to the superclass.
  2968. *
  2969. * RETURNS
  2970. *
  2971. * The return value is message dependent.
  2972. *
  2973. * CONFORMANCE
  2974. *
  2975. * ECMA-234, Win32
  2976. */
  2977. LRESULT WINAPI CallWindowProcA(
  2978. WNDPROC func, /* [in] window procedure */
  2979. HWND hwnd, /* [in] target window */
  2980. UINT msg, /* [in] message */
  2981. WPARAM wParam, /* [in] message dependent parameter */
  2982. LPARAM lParam /* [in] message dependent parameter */
  2983. ) {
  2984. WINDOWPROC *proc;
  2985. if (!func) return 0;
  2986. if (!(proc = WINPROC_GetPtr( func )))
  2987. return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
  2988. #if testing
  2989. func = WINPROC_GetProc( (WNDPROC)proc, WIN_PROC_32A );
  2990. return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
  2991. #endif
  2992. switch(proc->type)
  2993. {
  2994. case WIN_PROC_16:
  2995. if (!proc->thunk.t_from32.proc) return 0;
  2996. return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
  2997. hwnd, msg, wParam, lParam );
  2998. case WIN_PROC_32A:
  2999. if (!proc->thunk.t_from16.proc) return 0;
  3000. return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
  3001. hwnd, msg, wParam, lParam );
  3002. case WIN_PROC_32W:
  3003. if (!proc->thunk.t_from16.proc) return 0;
  3004. return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
  3005. hwnd, msg, wParam, lParam );
  3006. default:
  3007. WARN_(relay)("Invalid proc %p\n", proc );
  3008. return 0;
  3009. }
  3010. }
  3011. /**********************************************************************
  3012. * CallWindowProcW (USER32.@)
  3013. */
  3014. LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
  3015. WPARAM wParam, LPARAM lParam )
  3016. {
  3017. WINDOWPROC *proc;
  3018. if (!func) return 0;
  3019. if (!(proc = WINPROC_GetPtr( (WNDPROC)func )))
  3020. return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
  3021. #if testing
  3022. func = WINPROC_GetProc( (WNDPROC)proc, WIN_PROC_32W );
  3023. return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
  3024. #endif
  3025. switch(proc->type)
  3026. {
  3027. case WIN_PROC_16:
  3028. if (!proc->thunk.t_from32.proc) return 0;
  3029. return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
  3030. hwnd, msg, wParam, lParam );
  3031. case WIN_PROC_32A:
  3032. if (!proc->thunk.t_from16.proc) return 0;
  3033. return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
  3034. hwnd, msg, wParam, lParam );
  3035. case WIN_PROC_32W:
  3036. if (!proc->thunk.t_from16.proc) return 0;
  3037. return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
  3038. hwnd, msg, wParam, lParam );
  3039. default:
  3040. WARN_(relay)("Invalid proc %p\n", proc );
  3041. return 0;
  3042. }
  3043. }