appmanager.cpp
来自「This is a resource based on j2me embedde」· C++ 代码 · 共 2,071 行 · 第 1/5 页
CPP
2,071 行
/* * * * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */// MUST be disabled for WinCE#define USE_CONSOLE//#define _WIN32_WINNT 0x0500#include "appManager.h"#include "appManagerPermissions.h"#include "appManagerLCDUI.h"#include "appManagerProgress.h"#include "appManagerUtils.h"#include <stdlib.h>#include <string.h>#include <time.h>#include <javacall_memory.h>#include <javautil_unicode.h>#include <javacall_lcd.h>#include <javacall_ams_app_manager.h>#include <javacall_ams_installer.h>#include <javacall_keypress.h>#include <javacall_socket.h>#include <javacall_datagram.h>#ifdef USE_CONSOLE#include <io.h>#include <stdio.h>#include <fcntl.h>#endif/** Width of the main window calibrated to get the required child area */#define MAIN_WINDOW_WIDTH (MAIN_WINDOW_CHILD_AREA_WIDTH + 6)/** Height of the main window calibrated to get the required child area */#define MAIN_WINDOW_HEIGHT (MAIN_WINDOW_CHILD_AREA_HEIGHT + 45)#define WINDOW_SUBMENU_INDEX 2/** Width of a button on the toolbar */#define TB_BUTTON_WIDTH 16/** Height of a button on the toolbar */ #define TB_BUTTON_HEIGHT 16/** Width of icons used by the tree view */#define TREE_VIEW_ICON_WIDTH 16/** Height of icons used by the tree view */#define TREE_VIEW_ICON_HEIGHT 16/** Name of the file containing the background image. */#define DEF_BACKGROUND_FILE _T("background.bmp")/** Name of the file containing the splash screen image. */#define SPLASH_SCREEN_FILE _T("splash_screen_240x320.bmp")/** Time during which the splash scren is shown, in milliseconds */#define SPLASH_SCREEN_SHOW_TIME 2000/* This is needed by javacall MMS subsystem */extern "C" char* _phonenum = "1234567";/* * IMPL_NOTE: onyl needed to compile with WMA emulator. */extern "C" javacall_result try_process_wma_emulator(javacall_handle handle);/** The main window class name */static TCHAR g_szWindowClass[] = _T("NAMS");/** Title of the window with a list of MIDlets */static TCHAR g_szMidletTreeTitle[] = _T("Java MIDlets");/** Title of the information window */static TCHAR g_szInfoTitle[] = _T("Info");/** Default name of a folder */static TCHAR g_szDefaultFolderName[] = _T("Folder");/** Default name of a midlet suite */static TCHAR g_szDefaultSuiteName[] = _T("Midlet Suite");/** Handle to the current instance of the application */static HINSTANCE g_hInstance = NULL;/** Handle to the main application window */static HWND g_hMainWindow = NULL;/** Handle to the tree view control window */static HWND g_hMidletTreeView = NULL;/** Handle to the information window */static HWND g_hInfoDlg = NULL;/** Handle to the "Suite Settings" dialog window */static HWND g_hPermissionsDlg = NULL;/** Handle to the installation dialog window */static HWND g_hInstallDlg = NULL;/** Handle to the main toolbar window */static HWND g_hWndToolbar = NULL;/** * Handle to the popup menu associated with a tree item representing * a midlet. */static HMENU g_hMidletPopupMenu = NULL;/** * Handle to the popup menu associated with a tree item representing * a midlet suite. */static HMENU g_hSuitePopupMenu = NULL;/** * Handle to the popup menu associated with a tree item representing * a folder. */static HMENU g_hFolderPopupMenu = NULL;/** Handle to the default window procedure of the tree view control. */static WNDPROC g_DefTreeWndProc = NULL;/** Handle to the background bitmap. */static HBITMAP g_hMidletTreeBgBmp = NULL;/** Handle to the splash screen bitmap. */static HBITMAP g_hSplashScreenBmp = NULL;/** Copied suite, to be pasted into a new folder */static HTREEITEM g_htiCopiedSuite = NULL;/** Turns on/off MIDlet output to the main window */static BOOL g_fDrawBuffer = FALSE;/** Next free ID of a running application (MIDlet) */static javacall_app_id g_jAppId = 1;/** ID of the running installer */static javacall_app_id g_jInstallerId = JAVACALL_INVALID_APP_ID;/* * IMPL_NOTE: all hPrev* fields should be saved into a structure, and then it * should be passed as a parameter to AddSuiteToTree */HTREEITEM hPrev = (HTREEITEM)TVI_FIRST; HTREEITEM hPrevLev1Item = NULL; HTREEITEM hPrevLev2Item = NULL;// Forward declarations of functions included in this code module:LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK MidletTreeWndProc(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK InfoWndProc(HWND, UINT, WPARAM, LPARAM);INT_PTR CALLBACK TreeDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);INT_PTR CALLBACK InstallDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) ;static void DrawBuffer(HDC hdc);static HWND CreateMainView();static void CenterWindow(HWND hDlg);static HWND CreateMidletTreeView(HWND hWndParent);static HWND CreateMainToolbar(HWND hWndParent);static HWND CreateTreeDialog(HWND hWndParent, WORD wDialogIDD, WORD wViewIDC, WNDPROC ViewWndProc);static HWND CreateInstallDialog(HWND hWndParent);static BOOL InitMidletTreeViewItems(HWND hwndTV);static void AddSuiteToTree(HWND hwndTV, javacall_suite_id suiteId, int nLevel);static void SetImageList(HWND hwndTV, UINT* uResourceIds, UINT uResourceNum);static void CleanupTreeView(HWND hwndTV, WNDPROC DefWndProc);static void InitAms();static void CleanupAms();static void InitWindows();static void CleanupWindows();static void AddWindowMenuItem(javacall_const_utf16_string jsStr, TVI_INFO* pItemData);static TVI_INFO* RemoveWindowMenuItem(javacall_app_id appId);static void CheckWindowMenuItem(int index, BOOL fChecked);static void SetCheckedWindowMenuItem(TVI_INFO* pItemData);static TVI_INFO* GetWindowMenuItemData(UINT commandId);static void EnablePopupMenuItem(HMENU hSubMenu, UINT uIDM, BOOL fEnabled);static int mapKey(WPARAM wParam, LPARAM lParam);static LPTSTR JavacallUtf16ToTstr(javacall_const_utf16_string str);static javacall_utf16_string CloneJavacallUtf16(javacall_const_utf16_string str);static void ShowMidletTreeView(HWND hWnd, BOOL fShow);static BOOL AddComboboxItem(HWND hcbWnd, LPCTSTR pcszLabel, javacall_folder_id jFolderId);static int HandleNetworkStreamEvents(WPARAM wParam, LPARAM lParam);static int HandleNetworkDatagramEvents(WPARAM wParam, LPARAM lParam);static BOOL ProcessExists(LPCTSTR szName);/** * Retrieves a handle to the main application window. * Used by Javacall library for sending messages. * * @return handle to the main application window */extern "C" HWND midpGetWindowHandle() { return g_hMainWindow;}/** * Needed by javacall / annuciator.c * * @param screenWidth not used * @param screenHeight not used * * @return always NULL */extern "C" javacall_pixel*getTopbarBuffer(int* screenWidth, int* screenHeight) { (void)screenWidth; (void)screenHeight; return NULL;}//------------------------------------------------------------------------------/** * Shows a splash screen. */static void ShowSplashScreen() { g_hSplashScreenBmp = (HBITMAP)LoadImage(g_hInstance, SPLASH_SCREEN_FILE, IMAGE_BITMAP, MAIN_WINDOW_CHILD_AREA_WIDTH, MAIN_WINDOW_CHILD_AREA_HEIGHT, LR_LOADFROMFILE); if (g_hSplashScreenBmp != NULL) { SetTimer(g_hMainWindow, 1, SPLASH_SCREEN_SHOW_TIME, NULL); }}/** * Entry point of the Javacall executable. * * @param argc number of arguments (1 means no arguments) * @param argv the arguments, argv[0] is the executable's name * * @return the exit value (1 if OK) */extern "C" javacall_result JavaTaskImpl(int argc, char* argv[]) { javacall_result res = javanotify_ams_system_start(); wprintf(_T("SJWC exited, code: %d\n"), (int)res); return res;}/** * Thread function where Java runs. * * @lParam not used * * @return always 0 */DWORD WINAPI javaThread(LPVOID lpParam) { JavaTaskImpl(0, NULL); return 0; } /** * Checks if another copy of the Application Manager is already running. * * @param cszName name of this Application Manager * * @return TRUE if a running copy of the Application Manager already exists, * FALSE otherwise */BOOL ProcessExists(LPCTSTR cszName) { HANDLE hMutex = CreateMutex(NULL, TRUE, cszName); if (GetLastError() == ERROR_ALREADY_EXISTS) { CloseHandle(hMutex); return TRUE; } return FALSE;}#if 1/** * Program entry point. * * @param hInstance [in] handle to the current instance of the application * @param hPrevInstance [in] handle to the previous instance of the application * @param lpCmdLine [in] pointer to a null-terminated string that specifies * the command line for the application, excluding the * program name * @param nShowCmd [in] specifies how the window is to be shown * * @return the exit value contained in that message?s wParam parameter indicates * success, and that the function terminates when it receives a WM_QUIT * message. Zero indicates that the function terminates before entering * the message loop. */int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { (void)lpCmdLine;#ifdef USE_CONSOLE AllocConsole(); HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); intptr_t hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT); *stdout = *_fdopen(hConHandle, "w"); h = GetStdHandle(STD_ERROR_HANDLE); hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT); *stderr = *_fdopen(hConHandle, "w");#endif#elseint main(int argc, char* argv[]) { HINSTANCE hInstance = NULL; int nCmdShow = SW_SHOWNORMAL;#endif // Check whether an instance of the application is running at the moment if (ProcessExists(g_szTitle)) { TCHAR szBuf[127]; wsprintf(szBuf, _T("%s is already running!"), g_szTitle); MessageBox(NULL, szBuf, g_szTitle, MB_OK | MB_ICONERROR); return -1; } // Initialize random number generator srand((unsigned)time(NULL)); // Store instance handle in our global variable g_hInstance = hInstance; // Ensure that the common control DLL is loaded InitCommonControls(); // Load window resources (menus, background images, etc) InitWindows(); g_hMainWindow = CreateMainView(); if (!g_hMainWindow) { return -1; } ShowSplashScreen(); // Start JVM in a separate thread DWORD dwThreadId; HANDLE hThread = CreateThread( NULL, // default security attributes 0, // use default stack size javaThread, // thread function NULL, // argument to thread function 0, // use default creation flags &dwThreadId); // returns the thread identifier if (!hThread) { MessageBox(g_hMainWindow, _T("Can't start Java Thread!"), g_szTitle, NULL); return 1; } // Let native peer to start // IMPL_NOTE: need to wait for notification from the peer instead of sleep Sleep(1000); // Initialize Java AMS InitAms(); g_hWndToolbar = CreateMainToolbar(g_hMainWindow); // Create and init Java MIDlets tree view g_hMidletTreeView = CreateMidletTreeView(g_hMainWindow); if (!g_hMidletTreeView) { return -1; } InitMidletTreeViewItems(g_hMidletTreeView); // Create information dialog g_hInfoDlg = CreateTreeDialog(g_hMainWindow, IDD_INFO, IDC_TREEVIEW, InfoWndProc); // Create permissions dialog g_hPermissionsDlg = CreateTreeDialog(g_hMainWindow, IDD_PERMISSIONS, IDC_TREEVIEW, PermissionWndProc);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?