Fix parameters for MDI_RestoreFrameMenu in WM_DESTROY msg.
[wine] / windows / winhelp.c
1 /*
2  * Windows Help
3  */
4
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include "debugtools.h"
10 #include "wine/winuser16.h"
11 #include "wine/winbase16.h"
12 #include "winversion.h"
13 #include "heap.h"
14 #include "ldt.h"
15 #include "syslevel.h"
16
17 DEFAULT_DEBUG_CHANNEL(win)
18
19
20 /**********************************************************************
21  *             WinHelp16   (USER.171)
22  */
23 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
24                          DWORD dwData )
25 {
26   BOOL ret;
27   /* We might call WinExec() */
28   SYSLEVEL_ReleaseWin16Lock();
29   ret = WinHelpA( hWnd, lpHelpFile, wCommand, (DWORD)PTR_SEG_TO_LIN(dwData) );
30   SYSLEVEL_RestoreWin16Lock();
31   return ret;
32 }
33
34
35 /**********************************************************************
36  *             WinHelp32A   (USER32.579)
37  */
38 BOOL WINAPI WinHelpA( HWND hWnd, LPCSTR lpHelpFile, UINT wCommand,
39                           DWORD dwData )
40 {
41         static WORD WM_WINHELP = 0;
42         HWND hDest;
43         LPWINHELP lpwh;
44         HGLOBAL16 hwh;
45         HINSTANCE winhelp;
46         int size,dsize,nlen;
47
48
49         if(!WM_WINHELP) 
50           {
51             WM_WINHELP=RegisterWindowMessageA("WM_WINHELP");
52             if(!WM_WINHELP)
53               return FALSE;
54           }
55
56         hDest = FindWindowA( "MS_WINHELP", NULL );
57         if(!hDest) {
58           if(wCommand == HELP_QUIT)
59             return TRUE;
60           else
61             if ( VERSION_GetVersion() == WIN31 ) {
62               winhelp = WinExec ( "winhelp.exe -x", SW_SHOWNORMAL );
63               Yield16();
64             }
65             else {
66               winhelp = WinExec ( "winhlp32.exe -x", SW_SHOWNORMAL );
67             }     
68           if ( winhelp <= 32 ) return FALSE;
69           if ( ! ( hDest = FindWindowA ( "MS_WINHELP", NULL ) )) return FALSE;
70         }
71
72
73         switch(wCommand)
74         {
75                 case HELP_CONTEXT:
76                 case HELP_SETCONTENTS:
77                 case HELP_CONTENTS:
78                 case HELP_CONTEXTPOPUP:
79                 case HELP_FORCEFILE:
80                 case HELP_HELPONHELP:
81                 case HELP_FINDER:
82                 case HELP_QUIT:
83                         dsize=0;
84                         break;
85                 case HELP_KEY:
86                 case HELP_PARTIALKEY:
87                 case HELP_COMMAND:
88                         dsize = strlen( (LPSTR)dwData )+1;
89                         break;
90                 case HELP_MULTIKEY:
91                         dsize = ((LPMULTIKEYHELP)dwData)->mkSize;
92                         break;
93                 case HELP_SETWINPOS:
94                         dsize = ((LPHELPWININFO)dwData)->wStructSize;
95                         break;
96                 default:
97                         WARN("Unknown help command %d\n",wCommand);
98                         return FALSE;
99         }
100         if(lpHelpFile)
101                 nlen = strlen(lpHelpFile)+1;
102         else
103                 nlen = 0;
104         size = sizeof(WINHELP) + nlen + dsize;
105         hwh = GlobalAlloc16(0,size);
106         lpwh = GlobalLock16(hwh);
107         lpwh->size = size;
108         lpwh->command = wCommand;
109         lpwh->data = dwData;
110         if(nlen) {
111                 strcpy(((char*)lpwh) + sizeof(WINHELP),lpHelpFile);
112                 lpwh->ofsFilename = sizeof(WINHELP);
113         } else
114                 lpwh->ofsFilename = 0;
115         if(dsize) {
116                 memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,(LPSTR)dwData,dsize);
117                 lpwh->ofsData = sizeof(WINHELP)+nlen;
118         } else
119                 lpwh->ofsData = 0;
120         GlobalUnlock16(hwh);
121         return SendMessage16(hDest,WM_WINHELP,hWnd,hwh);
122 }
123
124
125 /**********************************************************************
126  *             WinHelp32W   (USER32.580)
127  */
128 BOOL WINAPI WinHelpW( HWND hWnd, LPCWSTR helpFile, UINT command,
129                           DWORD dwData )
130 {
131     LPSTR file = HEAP_strdupWtoA( GetProcessHeap(), 0, helpFile );
132     BOOL ret = WinHelpA( hWnd, file, command, dwData );
133     HeapFree( GetProcessHeap(), 0, file );
134     return ret;
135 }