ToolbarWindow.cpp
#include "StdAfx.h"
#include "ToolbarWindow.h"
CToolbarWindow::CToolbarWindow(void)
{
}
CToolbarWindow::~CToolbarWindow(void)
{
ImageList_Destroy(m_hImageList);
if ( IsWindow() )
DestroyWindow();
}
LRESULT CToolbarWindow::OnCreate ( UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/ )
{
//ボタンを作る為の下準備
SendMessage(TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_MIXEDBUTTONS);
SendMessage(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
SendMessage(TB_SETMAXTEXTROWS, 1, 0L);
SendMessage(TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_DRAWDDARROWS);
//画像を使う為の下準備
m_hImageList = ImageList_Create(16,16, ILC_COLOR16, 1, 0);
SendMessage ( TB_SETIMAGELIST, 0, (LPARAM)m_hImageList );
//ボタン作成
TBBUTTON btn;
ZeroMemory((void*)&btn, sizeof(TBBUTTON));
//とりあえず適当に1000を振っておく
btn.idCommand = 1000;
//ENABLE指定
btn.fsState = TBSTATE_ENABLED;
//ボタンのスタイルを指定
btn.fsStyle = TBSTYLE_BUTTON | TBSTYLE_DROPDOWN | BTNS_AUTOSIZE | BTNS_SHOWTEXT;
//テキストを指定
int iIndex = (int)SendMessage(TB_ADDSTRING, 0, (LPARAM)L"くまー");
btn.iString = iIndex;
//画像を設定(とりあえず、C;\test.bmpに置く)
HBITMAP hBitmap = (HBITMAP) LoadImage ( NULL, L"C:\\test.bmp", IMAGE_BITMAP,16, 16, LR_LOADFROMFILE );
btn.iBitmap = ImageList_Add(m_hImageList, hBitmap, NULL);;
//必ず0にするらしい
btn.dwData = 0;
//ボタンを追加する
SendMessage(TB_ADDBUTTONS, 1, (LPARAM)&btn);
return 0;
}
LRESULT CToolbarWindow::OnKumaButton ( WORD /* wNotifyCode */, WORD /* wID */, HWND /* hWndCtl */, BOOL& /* bHandled */ )
{
CComVariant vRefleshLevel(REFRESH_COMPLETELY);
m_spBrowser->Refresh2(&vRefleshLevel);
return 0;
}
LRESULT CToolbarWindow::OnKumaMenuOne ( WORD /* wNotifyCode */, WORD /* wID */, HWND /* hWndCtl */, BOOL& /* bHandled */ )
{
//URLの指定
CComBSTR url ( L"http://ja.wikipedia.org/wiki/%E3%82%AF%E3%83%9E" );
//その他の引数は、NULLを送る
CComVariant vEmpty;
//で、Navigate
m_spBrowser->Navigate ( url, &vEmpty, &vEmpty, &vEmpty, &vEmpty );
return 0;
}
LRESULT CToolbarWindow::OnKumaMenuTwo ( WORD /* wNotifyCode */, WORD /* wID */, HWND /* hWndCtl */, BOOL& /* bHandled */ )
{
MessageBox ( _T("TWO"), _T("KUMA"), MB_OK );
return 0;
}
LRESULT CToolbarWindow::OnDropDown( int /* idCtrl */, LPNMHDR pnmh, BOOL& /* bHandled */ )
{
LPNMTOOLBAR lpNMToolBar = (LPNMTOOLBAR)pnmh;
if ( lpNMToolBar->iItem == 1000 )
{
//ポップアップメニューを作る
HMENU hMenu = CreatePopupMenu();
//MENUの設定
MENUITEMINFO menuInfo;
menuInfo.cbSize = sizeof( menuInfo );
//fTypeを使う、文字列を使う、wIDを使う
menuInfo.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
menuInfo.fType = MFT_STRING;
//1つ目のメニュー設定
menuInfo.dwTypeData = _T("クマメニュー ONE");
menuInfo.wID = 1001;
InsertMenuItem ( hMenu, 0, FALSE, &menuInfo );
//2つ目のメニュー設定
menuInfo.dwTypeData = _T("クマメニュー TWO");
menuInfo.wID = 1002;
InsertMenuItem ( hMenu, 1, FALSE, &menuInfo );
//メニュー表示位置の取得
RECT rect;
SendMessage ( TB_GETRECT, (WPARAM)lpNMToolBar->iItem, (LPARAM)&rect );
GetWindowRect ( &rect );
//メニュー表示
TrackPopupMenu ( hMenu, TPM_LEFTALIGN, rect.left, rect.bottom, 0, m_hWnd, NULL );
}
return 0;
}
戻る
コメントスペース