fork(7) download
  1. // GuiApp.cpp : ÂĘĎňËŽË├│╠đ˛Á─╚Ű┐┌ÁŃíú
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "GuiApp_English.h"
  6.  
  7. int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine, int nCmdShow)
  8. {
  9. XInitXCGUI(); //initial
  10.  
  11. CUSBRelayWnd MyWnd;
  12. if(MyWnd.Create())
  13. {
  14. XRunXCGUI(); //run gui
  15. }
  16. return 0;
  17. }
  18.  
  19. //create main window
  20. BOOL CUSBRelayWnd::Create()
  21. {
  22. m_hWindow = XWnd_CreateWindow(0, 0, 290, 430, L"USB Relay Manager"); //main window
  23. if(m_hWindow)
  24. {
  25. XWnd_EnableDragBorder(m_hWindow, FALSE);
  26. XWnd_EnableMaxButton(m_hWindow, FALSE);
  27.  
  28. //1. create find device button
  29. m_hFindDeviceBtn = XBtn_Create(10, 10, 90, 25, L"Find device", m_hWindow);
  30. //register the button click event
  31. XCGUI_RegEleEvent(m_hFindDeviceBtn, XE_BNCLICK, &CUSBRelayWnd::OnFindDeviceBtnClick);
  32.  
  33. //2. create the device list combobox
  34. m_hDeviceListBox = XComboBox_Create(110, 10, 150, 25, m_hWindow);
  35.  
  36. //3. create open device button
  37. m_hOpenDeviceBtn = XBtn_Create(10, 45, 90, 25, L"open device", m_hWindow);
  38. //register the button click event
  39. XCGUI_RegEleEvent(m_hOpenDeviceBtn, XE_BNCLICK, &CUSBRelayWnd::OnOpenDeviceBtnClick);
  40.  
  41. //4. create open status label
  42. m_hOpenStatus = XEle_Create(110, 45, 50, 25, m_hWindow);
  43. XEle_SetBkColor(m_hOpenStatus, RGB(255, 0, 0));
  44.  
  45. //5. create close device button
  46. m_hOpenDeviceBtn = XBtn_Create(170, 45, 90, 25, L"close device", m_hWindow);
  47. //disable before open a device
  48.  
  49. //register the button click event
  50. XCGUI_RegEleEvent(m_hOpenDeviceBtn, XE_BNCLICK, &CUSBRelayWnd::OnCloseDeviceBtnClick);
  51.  
  52. int pos_text_x = 10;
  53. int pos_open_btn_x = 105;
  54. int pos_status_label_x = 170;
  55. int pos_close_btn_x = 200;
  56.  
  57. int pos_y = 80;
  58.  
  59. //6. create the buttons and lables for all relay
  60. for (int i = 0; i < 8; i++)
  61. {
  62. wchar_t relayName[20] = {0};
  63. wsprintf(relayName, L"Realy %d", i+1);
  64.  
  65. m_hRelayText[i] = XEdit_Create(pos_text_x, pos_y, 90, 25, m_hWindow);
  66. XEdit_SetText(m_hRelayText[i], relayName);
  67.  
  68. m_hRelayOpenBtn[i] = XBtn_Create(pos_open_btn_x, pos_y, 60, 25, L"open", m_hWindow);
  69. XCGUI_RegEleEvent(m_hRelayOpenBtn[i], XE_BNCLICK, &CUSBRelayWnd::OnOpenRelayBtnClick);
  70.  
  71. m_hRelayStatusLabel[i] = XEle_Create(pos_status_label_x, pos_y, 25, 25, m_hWindow);
  72. XEle_SetBkColor(m_hRelayStatusLabel[i], RGB(255, 0, 0));
  73.  
  74. m_hRelayCloseBtn[i] = XBtn_Create(pos_close_btn_x, pos_y, 60, 25, L"close", m_hWindow);
  75. XCGUI_RegEleEvent(m_hRelayCloseBtn[i], XE_BNCLICK, &CUSBRelayWnd::OnCloseRelayBtnClick);
  76.  
  77. pos_y += 30;
  78. }
  79.  
  80. //7. create open-all relay button
  81. m_hOpenAllRelayBtn = XBtn_Create(10, pos_y+10, 120, 50, L"Open All", m_hWindow);
  82. XCGUI_RegEleEvent(m_hOpenAllRelayBtn, XE_BNCLICK, &CUSBRelayWnd::OnOpenAllRelayBtnClick);
  83.  
  84. //8. create close-all relay button
  85. m_hCloseAllRelayBtn = XBtn_Create(140, pos_y+10, 120, 50, L"Close All", m_hWindow);
  86. XCGUI_RegEleEvent(m_hCloseAllRelayBtn, XE_BNCLICK, &CUSBRelayWnd::OnCloseAllRelayBtnClick);
  87.  
  88. //initial usb_relay_device lib
  89. usb_relay_init();
  90.  
  91. XWnd_ShowWindow(m_hWindow, SW_SHOW); //¤ď╩ż┤░┐┌
  92. return true;
  93. }
  94. return false;
  95. }
  96.  
  97. BOOL CUSBRelayWnd::OnFindDeviceBtnClick( HELE hEle,HELE hEleEvent )
  98. {
  99. if (m_bOpened)
  100. {
  101. XMessageBox(XEle_GetHWindow(hEle), L"Close Current Device First", L"Attention", XMB_OK);
  102. return TRUE;
  103. }
  104.  
  105. if (m_pDeviceList)
  106. {
  107. usb_relay_device_free_enumerate(m_pDeviceList);
  108. m_pDeviceList = NULL;
  109. }
  110.  
  111. m_pDeviceList = usb_relay_device_enumerate();
  112. if (m_pDeviceList)
  113. {
  114. struct usb_relay_device_info *cur_device = m_pDeviceList;
  115. while (cur_device)
  116. {
  117. XComboBox_AddString( m_hDeviceListBox, (wchar_t*)(Ansi2WChar((char*)(cur_device->serial_number)).c_str()) );
  118. m_mapIndexToDevice[Ansi2WChar((char*)(cur_device->serial_number))] = cur_device;
  119.  
  120. cur_device = cur_device->next;
  121. }
  122. }
  123.  
  124. return TRUE;
  125. }
  126.  
  127. BOOL CUSBRelayWnd::OnOpenDeviceBtnClick( HELE hEle,HELE hEleEvent )
  128. {
  129. if (m_bOpened)
  130. {
  131. XMessageBox(XEle_GetHWindow(hEle), L"Close Current Device First", L"Attention", XMB_OK);
  132. return TRUE;
  133. }
  134.  
  135. int index = XComboBox_GetSelectItem(m_hDeviceListBox);
  136. if (index > -1)
  137. {
  138. wchar_t *serial = XComboBox_GetItemText(m_hDeviceListBox, index);
  139. std::map<wstring ,struct usb_relay_device_info*>::const_iterator fd = m_mapIndexToDevice.find(wstring(serial));
  140. if (fd != m_mapIndexToDevice.end())
  141. {
  142. //1. open usb relay device
  143. m_hCurDevice = usb_relay_device_open(fd->second);
  144. if (m_hCurDevice)
  145. {
  146. //2. Get status
  147. unsigned int status = 0;
  148. if (0 == usb_relay_device_get_status(m_hCurDevice, &status))
  149. {
  150. for (int i = 0; i < fd->second->type; i++)
  151. {
  152. if ((1<<i) & status)
  153. {
  154. XEle_SetBkColor(m_hRelayStatusLabel[i], RGB(0, 255, 0));
  155. XEle_RedrawEle(m_hRelayStatusLabel[i], TRUE);
  156. }
  157. }
  158. XEle_SetBkColor(m_hOpenStatus, RGB(0, 255, 0));
  159. XEle_RedrawEle(m_hOpenStatus, TRUE);
  160. m_bOpened = TRUE;
  161. m_hCureDeviceIndex = fd->second->type;
  162. }
  163. else
  164. {
  165. usb_relay_device_close(m_hCurDevice);
  166. m_hCurDevice = 0;
  167. XMessageBox(XEle_GetHWindow(hEle), L"Open Device Error!!", L"Error", XMB_OK);
  168. }
  169.  
  170. }
  171. else
  172. {
  173. XMessageBox(XEle_GetHWindow(hEle), L"Open Device Error!!", L"Error", XMB_OK);
  174. }
  175. }
  176. else
  177. {
  178. XMessageBox(XEle_GetHWindow(hEle), L"The Device is not valid", L"Error", XMB_OK);
  179. }
  180. }
  181. else
  182. {
  183. XMessageBox(XEle_GetHWindow(hEle), L"Select the device first", L"Error", XMB_OK);
  184. }
  185.  
  186. return TRUE;
  187. }
  188.  
  189. BOOL CUSBRelayWnd::OnCloseDeviceBtnClick( HELE hEle,HELE hEleEvent )
  190. {
  191. if (!m_bOpened)
  192. {
  193. XMessageBox(XEle_GetHWindow(hEle), L"Open Device First", L"Error", XMB_OK);
  194. return TRUE;
  195. }
  196.  
  197. usb_relay_device_close(m_hCurDevice);
  198. m_hCurDevice = 0;
  199. m_bOpened = FALSE;
  200. XEle_SetBkColor(m_hOpenStatus, RGB(255, 0, 0));
  201. XEle_RedrawEle(m_hOpenStatus, TRUE);
  202.  
  203. for (int i = 0; i < m_hCureDeviceIndex; i++)
  204. {
  205. XEle_SetBkColor(m_hRelayStatusLabel[i], RGB(255, 0, 0));
  206. XEle_RedrawEle(m_hRelayStatusLabel[i], TRUE);
  207. }
  208.  
  209. return TRUE;
  210. }
  211.  
  212. BOOL CUSBRelayWnd::OnOpenRelayBtnClick( HELE hEle, HELE hEleEvent )
  213. {
  214. if (!m_bOpened)
  215. {
  216. XMessageBox(XEle_GetHWindow(hEle), L"Open Device First", L"Error", XMB_OK);
  217. return TRUE;
  218. }
  219. for (int i = 0; i < 8; i++)
  220. {
  221. if (hEle == m_hRelayOpenBtn[i])
  222. {
  223. int ret = usb_relay_device_open_one_relay_channel(m_hCurDevice, i+1);
  224. if (ret == 0)
  225. {
  226. XEle_SetBkColor(m_hRelayStatusLabel[i], RGB(0, 255, 0));
  227. XEle_RedrawEle(m_hRelayStatusLabel[i],TRUE);
  228. }
  229. }
  230. }
  231. return TRUE;
  232. }
  233.  
  234. BOOL CUSBRelayWnd::OnCloseRelayBtnClick( HELE hEle, HELE hEleEvent )
  235. {
  236. if (!m_bOpened)
  237. {
  238. XMessageBox(XEle_GetHWindow(hEle), L"Open Device First", L"Error", XMB_OK);
  239. return TRUE;
  240. }
  241. for (int i = 0; i < 8; i++)
  242. {
  243. if (hEle == m_hRelayCloseBtn[i])
  244. {
  245. int ret = usb_relay_device_close_one_relay_channel(m_hCurDevice, i+1);
  246. if (ret == 0)
  247. {
  248. XEle_SetBkColor(m_hRelayStatusLabel[i], RGB(255, 0, 0));
  249. XEle_RedrawEle(m_hRelayStatusLabel[i],TRUE);
  250. }
  251. }
  252. }
  253. return TRUE;
  254. }
  255.  
  256. BOOL CUSBRelayWnd::OnOpenAllRelayBtnClick( HELE hEle, HELE hEleEvent )
  257. {
  258. if (!m_bOpened)
  259. {
  260. XMessageBox(XEle_GetHWindow(hEle), L"Open Device First", L"Error", XMB_OK);
  261. return TRUE;
  262. }
  263. int ret = usb_relay_device_open_all_relay_channel(m_hCurDevice);
  264. if (ret == 0)
  265. {
  266. for(int i = 0; i < m_hCureDeviceIndex; i++)
  267. {
  268. XEle_SetBkColor(m_hRelayStatusLabel[i], RGB(0, 255, 0));
  269. XEle_RedrawEle(m_hRelayStatusLabel[i], TRUE);
  270. }
  271. }
  272. return TRUE;
  273. }
  274.  
  275. BOOL CUSBRelayWnd::OnCloseAllRelayBtnClick( HELE hEle, HELE hEleEvent )
  276. {
  277. if (!m_bOpened)
  278. {
  279. XMessageBox(XEle_GetHWindow(hEle), L"Open Device First", L"Error", XMB_OK);
  280. return TRUE;
  281. }
  282. int ret = usb_relay_device_close_all_relay_channel(m_hCurDevice);
  283. if (ret == 0)
  284. {
  285. for(int i = 0; i < m_hCureDeviceIndex; i++)
  286. {
  287. XEle_SetBkColor(m_hRelayStatusLabel[i], RGB(255, 0, 0));
  288. XEle_RedrawEle(m_hRelayStatusLabel[i], TRUE);
  289. }
  290. }
  291. return TRUE;
  292. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:4: error: illegal character: \35
#include "stdafx.h"
^
Main.java:4: error: class, interface, or enum expected
#include "stdafx.h"
         ^
Main.java:5: error: illegal character: \35
#include "GuiApp_English.h"
^
Main.java:11: error: class, interface, or enum expected
	CUSBRelayWnd  MyWnd;
	^
Main.java:12: error: class, interface, or enum expected
	if(MyWnd.Create())
	^
Main.java:15: error: class, interface, or enum expected
	}
	^
