WinFb
Local.h
Vector<WString>& coreCmdLine__();
Vector<WString> SplitCmdLine__(const char *cmd);
void FBInit(HINSTANCE hInstance);
#define GUI_APP_MAIN \
void GuiMainFn_();\
\
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow) \
{ \
UPP::coreCmdLine__() = UPP::SplitCmdLine__(UPP::FromSystemCharset(lpCmdLine)); \
UPP::AppInitEnvironment__(); \
UPP::FBInit(hInstance); \
AppExecute__(GuiMainFn_); \
Ctrl::ExitFB(); \
return UPP::GetExitCode(); \
} \
\
void GuiMainFn_()
Keys.h
#ifndef _WinFb_Keys_h_
#define _WinFb_Keys_h_
K_BACK = VK_BACK + K_DELTA,
K_BACKSPACE = VK_BACK + K_DELTA,
K_TAB = 9,
K_SPACE = 32,
K_RETURN = 13,
K_ENTER = K_RETURN,
K_SHIFT_KEY = VK_SHIFT + K_DELTA,
K_CTRL_KEY = VK_CONTROL + K_DELTA,
K_ALT_KEY = VK_MENU + K_DELTA,
K_CAPSLOCK = VK_CAPITAL + K_DELTA,
K_ESCAPE = VK_ESCAPE + K_DELTA,
K_PRIOR = VK_PRIOR + K_DELTA,
K_PAGEUP = VK_PRIOR + K_DELTA,
K_NEXT = VK_NEXT + K_DELTA,
K_PAGEDOWN = VK_NEXT + K_DELTA,
K_END = VK_END + K_DELTA,
K_HOME = VK_HOME + K_DELTA,
K_LEFT = VK_LEFT + K_DELTA,
K_UP = VK_UP + K_DELTA,
K_RIGHT = VK_RIGHT + K_DELTA,
K_DOWN = VK_DOWN + K_DELTA,
K_INSERT = VK_INSERT + K_DELTA,
K_DELETE = VK_DELETE + K_DELTA,
K_NUMPAD0 = VK_NUMPAD0 + K_DELTA,
K_NUMPAD1 = VK_NUMPAD1 + K_DELTA,
K_NUMPAD2 = VK_NUMPAD2 + K_DELTA,
K_NUMPAD3 = VK_NUMPAD3 + K_DELTA,
K_NUMPAD4 = VK_NUMPAD4 + K_DELTA,
K_NUMPAD5 = VK_NUMPAD5 + K_DELTA,
K_NUMPAD6 = VK_NUMPAD6 + K_DELTA,
K_NUMPAD7 = VK_NUMPAD7 + K_DELTA,
K_NUMPAD8 = VK_NUMPAD8 + K_DELTA,
K_NUMPAD9 = VK_NUMPAD9 + K_DELTA,
K_MULTIPLY = VK_MULTIPLY + K_DELTA,
K_ADD = VK_ADD + K_DELTA,
K_SEPARATOR = VK_SEPARATOR + K_DELTA,
K_SUBTRACT = VK_SUBTRACT + K_DELTA,
K_DECIMAL = VK_DECIMAL + K_DELTA,
K_DIVIDE = VK_DIVIDE + K_DELTA,
K_SCROLL = VK_SCROLL + K_DELTA,
K_F1 = VK_F1 + K_DELTA,
K_F2 = VK_F2 + K_DELTA,
K_F3 = VK_F3 + K_DELTA,
K_F4 = VK_F4 + K_DELTA,
K_F5 = VK_F5 + K_DELTA,
K_F6 = VK_F6 + K_DELTA,
K_F7 = VK_F7 + K_DELTA,
K_F8 = VK_F8 + K_DELTA,
K_F9 = VK_F9 + K_DELTA,
K_F10 = VK_F10 + K_DELTA,
K_F11 = VK_F11 + K_DELTA,
K_F12 = VK_F12 + K_DELTA,
K_A = 'A' + K_DELTA,
K_B = 'B' + K_DELTA,
K_C = 'C' + K_DELTA,
K_D = 'D' + K_DELTA,
K_E = 'E' + K_DELTA,
K_F = 'F' + K_DELTA,
K_G = 'G' + K_DELTA,
K_H = 'H' + K_DELTA,
K_I = 'I' + K_DELTA,
K_J = 'J' + K_DELTA,
K_K = 'K' + K_DELTA,
K_L = 'L' + K_DELTA,
K_M = 'M' + K_DELTA,
K_N = 'N' + K_DELTA,
K_O = 'O' + K_DELTA,
K_P = 'P' + K_DELTA,
K_Q = 'Q' + K_DELTA,
K_R = 'R' + K_DELTA,
K_S = 'S' + K_DELTA,
K_T = 'T' + K_DELTA,
K_U = 'U' + K_DELTA,
K_V = 'V' + K_DELTA,
K_W = 'W' + K_DELTA,
K_X = 'X' + K_DELTA,
K_Y = 'Y' + K_DELTA,
K_Z = 'Z' + K_DELTA,
K_0 = '0' + K_DELTA,
K_1 = '1' + K_DELTA,
K_2 = '2' + K_DELTA,
K_3 = '3' + K_DELTA,
K_4 = '4' + K_DELTA,
K_5 = '5' + K_DELTA,
K_6 = '6' + K_DELTA,
K_7 = '7' + K_DELTA,
K_8 = '8' + K_DELTA,
K_9 = '9' + K_DELTA,
K_CTRL_LBRACKET = K_CTRL|219|K_DELTA,
K_CTRL_RBRACKET = K_CTRL|221|K_DELTA,
K_CTRL_MINUS = K_CTRL|0xbd|K_DELTA,
K_CTRL_GRAVE = K_CTRL|0xc0|K_DELTA,
K_CTRL_SLASH = K_CTRL|0xbf|K_DELTA,
K_CTRL_BACKSLASH = K_CTRL|0xdc|K_DELTA,
K_CTRL_COMMA = K_CTRL|0xbc|K_DELTA,
K_CTRL_PERIOD = K_CTRL|0xbe|K_DELTA,
K_CTRL_SEMICOLON = K_CTRL|0xbe|K_DELTA,
K_CTRL_EQUAL = K_CTRL|0xbb|K_DELTA,
K_CTRL_APOSTROPHE= K_CTRL|0xde|K_DELTA,
K_BREAK = VK_CANCEL + K_DELTA,
#endif
WinFb.h
#ifndef _WinFb_WinFb_h
#define _WinFb_WinFb_h
#include <CtrlCore/CtrlCore.h>
NAMESPACE_UPP
LRESULT CALLBACK fbWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void fbUpdate(HDC hdc, const Rect& r);
END_UPP_NAMESPACE
#endif
Proc.cpp
#include "WinFb.h"
#ifdef flagWINFB
NAMESPACE_UPP
#define LLOG(x) //DLOG(x)
bool GetShift() { return !!(GetKeyState(VK_SHIFT) & 0x8000); }
bool GetCtrl() { return !!(GetKeyState(VK_CONTROL) & 0x8000); }
bool GetAlt() { return !!(GetKeyState(VK_MENU) & 0x8000); }
bool GetCapsLock() { return !!(GetKeyState(VK_CAPITAL) & 1); }
bool GetMouseLeft() { return !!(GetKeyState(VK_LBUTTON) & 0x8000); }
bool GetMouseRight() { return !!(GetKeyState(VK_RBUTTON) & 0x8000); }
bool GetMouseMiddle() { return !!(GetKeyState(VK_MBUTTON) & 0x8000); }
dword fbKEYtoK(dword chr) {
if(chr == VK_TAB)
chr = K_TAB;
else
if(chr == VK_SPACE)
chr = K_SPACE;
else
if(chr == VK_RETURN)
chr = K_RETURN;
else
chr = chr + K_DELTA;
if(chr == K_ALT_KEY || chr == K_CTRL_KEY || chr == K_SHIFT_KEY)
return chr;
if(GetCtrl()) chr |= K_CTRL;
if(GetAlt()) chr |= K_ALT;
if(GetShift()) chr |= K_SHIFT;
return chr;
}
#ifdef _DEBUG
#define x_MSG(x) { x, #x },
Tuple2<int, const char *> sWinMsg[] = {
#include <CtrlCore/Win32Msg.i>
{0, NULL}
};
#endif
LRESULT CALLBACK fbWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
GuiLock __;
#ifdef _DEBUG
Tuple2<int, const char *> *x = FindTuple(sWinMsg, __countof(sWinMsg), message);
if(x)
LLOG(x->b << ", wParam: " << wParam << ", lParam: " << lParam);
#endif
// LLOG("Ctrl::WindowProc(" << message << ") in " << ::Name(this) << ", focus " << (void *)::GetFocus());
switch(message) {
case WM_PAINT:
ASSERT(hwnd);
if(hwnd) {
PAINTSTRUCT ps;
HDC dc = BeginPaint(hwnd, &ps);
fbUpdate(dc, ps.rcPaint);
#if 0
Rect r = ps.rcPaint;
::PatBlt(dc, r.left, r.top, r.GetWidth(), r.GetHeight(), DSTINVERT);
Sleep(40);
::PatBlt(dc, r.left, r.top, r.GetWidth(), r.GetHeight(), DSTINVERT);
#endif
EndPaint(hwnd, &ps);
}
return 0L;
case WM_LBUTTONDOWN:
Ctrl::DoMouseFB(Ctrl::LEFTDOWN, Point((dword)lParam));
return 0L;
case WM_LBUTTONUP:
Ctrl::DoMouseFB(Ctrl::LEFTUP, Point((dword)lParam));
return 0L;
case WM_LBUTTONDBLCLK:
Ctrl::DoMouseFB(Ctrl::LEFTDOUBLE, Point((dword)lParam));
return 0L;
case WM_RBUTTONDOWN:
Ctrl::DoMouseFB(Ctrl::RIGHTDOWN, Point((dword)lParam));
return 0L;
case WM_RBUTTONUP:
Ctrl::DoMouseFB(Ctrl::RIGHTUP, Point((dword)lParam));
return 0L;
case WM_RBUTTONDBLCLK:
Ctrl::DoMouseFB(Ctrl::RIGHTDOUBLE, Point((dword)lParam));
return 0L;
case WM_MBUTTONDOWN:
Ctrl::DoMouseFB(Ctrl::MIDDLEDOWN, Point((dword)lParam));
return 0L;
case WM_MBUTTONUP:
Ctrl::DoMouseFB(Ctrl::MIDDLEUP, Point((dword)lParam));
return 0L;
case WM_MBUTTONDBLCLK:
Ctrl::DoMouseFB(Ctrl::MIDDLEDOUBLE, Point((dword)lParam));
return 0L;
case WM_MOUSEMOVE:
Ctrl::DoMouseFB(Ctrl::MOUSEMOVE, Point((dword)lParam));
return 0L;
case 0x20a: // WM_MOUSEWHEEL:
{
Point p(0, 0);
::ClientToScreen(hwnd, p);
Ctrl::DoMouseFB(Ctrl::MOUSEWHEEL, Point((dword)lParam) - p, (short)HIWORD(wParam));
}
return 0L;
case WM_SETCURSOR:
if(LOWORD((dword)lParam) == HTCLIENT) {
SetCursor(NULL);
return TRUE;
}
break;
// case WM_MENUCHAR:
// return MAKELONG(0, MNC_SELECT);
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_CHAR:
// ignorekeyup = false;
case WM_KEYUP:
case WM_SYSKEYUP:
{
String msgdump;
switch(message)
{
case WM_KEYDOWN: msgdump << "WM_KEYDOWN"; break;
case WM_KEYUP: msgdump << "WM_KEYUP"; break;
case WM_SYSKEYDOWN: msgdump << "WM_SYSKEYDOWN"; break;
case WM_SYSKEYUP: msgdump << "WM_SYSKEYUP"; break;
case WM_CHAR: msgdump << "WM_CHAR"; break;
}
msgdump << " wParam = 0x" << FormatIntHex(wParam, 8)
<< ", lParam = 0x" << FormatIntHex(lParam, 8);
LLOG(msgdump);
dword keycode = 0;
if(message == WM_KEYDOWN) {
keycode = fbKEYtoK((dword)wParam);
if(keycode == K_SPACE)
keycode = 0;
}
else
if(message == WM_KEYUP)
keycode = fbKEYtoK((dword)wParam) | K_KEYUP;
else
if(message == WM_SYSKEYDOWN /*&& ((lParam & 0x20000000) || wParam == VK_F10)*/)
keycode = fbKEYtoK((dword)wParam);
else
if(message == WM_SYSKEYUP /*&& ((lParam & 0x20000000) || wParam == VK_F10)*/)
keycode = fbKEYtoK((dword)wParam) | K_KEYUP;
else
if(message == WM_CHAR && wParam != 127 && wParam > 32 || wParam == 32 && fbKEYtoK(VK_SPACE) == K_SPACE)
keycode = (dword)wParam;
bool b = false;
if(keycode)
b = Ctrl::DoKeyFB(keycode, LOWORD(lParam));
// LLOG("key processed = " << b);
// if(b || (message == WM_SYSKEYDOWN || message == WM_SYSKEYUP)
// && wParam != VK_F4 && !PassWindowsKey((dword)wParam)) // 17.11.2003 Mirek -> invoke system menu
// return 0L;
break;
}
break;
// case WM_GETDLGCODE:
// return wantfocus ? 0 : DLGC_STATIC;
case WM_ERASEBKGND:
return 1L;
case WM_SIZE:
Ctrl::SetFramebufferSize(Size(LOWORD(lParam), HIWORD(lParam)));
return 0L;
case WM_HELP:
return TRUE;
case WM_CLOSE:
Ctrl::EndSession();
return 0L;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
END_UPP_NAMESPACE
#endif
Win.cpp
#include "WinFb.h"
#ifdef flagWINFB
NAMESPACE_UPP
#define LLOG(x) //DLOG(x)
HWND fbHWND;
bool FBIsWaitingEvent()
{
MSG msg;
return PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
}
bool FBProcessEvent(bool *quit)
{
MSG msg;
if(PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
if(msg.message == WM_QUIT && quit)
*quit = true;
TranslateMessage(&msg);
DispatchMessageW(&msg);
return true;
}
return false;
}
void FBQuitSession()
{
::PostQuitMessage(0);
}
void FBSleep(int ms)
{
TimeStop tm;
MsgWaitForMultipleObjects(0, NULL, FALSE, ms, QS_ALLINPUT);
LLOG("@ FBSleep " << tm.Elapsed());
}
void FBInit(HINSTANCE hInstance)
{
GuiLock __;
Ctrl::InitFB();
WNDCLASSW wc;
Zero(wc);
wc.style = CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)fbWindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)NULL;
wc.lpszClassName = L"UPP-FB-CLASS";
RegisterClassW(&wc);
fbHWND = CreateWindowW(L"UPP-FB-CLASS", L"",
WS_OVERLAPPED|WS_VISIBLE|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
SetTimer(fbHWND, 1, 10, NULL);
// Csizeinit();
}
void fbUpdate(HDC hdc, const Rect& r_)
{
const ImageBuffer& framebuffer = Ctrl::GetFrameBuffer();
Size sz = framebuffer.GetSize();
Rect r = sz;
// Rect r = r_;
LLOG("fbUpdate " << r);
Buffer<byte> data;
data.Alloc(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256);
BITMAPINFOHEADER *hi = (BITMAPINFOHEADER *) ~data;;
memset(hi, 0, sizeof(BITMAPINFOHEADER));
hi->biSize = sizeof(BITMAPINFOHEADER);
hi->biPlanes = 1;
hi->biBitCount = 32;
hi->biCompression = BI_RGB;
hi->biSizeImage = 0;
hi->biClrUsed = 0;
hi->biClrImportant = 0;
hi->biWidth = sz.cx;
hi->biHeight = -sz.cy;
::SetDIBitsToDevice(hdc, r.left, r.top, r.GetWidth(), r.GetHeight(),
r.left, -r.top - r.GetHeight() + sz.cy, 0, sz.cy,
~framebuffer, (BITMAPINFO *)~data, DIB_RGB_COLORS);
}
void FBInitUpdate()
{
}
void FBUpdate(const Rect& r)
{
LLOG("FBUpdate " << r);
if(fbHWND) {
HDC hdc = GetDC(fbHWND);
fbUpdate(hdc, r);
#if 0
::PatBlt(hdc, r.left, r.top, r.GetWidth(), r.GetHeight(), DSTINVERT);
Sleep(40);
::PatBlt(hdc, r.left, r.top, r.GetWidth(), r.GetHeight(), DSTINVERT);
#endif
ReleaseDC(fbHWND, hdc);
}
// ::InvalidateRect(fbHWND, NULL, false);
}
void FBFlush()
{
::UpdateWindow(fbHWND);
GdiFlush();
}
END_UPP_NAMESPACE
#endif
|