00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "cBasicViewer.h"
00010
00011 #include <windows.h>
00012 #include <process.h>
00013 #include <string.h>
00014
00015 using namespace::BVThread;
00016
00017
00018
00019 const LPCTSTR cBasicViewer::ClassName = "cBasicViewerWindow";
00020 bool cBasicViewer::Registered = false;
00021 HINSTANCE cBasicViewer::ModuleInstance = NULL;
00022
00023
00024
00025
00026
00030
00031 cBasicViewer::cBasicViewer(int Width, int Height, char *title)
00032 {
00033
00034 this->width = max(Width,120);
00035 this->height = max(Height,100);
00036
00037
00038
00039 strcpy(this->title, title);
00040
00041
00042 DCMutex=CreateMutex(NULL, false, NULL);
00043 RunMutex=CreateMutex(NULL, false, NULL);
00044
00045
00046 _beginthread((void (*)(void *))ViewerThreadProcess, 0, this);
00047
00048 while(WaitForSingleObject(RunMutex,0)!=WAIT_TIMEOUT)
00049 ReleaseMutex(RunMutex);
00050
00051 while(!PostThreadMessage(ThreadID, TH_MESSAGE, TH_CHECK, NULL))
00052 Sleep(0);
00053
00054
00055
00056 }
00057
00058
00059
00060
00061
00065
00066 cBasicViewer::~cBasicViewer()
00067 {
00068
00069 PostThreadMessage(ThreadID, TH_MESSAGE, TH_DIE, NULL);
00070
00071 WaitForSingleObject(RunMutex, INFINITE);
00072
00073
00074 }
00075
00076
00077
00078
00079
00083
00084 HDC cBasicViewer::BeginDraw()
00085 {
00086
00087 WaitForSingleObject(DCMutex, INFINITE);
00088
00089
00090 return hMemDC;
00091 }
00092
00093
00094
00095
00096
00100
00101 void cBasicViewer::EndDraw()
00102 {
00103
00104 ReleaseMutex(DCMutex);
00105
00106 }
00107
00108
00109
00110
00111
00113
00114 void cBasicViewer::Show()
00115 {
00116
00117 PostThreadMessage(ThreadID, TH_MESSAGE, TH_SHOW, NULL);
00118 }
00119
00120
00121
00122
00123
00125
00126 void cBasicViewer::Hide()
00127 {
00128
00129 PostThreadMessage(ThreadID, TH_MESSAGE, TH_HIDE, NULL);
00130 }
00131
00132
00133
00134
00135
00137
00138 void cBasicViewer::Update()
00139 {
00140
00141 PostThreadMessage(ThreadID, TH_MESSAGE, TH_UPDATE, NULL);
00142 }
00143
00144
00145
00146
00147
00149
00150 void cBasicViewer::RegisterViewerClass()
00151 {
00152 WNDCLASS wc;
00153 if(!Registered) {
00154
00155
00156 ModuleInstance = (HINSTANCE)GetModuleHandle(NULL);
00157
00158
00159 wc.style = CS_OWNDC | BV_CLASSSTYLE;
00160
00161 wc.lpfnWndProc = (WNDPROC)ViewerWndProc;
00162 wc.cbClsExtra = 0;
00163 wc.cbWndExtra = 0;
00164 wc.hInstance = ModuleInstance;
00165 wc.hIcon = VIEWER_ICON();
00166 wc.hCursor = VIEWER_CURSOR();
00167
00168 wc.hbrBackground = NULL;
00169 wc.lpszMenuName = NULL;
00170 wc.lpszClassName = ClassName;
00171
00172
00173 RegisterClass(&wc);
00174
00175 Registered = true;
00176 }
00177 }