Main.java:17: error: class, interface, or enum expected
}
^
Main.java:23: error: class, interface, or enum expected
	if(m_hWindow)
	^
Main.java:26: error: class, interface, or enum expected
		XWnd_EnableMaxButton(m_hWindow, FALSE);
		^
Main.java:29: error: class, interface, or enum expected
		m_hFindDeviceBtn = XBtn_Create(10, 10, 90, 25, L"Find device", m_hWindow); 
		^
Main.java:31: error: class, interface, or enum expected
		XCGUI_RegEleEvent(m_hFindDeviceBtn, XE_BNCLICK, &CUSBRelayWnd::OnFindDeviceBtnClick); 
		^
Main.java:34: error: class, interface, or enum expected
		m_hDeviceListBox = XComboBox_Create(110, 10, 150, 25, m_hWindow);
		^
Main.java:37: error: class, interface, or enum expected
		m_hOpenDeviceBtn = XBtn_Create(10, 45, 90, 25, L"open device", m_hWindow);
		^
Main.java:39: error: class, interface, or enum expected
		XCGUI_RegEleEvent(m_hOpenDeviceBtn, XE_BNCLICK, &CUSBRelayWnd::OnOpenDeviceBtnClick);
		^
Main.java:42: error: class, interface, or enum expected
		m_hOpenStatus = XEle_Create(110, 45, 50, 25, m_hWindow);
		^
