5 #include "VisionExample.h"
6 #include "VisionExampleDoc.h"
9 #include "videoInput.h"
14 static char THIS_FILE[] = __FILE__;
20 IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
22 BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
27 ON_MESSAGE(WM_MYMESSAGE , OnChangeStatusBar)
30 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT, 0, 0xFFFF, OnToolTipText)
33 static UINT indicators[] =
41 CMainFrame::CMainFrame()
44 m_comboBoxConfigFile = NULL;
45 m_comboBoxCamResolution = NULL;
46 m_comboBoxCamDevice = NULL;
47 m_comboBoxMaxFaces = NULL;
50 CMainFrame::~CMainFrame()
60 POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition();
61 CDocTemplate* pDocTemplate = AfxGetApp()->GetNextDocTemplate(pos);
62 pos = pDocTemplate->GetFirstDocPosition();
73 POSITION pos = pDoc->GetFirstViewPosition();
78 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
80 if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
83 if (!m_wndToolBar.CreateEx(
this, TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | TBSTYLE_AUTOSIZE,
84 WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_FLYBY) ||
85 !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
87 TRACE0(
"Failed to create toolbar\n");
91 if (!m_wndReBar.Create(
this) ||
92 !m_wndDlgBar.Create(
this, IDD_DIALOGBAR, CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY, IDD_DIALOGBAR) ||
93 !m_wndReBar.AddBar(&m_wndDlgBar) ||
94 !m_wndReBar.AddBar(&m_wndToolBar))
96 TRACE0(
"Failed to create rebar\n");
100 if (!m_wndStatusBar.Create(
this) ||
101 !m_wndStatusBar.SetIndicators(indicators,
102 sizeof(indicators)/
sizeof(UINT)))
104 TRACE0(
"Failed to create status bar\n");
108 m_comboBoxConfigFile = (CComboBox *)m_wndDlgBar.GetDlgItem(ID_COMBO_CONFIG_FILE);
109 m_comboBoxCamResolution = (CComboBox *)m_wndDlgBar.GetDlgItem(ID_COMBO_CAM_RESOLUTION);
110 m_comboBoxCamDevice = (CComboBox *)m_wndDlgBar.GetDlgItem(ID_COMBO_CAM_DEVICE);
111 m_comboBoxMaxFaces = (CComboBox *)m_wndDlgBar.GetDlgItem(ID_COMBO_MAX_FACES);
117 BOOL CMainFrame::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
119 ASSERT(pNMHDR->code == TTN_NEEDTEXT);
121 TOOLTIPTEXT* pTTT = (TOOLTIPTEXT*)pNMHDR;
122 TCHAR szFullText[512];
124 UINT nID = pNMHDR->idFrom;
126 if (pTTT->uFlags & TTF_IDISHWND)
129 nID = ::GetDlgCtrlID((HWND)nID);
134 strTipText.LoadString(nID);
135 lstrcpyn(pTTT->szText, strTipText,
sizeof(pTTT->szText));
140 ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,
141 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE | SWP_NOOWNERZORDER);
153 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
162 cs.x = (::GetSystemMetrics(SM_CXSCREEN) - xsize) / 2;
163 cs.y = (::GetSystemMetrics(SM_CYSCREEN) - ysize) / 2;
165 if( !CFrameWnd::PreCreateWindow(cs) )
172 LRESULT CMainFrame::OnChangeStatusBar(WPARAM wParam, LPARAM lParam)
176 CString* strStatusText = (CString*) wParam;
178 if (m_wndStatusBar) m_wndStatusBar.SetPaneText( 0, *strStatusText, TRUE );
180 delete strStatusText;
190 void CMainFrame::AssertValid()
const
192 CFrameWnd::AssertValid();
195 void CMainFrame::Dump(CDumpContext& dc)
const
202 void CMainFrame::ShowAvailConfigFiles(
char *path,
char *currentChoice)
205 WIN32_FIND_DATA FileData;
209 temp = currentChoice;
211 while (m_comboBoxConfigFile->GetCount() >0) m_comboBoxConfigFile->DeleteString(0);
213 dupa.Format(
"%s", path);
214 if (dupa ==
"")
return;
216 hSearch = FindFirstFile(dupa, &FileData);
218 if (hSearch == INVALID_HANDLE_VALUE){
221 FORMAT_MESSAGE_ALLOCATE_BUFFER |
222 FORMAT_MESSAGE_FROM_SYSTEM |
223 FORMAT_MESSAGE_IGNORE_INSERTS,
232 LocalFree( lpMsgBuf );
237 if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){
238 std::string cfgFileName = FileData.cFileName;
239 if(cfgFileName.find(
"NeuralNet.cfg") == std::string::npos)
240 m_comboBoxConfigFile->InsertString(iIndex, FileData.cFileName);
241 if (!temp.CompareNoCase(FileData.cFileName))
242 m_comboBoxConfigFile->SetCurSel(iIndex);
245 }
while (FindNextFile(hSearch, &FileData));
246 m_comboBoxConfigFile->EnableWindow(m_comboBoxConfigFile->GetCount());
249 void CMainFrame::ShowAvailCamResolutions()
251 while (m_comboBoxCamResolution->GetCount() > 0) m_comboBoxCamResolution->DeleteString(0);
255 m_comboBoxCamResolution->InsertString(iIndex++,
"320x240");
256 m_comboBoxCamResolution->InsertString(iIndex++,
"640x480");
257 m_comboBoxCamResolution->InsertString(iIndex++,
"800x600");
258 m_comboBoxCamResolution->InsertString(iIndex++,
"1280x720");
259 m_comboBoxCamResolution->InsertString(iIndex++,
"1920x1080");
260 m_comboBoxCamResolution->InsertString(iIndex++,
"2560x1440");
261 m_comboBoxCamResolution->InsertString(iIndex++,
"4096x2160");
263 m_comboBoxCamResolution->SetCurSel(2);
265 m_comboBoxCamResolution->EnableWindow(m_comboBoxCamResolution->GetCount());
268 void CMainFrame::ShowAvailCamDevices()
270 while (m_comboBoxCamDevice->GetCount() > 0) m_comboBoxCamDevice->DeleteString(0);
272 int n = videoInput::listDevices();
274 for (
int i = 0; i < n; ++i) {
275 m_comboBoxCamDevice->InsertString(i, videoInput::getDeviceName(i));
278 m_comboBoxCamDevice->SetCurSel(0);
280 m_comboBoxCamDevice->EnableWindow(m_comboBoxCamDevice->GetCount());
283 void CMainFrame::ShowAvailMaxFaces()
285 while (m_comboBoxMaxFaces->GetCount() > 0) m_comboBoxMaxFaces->DeleteString(0);
287 for (
int i = 0; i < 10; i++)
288 m_comboBoxMaxFaces->InsertString(i, std::to_string(i+1).c_str());
290 m_comboBoxMaxFaces->SetCurSel(2);
292 m_comboBoxMaxFaces->EnableWindow(m_comboBoxMaxFaces->GetCount());
295 void CMainFrame::GetConfigFilename(CString& strName)
297 m_comboBoxConfigFile = (CComboBox *)m_wndDlgBar.GetDlgItem(ID_COMBO_CONFIG_FILE);
298 m_comboBoxConfigFile->GetLBText(m_comboBoxConfigFile->GetCurSel(), strName);
301 void CMainFrame::GetCameraResolution(CString& strName)
303 m_comboBoxCamResolution = (CComboBox *)m_wndDlgBar.GetDlgItem(ID_COMBO_CAM_RESOLUTION);
304 m_comboBoxCamResolution->GetLBText(m_comboBoxCamResolution->GetCurSel(), strName);
307 int CMainFrame::GetCameraDevice()
309 m_comboBoxCamDevice = (CComboBox *)m_wndDlgBar.GetDlgItem(ID_COMBO_CAM_DEVICE);
310 return m_comboBoxCamDevice ? m_comboBoxCamDevice->GetCurSel() : 0;
313 int CMainFrame::GetMaxFaces()
315 m_comboBoxMaxFaces = (CComboBox *)m_wndDlgBar.GetDlgItem(ID_COMBO_MAX_FACES);
316 return m_comboBoxMaxFaces ? m_comboBoxMaxFaces->GetCurSel() + 1 : 1;
The OpenGL-enabled window with rendering and basic interaction.