winhelp.c 2.88 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1
/*
Alexandre Julliard's avatar
Alexandre Julliard committed
2
 * Windows Help
Alexandre Julliard's avatar
Alexandre Julliard committed
3
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
4

Alexandre Julliard's avatar
Alexandre Julliard committed
5 6 7 8
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
9
#include "debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
10 11
#include "windows.h"
#include "heap.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
12
#include "ldt.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
13 14


Alexandre Julliard's avatar
Alexandre Julliard committed
15
/**********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
16
 *             WinHelp16   (USER.171)
Alexandre Julliard's avatar
Alexandre Julliard committed
17
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
18 19
BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
                         DWORD dwData )
Alexandre Julliard's avatar
Alexandre Julliard committed
20 21 22 23 24 25 26
{
    return WinHelp32A( hWnd, lpHelpFile, wCommand,
                       (DWORD)PTR_SEG_TO_LIN(dwData) );
}


/**********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
27
 *             WinHelp32A   (USER32.579)
Alexandre Julliard's avatar
Alexandre Julliard committed
28
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
29 30
BOOL32 WINAPI WinHelp32A( HWND32 hWnd, LPCSTR lpHelpFile, UINT32 wCommand,
                          DWORD dwData )
Alexandre Julliard's avatar
Alexandre Julliard committed
31
{
Alexandre Julliard's avatar
Alexandre Julliard committed
32
	static WORD WM_WINHELP = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
33
	HWND32 hDest;
Alexandre Julliard's avatar
Alexandre Julliard committed
34
	LPWINHELP lpwh;
Alexandre Julliard's avatar
Alexandre Julliard committed
35
	HGLOBAL16 hwh;
Alexandre Julliard's avatar
Alexandre Julliard committed
36 37
	int size,dsize,nlen;
        if (wCommand != HELP_QUIT)  /* FIXME */
Alexandre Julliard's avatar
Alexandre Julliard committed
38 39
	{
            if (WinExec32("winhelp.exe -x",SW_SHOWNORMAL) <= 32)
Alexandre Julliard's avatar
Alexandre Julliard committed
40
		return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
41 42 43 44 45 46 47 48

	    /* NOTE: Probably, this should be directed yield, 
		     to let winhelp open the window in all cases. */
	    Yield16();
	}

	if(!WM_WINHELP) 
	{
Alexandre Julliard's avatar
Alexandre Julliard committed
49
		WM_WINHELP=RegisterWindowMessage32A("WM_WINHELP");
Alexandre Julliard's avatar
Alexandre Julliard committed
50 51
		if(!WM_WINHELP)
			return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
52
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
53

Alexandre Julliard's avatar
Alexandre Julliard committed
54
	hDest = FindWindow32A( "MS_WINHELP", NULL );
Alexandre Julliard's avatar
Alexandre Julliard committed
55
	if(!hDest)
Alexandre Julliard's avatar
Alexandre Julliard committed
56 57 58 59
		if(wCommand == HELP_QUIT)
			return TRUE;
		else
			return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
60 61 62 63
	switch(wCommand)
	{
		case HELP_CONTEXT:
		case HELP_SETCONTENTS:
Alexandre Julliard's avatar
Alexandre Julliard committed
64
		case HELP_CONTENTS:
Alexandre Julliard's avatar
Alexandre Julliard committed
65 66 67
		case HELP_CONTEXTPOPUP:
		case HELP_FORCEFILE:
		case HELP_HELPONHELP:
Alexandre Julliard's avatar
Alexandre Julliard committed
68
		case HELP_FINDER:
Alexandre Julliard's avatar
Alexandre Julliard committed
69 70 71 72 73 74
		case HELP_QUIT:
			dsize=0;
			break;
		case HELP_KEY:
		case HELP_PARTIALKEY:
		case HELP_COMMAND:
Alexandre Julliard's avatar
Alexandre Julliard committed
75
			dsize = strlen( (LPSTR)dwData )+1;
Alexandre Julliard's avatar
Alexandre Julliard committed
76 77
			break;
		case HELP_MULTIKEY:
Alexandre Julliard's avatar
Alexandre Julliard committed
78
			dsize = ((LPMULTIKEYHELP)dwData)->mkSize;
Alexandre Julliard's avatar
Alexandre Julliard committed
79 80
			break;
		case HELP_SETWINPOS:
Alexandre Julliard's avatar
Alexandre Julliard committed
81
			dsize = ((LPHELPWININFO)dwData)->wStructSize;
Alexandre Julliard's avatar
Alexandre Julliard committed
82 83
			break;
		default:
Alexandre Julliard's avatar
Alexandre Julliard committed
84
			WARN( win,"Unknown help command %d\n",wCommand);
Alexandre Julliard's avatar
Alexandre Julliard committed
85 86 87
			return FALSE;
	}
	if(lpHelpFile)
Alexandre Julliard's avatar
Alexandre Julliard committed
88
		nlen = strlen(lpHelpFile)+1;
Alexandre Julliard's avatar
Alexandre Julliard committed
89 90 91
	else
		nlen = 0;
	size = sizeof(WINHELP) + nlen + dsize;
Alexandre Julliard's avatar
Alexandre Julliard committed
92 93
	hwh = GlobalAlloc16(0,size);
	lpwh = GlobalLock16(hwh);
Alexandre Julliard's avatar
Alexandre Julliard committed
94 95
	lpwh->size = size;
	lpwh->command = wCommand;
Alexandre Julliard's avatar
Alexandre Julliard committed
96
	lpwh->data = dwData;
Alexandre Julliard's avatar
Alexandre Julliard committed
97 98
	if(nlen) {
		strcpy(((char*)lpwh) + sizeof(WINHELP),lpHelpFile);
Alexandre Julliard's avatar
Alexandre Julliard committed
99 100 101
		lpwh->ofsFilename = sizeof(WINHELP);
 	} else
		lpwh->ofsFilename = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
102
	if(dsize) {
Alexandre Julliard's avatar
Alexandre Julliard committed
103
		memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,(LPSTR)dwData,dsize);
Alexandre Julliard's avatar
Alexandre Julliard committed
104 105 106
		lpwh->ofsData = sizeof(WINHELP)+nlen;
	} else
		lpwh->ofsData = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
107
	GlobalUnlock16(hwh);
Alexandre Julliard's avatar
Alexandre Julliard committed
108
	return SendMessage16(hDest,WM_WINHELP,hWnd,hwh);
Alexandre Julliard's avatar
Alexandre Julliard committed
109
}
Alexandre Julliard's avatar
Alexandre Julliard committed
110 111 112


/**********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
113
 *             WinHelp32W   (USER32.580)
Alexandre Julliard's avatar
Alexandre Julliard committed
114
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
115 116
BOOL32 WINAPI WinHelp32W( HWND32 hWnd, LPCWSTR helpFile, UINT32 command,
                          DWORD dwData )
Alexandre Julliard's avatar
Alexandre Julliard committed
117 118 119 120 121 122
{
    LPSTR file = HEAP_strdupWtoA( GetProcessHeap(), 0, helpFile );
    BOOL32 ret = WinHelp32A( hWnd, file, command, dwData );
    HeapFree( GetProcessHeap(), 0, file );
    return ret;
}