4) Поток польз. интерфейса

  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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// UserUIView.cpp : implementation of the CUserUIView class
//
#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "UserUI.h"
#endif
#include "UserUIDoc.h"
#include "UserUIView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
UserUIThread* uiThread = NULL;
// CUserUIView
IMPLEMENT_DYNCREATE(CUserUIView, CView)
BEGIN_MESSAGE_MAP(CUserUIView, CView)
// Standard printing commands
ON_COMMAND(ID_THREAD_START, &CUserUIView::StartThread)
ON_COMMAND(ID_THREAD_DIE, &CUserUIView::DieBitchThread)
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
END_MESSAGE_MAP()
// CUserUIView construction/destruction
void CUserUIView::StartThread()
{
uiThread = (UserUIThread*)AfxBeginThread(RUNTIME_CLASS(UserUIThread));
}
void CUserUIView::DieBitchThread()
{
if (uiThread)
uiThread->PostThreadMessage(42, (WPARAM)0, (LPARAM)0);
}
CUserUIView::CUserUIView()
{
// TODO: add construction code here
}
CUserUIView::~CUserUIView()
{
}
BOOL CUserUIView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
// CUserUIView drawing
void CUserUIView::OnDraw(CDC* /*pDC*/)
{
CUserUIDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: add draw code for native data here
}
// CUserUIView printing
BOOL CUserUIView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CUserUIView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CUserUIView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
// CUserUIView diagnostics
#ifdef _DEBUG
void CUserUIView::AssertValid() const
{
CView::AssertValid();
}
void CUserUIView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CUserUIDoc* CUserUIView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CUserUIDoc)));
return (CUserUIDoc*)m_pDocument;
}
#endif //_DEBUG
// CUserUIView message handlers
#pragma once
// UserUIThread
class UserUIThread : public CWinThread
{
DECLARE_DYNCREATE(UserUIThread)
protected:
UserUIThread(); // protected constructor used by dynamic creation
virtual ~UserUIThread();
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
protected:
afx_msg void DieBitch(WPARAM,LPARAM);
DECLARE_MESSAGE_MAP()
};
// UserUIThread.cpp : implementation file
//
#include "stdafx.h"
#include "UserUI.h"
#include "UserUIThread.h"
// UserUIThread
IMPLEMENT_DYNCREATE(UserUIThread, CWinThread)
UserUIThread::UserUIThread()
{
}
UserUIThread::~UserUIThread()
{
}
BOOL UserUIThread::InitInstance()
{
// TODO: perform and per-thread initialization here
CWnd uiWnd;
uiWnd.CreateEx(0,
AfxRegisterWndClass(
CS_HREDRAW | CS_VREDRAW,
LoadCursor(NULL, IDC_ARROW),
(HBRUSH)(COLOR_WINDOW + 1),
LoadIcon(NULL, MAKEINTRESOURCE(IDR_MAINFRAME))
),
_T("tipa okno"),
WS_VISIBLE | WS_OVERLAPPED,
CRect(100, 100, 500, 500),
NULL,
NULL);
CWinThread::Run();
return TRUE;
}
int UserUIThread::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(UserUIThread, CWinThread)
ON_THREAD_MESSAGE(42, &UserUIThread::DieBitch)
END_MESSAGE_MAP()
// UserUIThread message handlers
void UserUIThread::DieBitch(WPARAM wParam, LPARAM lParam)
{
PostQuitMessage(1);
}