#pragma once
// insterface
typedef struct ITaskbarList3 TaskbarListInterface;
class TaskbarGage
{
public:
TaskbarGage();
~TaskbarGage();
void init(wxWindow* window);
void clear(); // taskbar에서 gauge 제거
void normal();
void pause();
void indeterminate();
void error();
void update(unsigned __int64 now, unsigned __int64 total);
bool isMoreThanWindows7();
private:
UINT64 now_;
UINT64 total_;
wxWindow* window_;
TaskbarListInterface* interface_;
};
#include "stdafx.h"
#include "taskbar_gage.h"
// Windows Header Files:
#include <windows.h>
#include <windowsx.h>
// Header Files for Windows 7 Taskbar features
#include <shobjidl.h>
#include <propkey.h>
#include <propvarutil.h>
#include <shlobj.h>
#include <shellapi.h>
TaskbarGage::TaskbarGage() : window_(0), interface_(0), total_(0), now_(0) {}
void TaskbarGage::init(wxWindow* window) {
window_ = window;
if (isMoreThanWindows7()) {
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&interface_));
if (FAILED(hr)) {
interface_ = NULL;
}
}
}
TaskbarGage::~TaskbarGage() {
if (interface_) {
interface_->Release();
CoUninitialize();
}
}
bool TaskbarGage::isMoreThanWindows7() {
int os_major_version = 0;
int os_minor_version = 0;
wxOperatingSystemId os = wxGetOsVersion(&os_major_version, &os_minor_version);
// windows7 이나 Windows Server 2008 R2 이상
return (os & wxOS_WINDOWS && os_major_version >=6 && os_minor_version > 0);
}
void TaskbarGage::clear() {
if (interface_) interface_->SetProgressState(window_->GetHandle(), TBPF_NOPROGRESS);
}
void TaskbarGage::normal() {
if (interface_) interface_->SetProgressState(window_->GetHandle(), TBPF_NORMAL);
}
void TaskbarGage::pause() {
if (interface_) interface_->SetProgressState(window_->GetHandle(), TBPF_PAUSED);
}
void TaskbarGage::indeterminate() {
if (interface_) interface_->SetProgressState(window_->GetHandle(), TBPF_INDETERMINATE);
}
void TaskbarGage::error() {
if (interface_) interface_->SetProgressState(window_->GetHandle(), TBPF_ERROR);
}
void TaskbarGage::update(UINT64 now, UINT64 total) {
if (interface_) {
if (total == total_ && now == now_) return;
total_ = total;
now_ = now;
interface_->SetProgressValue(window_->GetHandle(), now, total);
}
}
'C++' 카테고리의 다른 글
std::regex - 대충 이런 느낌 (0) | 2012.08.01 |
---|---|
wxWidgets 컴파일 (0) | 2012.07.24 |
윈도우 폴더 관련 (0) | 2012.07.24 |
wxWidgets tray icon (wxTaskBarIcon) (0) | 2012.07.24 |
wxZip 사용 (0) | 2012.07.24 |
wxRichTextCtrl 사용방법 (0) | 2012.07.14 |
wxColour #FF000000 - 알파 인식여부 확인 (0) | 2012.07.11 |
wxRegEx 사용하여 특정 문자 치환 (0) | 2012.07.11 |