Release 971221
[wine.git] / windows / winhelp.c
blobd8521d483e49b9327b9166c18be1c87961606da7
1 /*
2 * Windows Help
3 */
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include "windows.h"
10 #include "heap.h"
11 #include "ldt.h"
14 /**********************************************************************
15 * WinHelp16 (USER.171)
17 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
18 DWORD dwData )
20 return WinHelp32A( hWnd, lpHelpFile, wCommand,
21 (DWORD)PTR_SEG_TO_LIN(dwData) );
25 /**********************************************************************
26 * WinHelp32A (USER32.578)
28 BOOL32 WINAPI WinHelp32A( HWND32 hWnd, LPCSTR lpHelpFile, UINT32 wCommand,
29 DWORD dwData )
31 static WORD WM_WINHELP = 0;
32 HWND32 hDest;
33 LPWINHELP lpwh;
34 HGLOBAL16 hwh;
35 int size,dsize,nlen;
36 if (wCommand != HELP_QUIT) /* FIXME */
38 if (WinExec32("winhelp.exe -x",SW_SHOWNORMAL) <= 32)
39 return FALSE;
41 /* NOTE: Probably, this should be directed yield,
42 to let winhelp open the window in all cases. */
43 Yield16();
46 if(!WM_WINHELP)
48 WM_WINHELP=RegisterWindowMessage32A("WM_WINHELP");
49 if(!WM_WINHELP)
50 return FALSE;
53 hDest = FindWindow32A( "MS_WINHELP", NULL );
54 if(!hDest)
55 if(wCommand == HELP_QUIT)
56 return TRUE;
57 else
58 return FALSE;
59 switch(wCommand)
61 case HELP_CONTEXT:
62 case HELP_SETCONTENTS:
63 case HELP_CONTENTS:
64 case HELP_CONTEXTPOPUP:
65 case HELP_FORCEFILE:
66 case HELP_HELPONHELP:
67 case HELP_FINDER:
68 case HELP_QUIT:
69 dsize=0;
70 break;
71 case HELP_KEY:
72 case HELP_PARTIALKEY:
73 case HELP_COMMAND:
74 dsize = strlen( (LPSTR)dwData )+1;
75 break;
76 case HELP_MULTIKEY:
77 dsize = ((LPMULTIKEYHELP)dwData)->mkSize;
78 break;
79 case HELP_SETWINPOS:
80 dsize = ((LPHELPWININFO)dwData)->wStructSize;
81 break;
82 default:
83 fprintf(stderr,"Unknown help command %d\n",wCommand);
84 return FALSE;
86 if(lpHelpFile)
87 nlen = strlen(lpHelpFile)+1;
88 else
89 nlen = 0;
90 size = sizeof(WINHELP) + nlen + dsize;
91 hwh = GlobalAlloc16(0,size);
92 lpwh = GlobalLock16(hwh);
93 lpwh->size = size;
94 lpwh->command = wCommand;
95 lpwh->data = dwData;
96 if(nlen) {
97 strcpy(((char*)lpwh) + sizeof(WINHELP),lpHelpFile);
98 lpwh->ofsFilename = sizeof(WINHELP);
99 } else
100 lpwh->ofsFilename = 0;
101 if(dsize) {
102 memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,(LPSTR)dwData,dsize);
103 lpwh->ofsData = sizeof(WINHELP)+nlen;
104 } else
105 lpwh->ofsData = 0;
106 GlobalUnlock16(hwh);
107 return SendMessage16(hDest,WM_WINHELP,hWnd,hwh);
111 /**********************************************************************
112 * WinHelp32W (USER32.579)
114 BOOL32 WINAPI WinHelp32W( HWND32 hWnd, LPCWSTR helpFile, UINT32 command,
115 DWORD dwData )
117 LPSTR file = HEAP_strdupWtoA( GetProcessHeap(), 0, helpFile );
118 BOOL32 ret = WinHelp32A( hWnd, file, command, dwData );
119 HeapFree( GetProcessHeap(), 0, file );
120 return ret;