winceapp_export.cpp
来自「This is a resource based on j2me embedde」· C++ 代码 · 共 1,422 行 · 第 1/3 页
CPP
1,422 行
/* * * * 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. *//* * This file implements the launching of the stand-along CDC-HI VM * on the WinCE platform. */#include <windows.h>#include <windowsx.h>#include <aygshell.h>#include <commctrl.h>#include <sipapi.h>#include <tpcshell.h>#if ENABLE_DIRECT_DRAW#include <ddraw.h>#endif#ifdef ENABLE_JSR_184#include <swvapi.h>#endif/** * The functions exported by gx.h use C++ linkage, hence this file * must be C++. */#define GXDLL_EXPORTS#include <gx.h>extern "C" {#include <kni.h>#include <midpError.h>#include <midp_logging.h>#include <winceapp_export.h>#include <gxj_putpixel.h>#include <midpMalloc.h>#include <midp_properties_port.h>#include <midp_constants_data.h>#include <keymap_input.h>#include <commonKNIMacros.h>#include <midpEventUtil.h>#include <midp_foreground_id.h>#include <midp_mastermode_port.h>#include <anc_indicators.h>#define KEYMAP_MD_KEY_HOME (KEYMAP_KEY_MACHINE_DEP)/* global variables defined in midp_msgQueue_md.c */extern int inMidpEventLoop;extern int lastWmSettingChangeTick;jboolean bVirtualModeEnabled = KNI_FALSE;gxj_screen_buffer gxj_system_screen_buffer;static HWND hwndToolbar = NULL;static HWND hwndMain = NULL;static HWND hwndTextActive = NULL;static HWND hwndTextField = NULL;static HWND hwndTextBox = NULL;static WNDPROC oldTextFieldProc;static WNDPROC oldTextBoxProc;static int editBoxShown = 0;static int editCHX, editCHY, editCHW, editCHH; /* in CHAM coordinates */static int titleHeight = JWC_WINCE_TITLE_HEIGHT;static RECT rcVisibleDesktop;static HANDLE eventThread;static HINSTANCE instanceMain;static jboolean reverse_orientation;static int lastKeyPressed = 0;static HANDLE eventWindowInit;/* IMPL_NOTE: the drawing code requires 16-bit per pixel mode *//* Bitmap and memory DC needed for GDI draw, if DD/GAPI draw fails, also for the rotated screen orientation */HBITMAP g_hBitmap = NULL;HDC g_hMemDC = NULL;struct ScreenAccess { int width; int height;#if ENABLE_DIRECT_DRAW LPDIRECTDRAW pDD; LPDIRECTDRAWSURFACE pDDSPrimary; LPDIRECTDRAWSURFACE pDDSMemory; // Normal paint memory surface LPDIRECTDRAWSURFACE pDDSDirect; // Buffer surface for winceapp_direct_flush() //LPDIRECTDRAWCLIPPER pDDClipper; #else int yPitch; gxj_pixel_type* pixels;#endif};static ScreenAccess g_screen;/* IMPL_NOTE: need a better way for quitting. */extern int _quit_now; /* defined in Scheduler.cpp */extern int midpPaintAllowed;extern int wince_init_fonts(); /* DirectDraw only. */DWORD lastUserInputTick = 0;static void processSkippedRefresh();static LRESULT processKey(HWND hwnd, UINT action, int key);static LRESULT processSystemKey(HWND hwnd, int key);static void updateEditorForRotation();/** * @file * Additional porting API for Java Widgets based port of abstract * command manager. */static LRESULT CALLBACKmyTextProc(HWND hwnd, WNDPROC oldproc, UINT msg, WPARAM wp, LPARAM lp, int isMultiLine) { int c = KEYMAP_KEY_INVALID; lastUserInputTick = GetTickCount(); switch (msg) { case WM_KEYDOWN: case WM_KEYUP: switch (wp) { case VK_UP: c = KEYMAP_KEY_UP; break; case VK_DOWN: c = KEYMAP_KEY_DOWN; break; case VK_LEFT: c = KEYMAP_KEY_LEFT; break; case VK_RIGHT: c = KEYMAP_KEY_RIGHT; break; default: break; } } if (c == KEYMAP_KEY_LEFT) { /* Don't send the key to MIDP unless we are at the first character */ WORD w = (WORD)SendMessage(hwnd, EM_GETSEL, 0, 0L); int caret = LOWORD(w); if (caret != 0) c = KEYMAP_KEY_INVALID; } else if (c == KEYMAP_KEY_RIGHT) { /* Don't send the key to MIDP unless we are at the last character */ WORD w = (WORD)SendMessage(hwnd, EM_GETSEL, 0, 0L); int strLen = GetWindowTextLength(hwnd); int caret = LOWORD(w); if (caret < strLen) c = KEYMAP_KEY_INVALID; } if (isMultiLine) { switch (c) { case KEYMAP_KEY_UP: case KEYMAP_KEY_DOWN: case KEYMAP_KEY_LEFT: case KEYMAP_KEY_RIGHT: /** * TODO: currenrly MIDP doesn't support Forms with multi-line * widgets, so we don't need to do anything special. * * In the future, if we need to traverse out from a multi-line * text box, we need to see if, e.g.: caret is at top line in the * editor and user presses UP. */ c = KEYMAP_KEY_INVALID; } } if (c != KEYMAP_KEY_INVALID) { pMidpEventResult->type = MIDP_KEY_EVENT; pMidpEventResult->CHR = c; pMidpEventResult->ACTION = (msg == WM_KEYDOWN) ? KEYMAP_STATE_PRESSED:KEYMAP_STATE_RELEASED; pSignalResult->waitingFor = UI_SIGNAL; pMidpEventResult->DISPLAY = gForegroundDisplayId; sendMidpKeyEvent(pMidpEventResult, sizeof(*pMidpEventResult)); return 0; } else return CallWindowProc(oldproc, hwnd, msg, wp, lp);}static LRESULT CALLBACKmyTextFieldProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { return myTextProc(hwnd, oldTextFieldProc, msg, wp, lp, 0);}static LRESULT CALLBACKmyTextBoxProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { return myTextProc(hwnd, oldTextBoxProc, msg, wp, lp, 1);}static void createEditors() { /* Create the Text controls for text input. They are not visible yet. */ DWORD dwStyle = WS_CHILD | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL; hwndTextField = CreateWindow(TEXT("edit"), TEXT(""), dwStyle, 0, 0, 40, 40, hwndMain, 0, GetModuleHandle(NULL), NULL); SendMessage(hwndTextField, EM_SETLIMITTEXT, 2048, 0); oldTextFieldProc = (WNDPROC)GetWindowLong(hwndTextField, GWL_WNDPROC); SetWindowLong(hwndTextField, GWL_WNDPROC, (LONG)&myTextFieldProc); dwStyle = WS_CHILD | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL | ES_MULTILINE; hwndTextBox = CreateWindow(TEXT("edit"), TEXT(""), dwStyle, 0, 40, 100, 100, hwndMain, 0, GetModuleHandle(NULL), NULL); SendMessage(hwndTextBox, EM_SETLIMITTEXT, 1024 * 10, 0); oldTextBoxProc = (WNDPROC)GetWindowLong(hwndTextBox, GWL_WNDPROC); SetWindowLong(hwndTextBox, GWL_WNDPROC, (LONG)&myTextBoxProc);}static void showToolbar(bool bShow) { ShowWindow(hwndToolbar, bShow ? SW_SHOWNORMAL : SW_HIDE); UpdateWindow(hwndToolbar);}static void updateDimensions() { SIPINFO sipinfo; RECT rc; memset(&sipinfo, 0, sizeof(sipinfo)); sipinfo.cbSize = sizeof(SIPINFO); SipGetInfo(&sipinfo); if (bVirtualModeEnabled) { memcpy(&rc, &sipinfo.rcVisibleDesktop, sizeof(rc)); if (sipinfo.fdwFlags & SIPF_ON) { rc.bottom = sipinfo.rcSipRect.top; } else { RECT rcToolbar; GetWindowRect(hwndToolbar, &rcToolbar); rc.bottom = rcToolbar.top; } } else { SHFullScreen(hwndMain, SHFS_HIDESIPBUTTON); GetWindowRect(hwndMain, &rc); rc.bottom = GetSystemMetrics(SM_CYSCREEN); } rcVisibleDesktop = rc; gxj_system_screen_buffer.width = rc.right - rc.left; gxj_system_screen_buffer.height = rc.bottom - rc.top; MoveWindow(hwndMain, rc.left, rc.top, gxj_system_screen_buffer.width, gxj_system_screen_buffer.height, TRUE); showToolbar(bVirtualModeEnabled);}static void initPutpixelSurface() { /* Get initial screen dimensions */ updateDimensions(); /* Use the dimension to initialize Putpixel surface */ int screenSize = sizeof(gxj_pixel_type) * GetSystemMetrics(SM_CXSCREEN) * GetSystemMetrics(SM_CYSCREEN); gxj_system_screen_buffer.alphaData = 0; gxj_system_screen_buffer.pixelData = (gxj_pixel_type *)midpMalloc(screenSize); memset(gxj_system_screen_buffer.pixelData, 0xff, screenSize);}static void releasePutpixelSurface() { midpFree(gxj_system_screen_buffer.pixelData);}static void deleteGDIObjects() { if (NULL != g_hMemDC) { DeleteDC(g_hMemDC); g_hMemDC = NULL; } if (NULL != g_hBitmap) { DeleteObject(g_hBitmap); g_hBitmap = NULL; }}#if ENABLE_DIRECT_DRAWstatic void releaseDirectDraw();static void initDirectDraw() { /* Note: if DirectDraw fails to initialize, we will use GDI */ if (DD_OK != DirectDrawCreate(NULL, &g_screen.pDD, NULL)) return; if (DD_OK != g_screen.pDD->SetCooperativeLevel(hwndMain, DDSCL_NORMAL)/* || DD_OK != g_screen.pDD->CreateClipper(0, &g_screen.pDDClipper, NULL)*/) { g_screen.pDD->Release(); g_screen.pDD = NULL; return; } // Create the primary surface with 0 back buffer DDSURFACEDESC ddsd; ZeroMemory(&ddsd, sizeof(DDSURFACEDESC)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; if (/*DD_OK != g_screen.pDDClipper->SetHWnd(0, hwndMain) ||*/ DD_OK != g_screen.pDD->CreateSurface(&ddsd, &g_screen.pDDSPrimary, NULL)) { //g_screen.pDDClipper->Release(); //g_screen.pDDClipper = NULL; g_screen.pDD->Release(); g_screen.pDD = NULL; return; } if (/*DD_OK != g_screen.pDDSPrimary->SetClipper(g_screen.pDDClipper) ||*/ DD_OK != g_screen.pDDSPrimary->GetSurfaceDesc(&ddsd)) { releaseDirectDraw(); return; } g_screen.width = ddsd.dwWidth; g_screen.height = ddsd.dwHeight; wince_init_fonts();}static void releaseDirectDraw() { if (NULL == g_screen.pDD) return; if (NULL != g_screen.pDDSDirect) { g_screen.pDDSDirect->Release(); g_screen.pDDSDirect = NULL; } if (NULL != g_screen.pDDSMemory) { g_screen.pDDSMemory->Release(); g_screen.pDDSMemory = NULL; } if (NULL != g_screen.pDDSPrimary) { //g_screen.pDDSPrimary->SetClipper(NULL); g_screen.pDDSPrimary->Release(); g_screen.pDDSPrimary = NULL; } /*if (NULL != g_screen.pDDClipper) { g_screen.pDDClipper->Release(); g_screen.pDDClipper = NULL; }*/ g_screen.pDD->Release(); g_screen.pDD = NULL;}/* * Flushing for direct_flush(); */static void doFlush(int height) { RECT srcRect, dstRect; srcRect.top = 0; srcRect.left = 0; srcRect.bottom = height; srcRect.right = winceapp_get_screen_width(); dstRect.top = rcVisibleDesktop.top; dstRect.left = 0; dstRect.bottom = height + rcVisibleDesktop.top; dstRect.right = winceapp_get_screen_width(); if (NULL != g_screen.pDDSDirect) g_screen.pDDSPrimary->Blt(&dstRect, g_screen.pDDSDirect, &srcRect, 0, NULL);}/** * Create memory based DD surface */static LPDIRECTDRAWSURFACE createMemorySurface(void* pVmem, int width, int height) { ASSERT(g_screen.pDD); ASSERT(pVmem); DDSURFACEDESC ddsd; LPDIRECTDRAWSURFACE pDDS = NULL; ZeroMemory(&ddsd, sizeof(DDSURFACEDESC)); ZeroMemory(&ddsd.ddpfPixelFormat, sizeof(DDPIXELFORMAT)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_LPSURFACE | DDSD_PITCH | DDSD_PIXELFORMAT | DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY; ddsd.dwWidth = width; ddsd.dwHeight = height; ddsd.lPitch = (LONG)sizeof(gxj_pixel_type) * width; ddsd.lpSurface = pVmem; // Set up the pixel format for 16-bit RGB (5-6-5). ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB; ddsd.ddpfPixelFormat.dwRGBBitCount = 16; ddsd.ddpfPixelFormat.dwRBitMask = 0x1f << 11; ddsd.ddpfPixelFormat.dwGBitMask = 0x3f << 5; ddsd.ddpfPixelFormat.dwBBitMask = 0x1f; if (DD_OK != g_screen.pDD->CreateSurface(&ddsd, &pDDS, NULL)) return NULL; else return pDDS;}#endif /* ENABLE_DIRECT_DRAW *//** * Initializes the WINCE native resources. */static PTCHAR _szAppName = TEXT(MAIN_WINDOW_CLASS_NAME);static PTCHAR _szTitle = TEXT(MAIN_WINDOW_CLASS_NAME);static HINSTANCE _hInstance;static BOOL InitApplication(HINSTANCE hInstance) { WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW ; wc.lpfnWndProc = (WNDPROC)winceapp_wndproc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hIcon = NULL; wc.hInstance = hInstance; wc.hCursor = NULL; wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = _szAppName; _hInstance = hInstance; return RegisterClass(&wc);}static void CreateMenuBar() { SHMENUBARINFO mbi; memset(&mbi, 0, sizeof(SHMENUBARINFO)); mbi.cbSize = sizeof(SHMENUBARINFO); mbi.hwndParent = hwndMain; mbi.dwFlags = SHCMBF_EMPTYBAR | SHCMBF_HIDDEN; mbi.hInstRes = _hInstance; if (SHCreateMenuBar(&mbi)) { hwndToolbar = mbi.hwndMB; }}static BOOL InitInstance(HINSTANCE hInstance, int CmdShow) { HWND _hwndMain = CreateWindowEx(WS_EX_CAPTIONOKBTN, _szAppName, _szTitle, WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (!_hwndMain) return FALSE;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?