📄 cammon.cpp
字号:
// CamMon.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "CamMon.h"
#include <commctrl.h>
#include <aygshell.h>
#include <sipapi.h>
#include "AllCam.h"
#include "wininet.h"
#include "CamConfigDlg.h"
#include <winsock.h>
#define MAX_LOADSTRING 100
#define TIMER_INTERVAL 50
#define PORTNUM 5111
enum StartupButtonIDC {
IDC_CAM1 =6000,
IDC_CAM2,
IDC_CAM3,
IDC_NEXT,
IDC_BACK
};
struct taghWndBtn {
HWND hCam1;
HWND hCam2;
HWND hCam3;
HWND hNext;
HWND hBack;
}hWndBtn;
// Global Variables:
HINSTANCE hInst; // The current instance
HWND hwndCB; // The command bar handle
CCamDesc theCam, *pCamera, *pCurCam;
CAllCam allCam;
DWORD GPRS_flag; // 1: is gprs connection, else not
DWORD Download_flag; // 1: Download
DWORD License_flag; // 1: legal user else temp user
SYSTEMTIME myTime;
int Login_min;
static SHACTIVATEINFO s_sai;
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass (HINSTANCE, LPTSTR);
BOOL InitInstance (HINSTANCE, int);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM);
HWND CreateRpCommandBar(HWND);
LRESULT CALLBACK DlgProc2120(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK DlgProc2400(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK DlgProcOther(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK DlgProcCameraConfig(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK DlgProcConnectionSetting(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK DlgProcRegister(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
void Trim(TCHAR *str, TCHAR c);
DWORD Get_GPRS_value();
void Set_GPRS_value(DWORD val);
void VerifyTimeoutUse();
#define REGISTER_PATH _T("SOFTWARE\\HKPolyU")
void Set_register_value(DWORD val);
DWORD Get_register_value();
void ShowBkGnd(HDC hdc, TCHAR *filename);
void ShowDlgBkGnd(HDC hdc, TCHAR *filename);
extern BOOL StartJpegConnection();
extern void EndJpegConnection();
extern BOOL ReadJpeg();
extern void DisplayJpeg(HWND hWnd);
void FnDrawBmp(HDC hdc,PTSTR FileName);
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_CAMMON);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// It is important to call this function so that the application
// will get 'well formed' small icons associated with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CAMMON));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}
//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd = NULL;
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The window class name
hInst = hInstance; // Store instance handle in our global variable
// Initialize global strings
LoadString(hInstance, IDC_CAMMON, szWindowClass, MAX_LOADSTRING);
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
//If it is already running, then focus on the window
hWnd = FindWindow(szWindowClass, szTitle);
if (hWnd)
{
SetForegroundWindow ((HWND) (((DWORD)hWnd) | 0x01));
return 0;
}
MyRegisterClass(hInstance, szWindowClass);
RECT rect;
GetClientRect(hWnd, &rect);
hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
//When the main window is created using CW_USEDEFAULT the height of the menubar (if one
// is created is not taken into account). So we resize the window after creating it
// if a menubar is present
{
RECT rc;
GetWindowRect(hWnd, &rc);
rc.bottom -= MENU_HEIGHT;
if (hwndCB)
MoveWindow(hWnd, rc.left, rc.top, rc.right, rc.bottom, FALSE);
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
void DisplayCameraButton(int pos)
{
::EnableWindow (hWndBtn.hCam1 , TRUE);
::EnableWindow (hWndBtn.hCam2 , TRUE);
::EnableWindow (hWndBtn.hCam3 , TRUE);
::EnableWindow (hWndBtn.hNext , TRUE);
::EnableWindow (hWndBtn.hBack , TRUE);
if(allCam.num ==0)
{
::EnableWindow (hWndBtn.hCam1 , FALSE);
::EnableWindow (hWndBtn.hCam2 , FALSE);
::EnableWindow (hWndBtn.hCam3 , FALSE);
::EnableWindow (hWndBtn.hNext , FALSE);
::EnableWindow (hWndBtn.hBack , FALSE);
return;
}
if(pos +2 < allCam.num )
{
::SetWindowText (hWndBtn.hCam1 , (allCam.pCam + allCam.curPos + 0)->Name );
::SetWindowText (hWndBtn.hCam2 , (allCam.pCam + allCam.curPos + 1)->Name );
::SetWindowText (hWndBtn.hCam3 , (allCam.pCam + allCam.curPos + 2)->Name );
}
else if(pos +1 < allCam.num )
{
::SetWindowText (hWndBtn.hCam1 , (allCam.pCam + allCam.curPos + 0)->Name );
::SetWindowText (hWndBtn.hCam2 , (allCam.pCam + allCam.curPos + 1)->Name );
::SetWindowText (hWndBtn.hCam3 , _T("Camera3") );
::EnableWindow (hWndBtn.hCam3 , FALSE);
}
else
{
::SetWindowText (hWndBtn.hCam1 , (allCam.pCam + allCam.curPos + 0)->Name );
::SetWindowText (hWndBtn.hCam2 , _T("Camera2") );
::SetWindowText (hWndBtn.hCam3 , _T("Camera3") );
::EnableWindow (hWndBtn.hCam2 , FALSE);
::EnableWindow (hWndBtn.hCam3 , FALSE);
}
//////////////////////////////
::EnableWindow (hWndBtn.hNext , TRUE);
::EnableWindow (hWndBtn.hBack , TRUE);
if(allCam.num <=3)
{
::EnableWindow (hWndBtn.hNext , FALSE);
::EnableWindow (hWndBtn.hBack , FALSE);
}
else if(pos +3 >= allCam.num )
{
::EnableWindow (hWndBtn.hNext , FALSE);
}
else if(pos <=0)
{
::EnableWindow (hWndBtn.hBack , FALSE);
}
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
int wmId, wmEvent;
PAINTSTRUCT ps;
int wid = 100, ht =30;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_CAMERA_CONFIG:
DialogBox(hInst, (LPCTSTR)IDD_DIALOG_CAM_CONFIG, hWnd, (DLGPROC)DlgProcCameraConfig);
allCam.RetrieveFromRegistry ();
::SetWindowText (hWndBtn.hCam1 , _T("Camera1") );
::SetWindowText (hWndBtn.hCam2 , _T("Camera2") );
::SetWindowText (hWndBtn.hCam3 , _T("Camera3") );
DisplayCameraButton(allCam.curPos);
break;
case IDM_CONNECTION_SETTING:
DialogBox(hInst, (LPCTSTR)IDD_DIALOG_CONNECTION_SETTING, hWnd, (DLGPROC)DlgProcConnectionSetting);
break;
case IDC_BACK:
allCam.curPos -= 3;
if(allCam.curPos <0) allCam.curPos +=allCam.num ;
if(allCam.curPos <0) allCam.curPos =0 ;
DisplayCameraButton(allCam.curPos);
break;
case IDC_NEXT:
allCam.curPos +=3;
if(allCam.curPos >= allCam.num ) allCam.curPos =0;
DisplayCameraButton(allCam.curPos);
break;
case IDC_CAM1:
pCurCam = allCam.pCam + allCam.curPos +0;
if(wcscmp(pCurCam->Type , _T("2120") ) ==0
|| wcscmp(pCurCam->Type , _T("2100") ) ==0 )
DialogBox(hInst, (LPCTSTR)IDD_DIALOG_2120, hWnd, (DLGPROC)DlgProc2120);
else if( wcscmp(pCurCam->Type , _T("2400") ) ==0 )
DialogBox(hInst, (LPCTSTR)IDD_DIALOG_2400, hWnd, (DLGPROC)DlgProc2400);
else
DialogBox(hInst, (LPCTSTR)IDD_DIALOG_OTHER, hWnd, (DLGPROC)DlgProcOther);
break;
case IDC_CAM2:
pCurCam = allCam.pCam + allCam.curPos +1;
if(wcscmp(pCurCam->Type , _T("2120") ) ==0
|| wcscmp(pCurCam->Type , _T("2100") ) ==0 )
DialogBox(hInst, (LPCTSTR)IDD_DIALOG_2120, hWnd, (DLGPROC)DlgProc2120);
else if( wcscmp(pCurCam->Type , _T("2400") ) ==0 )
DialogBox(hInst, (LPCTSTR)IDD_DIALOG_2400, hWnd, (DLGPROC)DlgProc2400);
else
DialogBox(hInst, (LPCTSTR)IDD_DIALOG_OTHER, hWnd, (DLGPROC)DlgProcOther);
break;
case IDC_CAM3:
pCurCam = allCam.pCam + allCam.curPos +2;
if(wcscmp(pCurCam->Type , _T("2120") ) ==0
|| wcscmp(pCurCam->Type , _T("2100") ) ==0 )
DialogBox(hInst, (LPCTSTR)IDD_DIALOG_2120, hWnd, (DLGPROC)DlgProc2120);
else if( wcscmp(pCurCam->Type , _T("2400") ) ==0 )
DialogBox(hInst, (LPCTSTR)IDD_DIALOG_2400, hWnd, (DLGPROC)DlgProc2400);
else
DialogBox(hInst, (LPCTSTR)IDD_DIALOG_OTHER, hWnd, (DLGPROC)DlgProcOther);
break;
case IDM_HELP_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
::sndPlaySound(_T("\\windows\\ExitSound.wav"),SND_ASYNC);
::PostQuitMessage (1);
break;
case IDOK:
SendMessage(hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd);
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_CREATE:
hwndCB = CreateRpCommandBar(hWnd);
Login_min =-1;
License_flag =Get_register_value();
if(License_flag ==0)
{
DialogBox(hInst, (LPCTSTR)IDD_DIALOG_REGISTER, hWnd, (DLGPROC)DlgProcRegister);
theCam.InitCameras ();
}
GPRS_flag = Get_GPRS_value();
Download_flag = 1;
allCam.RetrieveFromRegistry ();
pCamera = allCam.pCam;
pCamera += allCam.curPos ;
hWndBtn.hNext =::CreateWindow(L"button",_T(">") ,WS_VISIBLE,185,240,50, 20,hWnd,(HMENU)IDC_NEXT,hInst,NULL);
hWndBtn.hBack =::CreateWindow(L"button",_T("<") ,WS_VISIBLE,140,240,50, 20,hWnd,(HMENU)IDC_BACK,hInst,NULL);
hWndBtn.hCam1 =::CreateWindow(L"button",_T("Camera1") ,WS_VISIBLE,90,73,wid, ht,hWnd,(HMENU)IDC_CAM1,hInst,NULL);
hWndBtn.hCam2 =::CreateWindow(L"button",_T("Camera2") ,WS_VISIBLE,17,131,wid, ht,hWnd,(HMENU)IDC_CAM2,hInst,NULL);
hWndBtn.hCam3 =::CreateWindow(L"button",_T("Camera3") ,WS_VISIBLE,125,191,wid, ht,hWnd,(HMENU)IDC_CAM3,hInst,NULL);
pCurCam = allCam.pCam ;
DisplayCameraButton(allCam.curPos);
::sndPlaySound(_T("\\windows\\StartSound.wav"),SND_ASYNC);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
ShowBkGnd(hdc, _T("\\windows\\bkgnd.bmp") );
VerifyTimeoutUse();
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
CommandBar_Destroy(hwndCB);
PostQuitMessage(0);
break;
case WM_SETTINGCHANGE:
SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK DlgProc2120(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
SHINITDLGINFO shidi;
HDC hdc;
PAINTSTRUCT ps;
DWORD wmId;
HWND hItem;
HINTERNET hHttpOpenIO;
TCHAR ioCommand[1024];
switch (message)
{
case WM_LBUTTONDOWN:
Download_flag = 1;
break;
case WM_INITDIALOG:
// Create a Done button and size it.
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
::SetTimer(hDlg, 1, TIMER_INTERVAL, NULL);
hItem = ::GetDlgItem (hDlg, IDC_STATIC_NAME);
::SetWindowText (hItem, pCurCam->Name );
if(StartJpegConnection()==FALSE)
{
::KillTimer(hDlg,1);
TCHAR tempStr[1024];
wsprintf(tempStr, _T("The camera URL path is %s. \r\nPlease check its connection!"), pCurCam->Path );
::MessageBox (hDlg, tempStr, _T("Disconnected Camera"), MB_OK | MB_ICONEXCLAMATION ) ;
EndJpegConnection();
EndDialog(hDlg, IDOK);
}
Download_flag = 1;
if(pCurCam->IO ==0) // No I/O
{
hItem = ::GetDlgItem (hDlg, IDC_STATIC_2120);
::ShowWindow (hItem, SW_HIDE);
hItem = ::GetDlgItem (hDlg, IDC_RADIO_ON);
::ShowWindow (hItem, SW_HIDE);
hItem = ::GetDlgItem (hDlg, IDC_RADIO_OFF);
::ShowWindow (hItem, SW_HIDE);
}
return TRUE;
case WM_PAINT:
hdc = BeginPaint(hDlg, &ps);
if(pCurCam->IO ==0) //NO I/O
ShowDlgBkGnd(hdc, _T("\\windows\\OtherDlgBG.bmp"));
else
ShowDlgBkGnd(hdc, _T("\\windows\\2120DlgBG.bmp"));
EndPaint(hDlg, &ps);
break;
case WM_TIMER:
VerifyTimeoutUse();
if( GPRS_flag ==0 ) ReadJpeg( );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -