-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppView.cpp
executable file
·168 lines (117 loc) · 3.02 KB
/
AppView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*!
* This is the scroll view which connects to the itunes controller
*
* Copyright (c) 200x by Colin
*/
#include "stdafx.h"
#include "resource.h"
#include "mainFrm.h"
#include "AppView.h"
/// Does nothing
BOOL AppView::PreTranslateMessage(MSG* pMsg)
{
pMsg;
return FALSE;
}
/// Does nothing
AppView::AppView(CMainFrame * parent) :
parent(parent)
{
}
/// Does nothing
LRESULT AppView::OnCreate(LPCREATESTRUCT lpcs)
{
CenterWindow();
SetScrollOffset(lpcs->cx, lpcs->cy, FALSE);
SetScrollSize(lpcs->cx, lpcs->cy);
HRESULT hRes = ::CLSIDFromProgID(_T("iTunes.Application"), &iTunesCLSID);
if(FAILED(hRes))
{
g_report_error(hRes, _T("::CLSIDFromProgID"));
return hRes;
}
hRes = iTunes.CoCreateInstance(iTunesCLSID);
if(FAILED(hRes))
{
g_report_error(hRes, _T("IiTunes::CoCreateInstance"));
return hRes;
}
SetMsgHandled(false);
IConnectionPointContainer * icpc;
hRes = iTunes->QueryInterface(IID_IConnectionPointContainer, (PVOID *)&icpc);
if(FAILED(hRes))
{
g_report_error(hRes, _T("Query IConnectionPointContainer"));
return hRes;
}
hRes = icpc->FindConnectionPoint(DIID__IiTunesEvents, &m_comConnPt);
if(FAILED(hRes))
{
g_report_error(hRes, _T("IConnectionPointContainer::FindConnectionPoint"));
return hRes;
}
m_eventSink = new iTunesEventHandler(this);
hRes = m_comConnPt->Advise(m_eventSink, &m_comConnCookie);
if(FAILED(hRes))
{
g_report_error(hRes, _T("IConnectionPoint::Advise"));
return hRes;
}
icpc->Release();
//WaitForSingleObject(hThread, INFINITE);
return 0;
}
/// Does nothing
void AppView::OnDestroy()
{
if(m_comConnPt)
{
HRESULT hRes = m_comConnPt->Unadvise(m_comConnCookie);
if(FAILED(hRes))
{
g_report_error(hRes, _T("IConnectionPoint::Unadvise"));
}
m_comConnPt->Release();
}
iTunes.Release();
delete m_eventSink;
}
/// Does nothing
LRESULT AppView::OnPlay(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/)
{
CComPtr<IITTrack> rofl;
HRESULT hRes = iTunes->get_CurrentTrack(&rofl);
if(hRes != S_OK)
{
g_report_error(hRes, _T("CComPtr<IITTrack>::CurrentTrack"));
return 0;
}
BSTR artist, album, track;
HRESULT h = rofl->get_Name(&track);
bool balbum = rofl->get_Album(&album) == S_OK;
bool bartist = rofl->get_Artist(&artist) == S_OK;
bool btrack = rofl->get_Name(&track) == S_OK;
CComBSTR na(_T("N/A"));
CString buffer;
buffer.Format(_T("%s - [%s] - %s"),
bartist ? CString(artist) : CString(na),
balbum ? CString(album) : CString(na),
btrack ? CString(track) : CString(na));
if(LB_ERR == AddString(buffer))
{
MessageBox(0, 0, 0);
}
return 0;
}
/// Does nothing
LRESULT AppView::OnStop(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/)
{
// //AddString(L"stop");
return 0;
}
/// Does nothing
LRESULT AppView::OnTrackChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/)
{
// //AddString(L"change");
return 0;
}