ToolbarWindow.cpp


#include "StdAfx.h"
#include "ToolbarWindow.h"
#include "Resource.h"

CToolbarWindow::CToolbarWindow(void)
{
}

CToolbarWindow::~CToolbarWindow(void)
{
    if ( IsWindow() )
        DestroyWindow();
}

//WindowCreate時
LRESULT CToolbarWindow::OnCreate ( UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/ )
{
    //Init処理
    m_BtnCtrl.Init ( m_hWnd );

    //単純なクマーボタン
    m_BtnCtrl.AddButton ( ID_KUMA_BUTTON, L"クマ", L"kuma" );

    //IE操作用ボタン
    m_BtnCtrl.AddButton ( ID_IE_GO_BACK,    L"戻る",       L"back"     );
    m_BtnCtrl.AddButton ( ID_IE_GO_FORWARD, L"進む",       L"forward"  );
    m_BtnCtrl.AddButton ( ID_IE_LOAD_STOP,  L"停止",       L"stop"     );
    m_BtnCtrl.AddButton ( ID_IE_REFRESH,    L"更新",       L"refresh", TBSTYLE_DROPDOWN );
    m_BtnCtrl.AddButton ( ID_IE_GO_HOME,    L"ホーム",     L"home"     );
    m_BtnCtrl.AddButton ( ID_IE_URL_SEARCH, L"検索",       L"search"   );

    //更新ボタンはドロップダウンにして、複数タイプの更新を可能に
    m_BtnCtrl.AddMenu ( ID_IE_REFRESH, ID_IE_REFRESH_NORMAL,     L"通常" );
    m_BtnCtrl.AddMenu ( ID_IE_REFRESH, ID_IE_REFRESH_IFEXPIRED,  L"期限切れのみ" );
    m_BtnCtrl.AddMenu ( ID_IE_REFRESH, ID_IE_REFRESH_COMPLETELY, L"完全" );

    return 0;
}

//メニュードロップダウン
LRESULT CToolbarWindow::OnDropDown( int /* idCtrl */, LPNMHDR pnmh, BOOL& /* bHandled */ )
{
    LPNMTOOLBAR lpNMToolBar = (LPNMTOOLBAR)pnmh;
    m_BtnCtrl.DispMenu ( lpNMToolBar->iItem );

    return 0;
}

//ボタン用動作設定
LRESULT CToolbarWindow::OnKumaButtonCommand ( WORD /* wNotifyCode */, WORD wID, HWND /* hWndCtl */, BOOL& /* bHandled */ )
{
    //クマボタン
    if ( wID == ID_KUMA_BUTTON )
    {
        CComBSTR url ( L"http://ja.wikipedia.org/wiki/%E3%82%AF%E3%83%9E" );
        CComVariant vEmpty;
        m_spBrowser->Navigate ( url, &vEmpty, &vEmpty, &vEmpty, &vEmpty );
    }
    //戻るボタン
    else if ( wID == ID_IE_GO_BACK )
    {
        m_spBrowser->GoBack ( );
    }
    //進むボタン
    else if ( wID == ID_IE_GO_FORWARD )
    {
        m_spBrowser->GoForward ( );
    }
    //中止ボタン
    else if ( wID == ID_IE_LOAD_STOP )
    {
        m_spBrowser->Stop ( );
    }
    //更新ボタン
    else if ( wID == ID_IE_REFRESH )
    {
        m_spBrowser->Refresh ( );
    }
    //ホームボタン
    else if ( wID == ID_IE_GO_HOME )
    {
        m_spBrowser->GoHome ( );
    }
    //デフォルト検索ページ
    else if ( wID == ID_IE_URL_SEARCH )
    {
        m_spBrowser->GoSearch ( );
    }

    return 0;
}

//メニューアイテム用動作設定
LRESULT CToolbarWindow::OnKumaMenuCommand ( WORD /* wNotifyCode */, WORD wID, HWND /* hWndCtl */, BOOL& /* bHandled */ )
{
    //通常更新
    if ( wID == ID_IE_REFRESH_NORMAL )
    {
        CComVariant vType ( REFRESH_NORMAL );
        m_spBrowser->Refresh2 ( &vType );
    }
    //期限切れのみ更新
    else if ( wID == ID_IE_REFRESH_IFEXPIRED )
    {
        CComVariant vType ( REFRESH_IFEXPIRED );
        m_spBrowser->Refresh2 ( &vType );
    }
    //完全更新
    else if ( wID == ID_IE_REFRESH_COMPLETELY )
    {
        CComVariant vType ( REFRESH_COMPLETELY );
        m_spBrowser->Refresh2 ( &vType );
    }

    return 0;
}

戻る

コメントスペース