📄 nativegui.c
字号:
static intconvertKeyChar(WPARAM wParam, LPARAM lParam){ int shifted = GetKeyState(VK_SHIFT) < 0; switch (wParam) { case VK_F1: return KEY_SOFT1; case VK_F2: return KEY_SOFT2; case VK_F6: return VK_SUSPEND_ALL; case VK_F7: return VK_RESUME_ALL; case VK_F8: return VK_SUSPEND_CURRENT; case VK_F9: return VK_RESUME_PREVIOUS; case VK_MULTIPLY: suppressCode(lParam); return KEY_ASTERISK; case VK_DIVIDE: suppressCode(lParam); return KEY_POUND; case VK_ADD: case VK_SUBTRACT: case VK_DECIMAL: suppressCode(lParam); return KEY_INVALID; case VK_NUMPAD0: case VK_NUMPAD1: case VK_NUMPAD2: case VK_NUMPAD3: case VK_NUMPAD4: case VK_NUMPAD5: case VK_NUMPAD6: case VK_NUMPAD7: case VK_NUMPAD8: case VK_NUMPAD9: suppressCode(lParam); return '0' + (wParam - VK_NUMPAD0); /* depends on being contiguous */ case VK_UP: return KEY_UP; case VK_DOWN: return KEY_DOWN; case VK_LEFT: return KEY_LEFT; case VK_RIGHT: return KEY_RIGHT; case VK_RETURN: return KEY_SELECT; default: return KEY_INVALID; }}static LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { int x, y; PAINTSTRUCT ps; HDC hdc; LRESULT retval; HANDLE *mutex; static int penDown = KNI_FALSE; static XRectangle SCREEN_BOUNDS = { 0,0,0,0 }; static int delay_interval = 10; /* Delay 10 ms */ static int java_thread_schedule_tick = 42; if (SCREEN_BOUNDS.width == 0) { SCREEN_BOUNDS.x = x_offset; SCREEN_BOUNDS.y = y_offset; SCREEN_BOUNDS.width = PAINT_WIDTH; SCREEN_BOUNDS.height = paintHeight; } #ifdef INCLUDE_I18N if (isLocaleSupported() && FilterEvent(hwnd, iMsg, wParam, lParam, &kvmEvent, &gotEvent, &retval)) { return retval; }#endif switch (iMsg) { case WM_CREATE: hdc = GetDC(hwnd); CHECK_RETURN(SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT))); GetTextMetrics(hdc, &fixed_tm); CHECK_RETURN(SelectObject(hdc, GetStockObject(SYSTEM_FONT))); GetTextMetrics(hdc, &tm); ReleaseDC(hwnd, hdc); return 0; case WM_PAINT : hdc = BeginPaint(hwnd, &ps); mutex = (HANDLE*) TlsGetValue(tlsId); WaitForSingleObject(*mutex, INFINITE); DrawBitmap(hdc, hScreenBitmap, 0, 0, SRCCOPY); ReleaseMutex(*mutex); EndPaint(hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage (0); kvmEvent.type = systemKVMEvent; kvmEvent.chr = VK_SHUTDOWN; gotEvent = KNI_TRUE; return 0; case WM_APP: /* jsr135 eom event */ kvmEvent.type = mmEOMEvent; kvmEvent.chr = (int)lParam; kvmEvent.screenX = (short)(wParam & 0x7fff); /* playerID */ gotEvent = KNI_TRUE; break; case WM_CHAR: /* suppress ASCII control characters, except backspace */ if ((wParam < 32) && (wParam != 8)) { return 0; } /* also suppress characters from the numeric keypad */ if (isSuppressedCode(lParam)) { return 0; } kvmEvent.chr = wParam; kvmEvent.type = keyTypedKVMEvent; gotEvent = KNI_TRUE; return 0; case WM_KEYDOWN: case WM_KEYUP: { int key = convertKeyChar(wParam, lParam); if (key == KEY_INVALID) { return 0; } kvmEvent.chr = key; if (iMsg == WM_KEYUP) { kvmEvent.type = keyUpKVMEvent; } else if (lParam & 0x40000000) { kvmEvent.type = keyRepeatKVMEvent; } else { kvmEvent.type = keyDownKVMEvent; } if (wParam >= VK_F6 && wParam <= VK_F10) { kvmEvent.type = systemKVMEvent; } gotEvent = KNI_TRUE; if ((kvmEvent.chr == KEY_SOFT1) || (kvmEvent.chr == KEY_SOFT2)) { if (iMsg == WM_KEYDOWN) { gotEvent = LCDUIpopupMenuInternalEvent(kvmEvent.chr, &kvmEvent); if (gotEvent == KNI_FALSE) { gotEvent = LCDUImenuInternalEvent(kvmEvent.chr, &kvmEvent); } } else { gotEvent = KNI_FALSE; } } else if (iMsg != WM_KEYUP) { jboolean tmp; tmp = LCDUIpopupMenuInternalEvent(kvmEvent.chr, &kvmEvent); if (tmp == KNI_FALSE) { tmp = LCDUImenuInternalEvent(kvmEvent.chr, &kvmEvent); } if (tmp && (kvmEvent.type == invalidKVMEvent)) { gotEvent = KNI_FALSE; } } else if (kvmEvent.type == systemKVMEvent && iMsg != WM_KEYDOWN) { gotEvent = KNI_FALSE; } return 0; } case WM_SYSKEYDOWN: case WM_SYSKEYUP: { /*the only event of this type that we want MIDP to handle is the F10 key. if we receive any other event of this type, break.*/ if (wParam == VK_F10) { /* send a kvm event for key down on F10 */ if (iMsg == WM_SYSKEYDOWN) { kvmEvent.chr = VK_KILL_CURRENT; kvmEvent.type = systemKVMEvent; gotEvent = KNI_TRUE; } /* if we got a key up on F10 then return without sending a kvm event */ return 0; } } break; case WM_TIMER: KillTimer(hMainWindow, wParam); kvmEvent.type = timerKVMEvent; kvmEvent.chr = wParam; gotEvent = KNI_TRUE; return 0; case WM_MOUSEMOVE: if (! (wParam & MK_LBUTTON)) { return 0; } if (lastButton != NULL) { x = LOWORD(lParam); y = HIWORD(lParam); if (INSIDE(x, y, lastButton->bounds)) { /* we're still INSIDE--do nothing */ return 0; } else { /* Force a keyUp event on the old key */ kvmEvent.chr = lastButton->button; kvmEvent.type = keyUpKVMEvent; lastButton = NULL; gotEvent = KNI_TRUE; return 1; /* reprocesses this message */ } } /* FALL THROUGH */ case WM_LBUTTONDOWN: case WM_LBUTTONUP: { int i; /* Cast lParam to "short" to preserve sign */ x = (short)LOWORD(lParam); y = (short)HIWORD(lParam); if ((INSIDE(x, y, SCREEN_BOUNDS)) || (penDown == KNI_TRUE)) { /* The max possible values for the X & Y coordinates */ int maxX = x_offset + PAINT_WIDTH - 1; int maxY = y_offset + paintHeight - 1; gotEvent = KNI_TRUE; /* Check to see if we have moved the mouse outside of * the screen bounds while holding the mouse button. * If so, we still need to continue to send the mouse * events to the MIDlet, but, with at least one * coordinate "pegged" to the edge of the screen. */ kvmEvent.screenX = MIN(x, maxX) - x_offset; if (kvmEvent.screenX < 0) { kvmEvent.screenX = 0; } kvmEvent.screenY = MIN(y, maxY) - y_offset; if (kvmEvent.screenY < 0) { kvmEvent.screenY = 0; } switch (iMsg) { case WM_LBUTTONDOWN: penDown = KNI_TRUE; kvmEvent.type = penDownKVMEvent; SetCapture(hwnd); return 0; case WM_LBUTTONUP: if (!penDown) break; penDown = KNI_FALSE; kvmEvent.type = penUpKVMEvent; ReleaseCapture(); return 0; default: if (!penDown) break; kvmEvent.type = penMoveKVMEvent; return 0; } /* We received a button up or a drag event, but, we did not * receive the original button down. Ignore the event. */ gotEvent = KNI_FALSE; return 0; } else for (i = 0; i < NUMBEROF(Keys); ++i) { if (INSIDE(x, y, Keys[i].bounds)) { gotEvent = KNI_TRUE; lastButton = Keys + i;#ifdef SOUND_SUPPORTED if (iMsg == WM_LBUTTONDOWN) { MessageBeep(MB_OK); }#endif if (Keys[i].button == KEY_POWER) { kvmEvent.type = systemKVMEvent; kvmEvent.chr = VK_SHUTDOWN; return 0; } else if ( (Keys[i].button == KEY_SOFT1) || (Keys[i].button == KEY_SOFT2) ) { if (iMsg == WM_LBUTTONUP) { gotEvent = KNI_FALSE; } else { gotEvent = LCDUIpopupMenuInternalEvent(Keys[i].button, &kvmEvent); if (gotEvent == KNI_FALSE) { gotEvent = LCDUImenuInternalEvent(Keys[i].button, &kvmEvent); } } return 0; } else if (Keys[i].button == KEY_END) { if (iMsg == WM_LBUTTONDOWN) { LCDUIdismissMenu(); LCDUIdismissPopupMenu(); kvmEvent.type = systemKVMEvent; kvmEvent.chr = VK_KILL_CURRENT; gotEvent = KNI_TRUE; return 0; } else { break; } } else { jboolean tmp; kvmEvent.chr = (short)Keys[i].button; switch (iMsg) { case WM_LBUTTONDOWN: case WM_MOUSEMOVE: kvmEvent.type = keyDownKVMEvent; tmp = LCDUIpopupMenuInternalEvent ( Keys[i].button, &kvmEvent); if (tmp == KNI_FALSE) { tmp = LCDUImenuInternalEvent(Keys[i].button, &kvmEvent); } if (tmp && (kvmEvent.type == invalidKVMEvent)) { gotEvent = KNI_FALSE; } break; case WM_LBUTTONUP: lastButton = NULL; kvmEvent.type = keyUpKVMEvent; break; default: break; } } return 0; } } } return 0;#ifdef SKINS_MENU_SUPPORTED case WM_COMMAND: { int i = LOWORD(wParam); int len; FILE *f; char *buf = NULL; HDC hdc, hdcMem; HANDLE *mutex; HBITMAP tmp, img; BITMAPINFOHEADER *b; if ((i < 0) || (i >= numSkins) || ((f = fopen(skins[i], "r")) == NULL)) { b = phone_dib; } else { BITMAPFILEHEADER bh; char *p; fread(&bh, sizeof(bh), 1, f); len = bh.bfSize - sizeof(BITMAPFILEHEADER); p = buf = (unsigned char*)midpMalloc(len); if (p == NULL) { break; } while (len) { int n = fread(p, 1, len, f); if (n <= 0) break; p += n; len -= n; } fclose(f); b = (BITMAPINFOHEADER*) buf; } len = (b->biBitCount > 8) ? 0 : (b->biClrUsed ? b->biClrUsed : (1 << b->biBitCount)); hdc = GetDC(hwnd); hdcMem = CreateCompatibleDC(hdc); img = CreateDIBitmap(hdc, b, CBM_INIT, ((char *)b) + b->biSize + 4*len, (BITMAPINFO*)b, DIB_RGB_COLORS); ReleaseDC(hwn
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -