[!if DLL_APP] // [!output PROJECT_NAME].cpp : Defines the entry point for the DLL application. [!endif] [!if WIN_APP] // [!output PROJECT_NAME].cpp : Defines the entry point for the application. [!endif] [!if CONSOLE_APP] // [!output PROJECT_NAME].cpp : Defines the entry point for the console application. [!endif] // #include "stdafx.h" [!if WIN_APP || SUPPORT_MFC] #include "[!output PROJECT_NAME].h" [!else] [!if DLL_APP && EXPORT_SYMBOLS] #include "[!output PROJECT_NAME].h" [!endif] [!endif] #include #include [!if WIN_APP] #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE g_hInst; // current instance [!if !MULTIPLE_PLATFORM] [!if !STANDARDSHELL_UI_MODEL] HWND g_hWndMenuBar; // menu bar handle [!else] HWND g_hWndCommandBar; // command bar handle [!endif] [!else] [!if !STANDARDSHELL_UI_MODEL] HWND g_hWndMenuBar; // menu bar handle [!else] #ifdef SHELL_AYGSHELL HWND g_hWndMenuBar; // menu bar handle #else // SHELL_AYGSHELL HWND g_hWndCommandBar; // command bar handle #endif // SHELL_AYGSHELL [!endif] [!endif] // Forward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE, LPTSTR); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); [!if !MULTIPLE_PLATFORM] [!if !SMARTPHONE2003_UI_MODEL] INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); [!endif] [!else] [!if SMARTPHONE2003_UI_MODEL] #ifndef WIN32_PLATFORM_WFSP [!endif] INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); [!if SMARTPHONE2003_UI_MODEL] #endif // !WIN32_PLATFORM_WFSP [!endif] [!endif] int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { MSG msg; // Perform application initialization: if (!InitInstance(hInstance, nCmdShow)) { return FALSE; } [!if !MULTIPLE_PLATFORM] [!if !SMARTPHONE2003_UI_MODEL] HACCEL hAccelTable; hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_[!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME])); [!endif] [!else] [!if SMARTPHONE2003_UI_MODEL] #ifndef WIN32_PLATFORM_WFSP [!endif] HACCEL hAccelTable; hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_[!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME])); [!if SMARTPHONE2003_UI_MODEL] #endif // !WIN32_PLATFORM_WFSP [!endif] [!endif] // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { [!if !MULTIPLE_PLATFORM] [!if !SMARTPHONE2003_UI_MODEL] if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) [!endif] [!else] [!if SMARTPHONE2003_UI_MODEL] #ifndef WIN32_PLATFORM_WFSP [!endif] if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) [!if SMARTPHONE2003_UI_MODEL] #endif // !WIN32_PLATFORM_WFSP [!endif] [!endif] { 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_[!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME])); 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 [!if !MULTIPLE_PLATFORM] [!if POCKETPC2003_UI_MODEL || SMARTPHONE2003_UI_MODEL] // SHInitExtraControls should be called once during your application's initialization to initialize any // of the device specific controls such as CAPEDIT and SIPPREF. SHInitExtraControls(); [!endif] [!else] [!if POCKETPC2003_UI_MODEL || SMARTPHONE2003_UI_MODEL] #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP) // SHInitExtraControls should be called once during your application's initialization to initialize any // of the device specific controls such as CAPEDIT and SIPPREF. SHInitExtraControls(); #endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP [!endif] [!endif] LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_[!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME], szWindowClass, MAX_LOADSTRING); [!if !MULTIPLE_PLATFORM] [!if POCKETPC2003_UI_MODEL || SMARTPHONE2003_UI_MODEL] //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; } [!endif] [!else] [!if POCKETPC2003_UI_MODEL || SMARTPHONE2003_UI_MODEL] #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP) //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; } #endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP [!endif] [!endif] 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; } [!if !MULTIPLE_PLATFORM] [!if POCKETPC2003_UI_MODEL] // 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); } [!endif] [!else] [!if POCKETPC2003_UI_MODEL] #ifdef WIN32_PLATFORM_PSPC // 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); } #endif // WIN32_PLATFORM_PSPC [!endif] [!endif] ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); [!if !MULTIPLE_PLATFORM] [!if STANDARDSHELL_UI_MODEL] if (g_hWndCommandBar) { CommandBar_Show(g_hWndCommandBar, TRUE); } [!endif] [!else] [!if STANDARDSHELL_UI_MODEL] #ifndef SHELL_AYGSHELL if (g_hWndCommandBar) { CommandBar_Show(g_hWndCommandBar, TRUE); } #endif // !SHELL_AYGSHELL [!endif] [!endif] 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; [!if !MULTIPLE_PLATFORM] [!if POCKETPC2003_UI_MODEL] static SHACTIVATEINFO s_sai; [!endif] [!else] [!if STANDARDSHELL_UI_MODEL || SMARTPHONE2003_UI_MODEL] #if defined(SHELL_AYGSHELL) && !defined(WIN32_PLATFORM_WFSP) static SHACTIVATEINFO s_sai; #endif // SHELL_AYGSHELL && !WIN32_PLATFORM_WFSP [!else] static SHACTIVATEINFO s_sai; [!endif] [!endif] switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { [!if !MULTIPLE_PLATFORM] [!if !SMARTPHONE2003_UI_MODEL] case IDM_HELP_ABOUT: DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About); break; [!endif] [!else] [!if SMARTPHONE2003_UI_MODEL] #ifndef WIN32_PLATFORM_WFSP [!endif] case IDM_HELP_ABOUT: DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About); break; [!if SMARTPHONE2003_UI_MODEL] #endif // !WIN32_PLATFORM_WFSP [!endif] [!endif] [!if !MULTIPLE_PLATFORM] [!if STANDARDSHELL_UI_MODEL] case IDM_FILE_EXIT: DestroyWindow(hWnd); break; [!else] [!if !SMARTPHONE2003_UI_MODEL] case IDM_OK: SendMessage (hWnd, WM_CLOSE, 0, 0); break; [!else] case IDM_OK: DestroyWindow(hWnd); break; [!endif] [!endif] [!else] [!if STANDARDSHELL_UI_MODEL] #ifndef SHELL_AYGSHELL case IDM_FILE_EXIT: DestroyWindow(hWnd); break; #endif // !SHELL_AYGSHELL [!endif] [!if SMARTPHONE2003_UI_MODEL] #ifdef WIN32_PLATFORM_WFSP case IDM_OK: DestroyWindow(hWnd); break; #endif // WIN32_PLATFORM_WFSP [!endif] [!if POCKETPC2003_UI_MODEL] #ifdef WIN32_PLATFORM_PSPC case IDM_OK: SendMessage (hWnd, WM_CLOSE, 0, 0); break; #endif // WIN32_PLATFORM_PSPC [!endif] [!endif] default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_CREATE: [!if !MULTIPLE_PLATFORM] [!if STANDARDSHELL_UI_MODEL] g_hWndCommandBar = CommandBar_Create(g_hInst, hWnd, 1); CommandBar_InsertMenubar(g_hWndCommandBar, g_hInst, IDR_MENU, 0); CommandBar_AddAdornments(g_hWndCommandBar, 0, 0); [!else] 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; } [!if !SMARTPHONE2003_UI_MODEL] // Initialize the shell activate info structure memset(&s_sai, 0, sizeof (s_sai)); s_sai.cbSize = sizeof (s_sai); [!endif] [!endif] [!else] [!if STANDARDSHELL_UI_MODEL] #ifndef SHELL_AYGSHELL g_hWndCommandBar = CommandBar_Create(g_hInst, hWnd, 1); CommandBar_InsertMenubar(g_hWndCommandBar, g_hInst, IDR_MENU, 0); CommandBar_AddAdornments(g_hWndCommandBar, 0, 0); #endif // !SHELL_AYGSHELL [!endif] [!if POCKETPC2003_UI_MODEL || SMARTPHONE2003_UI_MODEL] #ifdef SHELL_AYGSHELL 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; } [!if SMARTPHONE2003_UI_MODEL] #ifndef WIN32_PLATFORM_WFSP [!endif] // Initialize the shell activate info structure memset(&s_sai, 0, sizeof (s_sai)); s_sai.cbSize = sizeof (s_sai); [!if SMARTPHONE2003_UI_MODEL] #endif // !WIN32_PLATFORM_WFSP [!endif] #endif // SHELL_AYGSHELL [!endif] [!endif] break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: [!if !MULTIPLE_PLATFORM] [!if STANDARDSHELL_UI_MODEL] CommandBar_Destroy(g_hWndCommandBar); [!else] CommandBar_Destroy(g_hWndMenuBar); [!endif] [!else] [!if STANDARDSHELL_UI_MODEL] #ifndef SHELL_AYGSHELL CommandBar_Destroy(g_hWndCommandBar); #endif // !SHELL_AYGSHELL [!endif] [!if POCKETPC2003_UI_MODEL || SMARTPHONE2003_UI_MODEL] #ifdef SHELL_AYGSHELL CommandBar_Destroy(g_hWndMenuBar); #endif // SHELL_AYGSHELL [!endif] [!endif] PostQuitMessage(0); break; [!if !MULTIPLE_PLATFORM] [!if POCKETPC2003_UI_MODEL] 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; [!endif] [!else] [!if STANDARDSHELL_UI_MODEL || SMARTPHONE2003_UI_MODEL] #if defined(SHELL_AYGSHELL) && !defined(WIN32_PLATFORM_WFSP) 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; #endif // SHELL_AYGSHELL && !WIN32_PLATFORM_WFSP [!else] 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; [!endif] [!endif] default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } [!if !MULTIPLE_PLATFORM] [!if !SMARTPHONE2003_UI_MODEL] // Message handler for about box. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: [!if STANDARDSHELL_UI_MODEL] RECT rectChild, rectParent; int DlgWidth, DlgHeight; // dialog width and height in pixel units int NewPosX, NewPosY; // trying to center the About dialog if (GetWindowRect(hDlg, &rectChild)) { GetClientRect(GetParent(hDlg), &rectParent); DlgWidth = rectChild.right - rectChild.left; DlgHeight = rectChild.bottom - rectChild.top ; NewPosX = (rectParent.right - rectParent.left - DlgWidth) / 2; NewPosY = (rectParent.bottom - rectParent.top - DlgHeight) / 2; // if the About box is larger than the physical screen if (NewPosX < 0) NewPosX = 0; if (NewPosY < 0) NewPosY = 0; SetWindowPos(hDlg, 0, NewPosX, NewPosY, 0, 0, SWP_NOZORDER | SWP_NOSIZE); } [!else] { // 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); } [!endif] return (INT_PTR)TRUE; case WM_COMMAND: [!if STANDARDSHELL_UI_MODEL] if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL)) [!else] if (LOWORD(wParam) == IDOK) [!endif] { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; case WM_CLOSE: EndDialog(hDlg, message); return TRUE; [!if POCKETPC2003_UI_MODEL] [!if SUPPORT_MFC] #ifdef _DEVICE_RESOLUTION_AWARE case WM_SIZE: { if (AfxIsDRAEnabled()) { DRA::RelayoutDialog( g_hInst, hDlg, DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_ABOUTBOX_WIDE) : MAKEINTRESOURCE(IDD_ABOUTBOX)); } } break; #endif [!endif] [!endif] } return (INT_PTR)FALSE; } [!endif] [!else] [!if SMARTPHONE2003_UI_MODEL] #ifndef WIN32_PLATFORM_WFSP [!endif] // Message handler for about box. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: [!if STANDARDSHELL_UI_MODEL] #ifndef SHELL_AYGSHELL RECT rectChild, rectParent; int DlgWidth, DlgHeight; // dialog width and height in pixel units int NewPosX, NewPosY; // trying to center the About dialog if (GetWindowRect(hDlg, &rectChild)) { GetClientRect(GetParent(hDlg), &rectParent); DlgWidth = rectChild.right - rectChild.left; DlgHeight = rectChild.bottom - rectChild.top ; NewPosX = (rectParent.right - rectParent.left - DlgWidth) / 2; NewPosY = (rectParent.bottom - rectParent.top - DlgHeight) / 2; // if the About box is larger than the physical screen if (NewPosX < 0) NewPosX = 0; if (NewPosY < 0) NewPosY = 0; SetWindowPos(hDlg, 0, NewPosX, NewPosY, 0, 0, SWP_NOZORDER | SWP_NOSIZE); } #endif // !SHELL_AYGSHELL [!endif] [!if POCKETPC2003_UI_MODEL] #ifdef SHELL_AYGSHELL { // 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); } #endif // SHELL_AYGSHELL [!endif] return (INT_PTR)TRUE; case WM_COMMAND: [!if STANDARDSHELL_UI_MODEL] #ifndef SHELL_AYGSHELL if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL)) #endif // !SHELL_AYGSHELL [!endif] [!if POCKETPC2003_UI_MODEL] #ifdef SHELL_AYGSHELL if (LOWORD(wParam) == IDOK) #endif [!endif] { EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; } break; case WM_CLOSE: EndDialog(hDlg, message); return (INT_PTR)TRUE; [!if POCKETPC2003_UI_MODEL] [!if SUPPORT_MFC] #ifdef _DEVICE_RESOLUTION_AWARE case WM_SIZE: { if (AfxIsDRAEnabled()) { DRA::RelayoutDialog( g_hInst, hDlg, DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_ABOUTBOX_WIDE) : MAKEINTRESOURCE(IDD_ABOUTBOX)); } } break; #endif [!endif] [!endif] } return (INT_PTR)FALSE; } [!if SMARTPHONE2003_UI_MODEL] #endif // !WIN32_PLATFORM_WFSP [!endif] [!endif] [!endif] [!if SUPPORT_MFC] #ifdef _DEBUG #define new DEBUG_NEW #endif // The one and only application object CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: MFC initialization failed\n")); nRetCode = 1; } else { // TODO: code your application's behavior here. } return nRetCode; } [!else] [!if DLL_APP] BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { [!if EXPORT_SYMBOLS] switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } [!endif] return TRUE; } [!if EXPORT_SYMBOLS] // This is an example of an exported variable [!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME]_API int n[!output SAFE_PROJECT_IDENTIFIER_NAME]=0; // This is an example of an exported function. [!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME]_API int fn[!output SAFE_PROJECT_IDENTIFIER_NAME](void) { return 42; } // This is the constructor of a class that has been exported. // see [!output PROJECT_NAME].h for the class definition C[!output SAFE_PROJECT_IDENTIFIER_NAME]::C[!output SAFE_PROJECT_IDENTIFIER_NAME]() { return; } [!endif] [!endif] [!if CONSOLE_APP] int _tmain(int argc, _TCHAR* argv[]) { return 0; } [!endif] [!endif]