Main.java:43: error: class, interface, or enum expected
		XEle_SetBkColor(m_hOpenStatus, RGB(255, 0, 0));
		^
Main.java:46: error: class, interface, or enum expected
		m_hOpenDeviceBtn = XBtn_Create(170, 45, 90, 25, L"close device", m_hWindow);
		^
Main.java:50: error: class, interface, or enum expected
		XCGUI_RegEleEvent(m_hOpenDeviceBtn, XE_BNCLICK, &CUSBRelayWnd::OnCloseDeviceBtnClick);
		^
Main.java:52: error: class, interface, or enum expected
		int pos_text_x = 10;
		^
Main.java:53: error: class, interface, or enum expected
		int pos_open_btn_x = 105;
		^
Main.java:54: error: class, interface, or enum expected
		int pos_status_label_x = 170;
		^
Main.java:55: error: class, interface, or enum expected
		int pos_close_btn_x = 200;
		^
Main.java:57: error: class, interface, or enum expected
		int pos_y = 80;
		^
Main.java:60: error: class, interface, or enum expected
		for (int i = 0; i < 8; i++)
		^
Main.java:60: error: class, interface, or enum expected
		for (int i = 0; i < 8; i++)
		                ^
Main.java:60: error: class, interface, or enum expected
		for (int i = 0; i < 8; i++)
		                       ^
