appmanager.cpp
来自「This is a resource based on j2me embedde」· C++ 代码 · 共 2,071 行 · 第 1/5 页
CPP
2,071 行
// Set image list for the permission tree view HWND hPermView = (HWND)GetWindowLongPtr(g_hPermissionsDlg, DWLP_USER); if (hPermView) { UINT uResourceIds[] = { IDI_PERMISSON_DENY, IDI_PERMISSON_ONESHOT, IDI_PERMISSON_SESSION, IDI_PERMISSON_ALLOW }; UINT uResourceNum = sizeof(uResourceIds) / sizeof(uResourceIds[0]); SetImageList(hPermView, uResourceIds, uResourceNum); } g_hInstallDlg = CreateInstallDialog(g_hMainWindow); CreateProgressDialog(g_hInstance, g_hMainWindow); // Show the main window ShowWindow(g_hMainWindow, nCmdShow); UpdateWindow(g_hMainWindow); // Main message loop MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } // Finalize MIDlet tree view CleanupTreeView(g_hMidletTreeView, g_DefTreeWndProc); // Finalize information view HWND hInfoView = (HWND)GetWindowLongPtr(g_hInfoDlg, DWLP_USER); if (hInfoView) { CleanupTreeView(hInfoView, g_DefTreeWndProc); } // Finalize permissions view if (hPermView) { CleanupTreeView(hPermView, g_DefTreeWndProc); } // Destroy all windows (destroy all child windows then the main window) DestroyWindow(g_hMainWindow); g_hMainWindow = NULL; // Free window resources (menus, background images, etc) CleanupWindows(); // Finalize Java AMS CleanupAms(); return (int) msg.wParam;}/** * Creates a toolbar. * * @param hWndParent handle to parent window of the toolbar * * @return handle of the created toolbar window if succeeded, NULL otherwise */static HWND CreateMainToolbar(HWND hWndParent) { RECT rcClient; // dimensions of client area // Get the dimensions of the parent window's client area, and create // the tree-view control. GetClientRect(hWndParent, &rcClient); TBBUTTON tbButtons[] = { 0, IDM_MIDLET_START_STOP, TBSTATE_ENABLED, BTNS_BUTTON, #if defined(_WIN32) | defined(_WIN64) {0},#endif 0L, 0, 1, IDM_INFO, TBSTATE_ENABLED, BTNS_BUTTON,#if defined(_WIN32) | defined(_WIN64) {0},#endif 0L, 0, 2, IDM_SUITE_INSTALL, TBSTATE_ENABLED, BTNS_BUTTON,#if defined(_WIN32) | defined(_WIN64) {0},#endif 0L, 0, 3, IDM_SUITE_REMOVE, TBSTATE_ENABLED, BTNS_BUTTON,#if defined(_WIN32) | defined(_WIN64) {0},#endif 0L, 0 }; HBITMAP hToolbarBmp = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_MAIN_TOOLBAR_BUTTONS)); if (hToolbarBmp == NULL) { wprintf(_T("ERROR: Can't load bitmap for the toolbar!")); return NULL; } HWND hWndToolbar = CreateToolbarEx(hWndParent, WS_CHILD | WS_BORDER | WS_VISIBLE | TBSTYLE_TOOLTIPS, IDC_MAIN_TOOLBAR, 4, // g_hInstance, IDB_MAIN_TOOLBAR_BUTTONS, NULL, (UINT)hToolbarBmp, tbButtons, 4, TB_BUTTON_WIDTH, TB_BUTTON_HEIGHT, TB_BUTTON_WIDTH, TB_BUTTON_HEIGHT, sizeof (TBBUTTON)); if (!hWndToolbar) { wprintf(_T("ERROR: Can't create a toolbar!")); return NULL; } return hWndToolbar;}/** * Creates the main window. * * @return handle to the created window if succeeded, NULL if failed */static HWND CreateMainView() { HWND hWnd; WNDCLASSEX wcex; // Customize main view class to assign own WndProc wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = MainWndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = g_hInstance; wcex.hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wcex.lpszMenuName = MAKEINTRESOURCE(ID_MENU_MAIN); wcex.lpszClassName = g_szWindowClass; wcex.hIconSm = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); if (!RegisterClassEx(&wcex)) { MessageBox(NULL, _T("Can't register main view class!"), g_szTitle, NULL); return NULL; } hWnd = CreateWindowEx( 0, g_szWindowClass, g_szTitle, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT, NULL, NULL, g_hInstance, NULL ); if (!hWnd) { MessageBox(NULL, _T("Create of main view failed!"), g_szTitle, NULL); return NULL; } return hWnd;}/** * Retrieves the default window procedure of the tree control. * * @return pointer to the default window procedure of the tree control */WNDPROC GetDefTreeWndProc() { return g_DefTreeWndProc;}/** * Initializes Java AMS subsystems. */static void InitAms() { javacall_result res = javanotify_ams_suite_storage_init(); if (res == JAVACALL_FAIL) { wprintf(_T("ERROR: Init of suite storage fail!\n")); }}/** * Finalizes Java AMS subsystems. */static void CleanupAms() { javacall_result res = javanotify_ams_suite_storage_cleanup(); if (res == JAVACALL_FAIL) { wprintf(_T("ERROR: Cleanup of suite storage fail!\n")); }}/** * Loads the background image and the menus. */static void InitWindows() { // Load backround image, just ignore if loading fails g_hMidletTreeBgBmp = (HBITMAP)LoadImage(g_hInstance, DEF_BACKGROUND_FILE, IMAGE_BITMAP, MAIN_WINDOW_CHILD_AREA_WIDTH, MAIN_WINDOW_CHILD_AREA_HEIGHT, LR_LOADFROMFILE); if (!g_hMidletTreeBgBmp) { DWORD res = GetLastError(); wprintf(_T("ERROR: LoadBitmap(IDB_MIDLET_TREE_BG) res: %d\n"), res); } // Load context menu shown for a MIDlet item in the tree view g_hMidletPopupMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(ID_MENU_POPUP_MIDLET)); if (!g_hMidletPopupMenu) { MessageBox(NULL, _T("Can't load MIDlet popup menu!"), g_szTitle, NULL); } // Load context menu shown for a suite item in the tree view g_hSuitePopupMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(ID_MENU_POPUP_SUITE)); if (!g_hSuitePopupMenu) { MessageBox(NULL, _T("Can't load suite popup menu!"), g_szTitle, NULL); } // Load context menu shown for a folder item in the tree view g_hFolderPopupMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(ID_MENU_POPUP_FOLDER)); if (!g_hFolderPopupMenu) { MessageBox(NULL, _T("Can't load folder popup menu!"), g_szTitle, NULL); }}/** * Frees the resources allocated for the menus. */static void CleanupWindows() { // Clean up resources allocated for MIDlet popup menu DestroyMenu(g_hMidletPopupMenu); g_hMidletPopupMenu = NULL; // Clean up resources allocated for suite popup menu DestroyMenu(g_hSuitePopupMenu); g_hSuitePopupMenu = NULL; // Clean up resources allocated for folder popup menu DestroyMenu(g_hFolderPopupMenu); g_hFolderPopupMenu = NULL; // Unregister main window class UnregisterClass(g_szWindowClass, g_hInstance);}/** * Frees resources allocated for tree nodes. * * @param hwndTV window handle to the tree view control * @param DefWndProc the original window procedure of the tree view control */static void CleanupTreeView(HWND hwndTV, WNDPROC DefWndProc) { // IMPL_NOTE: memory allocated by the application is freed in MainWndProc // by handling WM_NOTIFY message TreeView_DeleteAllItems(hwndTV); // Return back default window procedure for the tree view if (DefWndProc) { SetWindowLongPtr(hwndTV, GWLP_WNDPROC, (LONG_PTR)DefWndProc); }}/** * Frees resources allocated for tree nodes. * * @param hWndParent handle to the parent window of the tree view control * * @return handle to the new window if succeeded, NULL if failed */static HWND CreateMidletTreeView(HWND hWndParent) { RECT rcClient; // dimensions of client area HWND hwndTV; // handle to tree-view control // Get the dimensions of the parent window's client area, and create // the tree-view control. GetClientRect(hWndParent, &rcClient); wprintf(_T("Parent window area w=%d, h=%d\n"), rcClient.right, rcClient.bottom); hwndTV = CreateWindowEx(0, WC_TREEVIEW, g_szMidletTreeTitle, /*WS_VISIBLE |*/ WS_CHILD | WS_BORDER | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT, 0, TB_BUTTON_HEIGHT + 12, rcClient.right, rcClient.bottom - 12, hWndParent, (HMENU)IDC_TREEVIEW_MIDLETS, g_hInstance, NULL); if (!hwndTV) { MessageBox(hWndParent, _T("Create MIDlet tree view failed!"), g_szTitle, NULL); return NULL; } // Store default Tree View WndProc in global variable and set custom // WndProc. WNDPROC DefTreeWndProc = (WNDPROC)SetWindowLongPtr(hwndTV, GWLP_WNDPROC, (LONG_PTR)MidletTreeWndProc); if (!g_DefTreeWndProc) { g_DefTreeWndProc = DefTreeWndProc; } // Create an image list for the MIDlet tree view. UINT uResourceIds[] = { IDB_DEF_MIDLET_ICON, IDB_DEF_MIDLET_ICON_1, IDB_DEF_MIDLET_ICON_2, IDB_DEF_MIDLET_ICON_3, IDB_DEF_SUITE_ICON, IDB_FOLDER_ICON }; UINT uResourceNum = sizeof(uResourceIds) / sizeof(uResourceIds[0]); SetImageList(hwndTV, uResourceIds, uResourceNum); return hwndTV;}/** * Sets up an image list for the tree view control. * * @param hwndTV handle of the tree view control * @param uResourceIds identifiers of the resources with the images to be used * for the image list * @param uResourceNum number of entries in uResourceIds array */static void SetImageList(HWND hwndTV, UINT* uResourceIds, UINT uResourceNum) { HIMAGELIST hTreeImageList = ImageList_Create( TREE_VIEW_ICON_WIDTH, TREE_VIEW_ICON_HEIGHT, ILC_COLOR, uResourceNum, uResourceNum * 3); if (hTreeImageList == NULL) { wprintf(_T("ERROR: Can't create an image list for TreeView!")); } else { // adding icons into the image list for (int i = 0; i < uResourceNum; i++) { //HBITMAP hImg = LoadBitmap(g_hInstance, // MAKEINTRESOURCE(uResourceIds[i])); HICON hImg = LoadIcon(g_hInstance, MAKEINTRESOURCE(uResourceIds[i])); if (hImg == NULL) { wprintf(_T("ERROR: Can't load an image # %d!\n"), i); // not fatal, continue } else { //int res = ImageList_Add(hTreeImageList, hImg, NULL); int res = ImageList_AddIcon(hTreeImageList, hImg); if (res < 0) { wprintf(_T("ERROR: Failed to add an image # %d ") _T("to the tree view list!\n"), i); } DeleteObject(hImg); } } TreeView_SetImageList(hwndTV, hTreeImageList, TVSIL_NORMAL); }}/** * Shows or hides the tree view control holding all information about * the folders, midlet suites and midlets belonging to each suite. * * @param hWnd handle to the window to show instead of the tree view, * or to hide if the tree view is shown * @param fShow TRUE to show the tree view, FALSE - to hide it */static void ShowMidletTreeView(HWND hWnd, BOOL fShow) { if (fShow) { // Hide the window if (hWnd) { ShowWindow(hWnd, SW_HIDE); } // Show MIDlet tree view if (g_hMidletTreeView) { ShowWindow(g_hMidletTreeView, SW_SHOWNORMAL); } // Show tool bar if (g_hWndToolbar) { ShowWindow(g_hWndToolbar, SW_SHOWNORMAL); } } else { // Hide MIDlet tree view if (g_hMidletTreeView) { ShowWindow(g_hMidletTreeView, SW_HIDE); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?