📄 cecamera.cpp
字号:
// Limits the amount of text the user can enter into the edit controls
SendDlgItemMessage(hwndDlg, IDC_INITIAL_DIR, EM_LIMITTEXT, MAX_INITIAL_DIR, 0);
SendDlgItemMessage(hwndDlg, IDC_DEFAULT_FILE_NAME, EM_LIMITTEXT, MAX_FILE_NAME, 0);
SendDlgItemMessage(hwndDlg, IDC_TITLE, EM_LIMITTEXT, MAX_TITLE, 0);
SendDlgItemMessage(hwndDlg, IDC_RESOLUTION_WIDTH, EM_LIMITTEXT, MAX_RESOLUTION_WIDTH, 0);
SendDlgItemMessage(hwndDlg, IDC_RESOLUTION_HEIGHT, EM_LIMITTEXT, MAX_RESOLUTION_HEIGHT, 0);
SendDlgItemMessage(hwndDlg, IDC_VIDEO_TIME_LIMIT, EM_LIMITTEXT, MAX_VIDEO_TIME_LIMIT, 0);
// Specify all options as default value
ResetOptions(hwndDlg);
// In order to make Back work properly, it's necessary to
// override it and then call the appropriate SH API
if (g_bSmartphone)
{
SendMessage(shmbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK,
MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
}
bSuccess = TRUE;
}
}
}
}
return bSuccess;
}
// ***************************************************************************
// Function Name: StartCamera
//
// Purpose: Launches Camera using Camera API with specified arguments
//
// Arguments:
// HWND hwndDlg - Handle to the main dialog
//
// Return Values: none
//
// Description:
// Calling SHCameraCapture() function to start Camera for
// taking the pictures or videos.
VOID StartCamera(HWND hwndDlg)
{
HRESULT hr;
HRESULT hReturn;
SHCAMERACAPTURE shcc;
LONG lCheckStateInitialDir;
LONG lCheckStateDefaultFileName;
LONG lCheckStateTitle;
LONG lCheckStateResolution;
LONG lCheckStateVideoTimeLimit;
TCHAR szInitialDir[MAX_INITIAL_DIR] = { 0 };
TCHAR szDefaultFileName[MAX_FILE_NAME] = { 0 };
TCHAR szTitle[MAX_TITLE] = { 0 };
DWORD dwResolutionWidth;
DWORD dwResolutionHeight;
DWORD dwVideoTimeLimit;
LPCTSTR szFormat;
TCHAR szMessage[MAX_MESSAGE] = { 0 };
// Get the state of the checkboxs
lCheckStateInitialDir = SendDlgItemMessage(hwndDlg, IDC_CHECK_INITIAL_DIR, BM_GETCHECK, 0, 0);
lCheckStateDefaultFileName = SendDlgItemMessage(hwndDlg, IDC_CHECK_DEFAULT_FILE_NAME, BM_GETCHECK, 0, 0);
lCheckStateTitle = SendDlgItemMessage(hwndDlg, IDC_CHECK_TITLE, BM_GETCHECK, 0, 0);
lCheckStateResolution = SendDlgItemMessage(hwndDlg, IDC_CHECK_RESOLUTION, BM_GETCHECK, 0, 0);
lCheckStateVideoTimeLimit = SendDlgItemMessage(hwndDlg, IDC_CHECK_VIDEO_TIME_LIMIT, BM_GETCHECK, 0, 0);
// Get the user inputs of the edit controls
GetDlgItemText(hwndDlg, IDC_INITIAL_DIR, szInitialDir, ARRAYSIZE(szInitialDir));
GetDlgItemText(hwndDlg, IDC_DEFAULT_FILE_NAME, szDefaultFileName, ARRAYSIZE(szDefaultFileName));
GetDlgItemText(hwndDlg, IDC_TITLE, szTitle, ARRAYSIZE(szTitle));
dwResolutionWidth = GetDlgItemInt(hwndDlg, IDC_RESOLUTION_WIDTH, NULL, FALSE);
dwResolutionHeight = GetDlgItemInt(hwndDlg, IDC_RESOLUTION_HEIGHT, NULL, FALSE);
dwVideoTimeLimit = GetDlgItemInt(hwndDlg, IDC_VIDEO_TIME_LIMIT, NULL, FALSE);
// Specify the arguments of SHCAMERACAPTURE
ZeroMemory(&shcc, sizeof(shcc));
shcc.cbSize = sizeof(shcc);
shcc.hwndOwner = hwndDlg;
shcc.pszInitialDir = (BST_UNCHECKED == lCheckStateInitialDir) ? CECAMERA_DEFAULT_INITIAL_DIR : szInitialDir;
shcc.pszDefaultFileName = (BST_UNCHECKED == lCheckStateDefaultFileName) ? CECAMERA_DEFAULT_FILE_NAME : szDefaultFileName;
shcc.pszTitle = (BST_UNCHECKED == lCheckStateTitle) ? CECAMERA_DEFAULT_TITLE : szTitle;
shcc.StillQuality = g_StillQuality;
shcc.VideoTypes = g_VideoTypes;
shcc.nResolutionWidth = (BST_UNCHECKED == lCheckStateResolution) ? CECAMERA_DEFAULT_RESOLUTION_WIDTH : dwResolutionWidth;
shcc.nResolutionHeight = (BST_UNCHECKED == lCheckStateResolution) ? CECAMERA_DEFAULT_RESOLUTION_HEIGHT : dwResolutionHeight;
shcc.nVideoTimeLimit = (BST_UNCHECKED == lCheckStateVideoTimeLimit) ? CECAMERA_DEFAULT_VIDEO_TIME_LIMIT : dwVideoTimeLimit;
shcc.Mode = g_Mode;
// Call SHCameraCapture() function
hReturn = SHCameraCapture(&shcc);
// Check the return codes of the SHCameraCapture() function
switch (hReturn)
{
case S_OK:
// The method completed successfully.
szFormat = (LPCTSTR)LoadString(g_hInstance, IDS_NOERROR, NULL, 0);
CPR(szFormat);
CHR(StringCchPrintf(szMessage, ARRAYSIZE(szMessage), szFormat, shcc.szFile));
MessageBox(hwndDlg, szMessage, g_szCaption, MB_OK | MB_ICONINFORMATION);
break;
case S_FALSE:
// The user canceled the Camera Capture dialog box.
break;
case E_INVALIDARG:
// An invalid argument was specified.
szFormat = (LPCTSTR)LoadString(g_hInstance, IDS_ERROR_INVALIDARG, NULL, 0);
CPR(szFormat);
MessageBox(hwndDlg, szFormat, g_szCaption, MB_OK | MB_ICONEXCLAMATION);
break;
case E_OUTOFMEMORY:
// There is not enough memory to save the image or video.
szFormat = (LPCTSTR)LoadString(g_hInstance, IDS_ERROR_OUTOFMEMORY, NULL, 0);
CPR(szFormat);
MessageBox(hwndDlg, szFormat, g_szCaption, MB_OK | MB_ICONSTOP);
break;
default:
// An unknown error occurred.
szFormat = (LPCTSTR)LoadString(g_hInstance, IDS_ERROR_UNKNOWN, NULL, 0);
CPR(szFormat);
CHR(StringCchPrintf(szMessage, ARRAYSIZE(szMessage), szFormat, hReturn));
MessageBox(hwndDlg, szMessage, g_szCaption, MB_OK | MB_ICONSTOP);
break;
}
Error:
return;
}
// ***************************************************************************
// Function Name: ShowAboutBox
//
// Purpose: Show program information
//
// Arguments:
// HWND hwndDlg - Handle to the main dialog
//
// Return Values: none
//
// Description:
// Display a message box for program information.
VOID ShowAboutBox(HWND hwndDlg)
{
HRESULT hr;
LPCTSTR szAbout;
// Load the about string from resource and display it
szAbout = (LPCTSTR)LoadString(g_hInstance, IDS_ABOUT, NULL, 0);
CPR(szAbout);
MessageBox(hwndDlg, szAbout, g_szCaption, MB_OK);
Error:
return;
}
// ***************************************************************************
// Function Name: ResetOptions
//
// Purpose: Resets all settings as the default value
//
// Arguments:
// HWND hwndDlg - Handle to the main dialog
//
// Return Values: none
//
// Description:
// Resets all settings as the default value and updates UI.
VOID ResetOptions(HWND hwndDlg)
{
HRESULT hr;
// Uncheck all checkboxs to specify the options using the default value
SendDlgItemMessage(hwndDlg, IDC_CHECK_INITIAL_DIR, BM_SETCHECK, BST_UNCHECKED, 0);
SendDlgItemMessage(hwndDlg, IDC_CHECK_DEFAULT_FILE_NAME, BM_SETCHECK, BST_UNCHECKED, 0);
SendDlgItemMessage(hwndDlg, IDC_CHECK_TITLE, BM_SETCHECK, BST_UNCHECKED, 0);
SendDlgItemMessage(hwndDlg, IDC_CHECK_RESOLUTION, BM_SETCHECK, BST_UNCHECKED, 0);
SendDlgItemMessage(hwndDlg, IDC_CHECK_VIDEO_TIME_LIMIT, BM_SETCHECK, BST_UNCHECKED, 0);
// Set the default value for the options
CBR(SetDlgItemText(hwndDlg, IDC_INITIAL_DIR, CECAMERA_DEFAULT_INITIAL_DIR));
CBR(SetDlgItemText(hwndDlg, IDC_DEFAULT_FILE_NAME, CECAMERA_DEFAULT_FILE_NAME));
CBR(SetDlgItemText(hwndDlg, IDC_TITLE, CECAMERA_DEFAULT_TITLE));
CBR(SetDlgItemInt(hwndDlg, IDC_RESOLUTION_WIDTH, CECAMERA_DEFAULT_RESOLUTION_WIDTH, 0));
CBR(SetDlgItemInt(hwndDlg, IDC_RESOLUTION_HEIGHT, CECAMERA_DEFAULT_RESOLUTION_HEIGHT, 0));
CBR(SetDlgItemInt(hwndDlg, IDC_VIDEO_TIME_LIMIT, CECAMERA_DEFAULT_VIDEO_TIME_LIMIT, 0));
// Disable the edit controls since specify using default settings
EnableWindow(GetDlgItem(hwndDlg, IDC_INITIAL_DIR), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_DEFAULT_FILE_NAME), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_TITLE), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_RESOLUTION_WIDTH), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_RESOLUTION_HEIGHT), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_VIDEO_TIME_LIMIT), FALSE);
// Checks the menu item and makes it a radio item
CBR(CheckMenuRadioItem(GetSubMenu(g_hMainMenu, 0), IDM_MODE_STILL, IDM_MODE_VIDEOWITHAUDIO, IDM_MODE_STILL, MF_BYCOMMAND));
CBR(CheckMenuRadioItem(GetSubMenu(g_hMainMenu, 1), IDM_STILLQUALITY_DEFAULT, IDM_STILLQUALITY_HIGH, IDM_STILLQUALITY_DEFAULT, MF_BYCOMMAND));
CBR(CheckMenuRadioItem(GetSubMenu(g_hMainMenu, 2), IDM_VIDEOTYPES_ALL, IDM_VIDEOTYPES_MESSAGING, IDM_VIDEOTYPES_ALL, MF_BYCOMMAND));
// Set the global variables as default value
g_StillQuality = CECAMERA_DEFAULT_STILL_QUALITY;
g_VideoTypes = CECAMERA_DEFAULT_VIDEO_TYPES;
g_Mode = CECAMERA_DEFAULT_MODE;
Error:
return;
}
// ***************************************************************************
// Function Name: ChangeMode
//
// Purpose: Changes "Mode" parameter of SHCameraCapture()
//
// Arguments:
// WORD wMode - The identifier of the menu item
//
// Return Values: none
//
// Description:
// Changes "Mode" parameter of SHCameraCapture(),
// also checks the specified menu item of "Mode".
VOID ChangeMode(WORD wMode)
{
HRESULT hr;
// Update the menu item "Mode"
CBR(CheckMenuRadioItem(GetSubMenu(g_hMainMenu, 0), IDM_MODE_STILL, IDM_MODE_VIDEOWITHAUDIO, wMode, MF_BYCOMMAND));
// Set the global variables as user specified value
switch (wMode)
{
case IDM_MODE_STILL:
g_Mode = CAMERACAPTURE_MODE_STILL;
break;
case IDM_MODE_VIDEOONLY:
g_Mode = CAMERACAPTURE_MODE_VIDEOONLY;
break;
case IDM_MODE_VIDEOWITHAUDIO:
g_Mode = CAMERACAPTURE_MODE_VIDEOWITHAUDIO;
break;
default:
CBR(FALSE);
break;
}
Error:
return;
}
// ***************************************************************************
// Function Name: ChangeStillQuality
//
// Purpose: Changes "StillQuality" parameter of SHCameraCapture()
//
// Arguments:
// WORD wStillQuality - The identifier of the menu item
//
// Return Values: none
//
// Description:
// Changes "StillQuality" parameter of SHCameraCapture(),
// also checks the specified menu item of "StillQuality".
VOID ChangeStillQuality(WORD wStillQuality)
{
HRESULT hr;
// Update the menu item "StillQuality"
CBR(CheckMenuRadioItem(GetSubMenu(g_hMainMenu, 1), IDM_STILLQUALITY_DEFAULT, IDM_STILLQUALITY_HIGH, wStillQuality, MF_BYCOMMAND));
// Set the global variables as user specified value
switch (wStillQuality)
{
case IDM_STILLQUALITY_DEFAULT:
g_StillQuality = CAMERACAPTURE_STILLQUALITY_DEFAULT;
break;
case IDM_STILLQUALITY_LOW:
g_StillQuality = CAMERACAPTURE_STILLQUALITY_LOW;
break;
case IDM_STILLQUALITY_NORMAL:
g_StillQuality = CAMERACAPTURE_STILLQUALITY_NORMAL;
break;
case IDM_STILLQUALITY_HIGH:
g_StillQuality = CAMERACAPTURE_STILLQUALITY_HIGH;
break;
default:
CBR(FALSE);
break;
}
Error:
return;
}
// ***************************************************************************
// Function Name: ChangeVideoTypes
//
// Purpose: Changes "VideoTypes" parameter of SHCameraCapture()
//
// Arguments:
// WORD wVideoTypes - The identifier of the menu item
//
// Return Values: none
//
// Description:
// Changes "VideoTypes" parameter of SHCameraCapture(),
// also checks the specified menu item of "VideoTypes".
VOID ChangeVideoTypes(WORD wVideoTypes)
{
HRESULT hr;
// Update the menu item "VideoTypes"
CBR(CheckMenuRadioItem(GetSubMenu(g_hMainMenu, 2), IDM_VIDEOTYPES_ALL, IDM_VIDEOTYPES_MESSAGING, wVideoTypes, MF_BYCOMMAND));
// Set the global variables as user specified value
switch (wVideoTypes)
{
case IDM_VIDEOTYPES_ALL:
g_VideoTypes = CAMERACAPTURE_VIDEOTYPE_ALL;
break;
case IDM_VIDEOTYPES_STANDARD:
g_VideoTypes = CAMERACAPTURE_VIDEOTYPE_STANDARD;
break;
case IDM_VIDEOTYPES_MESSAGING:
g_VideoTypes = CAMERACAPTURE_VIDEOTYPE_MESSAGING;
break;
default:
CBR(FALSE);
break;
}
Error:
return;
}
// ***************************************************************************
// Function Name: ChangeOptions
//
// Purpose: Enable/Disable user input of the edit controls
//
// Arguments:
// HWND hwndDlg - Handle to the main dialog
// WORD wOptions - The identifier of the control
//
// Return Values: none
//
// Description:
// Enable/Disable user input of the edit controls for allowing/disallowing
// the user to specify the settings of the Camera API.
VOID ChangeOptions(HWND hwndDlg, WORD wOptions)
{
HRESULT hr;
LONG lCheckState;
BOOL bEnable;
// Get the check state of the check box
lCheckState = SendDlgItemMessage(hwndDlg, wOptions, BM_GETCHECK, 0, 0);
bEnable = (BST_UNCHECKED == lCheckState) ? FALSE : TRUE;
// Enable/Disable user input of the edit controls
switch (wOptions)
{
case IDC_CHECK_INITIAL_DIR:
EnableWindow(GetDlgItem(hwndDlg, IDC_INITIAL_DIR), bEnable);
break;
case IDC_CHECK_DEFAULT_FILE_NAME:
EnableWindow(GetDlgItem(hwndDlg, IDC_DEFAULT_FILE_NAME), bEnable);
break;
case IDC_CHECK_TITLE:
EnableWindow(GetDlgItem(hwndDlg, IDC_TITLE), bEnable);
break;
case IDC_CHECK_RESOLUTION:
EnableWindow(GetDlgItem(hwndDlg, IDC_RESOLUTION_WIDTH), bEnable);
EnableWindow(GetDlgItem(hwndDlg, IDC_RESOLUTION_HEIGHT), bEnable);
break;
case IDC_CHECK_VIDEO_TIME_LIMIT:
EnableWindow(GetDlgItem(hwndDlg, IDC_VIDEO_TIME_LIMIT), bEnable);
break;
default:
CBR(FALSE);
break;
}
Error:
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -