HICON and HCURSOR should be interchangeable.
[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 "windef.h"
11 #include "wingdi.h"
12 #include "wine/winuser16.h"
13 #include "wine/winbase16.h"
14 #include "heap.h"
15 #include "ldt.h"
16 #include "syslevel.h"
17
18 DEFAULT_DEBUG_CHANNEL(win);
19
20
21 /* WinHelp internal structure */
22 typedef struct
23 {
24     WORD size;
25     WORD command;
26     LONG data;
27     LONG reserved;
28     WORD ofsFilename;
29     WORD ofsData;
30 } WINHELP,*LPWINHELP;
31
32 /**********************************************************************
33  *             WinHelp16   (USER.171)
34  */
35 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
36                          DWORD dwData )
37 {
38   BOOL ret;
39   /* We might call WinExec() */
40   SYSLEVEL_ReleaseWin16Lock();
41
42   if (!(ret = WinHelpA( hWnd, lpHelpFile, wCommand, (DWORD)PTR_SEG_TO_LIN(dwData) )))
43   {
44       /* try to start the 16-bit winhelp */
45       if (WinExec( "winhelp.exe -x", SW_SHOWNORMAL ) >= 32)
46       {
47           Yield16();
48           ret = WinHelpA( hWnd, lpHelpFile, wCommand, (DWORD)PTR_SEG_TO_LIN(dwData) );
49       }
50   }
51
52   SYSLEVEL_RestoreWin16Lock();
53   return ret;
54 }
55
56
57 /**********************************************************************
58  *             WinHelpA   (USER32.579)
59  */
60 BOOL WINAPI WinHelpA( HWND hWnd, LPCSTR lpHelpFile, UINT wCommand,
61                           DWORD dwData )
62 {
63         static WORD WM_WINHELP = 0;
64         HWND hDest;
65         LPWINHELP lpwh;
66         HGLOBAL16 hwh;
67         int size,dsize,nlen;
68
69
70         if(!WM_WINHELP) 
71           {
72             WM_WINHELP=RegisterWindowMessageA("WM_WINHELP");
73             if(!WM_WINHELP)
74               return FALSE;
75           }
76
77         hDest = FindWindowA( "MS_WINHELP", NULL );
78         if(!hDest) {
79           if(wCommand == HELP_QUIT) return TRUE;
80           if (WinExec ( "winhlp32.exe -x", SW_SHOWNORMAL ) < 32) {
81               FIXME("cant start winhlp32.exe -x?\n");
82               return FALSE;
83           }
84           if ( ! ( hDest = FindWindowA ( "MS_WINHELP", NULL ) )) {
85               FIXME("did not find MS_WINHELP\n");
86               return FALSE;
87           }
88         }
89
90
91         switch(wCommand)
92         {
93                 case HELP_CONTEXT:
94                 case HELP_SETCONTENTS:
95                 case HELP_CONTENTS:
96                 case HELP_CONTEXTPOPUP:
97                 case HELP_FORCEFILE:
98                 case HELP_HELPONHELP:
99                 case HELP_FINDER:
100                 case HELP_QUIT:
101                         dsize=0;
102                         break;
103                 case HELP_KEY:
104                 case HELP_PARTIALKEY:
105                 case HELP_COMMAND:
106                         dsize = dwData ? strlen( (LPSTR)dwData )+1: 0;
107                         break;
108                 case HELP_MULTIKEY:
109                         dsize = ((LPMULTIKEYHELPA)dwData)->mkSize;
110                         break;
111                 case HELP_SETWINPOS:
112                         dsize = ((LPHELPWININFOA)dwData)->wStructSize;
113                         break;
114                 default:
115                         FIXME("Unknown help command %d\n",wCommand);
116                         return FALSE;
117         }
118         if(lpHelpFile)
119                 nlen = strlen(lpHelpFile)+1;
120         else
121                 nlen = 0;
122         size = sizeof(WINHELP) + nlen + dsize;
123         hwh = GlobalAlloc16(0,size);
124         lpwh = GlobalLock16(hwh);
125         lpwh->size = size;
126         lpwh->command = wCommand;
127         lpwh->data = dwData;
128         if(nlen) {
129                 strcpy(((char*)lpwh) + sizeof(WINHELP),lpHelpFile);
130                 lpwh->ofsFilename = sizeof(WINHELP);
131         } else
132                 lpwh->ofsFilename = 0;
133         if(dsize) {
134                 memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,(LPSTR)dwData,dsize);
135                 lpwh->ofsData = sizeof(WINHELP)+nlen;
136         } else
137                 lpwh->ofsData = 0;
138         GlobalUnlock16(hwh);
139         return SendMessage16(hDest,WM_WINHELP,hWnd,hwh);
140 }
141
142
143 /**********************************************************************
144  *             WinHelpW   (USER32.580)
145  */
146 BOOL WINAPI WinHelpW( HWND hWnd, LPCWSTR helpFile, UINT command,
147                           DWORD dwData )
148 {
149     LPSTR file = HEAP_strdupWtoA( GetProcessHeap(), 0, helpFile );
150     BOOL ret = WinHelpA( hWnd, file, command, dwData );
151     HeapFree( GetProcessHeap(), 0, file );
152     return ret;
153 }