sl@0
|
1 |
// SoundGraphAccess.cpp : Defines the entry point for the application.
|
sl@0
|
2 |
//
|
sl@0
|
3 |
|
sl@0
|
4 |
#include "stdafx.h"
|
sl@0
|
5 |
#include "SoundGraphAccess.h"
|
sl@0
|
6 |
#include "iMONDisplayAPI.h"
|
lenclud@3
|
7 |
#include <stdio.h>
|
sl@0
|
8 |
|
lenclud@3
|
9 |
#define WM_DSP_PLUGIN_NOTIFY WM_APP + 1100
|
lenclud@3
|
10 |
#define WM_IMON_INIT WM_APP + 1101
|
lenclud@3
|
11 |
#define WM_IMON_UNINIT WM_APP + 1102
|
lenclud@3
|
12 |
#define WM_IMON_IS_INIT WM_APP + 1103
|
lenclud@3
|
13 |
#define WM_IMON_IS_PLUGIN_MODE_ENABLED WM_APP + 1104
|
lenclud@4
|
14 |
#define WM_IMON_DISPLAY_SET_VFD_TEXT WM_APP + 1105
|
lenclud@3
|
15 |
|
lenclud@3
|
16 |
//
|
sl@0
|
17 |
#define MAX_LOADSTRING 100
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
// Global Variables:
|
sl@0
|
21 |
HINSTANCE hInst = 0; // current instance
|
sl@0
|
22 |
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
|
sl@0
|
23 |
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
|
lenclud@3
|
24 |
HANDLE gThreadReceiver = INVALID_HANDLE_VALUE;
|
lenclud@3
|
25 |
//HANDLE gThreadSender = INVALID_HANDLE_VALUE;
|
sl@0
|
26 |
BOOL gQuit=FALSE;
|
sl@0
|
27 |
|
sl@0
|
28 |
LPTSTR gPipeNameSender = TEXT("\\\\.\\pipe\\sga-sender");
|
sl@0
|
29 |
LPTSTR gPipeNameReceiver = TEXT("\\\\.\\pipe\\sga-receiver");
|
lenclud@3
|
30 |
HANDLE gPipeSender=INVALID_HANDLE_VALUE;
|
lenclud@3
|
31 |
HANDLE gPipeReceiver=INVALID_HANDLE_VALUE;
|
sl@0
|
32 |
|
sl@0
|
33 |
char gBufferReceiver[256];
|
sl@0
|
34 |
char gBufferSender[256];
|
lenclud@4
|
35 |
//
|
lenclud@4
|
36 |
char gTextFirstLine[256];
|
lenclud@4
|
37 |
char gTextSecondLine[256];
|
lenclud@4
|
38 |
wchar_t gTextFirstLine16[256];
|
lenclud@4
|
39 |
wchar_t gTextSecondLine16[256];
|
sl@0
|
40 |
|
lenclud@2
|
41 |
//
|
lenclud@2
|
42 |
HWND gWnd;
|
sl@0
|
43 |
|
sl@0
|
44 |
//
|
sl@0
|
45 |
BOOL m_bVfdConnected;
|
sl@0
|
46 |
BOOL m_bLcdConnected;
|
sl@0
|
47 |
|
sl@0
|
48 |
// Forward declarations of functions included in this code module:
|
sl@0
|
49 |
ATOM MyRegisterClass(HINSTANCE hInstance);
|
sl@0
|
50 |
BOOL InitInstance(HINSTANCE, int);
|
sl@0
|
51 |
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
sl@0
|
52 |
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
|
sl@0
|
53 |
|
lenclud@3
|
54 |
//Supported responses
|
lenclud@3
|
55 |
const char KRspDone[]="done:";
|
lenclud@3
|
56 |
const char KRspPending[]="pending:";
|
lenclud@3
|
57 |
const char KRspError[]="error:";
|
lenclud@3
|
58 |
const char KRspClose[]="close:";
|
lenclud@3
|
59 |
const char KRspOpen[]="open:";
|
lenclud@3
|
60 |
const char KRspUnknown[]="unknown:";
|
lenclud@3
|
61 |
const char KRspTrue[]="true:";
|
lenclud@3
|
62 |
const char KRspFalse[]="false:";
|
lenclud@3
|
63 |
//Supported incoming messages
|
lenclud@3
|
64 |
const char KMsgInit[]="init:";
|
lenclud@3
|
65 |
const char KMsgUninit[]="uninit:";
|
lenclud@3
|
66 |
const char KMsgIsInit[]="is-init:";
|
lenclud@3
|
67 |
const char KMsgIsPluginModeEnabled[]="is-plugin-mode-enabled:";
|
lenclud@4
|
68 |
const char KMsgSetVfdText[]="set-vfd-text:";
|
lenclud@4
|
69 |
|
lenclud@2
|
70 |
|
lenclud@2
|
71 |
/**
|
lenclud@2
|
72 |
Send a message to our server.
|
lenclud@2
|
73 |
*/
|
lenclud@2
|
74 |
void SendMessageToServer(const char* aResponse)
|
lenclud@2
|
75 |
{
|
lenclud@2
|
76 |
DWORD cbWritten=0;
|
lenclud@3
|
77 |
char msg[512];
|
lenclud@3
|
78 |
sprintf(msg,"%s\n",aResponse);
|
lenclud@3
|
79 |
OutputDebugStringA(msg);
|
lenclud@2
|
80 |
WriteFile(gPipeSender, aResponse, strlen(aResponse), &cbWritten, NULL);
|
lenclud@2
|
81 |
}
|
lenclud@2
|
82 |
|
lenclud@2
|
83 |
|
lenclud@2
|
84 |
/**
|
lenclud@2
|
85 |
Handle messages from our server.
|
lenclud@2
|
86 |
*/
|
lenclud@2
|
87 |
void MessageReceived(const char* aMsg)
|
lenclud@2
|
88 |
{
|
lenclud@2
|
89 |
//
|
lenclud@3
|
90 |
if (strcmp(aMsg,KMsgInit)==0)
|
lenclud@2
|
91 |
{
|
lenclud@2
|
92 |
//IMON API call need to be done from window thread for some reason
|
lenclud@3
|
93 |
SendMessageToServer(KRspPending);
|
lenclud@3
|
94 |
PostMessage(gWnd,WM_IMON_INIT,0,0);
|
lenclud@3
|
95 |
}
|
lenclud@3
|
96 |
else if (strcmp(aMsg,KMsgUninit)==0)
|
lenclud@3
|
97 |
{
|
lenclud@3
|
98 |
//IMON API call need to be done from window thread for some reason
|
lenclud@3
|
99 |
SendMessageToServer(KRspPending);
|
lenclud@3
|
100 |
PostMessage(gWnd,WM_IMON_UNINIT,0,0);
|
lenclud@3
|
101 |
}
|
lenclud@3
|
102 |
else if (strcmp(aMsg,KMsgIsPluginModeEnabled)==0)
|
lenclud@3
|
103 |
{
|
lenclud@3
|
104 |
//IMON API call need to be done from window thread for some reason
|
lenclud@3
|
105 |
SendMessageToServer(KRspPending);
|
lenclud@3
|
106 |
PostMessage(gWnd,WM_IMON_IS_PLUGIN_MODE_ENABLED,0,0);
|
lenclud@3
|
107 |
}
|
lenclud@3
|
108 |
else if (strcmp(aMsg,KMsgIsInit)==0)
|
lenclud@3
|
109 |
{
|
lenclud@3
|
110 |
//IMON API call need to be done from window thread for some reason
|
lenclud@3
|
111 |
SendMessageToServer(KRspPending);
|
lenclud@3
|
112 |
PostMessage(gWnd,WM_IMON_IS_INIT,0,0);
|
lenclud@3
|
113 |
}
|
lenclud@4
|
114 |
else if (strstr(aMsg,KMsgSetVfdText)==aMsg)
|
lenclud@4
|
115 |
{
|
lenclud@4
|
116 |
int textLen=strlen(aMsg)-strlen(KMsgSetVfdText);
|
lenclud@4
|
117 |
strncpy(gTextFirstLine,aMsg+strlen(KMsgSetVfdText),textLen);
|
lenclud@4
|
118 |
gTextFirstLine[textLen]='\0';
|
lenclud@4
|
119 |
OutputDebugStringA(gTextFirstLine);
|
lenclud@4
|
120 |
int convertedChars = MultiByteToWideChar(CP_UTF8, 0, gTextFirstLine, -1, gTextFirstLine16, sizeof(gTextFirstLine16));
|
lenclud@4
|
121 |
OutputDebugString(gTextFirstLine16);
|
lenclud@4
|
122 |
//IMON API call need to be done from window thread for some reason
|
lenclud@4
|
123 |
SendMessageToServer(KRspPending);
|
lenclud@4
|
124 |
PostMessage(gWnd,WM_IMON_DISPLAY_SET_VFD_TEXT,0,0);
|
lenclud@4
|
125 |
}
|
lenclud@3
|
126 |
else
|
lenclud@3
|
127 |
{
|
lenclud@3
|
128 |
SendMessageToServer(KRspUnknown);
|
lenclud@3
|
129 |
}
|
lenclud@3
|
130 |
}
|
lenclud@3
|
131 |
|
lenclud@3
|
132 |
|
lenclud@3
|
133 |
|
lenclud@3
|
134 |
/**
|
lenclud@3
|
135 |
Connect our named pipes from here.
|
lenclud@3
|
136 |
First connect our read pipe then our write pipe.
|
lenclud@3
|
137 |
Then notify our server we are connected.
|
lenclud@3
|
138 |
Then keep on waiting for incoming messages.
|
lenclud@3
|
139 |
*/
|
lenclud@3
|
140 |
DWORD WINAPI ThreadReceiver( LPVOID lpParam )
|
lenclud@3
|
141 |
{
|
lenclud@3
|
142 |
//Keep on trying to connect on our read pipe
|
lenclud@3
|
143 |
while (gPipeReceiver==INVALID_HANDLE_VALUE && !gQuit)
|
lenclud@3
|
144 |
{
|
lenclud@3
|
145 |
OutputDebugStringA("Trying to connect...\n");
|
lenclud@3
|
146 |
gPipeReceiver=CreateFile(gPipeNameReceiver, GENERIC_READ ,0,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL);
|
lenclud@3
|
147 |
Sleep(1000);
|
lenclud@3
|
148 |
}
|
lenclud@3
|
149 |
|
lenclud@3
|
150 |
OutputDebugStringA("Read pipe open!\n");
|
lenclud@3
|
151 |
//Now try connecting on our write pipe
|
lenclud@3
|
152 |
gPipeSender=CreateFile(gPipeNameSender, GENERIC_WRITE ,0,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL);
|
lenclud@3
|
153 |
if (gPipeSender==INVALID_HANDLE_VALUE)
|
lenclud@3
|
154 |
{
|
lenclud@3
|
155 |
OutputDebugStringA("ERROR: Write pipe failure!\n");
|
lenclud@3
|
156 |
gQuit=TRUE;
|
lenclud@2
|
157 |
}
|
lenclud@2
|
158 |
else
|
lenclud@2
|
159 |
{
|
lenclud@3
|
160 |
OutputDebugStringA("Write pipe opened.\n");
|
lenclud@3
|
161 |
OutputDebugStringA("Connected.\n");
|
lenclud@3
|
162 |
SendMessageToServer(KRspOpen);
|
lenclud@2
|
163 |
}
|
lenclud@3
|
164 |
//
|
sl@0
|
165 |
|
sl@0
|
166 |
while(!gQuit)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
DWORD cbRead;
|
sl@0
|
169 |
BOOL success=ReadFile(gPipeReceiver,gBufferReceiver,sizeof(gBufferReceiver),&cbRead, NULL);
|
sl@0
|
170 |
if(success)
|
lenclud@3
|
171 |
{
|
sl@0
|
172 |
gBufferReceiver[cbRead]='\0';
|
sl@0
|
173 |
OutputDebugStringA(gBufferReceiver);
|
lenclud@2
|
174 |
MessageReceived(gBufferReceiver);
|
sl@0
|
175 |
}
|
lenclud@3
|
176 |
//if (!success && GetLastError() != ERROR_MORE_DATA)
|
lenclud@3
|
177 |
// {
|
lenclud@3
|
178 |
// OutputDebugStringA("Can't Read\n");
|
lenclud@3
|
179 |
// }
|
lenclud@3
|
180 |
//
|
lenclud@3
|
181 |
//Sleep(500);
|
lenclud@3
|
182 |
|
lenclud@3
|
183 |
if (!success)
|
sl@0
|
184 |
{
|
lenclud@3
|
185 |
gQuit=TRUE;
|
sl@0
|
186 |
}
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
lenclud@3
|
189 |
//Try tell our server
|
lenclud@3
|
190 |
SendMessageToServer(KRspClose);
|
lenclud@3
|
191 |
//Close our pipes
|
lenclud@3
|
192 |
CloseHandle(gPipeReceiver);
|
lenclud@3
|
193 |
gPipeReceiver=INVALID_HANDLE_VALUE;
|
lenclud@3
|
194 |
CloseHandle(gPipeSender);
|
lenclud@3
|
195 |
gPipeSender=INVALID_HANDLE_VALUE;
|
lenclud@3
|
196 |
//Quit our application
|
lenclud@3
|
197 |
PostMessage(gWnd,WM_CLOSE,0,0);
|
lenclud@3
|
198 |
|
sl@0
|
199 |
return 0;
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
|
sl@0
|
203 |
|
sl@0
|
204 |
/**
|
sl@0
|
205 |
*/
|
sl@0
|
206 |
int APIENTRY _tWinMain(HINSTANCE hInstance,
|
sl@0
|
207 |
HINSTANCE hPrevInstance,
|
sl@0
|
208 |
LPTSTR lpCmdLine,
|
sl@0
|
209 |
int nCmdShow)
|
sl@0
|
210 |
{
|
sl@0
|
211 |
UNREFERENCED_PARAMETER(hPrevInstance);
|
sl@0
|
212 |
UNREFERENCED_PARAMETER(lpCmdLine);
|
sl@0
|
213 |
|
lenclud@4
|
214 |
gTextFirstLine[0]='\0';
|
lenclud@4
|
215 |
gTextSecondLine[0]='\0';
|
lenclud@4
|
216 |
gTextFirstLine16[0]='\0';
|
lenclud@4
|
217 |
gTextSecondLine16[0]='\0';
|
lenclud@4
|
218 |
|
lenclud@4
|
219 |
|
sl@0
|
220 |
// TODO: Place code here.
|
sl@0
|
221 |
MSG msg;
|
sl@0
|
222 |
HACCEL hAccelTable;
|
sl@0
|
223 |
|
sl@0
|
224 |
// Initialize global strings
|
sl@0
|
225 |
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
|
sl@0
|
226 |
LoadString(hInstance, IDC_SOUNDGRAPHACCESS, szWindowClass, MAX_LOADSTRING);
|
sl@0
|
227 |
MyRegisterClass(hInstance);
|
sl@0
|
228 |
|
sl@0
|
229 |
// Perform application initialization:
|
sl@0
|
230 |
if (!InitInstance (hInstance, /*SW_HIDE*/ nCmdShow))
|
sl@0
|
231 |
{
|
sl@0
|
232 |
return FALSE;
|
sl@0
|
233 |
}
|
sl@0
|
234 |
|
sl@0
|
235 |
|
sl@0
|
236 |
|
sl@0
|
237 |
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SOUNDGRAPHACCESS));
|
sl@0
|
238 |
|
sl@0
|
239 |
// Main message loop:
|
sl@0
|
240 |
while (GetMessage(&msg, NULL, 0, 0))
|
sl@0
|
241 |
{
|
sl@0
|
242 |
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
|
sl@0
|
243 |
{
|
sl@0
|
244 |
TranslateMessage(&msg);
|
sl@0
|
245 |
DispatchMessage(&msg);
|
sl@0
|
246 |
}
|
sl@0
|
247 |
}
|
sl@0
|
248 |
|
sl@0
|
249 |
return (int) msg.wParam;
|
sl@0
|
250 |
}
|
sl@0
|
251 |
|
lenclud@2
|
252 |
/**
|
lenclud@2
|
253 |
*/
|
sl@0
|
254 |
void DisplayPluginMessage(UINT uErrCode, BOOL bError)
|
sl@0
|
255 |
{
|
lenclud@2
|
256 |
char* strErrMsg = "";
|
sl@0
|
257 |
|
sl@0
|
258 |
if(bError)
|
sl@0
|
259 |
{
|
sl@0
|
260 |
switch(uErrCode)
|
sl@0
|
261 |
{
|
lenclud@2
|
262 |
case DSPN_ERR_IN_USED: strErrMsg = ("Display Plug-in is Already Used by Other Application."); break;
|
lenclud@2
|
263 |
case DSPN_ERR_HW_DISCONNECTED: strErrMsg = ("iMON HW is Not Connected."); break;
|
lenclud@2
|
264 |
case DSPN_ERR_NOT_SUPPORTED_HW: strErrMsg = ("The Connected iMON HW doesn't Support Display Plug-in."); break;
|
lenclud@3
|
265 |
case DSPN_ERR_PLUGIN_DISABLED: strErrMsg = ("Display Plug-in Mode Option is Disabled."); break;
|
lenclud@2
|
266 |
case DSPN_ERR_IMON_NO_REPLY: strErrMsg = ("The Latest iMON is Not Installed or iMON Not Running."); break;
|
lenclud@3
|
267 |
case DSPN_ERR_UNKNOWN: strErrMsg = ("Unknown Failure."); break;
|
sl@0
|
268 |
}
|
sl@0
|
269 |
}
|
sl@0
|
270 |
else
|
sl@0
|
271 |
{
|
sl@0
|
272 |
switch(uErrCode)
|
sl@0
|
273 |
{
|
lenclud@3
|
274 |
case DSPNM_PLUGIN_SUCCEED: strErrMsg = ("Plug-in Mode Inited Successfully."); break;
|
lenclud@2
|
275 |
case DSPNM_IMON_RESTARTED: strErrMsg = ("iMON Started and Plug-in Mode Inited."); break;
|
lenclud@2
|
276 |
case DSPNM_HW_CONNECTED: strErrMsg = ("iMON HW Connected and Plug-in Mode Inited."); break;
|
sl@0
|
277 |
}
|
sl@0
|
278 |
}
|
sl@0
|
279 |
//
|
lenclud@2
|
280 |
OutputDebugStringA(strErrMsg);
|
lenclud@3
|
281 |
|
lenclud@3
|
282 |
char msg[256];
|
lenclud@3
|
283 |
if (bError)
|
lenclud@3
|
284 |
{
|
lenclud@3
|
285 |
sprintf(msg,"error:%s",strErrMsg);
|
lenclud@3
|
286 |
}
|
lenclud@3
|
287 |
else
|
lenclud@3
|
288 |
{
|
lenclud@3
|
289 |
sprintf(msg,"done:%s",strErrMsg);
|
lenclud@3
|
290 |
}
|
lenclud@3
|
291 |
SendMessageToServer(msg);
|
sl@0
|
292 |
}
|
sl@0
|
293 |
|
sl@0
|
294 |
|
sl@0
|
295 |
|
sl@0
|
296 |
//
|
sl@0
|
297 |
// FUNCTION: MyRegisterClass()
|
sl@0
|
298 |
//
|
sl@0
|
299 |
// PURPOSE: Registers the window class.
|
sl@0
|
300 |
//
|
sl@0
|
301 |
// COMMENTS:
|
sl@0
|
302 |
//
|
sl@0
|
303 |
// This function and its usage are only necessary if you want this code
|
sl@0
|
304 |
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
|
sl@0
|
305 |
// function that was added to Windows 95. It is important to call this function
|
sl@0
|
306 |
// so that the application will get 'well formed' small icons associated
|
sl@0
|
307 |
// with it.
|
sl@0
|
308 |
//
|
sl@0
|
309 |
ATOM MyRegisterClass(HINSTANCE hInstance)
|
sl@0
|
310 |
{
|
sl@0
|
311 |
WNDCLASSEX wcex;
|
sl@0
|
312 |
|
sl@0
|
313 |
wcex.cbSize = sizeof(WNDCLASSEX);
|
sl@0
|
314 |
|
sl@0
|
315 |
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
sl@0
|
316 |
wcex.lpfnWndProc = WndProc;
|
sl@0
|
317 |
wcex.cbClsExtra = 0;
|
sl@0
|
318 |
wcex.cbWndExtra = 0;
|
sl@0
|
319 |
wcex.hInstance = hInstance;
|
sl@0
|
320 |
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SOUNDGRAPHACCESS));
|
sl@0
|
321 |
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
|
sl@0
|
322 |
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
sl@0
|
323 |
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_SOUNDGRAPHACCESS);
|
sl@0
|
324 |
wcex.lpszClassName = szWindowClass;
|
sl@0
|
325 |
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
|
sl@0
|
326 |
|
sl@0
|
327 |
return RegisterClassEx(&wcex);
|
sl@0
|
328 |
}
|
sl@0
|
329 |
|
sl@0
|
330 |
//
|
sl@0
|
331 |
// FUNCTION: InitInstance(HINSTANCE, int)
|
sl@0
|
332 |
//
|
sl@0
|
333 |
// PURPOSE: Saves instance handle and creates main window
|
sl@0
|
334 |
//
|
sl@0
|
335 |
// COMMENTS:
|
sl@0
|
336 |
//
|
sl@0
|
337 |
// In this function, we save the instance handle in a global variable and
|
sl@0
|
338 |
// create and display the main program window.
|
sl@0
|
339 |
//
|
sl@0
|
340 |
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
sl@0
|
341 |
{
|
lenclud@2
|
342 |
|
sl@0
|
343 |
|
sl@0
|
344 |
hInst = hInstance; // Store instance handle in our global variable
|
sl@0
|
345 |
|
lenclud@2
|
346 |
gWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
|
sl@0
|
347 |
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
|
sl@0
|
348 |
|
lenclud@2
|
349 |
if (!gWnd)
|
sl@0
|
350 |
{
|
sl@0
|
351 |
return FALSE;
|
sl@0
|
352 |
}
|
sl@0
|
353 |
|
lenclud@2
|
354 |
ShowWindow(gWnd, nCmdShow);
|
lenclud@2
|
355 |
UpdateWindow(gWnd);
|
sl@0
|
356 |
|
sl@0
|
357 |
return TRUE;
|
sl@0
|
358 |
}
|
sl@0
|
359 |
|
sl@0
|
360 |
//
|
sl@0
|
361 |
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
|
sl@0
|
362 |
//
|
sl@0
|
363 |
// PURPOSE: Processes messages for the main window.
|
sl@0
|
364 |
//
|
sl@0
|
365 |
// WM_COMMAND - process the application menu
|
sl@0
|
366 |
// WM_PAINT - Paint the main window
|
sl@0
|
367 |
// WM_DESTROY - post a quit message and return
|
sl@0
|
368 |
//
|
sl@0
|
369 |
//
|
sl@0
|
370 |
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
sl@0
|
371 |
{
|
sl@0
|
372 |
int wmId, wmEvent;
|
sl@0
|
373 |
PAINTSTRUCT ps;
|
sl@0
|
374 |
HDC hdc;
|
sl@0
|
375 |
|
sl@0
|
376 |
switch (message)
|
sl@0
|
377 |
{
|
sl@0
|
378 |
case WM_CREATE:
|
sl@0
|
379 |
//IMON_Display_Uninit();
|
sl@0
|
380 |
//IMON_Display_Init(hWnd, WM_DSP_PLUGIN_NOTIFY);
|
sl@0
|
381 |
gThreadReceiver = CreateThread( NULL, 0, ThreadReceiver, NULL/*data pointer*/, 0, NULL);
|
sl@0
|
382 |
break;
|
sl@0
|
383 |
case WM_COMMAND:
|
sl@0
|
384 |
wmId = LOWORD(wParam);
|
sl@0
|
385 |
wmEvent = HIWORD(wParam);
|
sl@0
|
386 |
// Parse the menu selections:
|
sl@0
|
387 |
switch (wmId)
|
sl@0
|
388 |
{
|
sl@0
|
389 |
case IDM_ABOUT:
|
sl@0
|
390 |
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
|
sl@0
|
391 |
break;
|
sl@0
|
392 |
case IDM_EXIT:
|
sl@0
|
393 |
DestroyWindow(hWnd);
|
sl@0
|
394 |
break;
|
sl@0
|
395 |
default:
|
sl@0
|
396 |
return DefWindowProc(hWnd, message, wParam, lParam);
|
sl@0
|
397 |
}
|
sl@0
|
398 |
break;
|
sl@0
|
399 |
case WM_PAINT:
|
sl@0
|
400 |
hdc = BeginPaint(hWnd, &ps);
|
sl@0
|
401 |
// TODO: Add any drawing code here...
|
sl@0
|
402 |
EndPaint(hWnd, &ps);
|
sl@0
|
403 |
break;
|
sl@0
|
404 |
case WM_DESTROY:
|
sl@0
|
405 |
gQuit=TRUE;
|
sl@0
|
406 |
//To complete write op
|
lenclud@3
|
407 |
if (gPipeSender!=INVALID_HANDLE_VALUE)
|
sl@0
|
408 |
{
|
sl@0
|
409 |
CloseHandle(gPipeSender);
|
lenclud@3
|
410 |
gPipeSender=INVALID_HANDLE_VALUE;
|
sl@0
|
411 |
}
|
sl@0
|
412 |
//To complete read op
|
lenclud@3
|
413 |
if (gPipeReceiver!=INVALID_HANDLE_VALUE)
|
sl@0
|
414 |
{
|
sl@0
|
415 |
CloseHandle(gPipeReceiver);
|
lenclud@3
|
416 |
gPipeReceiver=INVALID_HANDLE_VALUE;
|
sl@0
|
417 |
}
|
lenclud@3
|
418 |
|
sl@0
|
419 |
WaitForSingleObject(gThreadReceiver,INFINITE);
|
sl@0
|
420 |
CloseHandle(gThreadReceiver);
|
sl@0
|
421 |
//IMON_Display_Uninit();
|
sl@0
|
422 |
PostQuitMessage(0);
|
sl@0
|
423 |
break;
|
lenclud@2
|
424 |
|
lenclud@2
|
425 |
case WM_IMON_UNINIT:
|
lenclud@2
|
426 |
IMON_Display_Uninit();
|
lenclud@3
|
427 |
SendMessageToServer(KRspDone);
|
lenclud@2
|
428 |
break;
|
lenclud@2
|
429 |
|
lenclud@2
|
430 |
case WM_IMON_INIT:
|
lenclud@2
|
431 |
IMON_Display_Uninit();
|
lenclud@2
|
432 |
IMON_Display_Init(hWnd, WM_DSP_PLUGIN_NOTIFY);
|
lenclud@2
|
433 |
break;
|
lenclud@3
|
434 |
//
|
lenclud@3
|
435 |
case WM_IMON_IS_PLUGIN_MODE_ENABLED:
|
lenclud@3
|
436 |
if (IMON_Display_IsPluginModeEnabled()==DSP_S_IN_PLUGIN_MODE)
|
lenclud@3
|
437 |
{
|
lenclud@3
|
438 |
SendMessageToServer(KRspTrue);
|
lenclud@3
|
439 |
}
|
lenclud@3
|
440 |
else
|
lenclud@3
|
441 |
{
|
lenclud@3
|
442 |
SendMessageToServer(KRspFalse);
|
lenclud@3
|
443 |
}
|
lenclud@3
|
444 |
break;
|
lenclud@3
|
445 |
//
|
lenclud@3
|
446 |
case WM_IMON_IS_INIT:
|
lenclud@3
|
447 |
if (IMON_Display_IsInited()==DSP_S_INITED)
|
lenclud@3
|
448 |
{
|
lenclud@3
|
449 |
SendMessageToServer(KRspTrue);
|
lenclud@3
|
450 |
}
|
lenclud@3
|
451 |
else
|
lenclud@3
|
452 |
{
|
lenclud@3
|
453 |
SendMessageToServer(KRspFalse);
|
lenclud@3
|
454 |
}
|
lenclud@3
|
455 |
break;
|
lenclud@4
|
456 |
//
|
lenclud@4
|
457 |
case WM_IMON_DISPLAY_SET_VFD_TEXT:
|
lenclud@4
|
458 |
if (DSP_SUCCEEDED==IMON_Display_SetVfdText(gTextFirstLine16,gTextSecondLine16))
|
lenclud@4
|
459 |
{
|
lenclud@4
|
460 |
SendMessageToServer(KRspDone);
|
lenclud@4
|
461 |
}
|
lenclud@4
|
462 |
else
|
lenclud@4
|
463 |
{
|
lenclud@4
|
464 |
SendMessageToServer(KRspError);
|
lenclud@4
|
465 |
}
|
lenclud@4
|
466 |
break;
|
lenclud@2
|
467 |
|
sl@0
|
468 |
case WM_DSP_PLUGIN_NOTIFY:
|
sl@0
|
469 |
switch(wParam)
|
sl@0
|
470 |
{
|
sl@0
|
471 |
case DSPNM_PLUGIN_SUCCEED:
|
sl@0
|
472 |
case DSPNM_IMON_RESTARTED:
|
sl@0
|
473 |
case DSPNM_HW_CONNECTED:
|
sl@0
|
474 |
{
|
sl@0
|
475 |
//GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
|
sl@0
|
476 |
m_bVfdConnected = FALSE;
|
sl@0
|
477 |
m_bLcdConnected = FALSE;
|
sl@0
|
478 |
if((lParam & DSPN_DSP_VFD) == DSPN_DSP_VFD) m_bVfdConnected = TRUE;
|
sl@0
|
479 |
if((lParam & DSPN_DSP_LCD) == DSPN_DSP_LCD) m_bLcdConnected = TRUE;
|
sl@0
|
480 |
//UpdateControlUI();
|
sl@0
|
481 |
|
sl@0
|
482 |
DisplayPluginMessage(wParam, FALSE);
|
sl@0
|
483 |
}
|
sl@0
|
484 |
break;
|
sl@0
|
485 |
|
sl@0
|
486 |
case DSPNM_PLUGIN_FAILED:
|
sl@0
|
487 |
case DSPNM_HW_DISCONNECTED:
|
sl@0
|
488 |
case DSPNM_IMON_CLOSED:
|
sl@0
|
489 |
{
|
sl@0
|
490 |
//GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
|
sl@0
|
491 |
m_bVfdConnected = FALSE;
|
sl@0
|
492 |
m_bLcdConnected = FALSE;
|
sl@0
|
493 |
//UpdateControlUI();
|
sl@0
|
494 |
|
sl@0
|
495 |
DisplayPluginMessage(lParam, TRUE);
|
sl@0
|
496 |
}
|
sl@0
|
497 |
break;
|
sl@0
|
498 |
|
sl@0
|
499 |
case DSPNM_LCD_TEXT_SCROLL_DONE:
|
sl@0
|
500 |
{
|
sl@0
|
501 |
//TRACE(_T("LCD Text Scroll Finished.\n"));
|
sl@0
|
502 |
}
|
sl@0
|
503 |
break;
|
sl@0
|
504 |
}
|
sl@0
|
505 |
return 0;
|
sl@0
|
506 |
break;
|
sl@0
|
507 |
default:
|
sl@0
|
508 |
return DefWindowProc(hWnd, message, wParam, lParam);
|
sl@0
|
509 |
}
|
sl@0
|
510 |
return 0;
|
sl@0
|
511 |
}
|
sl@0
|
512 |
|
sl@0
|
513 |
// Message handler for about box.
|
sl@0
|
514 |
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
sl@0
|
515 |
{
|
sl@0
|
516 |
UNREFERENCED_PARAMETER(lParam);
|
sl@0
|
517 |
switch (message)
|
sl@0
|
518 |
{
|
sl@0
|
519 |
case WM_INITDIALOG:
|
sl@0
|
520 |
return (INT_PTR)TRUE;
|
sl@0
|
521 |
|
sl@0
|
522 |
case WM_COMMAND:
|
sl@0
|
523 |
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
|
sl@0
|
524 |
{
|
sl@0
|
525 |
EndDialog(hDlg, LOWORD(wParam));
|
sl@0
|
526 |
return (INT_PTR)TRUE;
|
sl@0
|
527 |
}
|
sl@0
|
528 |
break;
|
sl@0
|
529 |
}
|
sl@0
|
530 |
return (INT_PTR)FALSE;
|
sl@0
|
531 |
}
|
sl@0
|
532 |
|