#pragma once
// 트레이 아이콘임
class TrayIcon : public wxTaskBarIcon
{
DECLARE_EVENT_TABLE()
public:
TrayIcon(wxFrame& parent) : parent_(parent) {}
virtual ~TrayIcon(){}
void onMenuExit(wxCommandEvent&);
void onMenuShow(wxCommandEvent&);
void onMenuHide(wxCommandEvent&);
void onLeftButtonDClick(wxTaskBarIconEvent&);
virtual wxMenu* CreatePopupMenu();
void set_icon(const wxIcon& image, const wxString& tooltip = wxEmptyString);
private:
wxFrame& parent_;
};
#include "stdafx.h"
#include "tray_icon.h"
enum
{
PU_EXIT = 10001,
PU_SHOW,
PU_HIDE,
};
BEGIN_EVENT_TABLE(TrayIcon, wxTaskBarIcon)
EVT_MENU(PU_EXIT, TrayIcon::onMenuExit)
EVT_MENU(PU_SHOW, TrayIcon::onMenuShow)
EVT_MENU(PU_HIDE, TrayIcon::onMenuHide)
EVT_TASKBAR_LEFT_DCLICK(TrayIcon::onLeftButtonDClick)
END_EVENT_TABLE()
wxMenu* TrayIcon::CreatePopupMenu() {
wxMenu *menu = new wxMenu;
menu->Append(PU_EXIT, wxT("Exit"));
menu->AppendSeparator();
menu->Append(PU_SHOW, wxT("Show"));
menu->Append(PU_HIDE, wxT("Hide"));
return menu;
}
void TrayIcon::set_icon(const wxIcon& icon, const wxString& tooltip) {
if (!icon.IsOk()) return;
wxTaskBarIcon::SetIcon(icon, tooltip);
}
void TrayIcon::onMenuExit(wxCommandEvent& ) {
parent_.Close(true);
}
void TrayIcon::onMenuShow(wxCommandEvent& ) {
parent_.Show(true);
parent_.Iconize(false);
}
void TrayIcon::onMenuHide(wxCommandEvent&) {
parent_.Show(false);
parent_.Iconize(true);
}
void TrayIcon::onLeftButtonDClick(wxTaskBarIconEvent&) {
if (parent_.IsShown() && !parent_.IsIconized()) {
parent_.Show(false);
parent_.Iconize(true);
} else
if (parent_.IsShown() && parent_.IsIconized()) {
parent_.Show(true);
parent_.Iconize(false);
} else {
parent_.Show(true);
parent_.Iconize(false);
}
}
'C++' 카테고리의 다른 글
c++ logging library (0) | 2012.08.08 |
---|---|
std::regex - 대충 이런 느낌 (0) | 2012.08.01 |
wxWidgets 컴파일 (0) | 2012.07.24 |
윈도우 폴더 관련 (0) | 2012.07.24 |
taskbar gage (windows7 이상) (0) | 2012.07.24 |
wxZip 사용 (0) | 2012.07.24 |
wxRichTextCtrl 사용방법 (0) | 2012.07.14 |
wxColour #FF000000 - 알파 인식여부 확인 (0) | 2012.07.11 |