Exemplo n.º 1
0
/*!	WinHelp のかわりに HtmlHelp を呼び出す

	@author ryoji
	@date 2006.07.22 ryoji 新規
*/
BOOL MyWinHelp(HWND hwndCaller, UINT uCommand, DWORD_PTR dwData)
{
	UINT uCommandOrg = uCommand;	// WinHelp のコマンド
	bool bDesktop = false;	// デスクトップを親にしてヘルプ画面を出すかどうか
	HH_POPUP hp;	// ポップアップヘルプ用の構造体

	// Note: HH_TP_HELP_CONTEXTMENU や HELP_WM_HELP ではヘルプコンパイル時の
	// トピックファイルを Cshelp.txt 以外にしている場合、
	// そのファイル名を .chm パス名に追加指定する必要がある。
	//     例)sakura.chm::/xxx.txt

	switch( uCommandOrg )
	{
	case HELP_COMMAND:	// [ヘルプ]-[目次]
	case HELP_CONTENTS:
		uCommand = HH_DISPLAY_TOC;
		hwndCaller = ::GetDesktopWindow();
		bDesktop = true;
		break;
	case HELP_KEY:	// [ヘルプ]-[キーワード検索]
		uCommand = HH_DISPLAY_INDEX;
		hwndCaller = ::GetDesktopWindow();
		bDesktop = true;
		break;
	case HELP_CONTEXT:	// メニュー上での[F1]キー/ダイアログの[ヘルプ]ボタン
		uCommand = HH_HELP_CONTEXT;
		hwndCaller = ::GetDesktopWindow();
		bDesktop = true;
		break;
	case HELP_CONTEXTMENU:	// コントロール上での右クリック
	case HELP_WM_HELP:		// [?]ボタンを押してコントロールをクリック/コントロールにフォーカスを置いて[F1]キー
		uCommand = HH_DISPLAY_TEXT_POPUP;
		{
			// ポップアップヘルプ用の構造体に値をセットする
			HWND hwndCtrl;	// ヘルプ表示対象のコントロール
			int nCtrlID;	// 対象コントロールの ID
			DWORD* pHelpIDs;	// コントロール ID とヘルプ ID の対応表へのポインタ

			memset(&hp, 0, sizeof(hp));	// 構造体をゼロクリア
			hp.cbStruct = sizeof(hp);
			hp.pszFont = _T("MS Pゴシック, 9");
			hp.clrForeground = hp.clrBackground = -1;
			hp.rcMargins.left = hp.rcMargins.top = hp.rcMargins.right = hp.rcMargins.bottom = -1;
			if( uCommandOrg == HELP_CONTEXTMENU ){
				// マウスカーソル位置から対象コントロールと表示位置を求める
				if( !::GetCursorPos(&hp.pt) )
					return FALSE;
				hwndCtrl = ::WindowFromPoint(hp.pt);
			}
			else{
				// 対象コントロールは hwndCaller
				// [F1]キーの場合もあるので対象コントロールの位置から表示位置を決める
				RECT rc;
				hwndCtrl = hwndCaller;
				if( !::GetWindowRect( hwndCtrl, &rc ) )
					return FALSE;
				hp.pt.x = (rc.left + rc.right) / 2;
				hp.pt.y = rc.top;
			}
			// 対象コントロールに対応するヘルプ ID を探す
			nCtrlID = ::GetDlgCtrlID( hwndCtrl );
			if( nCtrlID <= 0 )
				return FALSE;
			pHelpIDs = (DWORD*)dwData;
			for (;;) {
				if( *pHelpIDs == 0 )
					return FALSE;	// 見つからなかった
				if( *pHelpIDs == (DWORD)nCtrlID )
					break;			// 見つかった
				pHelpIDs += 2;
			}
			hp.idString = *(pHelpIDs + 1);	// 見つけたヘルプ ID を設定する
			dwData = (DWORD_PTR)&hp;	// 引数をポップアップヘルプ用の構造体に差し替える
		}
		break;
	default:
		return FALSE;
	}

	LPCTSTR lpszHelp = GetHelpFilePath();
	if( IsFileExists( lpszHelp, true ) ){
		// HTML ヘルプを呼び出す
		HWND hWnd = OpenHtmlHelp( hwndCaller, lpszHelp, uCommand, dwData );
		if (bDesktop && hWnd != NULL){
			::SetForegroundWindow( hWnd );	// ヘルプ画面を手前に出す
		}
	}
	else {
		if( uCommandOrg == HELP_CONTEXTMENU)
			return FALSE;	// 右クリックでは何もしないでおく

		// オンラインヘルプを呼び出す
		if( uCommandOrg != HELP_CONTEXT )
			dwData = 1;	// 目次ページ

		TCHAR buf[256];
		_stprintf( buf, _T("https://sakura-editor.github.io/help/HLP%06Iu.html"), dwData );
		ShellExecute( ::GetActiveWindow(), NULL, buf, NULL, NULL, SW_SHOWNORMAL );
	}

	return TRUE;
}
Exemplo n.º 2
0
/******************************************************************************
DisplayHtmlHelp()

  Description:
    This function performs some error handling of the HtmlHelp() API.

  Returns:
    TRUE  - An HtmlHelp window was successfully created.
	FALSE - An HtmlHelp window could not be created.
*****************************************************************************/
BOOL CPropSheet::DisplayHtmlHelp()
{
	USES_CONVERSION; // For Unicode to ANSI string conversion

	HWND hwndHelp = NULL;
	CString strError, strCaption, strFile;
	HH_LAST_ERROR hherror;
	int index = GetActiveIndex();
	int context = -1;

	// Setting up the file name
	strFile.LoadString(IDS_HELPFILENAME);
	strFile = GetHelpFilePath() + strFile;

	// Setting up the index
	if (bNewDSN != TRUE) index += m_NewDSNIndexOffset;
	context = map[index];
#ifndef _WIN64
	// Win64 link gives unresolved reference
	hwndHelp = ::HtmlHelp(m_hWnd, strFile, HH_HELP_CONTEXT, context);
#endif

	if (hwndHelp == NULL)
	{
		// Try to get error message.
#ifndef _WIN64
	// Win64 link gives unresolved reference
		hwndHelp = ::HtmlHelp(m_hWnd,
							NULL, HH_GET_LAST_ERROR,
							reinterpret_cast<DWORD>(&hherror));
#endif

		// Generate an error message if we have one.
		if (hwndHelp != 0)
		{
			if (hherror.hr < 0)
			{
				// Is there a text message to display?
				if (hherror.description)
				{
					// Convert the String to ANSI
					TCHAR* pDesc = OLE2T(hherror.description) ;
					::SysFreeString(hherror.description) ;

					// Generate our message
					strError = pDesc;
				}
			}
		}

		// Couldn't determine error from HtmlHelp. Generate a generic error message.
		else
		{
			strError.Format(IDS_HELP_GENERIC_ERROR, strFile);
		}

		strCaption.LoadString(IDS_HELP_ERROR_CAPTION);
		MessageBox(strError, strCaption, MB_OK | MB_ICONERROR);
		return FALSE;
	}
	else
		return TRUE;
}