No longer directly accessing debuggee memory.
[wine] / windows / defwnd.c
1 /*
2  * Default window procedure
3  *
4  * Copyright 1993, 1996 Alexandre Julliard
5  *           1995 Alex Korobka
6  */
7
8 #include <string.h>
9
10 #include "win.h"
11 #include "user.h"
12 #include "heap.h"
13 #include "nonclient.h"
14 #include "winpos.h"
15 #include "dce.h"
16 #include "debugtools.h"
17 #include "spy.h"
18 #include "tweak.h"
19 #include "cache.h"
20 #include "windef.h"
21 #include "wingdi.h"
22 #include "wine/winuser16.h"
23
24 DEFAULT_DEBUG_CHANNEL(win)
25
26   /* bits in the dwKeyData */
27 #define KEYDATA_ALT             0x2000
28 #define KEYDATA_PREVSTATE       0x4000
29
30 static short iF10Key = 0;
31 static short iMenuSysKey = 0;
32
33 /***********************************************************************
34  *           DEFWND_HandleWindowPosChanged
35  *
36  * Handle the WM_WINDOWPOSCHANGED message.
37  */
38 static void DEFWND_HandleWindowPosChanged( WND *wndPtr, UINT flags )
39 {
40     WPARAM16 wp = SIZE_RESTORED;
41
42     if (!(flags & SWP_NOCLIENTMOVE))
43         SendMessage16( wndPtr->hwndSelf, WM_MOVE, 0,
44                     MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top));
45     if (!(flags & SWP_NOCLIENTSIZE))
46     {
47         if (wndPtr->dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
48         else if (wndPtr->dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
49
50         SendMessage16( wndPtr->hwndSelf, WM_SIZE, wp, 
51                      MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
52                             wndPtr->rectClient.bottom-wndPtr->rectClient.top));
53     }
54 }
55
56
57 /***********************************************************************
58  *           DEFWND_SetText
59  *
60  * Set the window text.
61  */
62 void DEFWND_SetText( WND *wndPtr, LPCSTR text )
63 {
64     if (!text) text = "";
65     if (wndPtr->text) HeapFree( SystemHeap, 0, wndPtr->text );
66     wndPtr->text = HEAP_strdupA( SystemHeap, 0, text );    
67     wndPtr->pDriver->pSetText(wndPtr, wndPtr->text);
68 }
69
70 /***********************************************************************
71  *           DEFWND_ControlColor
72  *
73  * Default colors for control painting.
74  */
75 HBRUSH DEFWND_ControlColor( HDC hDC, UINT16 ctlType )
76 {
77     if( ctlType == CTLCOLOR_SCROLLBAR)
78     {
79         HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
80         if (TWEAK_WineLook == WIN31_LOOK) {
81            SetTextColor( hDC, RGB(0, 0, 0) );
82            SetBkColor( hDC, RGB(255, 255, 255) );
83         } else {
84            COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
85            SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
86            SetBkColor( hDC, bk);
87
88            /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT 
89             * we better use 0x55aa bitmap brush to make scrollbar's background
90             * look different from the window background. 
91             */
92            if (bk == GetSysColor(COLOR_WINDOW)) {
93                return CACHE_GetPattern55AABrush();
94            }
95         }
96         UnrealizeObject( hb );
97         return hb;
98     }
99
100     SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
101
102     if (TWEAK_WineLook > WIN31_LOOK) {
103         if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
104             SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
105         else {
106             SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
107             return GetSysColorBrush(COLOR_3DFACE);
108         }
109     }
110     else
111         SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
112     return GetSysColorBrush(COLOR_WINDOW);
113 }
114
115
116 /***********************************************************************
117  *           DEFWND_SetRedraw
118  */
119 static void DEFWND_SetRedraw( WND* wndPtr, WPARAM wParam )
120 {
121     BOOL bVisible = wndPtr->dwStyle & WS_VISIBLE;
122
123     TRACE("%04x %i\n", wndPtr->hwndSelf, (wParam!=0) );
124
125     if( wParam )
126     {
127         if( !bVisible )
128         {
129             wndPtr->dwStyle |= WS_VISIBLE;
130             DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
131         }
132     }
133     else if( bVisible )
134     {
135         if( wndPtr->dwStyle & WS_MINIMIZE ) wParam = RDW_VALIDATE;
136         else wParam = RDW_ALLCHILDREN | RDW_VALIDATE;
137
138         PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, wParam, 0 );
139         DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
140         wndPtr->dwStyle &= ~WS_VISIBLE;
141     }
142 }
143
144 /***********************************************************************
145  *           DEFWND_Print
146  *
147  * This method handles the default behavior for the WM_PRINT message.
148  */
149 static void DEFWND_Print(
150   WND*  wndPtr,
151   HDC   hdc,
152   ULONG uFlags)
153 {
154   /*
155    * Visibility flag.
156    */
157   if ( (uFlags & PRF_CHECKVISIBLE) &&
158        !IsWindowVisible(wndPtr->hwndSelf) )
159       return;
160
161   /*
162    * Unimplemented flags.
163    */
164   if ( (uFlags & PRF_CHILDREN) ||
165        (uFlags & PRF_OWNED)    ||
166        (uFlags & PRF_NONCLIENT) )
167   {
168     WARN("WM_PRINT message with unsupported flags\n");
169   }
170
171   /*
172    * Background
173    */
174   if ( uFlags & PRF_ERASEBKGND)
175     SendMessageA(wndPtr->hwndSelf, WM_ERASEBKGND, (WPARAM)hdc, 0);
176
177   /*
178    * Client area
179    */
180   if ( uFlags & PRF_CLIENT)
181     SendMessageA(wndPtr->hwndSelf, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
182 }
183
184 /***********************************************************************
185  *           DEFWND_DefWinProc
186  *
187  * Default window procedure for messages that are the same in Win16 and Win32.
188  */
189 static LRESULT DEFWND_DefWinProc( WND *wndPtr, UINT msg, WPARAM wParam,
190                                   LPARAM lParam )
191 {
192     switch(msg)
193     {
194     case WM_NCPAINT:
195         return NC_HandleNCPaint( wndPtr->hwndSelf, (HRGN)wParam );
196
197     case WM_NCHITTEST:
198         return NC_HandleNCHitTest( wndPtr->hwndSelf, MAKEPOINT16(lParam) );
199
200     case WM_NCLBUTTONDOWN:
201         return NC_HandleNCLButtonDown( wndPtr, wParam, lParam );
202
203     case WM_LBUTTONDBLCLK:
204     case WM_NCLBUTTONDBLCLK:
205         return NC_HandleNCLButtonDblClk( wndPtr, wParam, lParam );
206
207     case WM_RBUTTONUP:
208     case WM_NCRBUTTONUP:
209         if ((wndPtr->flags & WIN_ISWIN32) || (TWEAK_WineLook > WIN31_LOOK))
210         {
211             ClientToScreen16(wndPtr->hwndSelf, (LPPOINT16)&lParam);
212             SendMessageA( wndPtr->hwndSelf, WM_CONTEXTMENU,
213                             wndPtr->hwndSelf, lParam);
214         }
215         break;
216
217     case WM_CONTEXTMENU:
218         if( wndPtr->dwStyle & WS_CHILD )
219             SendMessageA( wndPtr->parent->hwndSelf, msg, wParam, lParam );
220         else if (wndPtr->hSysMenu)
221         {
222             LONG hitcode;
223             POINT16 pt = MAKEPOINT16(lParam);
224
225             ScreenToClient16(wndPtr->hwndSelf, &pt);
226             hitcode = NC_HandleNCHitTest(wndPtr->hwndSelf, pt);
227
228             /* Track system popup if click was in the caption area. */
229             if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
230                 TrackPopupMenu(GetSystemMenu(wndPtr->hwndSelf, FALSE),
231                                TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
232                                pt.x, pt.y, 0, wndPtr->hwndSelf, NULL);
233         }
234         break;
235
236     case WM_NCACTIVATE:
237         return NC_HandleNCActivate( wndPtr, wParam );
238
239     case WM_NCDESTROY:
240         if (wndPtr->text) HeapFree( SystemHeap, 0, wndPtr->text );
241         wndPtr->text = NULL;
242         if (wndPtr->pVScroll) HeapFree( SystemHeap, 0, wndPtr->pVScroll );
243         if (wndPtr->pHScroll) HeapFree( SystemHeap, 0, wndPtr->pHScroll );
244         wndPtr->pVScroll = wndPtr->pHScroll = NULL;
245         return 0;
246
247     case WM_PRINT:
248         DEFWND_Print(wndPtr, (HDC)wParam, lParam);
249         return 0;
250
251     case WM_PAINTICON:
252     case WM_PAINT:
253         {
254             PAINTSTRUCT16 ps;
255             HDC16 hdc = BeginPaint16( wndPtr->hwndSelf, &ps );
256             if( hdc ) 
257             {
258               if( (wndPtr->dwStyle & WS_MINIMIZE) && wndPtr->class->hIcon )
259               {
260                 int x = (wndPtr->rectWindow.right - wndPtr->rectWindow.left -
261                         GetSystemMetrics(SM_CXICON))/2;
262                 int y = (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top -
263                         GetSystemMetrics(SM_CYICON))/2;
264                 TRACE("Painting class icon: vis rect=(%i,%i - %i,%i)\n",
265                 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom );
266                 DrawIcon( hdc, x, y, wndPtr->class->hIcon );
267               }
268               EndPaint16( wndPtr->hwndSelf, &ps );
269             }
270             return 0;
271         }
272
273     case WM_SETREDRAW:
274         DEFWND_SetRedraw( wndPtr, wParam );
275         return 0;
276
277     case WM_CLOSE:
278         DestroyWindow( wndPtr->hwndSelf );
279         return 0;
280
281     case WM_MOUSEACTIVATE:
282         if (wndPtr->dwStyle & WS_CHILD)
283         {
284             LONG ret = SendMessage16( wndPtr->parent->hwndSelf,
285                                       WM_MOUSEACTIVATE, wParam, lParam );
286             if (ret) return ret;
287         }
288
289         /* Caption clicks are handled by the NC_HandleNCLButtonDown() */ 
290         return (LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE;
291
292     case WM_ACTIVATE:
293         /* The default action in Windows is to set the keyboard focus to
294          * the window, if it's being activated and not minimized */
295         if (LOWORD(wParam) != WA_INACTIVE) {
296                 /* I don't know who put this SetWindowPos here, it does not
297                  * seem very logical to have it here... (FIXME?) */
298                 SetWindowPos(wndPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0,
299                          SWP_NOMOVE | SWP_NOSIZE);
300                 if (!(wndPtr->dwStyle & WS_MINIMIZE))
301                         SetFocus(wndPtr->hwndSelf);
302         }
303         break;
304
305     case WM_ERASEBKGND:
306     case WM_ICONERASEBKGND:
307         {
308             RECT rect;
309
310             if (!wndPtr->class->hbrBackground) return 0;
311
312             /*  Since WM_ERASEBKGND may receive either a window dc or a    */ 
313             /*  client dc, the area to be erased has to be retrieved from  */
314             /*  the device context.                                        */
315             GetClipBox( (HDC)wParam, &rect );
316
317             /* Always call the Win32 variant of FillRect even on Win16,
318              * since despite the fact that Win16, as well as Win32,
319              * supports special background brushes for a window class,
320              * the Win16 variant of FillRect does not.
321              */
322             FillRect( (HDC) wParam, &rect, wndPtr->class->hbrBackground);
323             return 1;
324         }
325
326     case WM_GETDLGCODE:
327         return 0;
328
329     case WM_CTLCOLORMSGBOX:
330     case WM_CTLCOLOREDIT:
331     case WM_CTLCOLORLISTBOX:
332     case WM_CTLCOLORBTN:
333     case WM_CTLCOLORDLG:
334     case WM_CTLCOLORSTATIC:
335     case WM_CTLCOLORSCROLLBAR:
336         return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
337
338     case WM_CTLCOLOR:
339         return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
340         
341     case WM_GETTEXTLENGTH:
342         if (wndPtr->text) return (LRESULT)strlen(wndPtr->text);
343         return 0;
344
345     case WM_SETCURSOR:
346         if (wndPtr->dwStyle & WS_CHILD)
347             if (SendMessage16(wndPtr->parent->hwndSelf, WM_SETCURSOR,
348                             wParam, lParam))
349                 return TRUE;
350         return NC_HandleSetCursor( wndPtr->hwndSelf, wParam, lParam );
351
352     case WM_SYSCOMMAND:
353         return NC_HandleSysCommand( wndPtr->hwndSelf, wParam,
354                                     MAKEPOINT16(lParam) );
355
356     case WM_KEYDOWN:
357         if(wParam == VK_F10) iF10Key = VK_F10;
358         break;
359
360     case WM_SYSKEYDOWN:
361         if( HIWORD(lParam) & KEYDATA_ALT )
362         {
363             /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
364               if( wParam == VK_MENU && !iMenuSysKey )
365                 iMenuSysKey = 1;
366               else
367                 iMenuSysKey = 0;
368             
369             iF10Key = 0;
370
371             if( wParam == VK_F4 )       /* try to close the window */
372             {
373                 HWND hWnd = WIN_GetTopParent( wndPtr->hwndSelf );
374                 wndPtr = WIN_FindWndPtr( hWnd );
375                 if( wndPtr && !(wndPtr->class->style & CS_NOCLOSE) )
376                     PostMessage16( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0 );
377                 WIN_ReleaseWndPtr(wndPtr);
378             }
379         } 
380         else if( wParam == VK_F10 )
381                 iF10Key = 1;
382              else
383                 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
384                     SendMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
385                                   (WPARAM16)SC_KEYMENU, (LPARAM)VK_SPACE);
386         break;
387
388     case WM_KEYUP:
389     case WM_SYSKEYUP:
390         /* Press and release F10 or ALT */
391         if (((wParam == VK_MENU) && iMenuSysKey) ||
392             ((wParam == VK_F10) && iF10Key))
393               SendMessage16( WIN_GetTopParent(wndPtr->hwndSelf),
394                              WM_SYSCOMMAND, SC_KEYMENU, 0L );
395         iMenuSysKey = iF10Key = 0;
396         break;
397
398     case WM_SYSCHAR:
399         iMenuSysKey = 0;
400         if (wParam == VK_RETURN && (wndPtr->dwStyle & WS_MINIMIZE))
401         {
402             PostMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
403                            (WPARAM16)SC_RESTORE, 0L ); 
404             break;
405         } 
406         if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
407         {
408             if (wParam == VK_TAB || wParam == VK_ESCAPE) break;
409             if (wParam == VK_SPACE && (wndPtr->dwStyle & WS_CHILD))
410                 SendMessage16( wndPtr->parent->hwndSelf, msg, wParam, lParam );
411             else
412                 SendMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
413                                (WPARAM16)SC_KEYMENU, (LPARAM)(DWORD)wParam );
414         } 
415         else /* check for Ctrl-Esc */
416             if (wParam != VK_ESCAPE) MessageBeep(0);
417         break;
418
419     case WM_SHOWWINDOW:
420         if (!lParam) return 0; /* sent from ShowWindow */
421         if (!(wndPtr->dwStyle & WS_POPUP) || !wndPtr->owner) return 0;
422         if ((wndPtr->dwStyle & WS_VISIBLE) && wParam) return 0;
423         else if (!(wndPtr->dwStyle & WS_VISIBLE) && !wParam) return 0;
424         ShowWindow( wndPtr->hwndSelf, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
425         break; 
426
427     case WM_CANCELMODE:
428         if (wndPtr->parent == WIN_GetDesktop()) EndMenu();
429         if (GetCapture() == wndPtr->hwndSelf) ReleaseCapture();
430         WIN_ReleaseDesktop();
431         break;
432
433     case WM_VKEYTOITEM:
434     case WM_CHARTOITEM:
435         return -1;
436
437     case WM_DROPOBJECT:
438         return DRAG_FILE;  
439
440     case WM_QUERYDROPOBJECT:
441         if (wndPtr->dwExStyle & WS_EX_ACCEPTFILES) return 1;
442         break;
443
444     case WM_QUERYDRAGICON:
445         {
446             HICON16 hIcon=0;
447             UINT16 len;
448
449             if( (hIcon=wndPtr->class->hCursor) ) return (LRESULT)hIcon;
450             for(len=1; len<64; len++)
451                 if((hIcon=LoadIcon16(wndPtr->hInstance,MAKEINTRESOURCE16(len))))
452                     return (LRESULT)hIcon;
453             return (LRESULT)LoadIcon16(0,IDI_APPLICATION16);
454         }
455         break;
456
457     case WM_ISACTIVEICON:
458         return ((wndPtr->flags & WIN_NCACTIVATED) != 0);
459
460     case WM_NOTIFYFORMAT:
461       if (IsWindowUnicode(wndPtr->hwndSelf)) return NFR_UNICODE;
462       else return NFR_ANSI;
463         
464     case WM_QUERYOPEN:
465     case WM_QUERYENDSESSION:
466         return 1;
467
468     case WM_SETICON:
469     case WM_GETICON:
470         {
471             LRESULT result = 0;
472             int index = GCL_HICON;
473
474             if (wParam == ICON_SMALL)
475                 index = GCL_HICONSM;
476
477             result = GetClassLongA(wndPtr->hwndSelf, index);
478
479             if (msg == WM_SETICON)
480                 SetClassLongA(wndPtr->hwndSelf, index, lParam);
481
482             return result;
483         }
484     case WM_HELP:
485         SendMessageA( wndPtr->parent->hwndSelf, msg, wParam, lParam );
486         break;
487     }
488
489     return 0;
490 }
491
492
493
494 /***********************************************************************
495  *           DefWindowProc16   (USER.107)
496  */
497 LRESULT WINAPI DefWindowProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
498                                 LPARAM lParam )
499 {
500     WND * wndPtr = WIN_FindWndPtr( hwnd );
501     LRESULT result = 0;
502
503     if (!wndPtr) return 0;
504     SPY_EnterMessage( SPY_DEFWNDPROC16, hwnd, msg, wParam, lParam );
505
506     switch(msg)
507     {
508     case WM_NCCREATE:
509         {
510             CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
511             if (cs->lpszName)
512                 DEFWND_SetText( wndPtr, (LPSTR)PTR_SEG_TO_LIN(cs->lpszName) );
513             result = 1;
514         }
515         break;
516
517     case WM_NCCALCSIZE:
518         {
519             RECT rect32;
520             CONV_RECT16TO32( (RECT16 *)PTR_SEG_TO_LIN(lParam), &rect32 );
521             result = NC_HandleNCCalcSize( wndPtr, &rect32 );
522             CONV_RECT32TO16( &rect32, (RECT16 *)PTR_SEG_TO_LIN(lParam) );
523         }
524         break;
525
526     case WM_WINDOWPOSCHANGING:
527         result = WINPOS_HandleWindowPosChanging16( wndPtr,
528                                        (WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam) );
529         break;
530
531     case WM_WINDOWPOSCHANGED:
532         {
533             WINDOWPOS16 * winPos = (WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam);
534             DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
535         }
536         break;
537
538     case WM_GETTEXT:
539         if (wParam && wndPtr->text)
540         {
541             lstrcpynA( (LPSTR)PTR_SEG_TO_LIN(lParam), wndPtr->text, wParam );
542             result = (LRESULT)strlen( (LPSTR)PTR_SEG_TO_LIN(lParam) );
543         }
544         break;
545
546     case WM_SETTEXT:
547         DEFWND_SetText( wndPtr, (LPSTR)PTR_SEG_TO_LIN(lParam) );
548         if( wndPtr->dwStyle & WS_CAPTION ) NC_HandleNCPaint( hwnd , (HRGN)1 );
549         break;
550
551     default:
552         result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam );
553         break;
554     }
555
556     WIN_ReleaseWndPtr(wndPtr);
557     SPY_ExitMessage( SPY_RESULT_DEFWND16, hwnd, msg, result );
558     return result;
559 }
560
561
562 /***********************************************************************
563  *  DefWindowProc32A [USER32.126] 
564  *
565  */
566 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam,
567                                  LPARAM lParam )
568 {
569     WND * wndPtr = WIN_FindWndPtr( hwnd );
570     LRESULT result = 0;
571
572     if (!wndPtr) return 0;
573     SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
574
575     switch(msg)
576     {
577     case WM_NCCREATE:
578         {
579             CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
580             if (cs->lpszName) DEFWND_SetText( wndPtr, cs->lpszName );
581             result = 1;
582         }
583         break;
584
585     case WM_NCCALCSIZE:
586         result = NC_HandleNCCalcSize( wndPtr, (RECT *)lParam );
587         break;
588
589     case WM_WINDOWPOSCHANGING:
590         result = WINPOS_HandleWindowPosChanging( wndPtr,
591                                                    (WINDOWPOS *)lParam );
592         break;
593
594     case WM_WINDOWPOSCHANGED:
595         {
596             WINDOWPOS * winPos = (WINDOWPOS *)lParam;
597             DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
598         }
599         break;
600
601     case WM_GETTEXT:
602         if (wParam && wndPtr->text)
603         {
604             lstrcpynA( (LPSTR)lParam, wndPtr->text, wParam );
605             result = (LRESULT)strlen( (LPSTR)lParam );
606         }
607         break;
608
609     case WM_SETTEXT:
610         DEFWND_SetText( wndPtr, (LPSTR)lParam );
611         NC_HandleNCPaint( hwnd , (HRGN)1 );  /* Repaint caption */
612         break;
613
614     default:
615         result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam );
616         break;
617     }
618
619     WIN_ReleaseWndPtr(wndPtr);
620     SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result );
621     return result;
622 }
623
624
625 /***********************************************************************
626  * DefWindowProc32W [USER32.127] Calls default window message handler
627  * 
628  * Calls default window procedure for messages not processed 
629  *  by application.
630  *
631  *  RETURNS
632  *     Return value is dependent upon the message.
633 */
634 LRESULT WINAPI DefWindowProcW( 
635     HWND hwnd,      /* [in] window procedure recieving message */
636     UINT msg,       /* [in] message identifier */
637     WPARAM wParam,  /* [in] first message parameter */
638     LPARAM lParam )   /* [in] second message parameter */
639 {
640     LRESULT result;
641
642     switch(msg)
643     {
644     case WM_NCCREATE:
645         {
646             CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
647             if (cs->lpszName)
648             {
649                 WND *wndPtr = WIN_FindWndPtr( hwnd );
650                 LPSTR str = HEAP_strdupWtoA(GetProcessHeap(), 0, cs->lpszName);
651                 DEFWND_SetText( wndPtr, str );
652                 HeapFree( GetProcessHeap(), 0, str );
653                 WIN_ReleaseWndPtr(wndPtr);
654             }
655             result = 1;
656         }
657         break;
658
659     case WM_GETTEXT:
660         {
661             LPSTR str = HeapAlloc( GetProcessHeap(), 0, wParam );
662             result = DefWindowProcA( hwnd, msg, wParam, (LPARAM)str );
663             lstrcpynAtoW( (LPWSTR)lParam, str, wParam );
664             HeapFree( GetProcessHeap(), 0, str );
665         }
666         break;
667
668     case WM_SETTEXT:
669         {
670             LPSTR str = HEAP_strdupWtoA( GetProcessHeap(), 0, (LPWSTR)lParam );
671             result = DefWindowProcA( hwnd, msg, wParam, (LPARAM)str );
672             HeapFree( GetProcessHeap(), 0, str );
673         }
674         break;
675
676     default:
677         result = DefWindowProcA( hwnd, msg, wParam, lParam );
678         break;
679     }
680     return result;
681 }