Main.java:63: error: class, interface, or enum expected
			wsprintf(relayName, L"Realy %d", i+1);
			^
Main.java:65: error: class, interface, or enum expected
			m_hRelayText[i] = XEdit_Create(pos_text_x, pos_y, 90, 25, m_hWindow);
			^
Main.java:66: error: class, interface, or enum expected
			XEdit_SetText(m_hRelayText[i], relayName);
			^
Main.java:68: error: class, interface, or enum expected
			m_hRelayOpenBtn[i] = XBtn_Create(pos_open_btn_x, pos_y, 60, 25, L"open", m_hWindow);
			^
Main.java:69: error: class, interface, or enum expected
			XCGUI_RegEleEvent(m_hRelayOpenBtn[i], XE_BNCLICK, &CUSBRelayWnd::OnOpenRelayBtnClick);
			^
Main.java:71: error: class, interface, or enum expected
			m_hRelayStatusLabel[i] = XEle_Create(pos_status_label_x, pos_y, 25, 25, m_hWindow);
			^
Main.java:72: error: class, interface, or enum expected
			XEle_SetBkColor(m_hRelayStatusLabel[i], RGB(255, 0, 0));
			^
Main.java:74: error: class, interface, or enum expected
			m_hRelayCloseBtn[i] = XBtn_Create(pos_close_btn_x, pos_y, 60, 25, L"close", m_hWindow);
			^
