A couple of optimizations.
[wine/multimedia.git] / windows / winhelp.c
blobc0e2d667474d69e62453c4b3e81740426bb725ce
1 /*
2 * Windows Help
3 */
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include "debugtools.h"
10 #include "windef.h"
11 #include "wingdi.h"
12 #include "wine/winuser16.h"
13 #include "wine/winbase16.h"
14 #include "win.h"
15 #include "heap.h"
17 DEFAULT_DEBUG_CHANNEL(win);
20 /* WinHelp internal structure */
21 typedef struct
23 WORD size;
24 WORD command;
25 LONG data;
26 LONG reserved;
27 WORD ofsFilename;
28 WORD ofsData;
29 } WINHELP,*LPWINHELP;
31 /**********************************************************************
32 * WinHelp (USER.171)
34 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
35 DWORD dwData )
37 BOOL ret;
38 DWORD mutex_count;
40 /* We might call WinExec() */
41 ReleaseThunkLock( &mutex_count );
43 if (!(ret = WinHelpA( WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData) )))
45 /* try to start the 16-bit winhelp */
46 if (WinExec( "winhelp.exe -x", SW_SHOWNORMAL ) >= 32)
48 K32WOWYield16();
49 ret = WinHelpA( WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData) );
53 RestoreThunkLock( mutex_count );
54 return ret;
58 /**********************************************************************
59 * WinHelpA (USER32.@)
61 BOOL WINAPI WinHelpA( HWND hWnd, LPCSTR lpHelpFile, UINT wCommand,
62 DWORD dwData )
64 static WORD WM_WINHELP = 0;
65 HWND hDest;
66 LPWINHELP lpwh;
67 HGLOBAL16 hwh;
68 int size,dsize,nlen;
71 if(!WM_WINHELP)
73 WM_WINHELP=RegisterWindowMessageA("WM_WINHELP");
74 if(!WM_WINHELP)
75 return FALSE;
78 hDest = FindWindowA( "MS_WINHELP", NULL );
79 if(!hDest) {
80 if(wCommand == HELP_QUIT) return TRUE;
81 if (WinExec ( "winhlp32.exe -x", SW_SHOWNORMAL ) < 32) {
82 ERR("can't start winhlp32.exe -x ?\n");
83 return FALSE;
85 if ( ! ( hDest = FindWindowA ( "MS_WINHELP", NULL ) )) {
86 FIXME("did not find MS_WINHELP (FindWindow() failed, maybe global window handling still unimplemented)\n");
87 return FALSE;
92 switch(wCommand)
94 case HELP_CONTEXT:
95 case HELP_SETCONTENTS:
96 case HELP_CONTENTS:
97 case HELP_CONTEXTPOPUP:
98 case HELP_FORCEFILE:
99 case HELP_HELPONHELP:
100 case HELP_FINDER:
101 case HELP_QUIT:
102 dsize=0;
103 break;
104 case HELP_KEY:
105 case HELP_PARTIALKEY:
106 case HELP_COMMAND:
107 dsize = dwData ? strlen( (LPSTR)dwData )+1: 0;
108 break;
109 case HELP_MULTIKEY:
110 dsize = ((LPMULTIKEYHELPA)dwData)->mkSize;
111 break;
112 case HELP_SETWINPOS:
113 dsize = ((LPHELPWININFOA)dwData)->wStructSize;
114 break;
115 default:
116 FIXME("Unknown help command %d\n",wCommand);
117 return FALSE;
119 if(lpHelpFile)
120 nlen = strlen(lpHelpFile)+1;
121 else
122 nlen = 0;
123 size = sizeof(WINHELP) + nlen + dsize;
124 hwh = GlobalAlloc16(0,size);
125 lpwh = GlobalLock16(hwh);
126 lpwh->size = size;
127 lpwh->command = wCommand;
128 lpwh->data = dwData;
129 if(nlen) {
130 strcpy(((char*)lpwh) + sizeof(WINHELP),lpHelpFile);
131 lpwh->ofsFilename = sizeof(WINHELP);
132 } else
133 lpwh->ofsFilename = 0;
134 if(dsize) {
135 memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,(LPSTR)dwData,dsize);
136 lpwh->ofsData = sizeof(WINHELP)+nlen;
137 } else
138 lpwh->ofsData = 0;
139 GlobalUnlock16(hwh);
140 return SendMessage16(hDest,WM_WINHELP,hWnd,hwh);
144 /**********************************************************************
145 * WinHelpW (USER32.@)
147 BOOL WINAPI WinHelpW( HWND hWnd, LPCWSTR helpFile, UINT command,
148 DWORD dwData )
150 LPSTR file = HEAP_strdupWtoA( GetProcessHeap(), 0, helpFile );
151 BOOL ret = WinHelpA( hWnd, file, command, dwData );
152 HeapFree( GetProcessHeap(), 0, file );
153 return ret;