در اینجا میخوایم کد نویسی unmanaged/managed برای Windows Embedded CE & Windows Mobile رو با همکاری همدیگه یاد بگیریم
Printable View
در اینجا میخوایم کد نویسی unmanaged/managed برای Windows Embedded CE & Windows Mobile رو با همکاری همدیگه یاد بگیریم
چیز هایی که نیاز داریم:
Visual Studio 2005 یا 2008
آخرین ورژن WindowsMobile SDK
ActiveSync یا Windows Mobile Device Center
(منبع :msdn)
خوبه . ادامه بدین . منتظریم .
پوشه ی سمپل های visual studio
Program Files\Windows Mobile 5.0 SDK R2\Samples\PocketPC\CPP
کسی تا الان برای Windows CE کد زده؟ اصلاً کد زنی برای Windows CE با Windows Mobile چقدر فرق داره؟
windows Mobile اساسش بر پایه Windows CE است اطلاعات بیشتر:::
کد:http://en.wikipedia.org/wiki/Microsoft_Windows_CE
کد:http://en.wikipedia.org/wiki/Windows_Mobile
کد:http://blogs.msdn.com/mikehall/archive/2007/01/17/windows-mobile-and-windows-embedded-ce-what-s-the-difference.aspx
سلام
کدنویسی Management (مدیریت شده) مایکروسافت تحت NET Compact Framework. صورت میگیرد و یا برنامه Visual Studio و تحت زبانهای دات نتی VB.Net و C#.Net و ... قابل انجام است.
برای آغاز پروزه کافی است NewProject->SmartDeviceProject را انتخاب کنید.
دقیقاً مثل زمان طراحی فرم های ویندوزی، یک فرم شبیه موبایل نمایش داده میشود که میتوانید نمایه برنامه را طراحی کنید و در بخش کدنویسی هم دستورات مربوطه را تایپ کنید.
NET CF. یا همان NET Compact Framework. نسخه فشرده شده NET Framework. که شامل بیشتر توابع و دستورات ان میشود.
از SQl Server CE هم میتوان به عنوان بانک اطلاعاتی در این برنامه ها استفاده کرد.
لینک های مرتبط:
در خصوص نسخه برای سیستم عامل Symbian در جهت پشتیبانی از NET Compact Framework. هم در تاپیک زیر بحث شده:کد:MSDN:
http://msdn.microsoft.com/en-us/netframework/aa497273.aspx
Team Blog:
http://blogs.msdn.com/netcfteam
Wikipedia:
http://en.wikipedia.org/wiki/.NET_Compact_Framework
Download .NET Compact Framework 2.0 Redistributable (for mobiles):
http://microsoft.com/DownLoads/details.aspx?familyid=9655156B-356B-4A2C-857C-E62F50AE9A55
Download .NET Compact Framework 3.5 Redistributable (for mobiles):
http://microsoft.com/downloads/details.aspx?FamilyID=E3821449-3C6B-42F1-9FD9-0041345B3385
[ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
در ضمن، VS مجهز به یک شبیه ساز بسیار کامل داخلی است، که اجازه میدهد برنامه های نوشته شده را بدون ریخت نصب روی موبایل فوراً Run و مشاهده کنید. (دقیقاً مثل اینکه موبایل جلویتان است)
کد نویسی مدیریت شده برای موبایل و غیر موبایل بسیار شبیه است.
مثلاً در یک برنامه ویندوزی #C اگر بخواهید با کلیک دکمه ای پیام Hello World نمایش داده شود، در رویداد کلیک چنین مینویسید:
حالا نکته جالب توجه انجا است که دقیقاً همین کد در NET CF. هم کار خواهد کرد!!!کد:private void button1_Click(object sender, EventArgs e)
{
System.Windows.Forms.MessageBox.Show("Hello World");
}
یعنی عملاً کسانی که به برنامه نویسی ویندوز عادی تحت یکی از زبان های VB.Net و C#.Net تسلط داشته باشند، خیلی سریع میتوانند برای موبایل هم کدنویسی کنند.
(
در واقع از جمله مزایای بزرگ Framework همین یکپارچگی بین پلتفرم های مختلف است ...
و امکان کدنویسی با یک زبان و کلاسهای مشترک برای Win و Web و XBox و Zone و Mobile و SmartDevice و...
و یا اینکه فایل کامپایلی نهایی تولید شده وابستگی به 32 بیتی و 64 بیتی و سیتم عامل و سخت افزار ندارد
)
=====
توضیحات فوق فقط در جهت معرفی ابزار Management برای کدنویسی موبایل و وسائل قابل حمل بوده و لزوماً برای Unmanagement صادق نمی باشد، البته VS از ++VC هم در بخش Unmanagement برای کدنویسی این تجهیزات پشتیبانی میکند.
جمیعاً موفق باشید.
همان طور که جناب _H2_ فرمودند با .Net می توان هم برای pc هم برای Mobile و ... برنامه نویسی کرد
برنامه نویسی unmanaged در محیط C++ با استفاده از API های Windows (پروژه های Win32) برای pc با پاکت پیسی 60% شباهت دارد پس کسانی که با برنامه نویسی با win32 - MFC - ATL آشنایی دارند خیلی راحت می توانند پیشرفت کنند
به دلیل پشتیبانی نکردن NET. از امکاناتی مانند BlueTooth و ... ترجیحا برای برنامه های سیستمی از unmanaged استفاده میکنیم اما برای برنامه های کاربردی از جمله بازی ها عقل حکم میکنه که از Net. استفاده کنیم
مهم
کد:http://msdn.microsoft.com/en-us/library/bb158532.aspx
سلام
یک نکته لازم است یادآوری کنم ...
دات نت کاملاً از استفاده از API ها پشتیبانی میکند و اگر شما هر کاری را بتوانید در ++VC با کمک API ها انجام دهید، حتماً ان کار را هم میتوانید با همان API ها در دات نت انجام دهید.
مثلاً import و تعریف استفاده از API در دات نت میتواند به سادگی زیر باشد:
در واقع همه تعاملات خود دات نت هم با سیستم عامل بر اساس API ها است و اگر شما API هایی بلد هستید و در دات نت کلاس آماده مخصوصی برای آن کار وجود ندارد، مثل سایر زبانهای برنامه نویسی تحت ویندوز، میتوانید از آن API ها استفاده کنید.کد://C#.Net
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
public static extern int GetCurrentThreadId();
[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern IntPtr RegisterDevice(string lpszType, int dwIndex, string lpszLib, byte[] dwInfo);
[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern bool DeregisterDevice(IntPtr handle);
//VB.Net
<System.Runtime.InteropServices.DllImport("kernel32.dll")> _
Public Shared Function GetCurrentThreadId() As Integer
End Function
<System.Runtime.InteropServices.DllImport("coredll.dll")> _
Private Shared Function RegisterDevice(ByVal lpszType As String, ByVal dwIndex As Integer, ByVal lpszLib As String, ByVal dwInfo As Byte()) As IntPtr
End Function
<System.Runtime.InteropServices.DllImport("coredll.dll")> _
Private Shared Function DeregisterDevice(ByVal handle As IntPtr) As Boolean
End Function
برای Bluetooth تاپیک زیر کمک زیادی نخواهد کرد ولی دیدنش هم خالی از لطف نیست:
[ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
موفق باشید.
شما اگه میخواین plug-in برای pocket PC بنویسین یا به منابع سیستمی که low level هستند دسترسی پیدا کنید و برایشان برنامه بنویسید تنها راه unmanaged code است (مثل طراحی برنامه برای صفحه ی Home یا Today)
اما برنمه هایی مثل ارسال sms یا ار با Camera را بهتر است با Net. بنویسید در زیر برنامه ی CeCamera به دو زبان C# و C++ آمده است:
کد:C++ :
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// ***************************************************************************
// CECamera.cpp
//
// Take pictures and videos using Camera native API.
//
#include <aygshell.h>
#include "Macros.h"
#include "resource.h"
// Macros
#define MAX_INITIAL_DIR MAX_PATH
#define MAX_FILE_NAME MAX_PATH
#define MAX_TITLE 64
#define MAX_RESOLUTION_WIDTH 10
#define MAX_RESOLUTION_HEIGHT 10
#define MAX_VIDEO_TIME_LIMIT 10
#define MAX_PLATFORM 64
#define MAX_CLASSNAME 64
#define MAX_MESSAGE MAX_PATH * 2
#define CECAMERA_DEFAULT_INITIAL_DIR NULL
#define CECAMERA_DEFAULT_FILE_NAME NULL
#define CECAMERA_DEFAULT_TITLE NULL
#define CECAMERA_DEFAULT_STILL_QUALITY CAMERACAPTURE_STILLQUALITY_DEFAULT
#define CECAMERA_DEFAULT_VIDEO_TYPES CAMERACAPTURE_VIDEOTYPE_ALL
#define CECAMERA_DEFAULT_RESOLUTION_WIDTH 0
#define CECAMERA_DEFAULT_RESOLUTION_HEIGHT 0
#define CECAMERA_DEFAULT_VIDEO_TIME_LIMIT 0
#define CECAMERA_DEFAULT_MODE CAMERACAPTURE_MODE_STILL
#define CECAMERA_MUTEX_NAME TEXT("__CECAMERA_MUTEX__")
#define CECAMERA_MAINDLG_CLASSNAME TEXT("Dialog")
// Global variables
BOOL g_bSmartphone = FALSE;
HINSTANCE g_hInstance = NULL;
HMENU g_hMainMenu = NULL;
LPCTSTR g_szCaption;
CAMERACAPTURE_STILLQUALITY g_StillQuality = CECAMERA_DEFAULT_STILL_QUALITY;
CAMERACAPTURE_VIDEOTYPES g_VideoTypes = CECAMERA_DEFAULT_VIDEO_TYPES;
CAMERACAPTURE_MODE g_Mode = CECAMERA_DEFAULT_MODE;
// Forward declarations of the functions
BOOL IsSmartphone();
BOOL IsFocusOnEditControl();
BOOL InitDialog(HWND hwndDlg);
VOID StartCamera(HWND hwndDlg);
VOID ShowAboutBox(HWND hwndDlg);
VOID ResetOptions(HWND hwndDlg);
VOID ChangeMode(WORD wMode);
VOID ChangeStillQuality(WORD wStillQuality);
VOID ChangeVideoTypes(WORD wVideoTypes);
VOID ChangeOptions(HWND hwndDlg, WORD wOptions);
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
// ***************************************************************************
// Function Name: WinMain
//
// Purpose: Main entry point into the CECamera program
//
// Arguments: Standard WinMain arguments
//
// Return Values: 0
//
// Description:
// Checks to see if a previous instance of the program is running,
// and if it is not, it pops up a dialog box allowing the user to
// specify the parameters for SHCameraCapture() API to launch Camera app.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
{
HRESULT hr;
HWND hWndPreInstance;
HANDLE hMutex = NULL;
// Load the caption of the main dialog from resource
g_szCaption = (LPCTSTR)LoadString(hInstance, IDS_CAPTION, NULL, 0);
CPR(g_szCaption);
// Use a global named mutex to detect another instance of CECamera
hMutex = CreateMutex(NULL, FALSE, CECAMERA_MUTEX_NAME);
CPR(hMutex);
if (ERROR_ALREADY_EXISTS == GetLastError())
{
// Already an instance running - attempt to switch to it and then exit
hWndPreInstance = FindWindow(CECAMERA_MAINDLG_CLASSNAME, g_szCaption);
CPR(hWndPreInstance);
SetForegroundWindow(hWndPreInstance);
}
else
{
// Store the hInstance
g_hInstance = hInstance;
// Determine if platform is Smartphone
g_bSmartphone = IsSmartphone();
// Create the dialog box
DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAINDLG), NULL, (DLGPROC)DialogProc);
}
Error:
if (NULL != hMutex)
{
// Release the global named mutex
CloseHandle(hMutex);
}
return hr;
}
// ***************************************************************************
// Function Name: DialogProc
//
// Purpose: Message Handler for CECamera Dialog Box
//
// Arguments: Standard Dialog Procedure Arguments
//
// Return Values:
// Returns TRUE if it processed the message, or FALSE if it did not.
//
// Description:
// Dialog Procedure for the main CECamera Dialog.
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
BOOL bHandled = TRUE;
switch (uMsg)
{
case WM_INITDIALOG:
// Make sure the dialog box was created
if (!InitDialog(hwndDlg))
{
PostMessage(hwndDlg, WM_CLOSE, 0, 0);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_START:
StartCamera(hwndDlg);
break;
case IDM_ABOUT:
ShowAboutBox(hwndDlg);
break;
case IDM_RESET:
ResetOptions(hwndDlg);
break;
case IDM_MODE_STILL:
// Fall through
case IDM_MODE_VIDEOONLY:
// Fall through
case IDM_MODE_VIDEOWITHAUDIO:
ChangeMode(LOWORD(wParam));
break;
case IDM_STILLQUALITY_DEFAULT:
// Fall through
case IDM_STILLQUALITY_LOW:
// Fall through
case IDM_STILLQUALITY_NORMAL:
// Fall through
case IDM_STILLQUALITY_HIGH:
ChangeStillQuality(LOWORD(wParam));
break;
case IDM_VIDEOTYPES_ALL:
// Fall through
case IDM_VIDEOTYPES_STANDARD:
// Fall through
case IDM_VIDEOTYPES_MESSAGING:
ChangeVideoTypes(LOWORD(wParam));
break;
case IDC_CHECK_INITIAL_DIR:
// Fall through
case IDC_CHECK_DEFAULT_FILE_NAME:
// Fall through
case IDC_CHECK_TITLE:
// Fall through
case IDC_CHECK_RESOLUTION:
// Fall through
case IDC_CHECK_VIDEO_TIME_LIMIT:
ChangeOptions(hwndDlg, LOWORD(wParam));
break;
case IDCANCEL:
// Fall through
case IDM_EXIT:
PostMessage(hwndDlg, WM_CLOSE, 0, 0);
break;
}
break;
case WM_CLOSE:
EndDialog(hwndDlg, IDCANCEL);
break;
case WM_ACTIVATE:
if (WA_ACTIVE == LOWORD(wParam))
{
// Set the focus to the main dialog if we are activated
SetFocus(hwndDlg);
}
break;
case WM_HOTKEY:
if (g_bSmartphone && VK_TBACK == HIWORD(lParam))
{
if (IsFocusOnEditControl())
{
// The current control with focus is an edit control
if (MOD_KEYUP & LOWORD(lParam))
{
// Delete a character on each KEYUP
SendMessage(GetFocus(), WM_CHAR, VK_BACK, 0);
}
else if (MOD_HOLD & LOWORD(lParam))
{
// Clear content from edit controls while pressing and holding the Back key
SetWindowText(GetFocus(), TEXT(""));
}
}
else if (MOD_KEYUP & LOWORD(lParam))
{
// The current control with focus is not an edit control,
// close the dialog and then back to the previous application
PostMessage(hwndDlg, WM_CLOSE, 0, 0);
SHNavigateBack();
}
}
break;
default:
// Specify that we didn't process this message, let the default
// dialog box window procedure to process this message
bHandled = FALSE;
break;
}
return bHandled;
}
// **************************************************************************
// Function Name: IsSmartphone
//
// Purpose: Determine if platform is Smartphone
//
// Arguments: none
//
// Return Values:
// TRUE if the current platform is a Smartphone platform
// FALSE if the current platform is not a Smartphone platform
//
// Description:
// This function retrieves the current platforms type and then
// does a case insensitive string comparison.
BOOL IsSmartphone()
{
HRESULT hr;
TCHAR szPlatform[MAX_PLATFORM] = { 0 };
BOOL bResult = FALSE;
CBR(SystemParametersInfo(SPI_GETPLATFORMTYPE, ARRAYSIZE(szPlatform), szPlatform, 0));
if (0 == _tcsicmp(szPlatform, TEXT("Smartphone")))
{
bResult = TRUE;
}
Error:
return bResult;
}
// **************************************************************************
// Function Name: IsFocusOnEditControl
//
// Purpose: Determine if the current control with focus is an edit control
//
// Arguments: none
//
// Return Values:
// TRUE if the current control with focus is an edit control
// FALSE if the current control with focus is not an edit control
//
// Description:
// This function retrieves the window class name of the current control
// with focus and then does a case insensitive string comparison.
BOOL IsFocusOnEditControl()
{
HRESULT hr;
TCHAR szClassName[MAX_CLASSNAME] = { 0 };
BOOL bResult = FALSE;
CBR(0 != GetClassName(GetFocus(), szClassName, ARRAYSIZE(szClassName)));
if (0 == _tcsicmp(szClassName, TEXT("Edit")))
{
bResult = TRUE;
}
Error:
return bResult;
}
// ***************************************************************************
// Function Name: InitDialog
//
// Purpose: UI Initialization
//
// Arguments:
// HWND hwndDlg - Handle to the main dialog
//
// Return Values:
// TRUE if initialization was successful
// FALSE if initialization failed
//
// Description:
// The purpose of this function is to create a full-screen dialog box with
// the Cancel button and creates a menu bar at the bottom of the dialog.
BOOL InitDialog(HWND hwndDlg)
{
SHINITDLGINFO shidi;
SHMENUBARINFO shmbi;
BOOL bSuccess = FALSE;
// Specify that the dialog box should stretch full screen
ZeroMemory(&shidi, sizeof(shidi));
shidi.dwMask = SHIDIM_FLAGS;
shidi.hDlg = hwndDlg;
shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
// Adds the Cancel button to close the dialog with IDCANCEL
// if the current platform is not a Smartphone platform
if (!g_bSmartphone)
{
shidi.dwFlags |= SHIDIF_CANCELBUTTON;
}
if (SHInitDialog(&shidi))
{
// Set up the menu bar
ZeroMemory(&shmbi, sizeof(shmbi));
shmbi.cbSize = sizeof(shmbi);
shmbi.hwndParent = hwndDlg;
shmbi.nToolBarId = IDR_MENUBAR;
shmbi.hInstRes = g_hInstance;
if (SHCreateMenuBar(&shmbi))
{
if (NULL != shmbi.hwndMB)
{
// Get the main menu and store it
g_hMainMenu = (HMENU)SendMessage(shmbi.hwndMB, SHCMBM_GETSUBMENU, 0, IDM_MENU);
if (NULL != g_hMainMenu)
{
// Set the window caption
SetWindowText(hwndDlg, g_szCaption);
// 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;
}
کد:
C#:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// ***************************************************************************
// CECamera.cs
//
// Take pictures and videos using Camera managed API.
//
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Globalization;
using Microsoft.WindowsMobile.Forms;
using System.IO;
namespace Microsoft.WindowsMobile.Samples.CECamera
{
/// <summary>
/// Main form for the CECamera application.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
// Default values for options
private const string cecameraDefaultInitialDirectory = null;
private const string cecameraDefaultPictureFileName = "picture1";
private const string cecameraDefaultPictureExtension = ".jpg";
private const string cecameraDefaultVideoFileName = "movie1";
private const string cecameraDefaultTitle = "Title";
private const string cecameraDefaultResolutionWidth = "100";
private const string cecameraDefaultResolutionHeight = "100";
private const string cecameraDefaultVideoTimeLimit = "25";
private System.Windows.Forms.MainMenu mainMenu;
private System.Windows.Forms.MenuItem menuStart;
private System.Windows.Forms.MenuItem menuMenu;
private System.Windows.Forms.MenuItem menuMode;
private System.Windows.Forms.MenuItem menuModeStill;
private System.Windows.Forms.MenuItem menuModeVideoOnly;
private System.Windows.Forms.MenuItem menuModeVideoWithAudio;
private System.Windows.Forms.MenuItem menuStillQuality;
private System.Windows.Forms.MenuItem menuStillQualityDefault;
private System.Windows.Forms.MenuItem menuStillQualityLow;
private System.Windows.Forms.MenuItem menuStillQualityNormal;
private System.Windows.Forms.MenuItem menuStillQualityHigh;
private System.Windows.Forms.MenuItem menuVideoTypes;
private System.Windows.Forms.MenuItem menuVideoTypesAll;
private System.Windows.Forms.MenuItem menuVideoTypesStandard;
private System.Windows.Forms.MenuItem menuVideoTypesMessaging;
private System.Windows.Forms.MenuItem menuSeparator1;
private System.Windows.Forms.MenuItem menuReset;
private System.Windows.Forms.MenuItem menuAbout;
private System.Windows.Forms.MenuItem menuSeparator2;
private System.Windows.Forms.MenuItem menuExit;
private System.Windows.Forms.CheckBox checkInitialDirectory;
private System.Windows.Forms.TextBox textInitialDirectory;
private System.Windows.Forms.CheckBox checkDefaultFileName;
private System.Windows.Forms.TextBox textDefaultFileName;
private System.Windows.Forms.CheckBox checkTitle;
private System.Windows.Forms.TextBox textTitle;
private System.Windows.Forms.CheckBox checkResolution;
private System.Windows.Forms.TextBox textResolutionWidth;
private System.Windows.Forms.Label labelX;
private System.Windows.Forms.TextBox textResolutionHeight;
private System.Windows.Forms.CheckBox checkVideoTimeLimit;
private System.Windows.Forms.TextBox textVideoTimeLimit;
/// <summary>
/// Constructor
/// </summary>
public MainForm()
{
//
// Required for Windows Form Designer support
//
this.InitializeComponent();
//
// Specify all options as default value
//
this.ResetOptions();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu = new System.Windows.Forms.MainMenu();
this.menuStart = new System.Windows.Forms.MenuItem();
this.menuMenu = new System.Windows.Forms.MenuItem();
this.menuMode = new System.Windows.Forms.MenuItem();
this.menuModeStill = new System.Windows.Forms.MenuItem();
this.menuModeVideoOnly = new System.Windows.Forms.MenuItem();
this.menuModeVideoWithAudio = new System.Windows.Forms.MenuItem();
this.menuStillQuality = new System.Windows.Forms.MenuItem();
this.menuStillQualityDefault = new System.Windows.Forms.MenuItem();
this.menuStillQualityLow = new System.Windows.Forms.MenuItem();
this.menuStillQualityNormal = new System.Windows.Forms.MenuItem();
this.menuStillQualityHigh = new System.Windows.Forms.MenuItem();
this.menuVideoTypes = new System.Windows.Forms.MenuItem();
this.menuVideoTypesAll = new System.Windows.Forms.MenuItem();
this.menuVideoTypesStandard = new System.Windows.Forms.MenuItem();
this.menuVideoTypesMessaging = new System.Windows.Forms.MenuItem();
this.menuSeparator1 = new System.Windows.Forms.MenuItem();
this.menuReset = new System.Windows.Forms.MenuItem();
this.menuAbout = new System.Windows.Forms.MenuItem();
this.menuSeparator2 = new System.Windows.Forms.MenuItem();
this.menuExit = new System.Windows.Forms.MenuItem();
this.checkInitialDirectory = new System.Windows.Forms.CheckBox();
this.textInitialDirectory = new System.Windows.Forms.TextBox();
this.checkDefaultFileName = new System.Windows.Forms.CheckBox();
this.textDefaultFileName = new System.Windows.Forms.TextBox();
this.checkTitle = new System.Windows.Forms.CheckBox();
this.textTitle = new System.Windows.Forms.TextBox();
this.checkResolution = new System.Windows.Forms.CheckBox();
this.textResolutionWidth = new System.Windows.Forms.TextBox();
this.labelX = new System.Windows.Forms.Label();
this.textResolutionHeight = new System.Windows.Forms.TextBox();
this.checkVideoTimeLimit = new System.Windows.Forms.CheckBox();
this.textVideoTimeLimit = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// mainMenu
//
this.mainMenu.MenuItems.Add(this.menuStart);
this.mainMenu.MenuItems.Add(this.menuMenu);
//
// menuStart
//
this.menuStart.Text = "Start";
this.menuStart.Click += new System.EventHandler(this.menuStart_Click);
//
// menuMenu
//
this.menuMenu.MenuItems.Add(this.menuMode);
this.menuMenu.MenuItems.Add(this.menuStillQuality);
this.menuMenu.MenuItems.Add(this.menuVideoTypes);
this.menuMenu.MenuItems.Add(this.menuSeparator1);
this.menuMenu.MenuItems.Add(this.menuReset);
this.menuMenu.MenuItems.Add(this.menuAbout);
this.menuMenu.MenuItems.Add(this.menuSeparator2);
this.menuMenu.MenuItems.Add(this.menuExit);
this.menuMenu.Text = "Menu";
//
// menuMode
//
this.menuMode.MenuItems.Add(this.menuModeStill);
this.menuMode.MenuItems.Add(this.menuModeVideoOnly);
this.menuMode.MenuItems.Add(this.menuModeVideoWithAudio);
this.menuMode.Text = "Mode";
//
// menuModeStill
//
this.menuModeStill.Text = "Still";
this.menuModeStill.Click += new System.EventHandler(this.menuModeStill_Click);
//
// menuModeVideoOnly
//
this.menuModeVideoOnly.Text = "Video Only";
this.menuModeVideoOnly.Click += new System.EventHandler(this.menuModeVideoOnly_Click);
//
// menuModeVideoWithAudio
//
this.menuModeVideoWithAudio.Text = "Video with Audio";
this.menuModeVideoWithAudio.Click += new System.EventHandler(this.menuModeVideoWithAudio_Click);
//
// menuStillQuality
//
this.menuStillQuality.MenuItems.Add(this.menuStillQualityDefault);
this.menuStillQuality.MenuItems.Add(this.menuStillQualityLow);
this.menuStillQuality.MenuItems.Add(this.menuStillQualityNormal);
this.menuStillQuality.MenuItems.Add(this.menuStillQualityHigh);
this.menuStillQuality.Text = "Still Quality";
//
// menuStillQualityDefault
//
this.menuStillQualityDefault.Text = "Default";
this.menuStillQualityDefault.Click += new System.EventHandler(this.menuStillQualityDefault_Click);
//
// menuStillQualityLow
//
this.menuStillQualityLow.Text = "Low";
this.menuStillQualityLow.Click += new System.EventHandler(this.menuStillQualityLow_Click);
//
// menuStillQualityNormal
//
this.menuStillQualityNormal.Text = "Normal";
this.menuStillQualityNormal.Click += new System.EventHandler(this.menuStillQualityNormal_Click);
//
// menuStillQualityHigh
//
this.menuStillQualityHigh.Text = "High";
this.menuStillQualityHigh.Click += new System.EventHandler(this.menuStillQualityHigh_Click);
//
// menuVideoTypes
//
this.menuVideoTypes.MenuItems.Add(this.menuVideoTypesAll);
this.menuVideoTypes.MenuItems.Add(this.menuVideoTypesStandard);
this.menuVideoTypes.MenuItems.Add(this.menuVideoTypesMessaging);
this.menuVideoTypes.Text = "Video Types";
//
// menuVideoTypesAll
//
this.menuVideoTypesAll.Text = "All";
this.menuVideoTypesAll.Click += new System.EventHandler(this.menuVideoTypesAll_Click);
//
// menuVideoTypesStandard
//
this.menuVideoTypesStandard.Text = "Standard";
this.menuVideoTypesStandard.Click += new System.EventHandler(this.menuVideoTypesStandard_Click);
//
// menuVideoTypesMessaging
//
this.menuVideoTypesMessaging.Text = "Messaging";
this.menuVideoTypesMessaging.Click += new System.EventHandler(this.menuVideoTypesMessaging_Click);
//
// menuSeparator1
//
this.menuSeparator1.Text = "-";
//
// menuReset
//
this.menuReset.Text = "Reset";
this.menuReset.Click += new System.EventHandler(this.menuReset_Click);
//
// menuAbout
//
this.menuAbout.Text = "About";
this.menuAbout.Click += new System.EventHandler(this.menuAbout_Click);
//
// menuSeparator2
//
this.menuSeparator2.Text = "-";
//
// menuExit
//
this.menuExit.Text = "Exit";
this.menuExit.Click += new System.EventHandler(this.menuExit_Click);
//
// checkInitialDirectory
//
this.checkInitialDirectory.Location = new System.Drawing.Point(5, 5);
this.checkInitialDirectory.Name = "checkInitialDirectory";
this.checkInitialDirectory.Size = new System.Drawing.Size(154, 16);
this.checkInitialDirectory.TabIndex = 0;
this.checkInitialDirectory.Text = "Initial Directory:";
this.checkInitialDirectory.CheckStateChanged += new System.EventHandler(this.checkInitialDirectory_CheckStateChanged);
//
// textInitialDirectory
//
this.textInitialDirectory.Location = new System.Drawing.Point(5, 25);
this.textInitialDirectory.MaxLength = 260;
this.textInitialDirectory.Name = "textInitialDirectory";
this.textInitialDirectory.Size = new System.Drawing.Size(141, 22);
this.textInitialDirectory.TabIndex = 1;
//
// checkDefaultFileName
//
this.checkDefaultFileName.Location = new System.Drawing.Point(5, 53);
this.checkDefaultFileName.Name = "checkDefaultFileName";
this.checkDefaultFileName.Size = new System.Drawing.Size(141, 16);
this.checkDefaultFileName.TabIndex = 2;
this.checkDefaultFileName.Text = "Default File Name:";
this.checkDefaultFileName.CheckStateChanged += new System.EventHandler(this.checkDefaultFileName_CheckStateChanged);
//
// textDefaultFileName
//
this.textDefaultFileName.Location = new System.Drawing.Point(5, 75);
this.textDefaultFileName.MaxLength = 260;
this.textDefaultFileName.Name = "textDefaultFileName";
this.textDefaultFileName.Size = new System.Drawing.Size(141, 22);
this.textDefaultFileName.TabIndex = 3;
//
// checkTitle
//
this.checkTitle.Location = new System.Drawing.Point(5, 102);
this.checkTitle.Name = "checkTitle";
this.checkTitle.Size = new System.Drawing.Size(108, 23);
this.checkTitle.TabIndex = 4;
this.checkTitle.Text = "Title:";
this.checkTitle.CheckStateChanged += new System.EventHandler(this.checkTitle_CheckStateChanged);
//
// textTitle
//
this.textTitle.Location = new System.Drawing.Point(5, 131);
this.textTitle.MaxLength = 64;
this.textTitle.Name = "textTitle";
this.textTitle.Size = new System.Drawing.Size(141, 22);
this.textTitle.TabIndex = 5;
//
// checkResolution
//
this.checkResolution.Location = new System.Drawing.Point(5, 158);
this.checkResolution.Name = "checkResolution";
this.checkResolution.Size = new System.Drawing.Size(154, 16);
this.checkResolution.TabIndex = 6;
this.checkResolution.Text = "Resolution (Width x Height):";
this.checkResolution.CheckStateChanged += new System.EventHandler(this.checkResolution_CheckStateChanged);
//
// textResolutionWidth
//
this.textResolutionWidth.Location = new System.Drawing.Point(5, 180);
this.textResolutionWidth.MaxLength = 10;
this.textResolutionWidth.Name = "textResolutionWidth";
this.textResolutionWidth.Size = new System.Drawing.Size(52, 22);
this.textResolutionWidth.TabIndex = 7;
//
// labelX
//
this.labelX.Location = new System.Drawing.Point(63, 180);
this.labelX.Name = "labelX";
this.labelX.Size = new System.Drawing.Size(24, 16);
this.labelX.Text = "x";
this.labelX.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// textResolutionHeight
//
this.textResolutionHeight.Location = new System.Drawing.Point(93, 180);
this.textResolutionHeight.MaxLength = 10;
this.textResolutionHeight.Name = "textResolutionHeight";
this.textResolutionHeight.Size = new System.Drawing.Size(53, 22);
this.textResolutionHeight.TabIndex = 9;
//
// checkVideoTimeLimit
//
this.checkVideoTimeLimit.Location = new System.Drawing.Point(5, 207);
this.checkVideoTimeLimit.Name = "checkVideoTimeLimit";
this.checkVideoTimeLimit.Size = new System.Drawing.Size(115, 19);
this.checkVideoTimeLimit.TabIndex = 10;
this.checkVideoTimeLimit.Text = "Video Time Limit:";
this.checkVideoTimeLimit.CheckStateChanged += new System.EventHandler(this.checkVideoTimeLimit_CheckStateChanged);
//
// textVideoTimeLimit
//
this.textVideoTimeLimit.Location = new System.Drawing.Point(5, 232);
this.textVideoTimeLimit.MaxLength = 10;
this.textVideoTimeLimit.Name = "textVideoTimeLimit";
this.textVideoTimeLimit.Size = new System.Drawing.Size(154, 22);
this.textVideoTimeLimit.TabIndex = 11;
//
// MainForm
//
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(240, 268);
this.Controls.Add(this.checkInitialDirectory);
this.Controls.Add(this.textInitialDirectory);
this.Controls.Add(this.checkDefaultFileName);
this.Controls.Add(this.textDefaultFileName);
this.Controls.Add(this.checkTitle);
this.Controls.Add(this.textTitle);
this.Controls.Add(this.checkResolution);
this.Controls.Add(this.textResolutionWidth);
this.Controls.Add(this.labelX);
this.Controls.Add(this.textResolutionHeight);
this.Controls.Add(this.checkVideoTimeLimit);
this.Controls.Add(this.textVideoTimeLimit);
this.Menu = this.mainMenu;
this.Name = "MainForm";
this.Text = "CECamera";
this.Closed += new System.EventHandler(this.MainForm_Closed);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Application.Run(new MainForm());
}
/// <summary>
/// Exit the application.
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void MainForm_Closed(object sender, System.EventArgs e)
{
Application.Exit();
}
/// <summary>
/// Enable/Disable user input of the textInitialDirectory edit control
/// for allowing/disallowing the user to specify the initial directory
/// of the CameraCaptureDialog.
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void checkInitialDirectory_CheckStateChanged(object sender, System.EventArgs e)
{
this.textInitialDirectory.Enabled = this.checkInitialDirectory.Checked;
}
/// <summary>
/// Enable/Disable user input of the textDefaultFileName edit control
/// for allowing/disallowing the user to specify the default file name
/// of the CameraCaptureDialog.
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void checkDefaultFileName_CheckStateChanged(object sender, System.EventArgs e)
{
this.textDefaultFileName.Enabled = this.checkDefaultFileName.Checked;
validateFileNameInput();
}
/// <summary>
/// Enable/Disable user input of the textTitle edit control
/// for allowing/disallowing the user to specify the title
/// of the CameraCaptureDialog.
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void checkTitle_CheckStateChanged(object sender, System.EventArgs e)
{
this.textTitle.Enabled = this.checkTitle.Checked;
}
/// <summary>
/// Enable/Disable user input of the textResolutionWidth and textResolutionHeight edit control
/// for allowing/disallowing the user to specify the resolution width and height
/// of the CameraCaptureDialog.
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void checkResolution_CheckStateChanged(object sender, System.EventArgs e)
{
this.textResolutionWidth.Enabled = this.checkResolution.Checked;
this.textResolutionHeight.Enabled = this.checkResolution.Checked;
}
/// <summary>
/// Enable/Disable user input of the textVideoTimeLimit edit control
/// for allowing/disallowing the user to specify the video time limit
/// of the CameraCaptureDialog.
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void checkVideoTimeLimit_CheckStateChanged(object sender, EventArgs e)
{
this.textVideoTimeLimit.Enabled = this.checkVideoTimeLimit.Checked;
}
/// <summary>
/// Launches Camera using CameraCaptureDialog with specified arguments.
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void menuStart_Click(object sender, System.EventArgs e)
{
CameraCaptureDialog cameraCapture = new CameraCaptureDialog();
cameraCapture.Owner = this;
// Specify the options as user specified.
if (this.checkInitialDirectory.Checked)
{
cameraCapture.InitialDirectory = this.textInitialDirectory.Text;
}
if (this.checkDefaultFileName.Checked)
{
if (this.menuModeStill.Checked)
{
if (cameraCapture.DefaultFileName != null)
{
// It is necessary to end picture files with ".jpg".
// Otherwise the argument is invalid.
cameraCapture.DefaultFileName = cameraCapture.DefaultFileName + cecameraDefaultPictureExtension;
}
}
else
{
// If it is a video, pass null. This will return a filename with a
// correct extension. Later on we rename the file and keep the extension.
cameraCapture.DefaultFileName = null;
}
}
if (this.checkTitle.Checked)
{
cameraCapture.Title = this.textTitle.Text;
}
if (this.checkResolution.Checked)
{
int resolutionWidth = 0;
int resolutionHeight = 0;
if (!ConvertStringToInt(this.textResolutionWidth.Text, ref resolutionWidth))
{
MessageBox.Show("Please input a valid resolution width.", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
textResolutionWidth.Focus();
return;
}
if (!ConvertStringToInt(this.textResolutionHeight.Text, ref resolutionHeight))
{
MessageBox.Show("Please input a valid resolution height.", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
textResolutionHeight.Focus();
return;
}
cameraCapture.Resolution = new Size(resolutionWidth, resolutionHeight);
}
if (this.checkVideoTimeLimit.Checked)
{
int videoTimeLimit = 0;
if (!ConvertStringToInt(this.textVideoTimeLimit.Text, ref videoTimeLimit))
{
MessageBox.Show("Please input a valid video time limit.", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
textVideoTimeLimit.Focus();
return;
}
cameraCapture.VideoTimeLimit = new TimeSpan(0, 0, videoTimeLimit);
}
// Specify capture mode
if (this.menuModeStill.Checked)
{
cameraCapture.Mode = CameraCaptureMode.Still;
}
else if (this.menuModeVideoOnly.Checked)
{
cameraCapture.Mode = CameraCaptureMode.VideoOnly;
}
else if (this.menuModeVideoWithAudio.Checked)
{
cameraCapture.Mode = CameraCaptureMode.VideoWithAudio;
}
// Specify still quality
if (this.menuStillQualityDefault.Checked)
{
cameraCapture.StillQuality = CameraCaptureStillQuality.Default;
}
else if (this.menuStillQualityLow.Checked)
{
cameraCapture.StillQuality = CameraCaptureStillQuality.Low;
}
else if (this.menuStillQualityNormal.Checked)
{
cameraCapture.StillQuality = CameraCaptureStillQuality.Normal;
}
else if (this.menuStillQualityHigh.Checked)
{
cameraCapture.StillQuality = CameraCaptureStillQuality.High;
}
// Specify video types
if (this.menuVideoTypesAll.Checked)
{
cameraCapture.VideoTypes = CameraCaptureVideoTypes.All;
}
else if (this.menuVideoTypesStandard.Checked)
{
cameraCapture.VideoTypes = CameraCaptureVideoTypes.Standard;
}
else if (this.menuVideoTypesMessaging.Checked)
{
cameraCapture.VideoTypes = CameraCaptureVideoTypes.Messaging;
}
try
{
// Displays the "Camera Capture" dialog box
if (DialogResult.OK == cameraCapture.ShowDialog())
{
string fileName = cameraCapture.FileName;
// If it is a video we rename the file so that it has the user entered
// default filename and the correct extension.
if (cameraCapture.Mode != CameraCaptureMode.Still)
{
string extension = fileName.Substring(fileName.LastIndexOf("."));
string directory = "";
if (fileName.LastIndexOf("\\") != -1)
{
directory = fileName.Substring(0, fileName.LastIndexOf("\\") + 1);
}
fileName = directory + this.textDefaultFileName.Text + extension;
System.IO.File.Move(cameraCapture.FileName, fileName);
}
// The method completed successfully.
MessageBox.Show("The picture or video has been successfully captured and saved to:\n\n" + fileName,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
}
}
catch (ArgumentException ex)
{
// An invalid argument was specified.
MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
catch (OutOfMemoryException ex)
{
// There is not enough memory to save the image or video.
MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
}
catch (InvalidOperationException ex)
{
// An unknown error occurred.
MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
}
}
/// <summary>
/// Checks the selected menu item of "Mode".
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void menuModeStill_Click(object sender, System.EventArgs e)
{
for (int i = 0; i < this.menuMode.MenuItems.Count; i++)
{
this.menuMode.MenuItems[i].Checked = false;
}
this.menuModeStill.Checked = true;
validateFileNameInput();
this.checkResolution.Enabled = true;
this.checkVideoTimeLimit.Checked = false;
this.checkVideoTimeLimit.Enabled = false;
}
/// <summary>
/// Checks the selected menu item of "Mode".
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void menuModeVideoOnly_Click(object sender, System.EventArgs e)
{
for (int i = 0; i < this.menuMode.MenuItems.Count; i++)
{
this.menuMode.MenuItems[i].Checked = false;
}
this.menuModeVideoOnly.Checked = true;
validateFileNameInput();
this.checkResolution.Checked = false;
this.checkResolution.Enabled = false;
this.checkVideoTimeLimit.Enabled = true;
}
/// <summary>
/// Checks the selected menu item of "Mode".
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void menuModeVideoWithAudio_Click(object sender, System.EventArgs e)
{
for (int i = 0; i < this.menuMode.MenuItems.Count; i++)
{
this.menuMode.MenuItems[i].Checked = false;
}
this.menuModeVideoWithAudio.Checked = true;
validateFileNameInput();
this.checkResolution.Checked = false;
this.checkResolution.Enabled = false;
this.checkVideoTimeLimit.Enabled = true;
}
/// <summary>
/// Verifies the filename to be consistent with the camera mode.
/// </summary>
private void validateFileNameInput()
{
if (this.menuModeStill.Checked)
{
if (textDefaultFileName.Text == null || textDefaultFileName.Text.Length == 0 ||
textDefaultFileName.Text.Equals(cecameraDefaultVideoFileName))
{
this.textDefaultFileName.Text = cecameraDefaultPictureFileName;
}
}
else
{
if (textDefaultFileName.Text == null || textDefaultFileName.Text.Length == 0 ||
textDefaultFileName.Text.Equals(cecameraDefaultPictureFileName))
{
textDefaultFileName.Text = cecameraDefaultVideoFileName;
}
}
}
/// <summary>
/// Checks the selected menu item of "Still Quality".
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void menuStillQualityDefault_Click(object sender, System.EventArgs e)
{
for (int i = 0; i < this.menuStillQuality.MenuItems.Count; i++)
{
this.menuStillQuality.MenuItems[i].Checked = false;
}
this.menuStillQualityDefault.Checked = true;
}
/// <summary>
/// Checks the selected menu item of "Still Quality".
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void menuStillQualityLow_Click(object sender, System.EventArgs e)
{
for (int i = 0; i < this.menuStillQuality.MenuItems.Count; i++)
{
this.menuStillQuality.MenuItems[i].Checked = false;
}
this.menuStillQualityLow.Checked = true;
}
/// <summary>
/// Checks the selected menu item of "Still Quality".
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void menuStillQualityNormal_Click(object sender, System.EventArgs e)
{
for (int i = 0; i < this.menuStillQuality.MenuItems.Count; i++)
{
this.menuStillQuality.MenuItems[i].Checked = false;
}
this.menuStillQualityNormal.Checked = true;
}
/// <summary>
/// Checks the selected menu item of "Still Quality".
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void menuStillQualityHigh_Click(object sender, System.EventArgs e)
{
for (int i = 0; i < this.menuStillQuality.MenuItems.Count; i++)
{
this.menuStillQuality.MenuItems[i].Checked = false;
}
this.menuStillQualityHigh.Checked = true;
}
/// <summary>
/// Checks the selected menu item of "Video Types".
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void menuVideoTypesAll_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.menuVideoTypes.MenuItems.Count; i++)
{
this.menuVideoTypes.MenuItems[i].Checked = false;
}
this.menuVideoTypesAll.Checked = true;
}
/// <summary>
/// Checks the selected menu item of "Video Types".
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void menuVideoTypesStandard_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.menuVideoTypes.MenuItems.Count; i++)
{
this.menuVideoTypes.MenuItems[i].Checked = false;
}
this.menuVideoTypesStandard.Checked = true;
}
/// <summary>
/// Checks the selected menu item of "Video Types".
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void menuVideoTypesMessaging_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.menuVideoTypes.MenuItems.Count; i++)
{
this.menuVideoTypes.MenuItems[i].Checked = false;
}
this.menuVideoTypesMessaging.Checked = true;
}
/// <summary>
/// Resets all settings as the default value and updates UI.
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void menuReset_Click(object sender, System.EventArgs e)
{
this.ResetOptions();
}
/// <summary>
/// Display a message box for program information.
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void menuAbout_Click(object sender, System.EventArgs e)
{
MessageBox.Show("CECamera Version 1.0\n\nSimple sample for CameraCaptureDialog.", this.Text);
}
/// <summary>
/// Close self to exit the application.
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">Event arguments</param>
private void menuExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
/// <summary>
/// Resets all settings as the default value and updates UI.
/// </summary>
private void ResetOptions()
{
// Uncheck all checkboxs to specify the options using the default value
this.checkInitialDirectory.Checked = false;
this.checkDefaultFileName.Checked = false;
this.checkTitle.Checked = false;
this.checkResolution.Checked = false;
this.checkVideoTimeLimit.Checked = false;
this.checkVideoTimeLimit.Enabled = false;
// Set the default value for the options
this.textInitialDirectory.Text = cecameraDefaultInitialDirectory;
this.textDefaultFileName.Text = cecameraDefaultPictureFileName;
this.textTitle.Text = cecameraDefaultTitle;
this.textResolutionWidth.Text = cecameraDefaultResolutionWidth;
this.textResolutionHeight.Text = cecameraDefaultResolutionHeight;
this.textVideoTimeLimit.Text = cecameraDefaultVideoTimeLimit;
// Disable the edit controls since specify using default settings
this.textInitialDirectory.Enabled = false;
this.textDefaultFileName.Enabled = false;
this.textTitle.Enabled = false;
this.textResolutionWidth.Enabled = false;
this.textResolutionHeight.Enabled = false;
this.textVideoTimeLimit.Enabled = false;
// Checks the menu item of "Mode" as default item
for (int i = 0; i < this.menuMode.MenuItems.Count; i++)
{
this.menuMode.MenuItems[i].Checked = false;
}
this.menuModeStill.Checked = true;
// Checks the menu item of "Still Quality" as default item
for (int i = 0; i < this.menuStillQuality.MenuItems.Count; i++)
{
this.menuStillQuality.MenuItems[i].Checked = false;
}
this.menuStillQualityDefault.Checked = true;
// Checks the menu item of "Video Types" as default item
for (int i = 0; i < this.menuVideoTypes.MenuItems.Count; i++)
{
this.menuVideoTypes.MenuItems[i].Checked = false;
}
this.menuVideoTypesAll.Checked = true;
}
/// <summary>
/// Converts the string to an integer.
/// </summary>
/// <param name="value">A string to convert</param>
/// <param name="result">A integer of the converted result</param>
/// <returns>true if converts successfully; otherwise, false.</returns>
private static bool ConvertStringToInt(string value, ref int result)
{
try
{
result = Convert.ToInt32(value, NumberFormatInfo.CurrentInfo);
}
catch (FormatException)
{
return false;
}
catch (OverflowException)
{
return false;
}
return true;
}
}
}
اگر سرعت اجرا برای پروژه ای مهم است بهتر است از unmanaged استفاده شود
مثلا یه بازی کارتی را با Net. بنویسیم و یه بازی سه بعدی فضایی رو با C++ بنویسیم
نحوه ی استفاده ی unmanagedCode در یک پروژه ی managed
کد:http://msdn.microsoft.com/en-us/library/bb677136.aspx
Add-In برای اضافه کردن unmanagedDll به برنامه
کد:http://www.red-gate.com/pinvoke/download
حالا که Addin رو نصب کردید به محل نصب برید و فایل PInvokeDotNetAddIn.AddIn رو با نوت پد باز کنید و همه خط ها رو پاک کنید و اینو جاش بذارید:
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<Extensibility xmlns="http://schemas.microsoft.com/AutomationExtensibility">
<HostApplication>
<Name>Microsoft Visual Studio Macros</Name>
<Version>8.0</Version>
</HostApplication>
<HostApplication>
<Name>Microsoft Visual Studio Macros</Name>
<Version>9.0</Version>
</HostApplication>
<HostApplication>
<Name>Microsoft Visual Studio</Name>
<Version>9.0</Version>
</HostApplication>
<HostApplication>
<Name>Microsoft Visual Studio</Name>
<Version>8.0</Version>
</HostApplication>
<Addin>
<FriendlyName>pInvoke.net Add-In</FriendlyName>
<Description>Red Gate pInvoke.net Visual Studio 2005 Add-In. Communicates with www.pinvoke.net</Description>
<Assembly>PInvokeDotNetAddIn2005.dll</Assembly>
<FullClassName>PInvokeDotNetAddIn.Connect</FullClassName>
<LoadBehavior>1</LoadBehavior>
<CommandPreload>1</CommandPreload>
<CommandLineSafe>0</CommandLineSafe>
</Addin>
</Extensibility>
حالا ویژوال رو بیارید بعد برید Tools->Options->Adiin and Macro Security
و آدرس مربوط به برنامه ی PInvoke.NET رو بهش اضافه کنید
حالا شما میتونید بدون دونستن unmanaged Coding از امکانات سیستمی (:دی) موبایل استفاده کنید
نمونه کدی که برای Restart گوشی با C# نوشتم :
کد:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace omnia
{
public partial class Form1 : Form
{
[DllImport("aygshell.dll", SetLastError = true)]
static extern bool ExitWindowsEx(uint S_R, uint reason);
public Form1()
{
InitializeComponent();
ExitWindowsEx(2, 0);
}
}
}
اگه يادتون باشه اين پست را در بخش گيمهاي ppc زده بوديننقل قول:
حالا با فرض من ميخوام يك گيم را كه رزوليشنش مثلا vga هست در يك گوشي ديگه كه مثلا wvga هست اجرا كنم
vga : 640*480
wvga : 800*480
من كه از اين برنامه نويسي و .. چيزي نميدونم
شما بگين چيكار ميشه كرد ؟
اگهخود گيم براتون نيازه براي مثال يك گيم كم حجم براتون بذارم تا تست كنيد
سلام این برنامه هر رزولوشنی را به wvga تبدیل میکنه + lanscape تنها کلید راست سخت افزاری را برای این کار بزنید،
دوستان omnia دار لطفا تست کنند و نتیجه را بگن تا مشکلات رفع کنم و با امکاناتی جدیدتر برنامه رو upload کنم
[ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
کد برنامه :کد:// aaa.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "aaa.h"
#include "winuserm.h"
extern "C" HRESULT DirectDrawCreate(LPGUID lpGUID,LPDIRECTDRAW *lplpDD,IUnknown *pUnkOuter){return DD_OK;}
#define MAX_LOADSTRING 100
LPDIRECTDRAW lp = NULL;
HRESULT hret;
// Global Variables:
HINSTANCE g_hInst; // current instance
HWND g_hWndMenuBar; // menu bar handle
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE, LPTSTR);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
// Perform application initialization:
if (!InitInstance(hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable;
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_AAA));
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_AAA));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}
//
// FUNCTION: InitInstance(HINSTANCE, 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;
TCHAR szTitle[MAX_LOADSTRING]; // title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // main window class name
g_hInst = hInstance; // Store instance handle in our global variable
// SHInitExtraControls should be called once during your application's initialization to initialize any
// of the device specific controls such as CAPEDIT and SIPPREF.
SHInitExtraControls();
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_AAA, szWindowClass, MAX_LOADSTRING);
//If it is already running, then focus on the window, and exit
hWnd = FindWindow(szWindowClass, szTitle);
if (hWnd)
{
// set focus to foremost child window
// The "| 0x00000001" is used to bring any owned windows to the foreground and
// activate them.
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
return 0;
}
if (!MyRegisterClass(hInstance, szWindowClass))
{
return FALSE;
}
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
if (g_hWndMenuBar)
{
RECT rc;
RECT rcMenuBar;
GetWindowRect(hWnd, &rc);
GetWindowRect(g_hWndMenuBar, &rcMenuBar);
rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// 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
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
DEVMODE dv;
static SHACTIVATEINFO s_sai;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_HELP_ABOUT:
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
break;
case IDM_OK:
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_CREATE:
SHMENUBARINFO mbi;
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hWnd;
mbi.nToolBarId = IDR_MENU;
mbi.hInstRes = g_hInst;
if (!SHCreateMenuBar(&mbi))
{
g_hWndMenuBar = NULL;
}
else
{
g_hWndMenuBar = mbi.hwndMB;
}
// Initialize the shell activate info structure
memset(&s_sai, 0, sizeof (s_sai));
s_sai.cbSize = sizeof (s_sai);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
CommandBar_Destroy(g_hWndMenuBar);
PostQuitMessage(0);
break;
case WM_ACTIVATE:
// Notify shell of our activate message
SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
break;
case WM_SETTINGCHANGE:
SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
break;
case WM_KEYDOWN:
switch(wParam)
{
case VK_RIGHT:
memset(&dv,0,sizeof(dv));
dv.dmSize = sizeof(dv);
EnumDisplaySettings(NULL,ENUM_REGISTRY_SETTINGS,&dv);
dv.dmFields = DM_PELSHEIGHT | DM_PELSWIDTH | DM_BITSPERPEL | DM_DISPLAYORIENTATION;
dv.dmDisplayOrientation = 1;dv.dmPelsHeight = 800;dv.dmPelsWidth = 480;
if(!(DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx(NULL,&dv,NULL,CDS_RESET,NULL)))
{
MessageBoxW(NULL,TEXT("af"),TEXT("zd"),0);
}
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
// Create a Done button and size it.
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
}
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
case WM_CLOSE:
EndDialog(hDlg, message);
return TRUE;
}
return (INT_PTR)FALSE;
}
رزرو شده-----------