Main.java:75: error: class, interface, or enum expected
			XCGUI_RegEleEvent(m_hRelayCloseBtn[i], XE_BNCLICK, &CUSBRelayWnd::OnCloseRelayBtnClick);
			^
Main.java:77: error: class, interface, or enum expected
			pos_y += 30;
			^
Main.java:78: error: class, interface, or enum expected
		}
		^
Main.java:82: error: class, interface, or enum expected
		XCGUI_RegEleEvent(m_hOpenAllRelayBtn, XE_BNCLICK, &CUSBRelayWnd::OnOpenAllRelayBtnClick);
		^
Main.java:85: error: class, interface, or enum expected
		m_hCloseAllRelayBtn = XBtn_Create(140, pos_y+10, 120, 50, L"Close All", m_hWindow);
		^
Main.java:86: error: class, interface, or enum expected
		XCGUI_RegEleEvent(m_hCloseAllRelayBtn, XE_BNCLICK, &CUSBRelayWnd::OnCloseAllRelayBtnClick);
		^
Main.java:89: error: class, interface, or enum expected
		usb_relay_init();
		^
Main.java:91: error: class, interface, or enum expected
		XWnd_ShowWindow(m_hWindow, SW_SHOW); //????????
		^
Main.java:92: error: class, interface, or enum expected
		return true;
		^
Main.java:93: error: class, interface, or enum expected
	}
	^
Main.java:95: error: class, interface, or enum expected
}
^
Main.java:102: error: class, interface, or enum expected
		return TRUE;
		^
Main.java:103: error: class, interface, or enum expected
	}
	^
Main.java:108: error: class, interface, or enum expected
		m_pDeviceList = NULL;
		^
Main.java:109: error: class, interface, or enum expected
	}
	^
Main.java:112: error: class, interface, or enum expected
	if (m_pDeviceList)
	^
Main.java:115: error: class, interface, or enum expected
		while (cur_device)
		^
Main.java:118: error: class, interface, or enum expected
			m_mapIndexToDevice[Ansi2WChar((char*)(cur_device->serial_number))] = cur_device;
			^
Main.java:120: error: class, interface, or enum expected
			cur_device = cur_device->next;
			^
Main.java:121: error: class, interface, or enum expected
		}
		^
Main.java:125: error: class, interface, or enum expected
}
^
Main.java:132: error: class, interface, or enum expected
		return TRUE;
		^
Main.java:133: error: class, interface, or enum expected
	}
	^
Main.java:136: error: class, interface, or enum expected
	if (index > -1)
	^
Main.java:139: error: class, interface, or enum expected
		std::map<wstring ,struct usb_relay_device_info*>::const_iterator fd = m_mapIndexToDevice.find(wstring(serial));
		^
Main.java:140: error: class, interface, or enum expected
		if (fd != m_mapIndexToDevice.end())
		^
Main.java:144: error: class, interface, or enum expected
			if (m_hCurDevice)
			^
Main.java:148: error: class, interface, or enum expected
				if (0 == usb_relay_device_get_status(m_hCurDevice, &status))
				^
Main.java:150: error: class, interface, or enum expected
					for (int i = 0; i < fd->second->type; i++)
					                ^
Main.java:150: error: class, interface, or enum expected
					for (int i = 0; i < fd->second->type; i++)
					                                      ^
Main.java:155: error: class, interface, or enum expected
							XEle_RedrawEle(m_hRelayStatusLabel[i], TRUE);
							^
Main.java:156: error: class, interface, or enum expected
						}
						^
Main.java:159: error: class, interface, or enum expected
					XEle_RedrawEle(m_hOpenStatus, TRUE);
					^
Main.java:160: error: class, interface, or enum expected
					m_bOpened = TRUE;
					^
Main.java:161: error: class, interface, or enum expected
					m_hCureDeviceIndex = fd->second->type;
					^
Main.java:162: error: class, interface, or enum expected
				}
				^
Main.java:166: error: class, interface, or enum expected
					m_hCurDevice = 0;
					^
Main.java:167: error: class, interface, or enum expected
					XMessageBox(XEle_GetHWindow(hEle), L"Open Device Error!!", L"Error", XMB_OK);
					^
Main.java:168: error: class, interface, or enum expected
				}
				^
Main.java:174: error: class, interface, or enum expected
			}
			^
Main.java:179: error: class, interface, or enum expected
		}
		^
Main.java:184: error: class, interface, or enum expected
	}
	^
Main.java:187: error: class, interface, or enum expected
}
^
Main.java:194: error: class, interface, or enum expected
		return TRUE;
		^
Main.java:195: error: class, interface, or enum expected
	}
	^
Main.java:198: error: class, interface, or enum expected
	m_hCurDevice = 0;
	^
Main.java:199: error: class, interface, or enum expected
	m_bOpened = FALSE;
	^
Main.java:200: error: class, interface, or enum expected
	XEle_SetBkColor(m_hOpenStatus, RGB(255, 0, 0));
	^
Main.java:201: error: class, interface, or enum expected
	XEle_RedrawEle(m_hOpenStatus, TRUE);
	^
Main.java:203: error: class, interface, or enum expected
	for (int i = 0; i < m_hCureDeviceIndex; i++)
	^
Main.java:203: error: class, interface, or enum expected
	for (int i = 0; i < m_hCureDeviceIndex; i++)
	                ^
Main.java:203: error: class, interface, or enum expected
	for (int i = 0; i < m_hCureDeviceIndex; i++)
	                                        ^
Main.java:206: error: class, interface, or enum expected
		XEle_RedrawEle(m_hRelayStatusLabel[i], TRUE);
		^
Main.java:207: error: class, interface, or enum expected
	}
	^
Main.java:210: error: class, interface, or enum expected
}
^
Main.java:217: error: class, interface, or enum expected
		return TRUE;
		^
Main.java:218: error: class, interface, or enum expected
	}
	^
Main.java:219: error: class, interface, or enum expected
	for (int i = 0; i < 8; i++)
	                ^
Main.java:219: error: class, interface, or enum expected
	for (int i = 0; i < 8; i++)
	                       ^
Main.java:224: error: class, interface, or enum expected
			if (ret == 0)
			^
Main.java:227: error: class, interface, or enum expected
				XEle_RedrawEle(m_hRelayStatusLabel[i],TRUE);
				^
Main.java:228: error: class, interface, or enum expected
			}
			^
Main.java:232: error: class, interface, or enum expected
}
^
Main.java:239: error: class, interface, or enum expected
		return TRUE;
		^
Main.java:240: error: class, interface, or enum expected
	}
	^
Main.java:241: error: class, interface, or enum expected
	for (int i = 0; i < 8; i++)
	                ^
100 errors
stdout
Standard output is empty