📄 message.c
字号:
/* --------- message.c ---------- */
#include "dflat.h"
#include "system.h"
static int handshaking = 0;
BOOL AllocTesting = FALSE;
jmp_buf AllocError;
BOOL AltDown = FALSE;
/* ---------- event queue ---------- */
static struct events
{
DFMESSAGE event;
int mx;
int my;
} EventQueue[DF_MAXMESSAGES];
/* ---------- message queue --------- */
static struct msgs
{
DFWINDOW wnd;
DFMESSAGE msg;
DF_PARAM p1;
DF_PARAM p2;
} MsgQueue[DF_MAXMESSAGES];
static int EventQueueOnCtr;
static int EventQueueOffCtr;
static int EventQueueCtr;
static int MsgQueueOnCtr;
static int MsgQueueOffCtr;
static int MsgQueueCtr;
DFWINDOW DfCaptureMouse;
DFWINDOW DfCaptureKeyboard;
static BOOL NoChildCaptureMouse;
static BOOL NoChildCaptureKeyboard;
//static int doubletimer = -1;
//static int delaytimer = -1;
static int clocktimer = -1;
static DFWINDOW Cwnd;
//static char ermsg[] = "Error accessing drive x";
static void StopMsg(void)
{
DfClearClipboard();
DfClearDialogBoxes();
DfRestoreCursor();
DfUnhideCursor();
}
SHORT DfGetScreenHeight (void)
{
return DfScreenHeight;
}
SHORT DfGetScreenWidth (void)
{
return DfScreenWidth;
}
/* ------------ initialize the message system --------- */
BOOL DfInitialize (VOID)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
AllocTesting = TRUE;
if (setjmp(AllocError) != 0)
{
StopMsg();
return FALSE;
}
/* get input and output handles */
DfInput = GetStdHandle (STD_INPUT_HANDLE);
DfOutput = GetStdHandle (STD_OUTPUT_HANDLE);
/* get screen size */
GetConsoleScreenBufferInfo (DfOutput, &csbi);
DfScreenHeight = (csbi.srWindow.Bottom - csbi.srWindow.Top) + 1;
DfScreenWidth = (csbi.srWindow.Right - csbi.srWindow.Left) + 1;
/* enable mouse events */
SetConsoleMode (DfInput, ENABLE_MOUSE_INPUT);
DfSaveCursor();
DfHideCursor();
DfCaptureMouse = NULL;
DfCaptureKeyboard = NULL;
NoChildCaptureMouse = FALSE;
NoChildCaptureKeyboard = FALSE;
MsgQueueOnCtr = 0;
MsgQueueOffCtr = 0;
MsgQueueCtr = 0;
EventQueueOnCtr = 0;
EventQueueOffCtr = 0;
EventQueueCtr = 0;
DfPostMessage (NULL, DFM_START, 0, 0);
return TRUE;
}
void DfTerminate (void)
{
}
/* ----- post an event and parameters to event queue ---- */
static void PostEvent(DFMESSAGE event, int p1, int p2)
{
if (EventQueueCtr != DF_MAXMESSAGES) {
EventQueue[EventQueueOnCtr].event = event;
EventQueue[EventQueueOnCtr].mx = p1;
EventQueue[EventQueueOnCtr].my = p2;
if (++EventQueueOnCtr == DF_MAXMESSAGES)
EventQueueOnCtr = 0;
EventQueueCtr++;
}
}
/* ------ collect mouse, clock, and keyboard events ----- */
static void collect_events(void)
{
static int OldShiftKeys = 0;
int sk = 0;
#ifdef TIMER_AVAILABLE
static BOOL flipflop = FALSE;
static char timestr[9];
struct tm *now;
int hr;
#endif
HANDLE DfInput = GetStdHandle (STD_INPUT_HANDLE);
INPUT_RECORD ir;
DWORD dwRead;
int c;
#ifdef TIMER_AVAILABLE
/* -------- test for a clock event (one/second) ------- */
if (DfTimedOut(clocktimer))
{
/* ----- get the current time ----- */
time_t t = time(NULL);
now = localtime(&t);
hr = now->tm_hour > 12 ?
now->tm_hour - 12 :
now->tm_hour;
if (hr == 0)
hr = 12;
sprintf(timestr, "%2d:%02d", hr, now->tm_min);
strcpy(timestr+5, now->tm_hour > 11 ? "pm " : "am ");
/* ------- blink the : at one-second intervals ----- */
if (flipflop)
*(timestr+2) = ' ';
flipflop ^= TRUE;
/* -------- reset the timer -------- */
DfSetTimer(clocktimer, 1);
/* -------- post the clock event -------- */
PostEvent(DFM_CLOCKTICK, (DF_PARAM)timestr, 0);
}
#endif
// WaitForSingleObject (DfInput, INFINITE);
ReadConsoleInput (DfInput, &ir, 1, &dwRead);
if ((ir.EventType == KEY_EVENT) &&
(ir.Event.KeyEvent.bKeyDown == TRUE))
{
/* handle key down events */
/* handle shift state changes */
if (ir.Event.KeyEvent.dwControlKeyState &
(LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
{
sk |= DF_ALTKEY;
}
if (ir.Event.KeyEvent.dwControlKeyState &
(LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
{
sk |= DF_CTRLKEY;
}
if (ir.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED)
{
sk |= DF_LEFTSHIFT + DF_RIGHTSHIFT;
}
if (sk != OldShiftKeys)
{
OldShiftKeys = sk;
/* the shift status changed */
PostEvent(DFM_SHIFT_CHANGED, sk, 0);
#if 0
if (sk & DF_ALTKEY)
AltDown = TRUE;
else
AltDown = FALSE;
#endif
}
if (ir.Event.KeyEvent.uChar.AsciiChar == 0)
{
switch (ir.Event.KeyEvent.wVirtualKeyCode)
{
case VK_F1:
c = DF_F1;
break;
case VK_F4:
if (sk & DF_ALTKEY)
c = DF_ALT_F4;
else if (sk & DF_CTRLKEY)
c = DF_CTRL_F4;
else
c = DF_F4;
case VK_F10:
c = DF_F10;
break;
case VK_UP:
c = DF_UP;
break;
case VK_DOWN:
c = DF_DN;
break;
case VK_LEFT:
c = DF_BS;
break;
case VK_RIGHT:
c = DF_FWD;
break;
case VK_INSERT:
c = DF_INS;
break;
case VK_DELETE:
c = DF_DEL;
break;
case VK_HOME:
c = DF_HOME;
break;
case VK_END:
c = DF_END;
break;
case VK_PRIOR:
c = DF_PGUP;
break;
case VK_NEXT:
c = DF_PGDN;
break;
default:
return;
}
}
else
{
/* special handling of SHIFT+TAB */
if (ir.Event.KeyEvent.uChar.AsciiChar == VK_TAB &&
(ir.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED))
c = DF_SHIFT_HT;
else
c = ir.Event.KeyEvent.uChar.AsciiChar;
}
PostEvent (DFM_KEYBOARD, c, sk);
}
else if (ir.EventType == MOUSE_EVENT)
{
/* handle mouse events */
if (ir.Event.MouseEvent.dwEventFlags == MOUSE_MOVED)
{
PostEvent (MOUSE_MOVED,
ir.Event.MouseEvent.dwMousePosition.X,
ir.Event.MouseEvent.dwMousePosition.Y);
}
else if (ir.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK)
{
if (ir.Event.MouseEvent.dwButtonState ==
FROM_LEFT_1ST_BUTTON_PRESSED)
{
PostEvent (DOUBLE_CLICK,
ir.Event.MouseEvent.dwMousePosition.X,
ir.Event.MouseEvent.dwMousePosition.Y);
}
}
else if (ir.Event.MouseEvent.dwEventFlags == 0)
{
/* single click */
if (ir.Event.MouseEvent.dwButtonState ==
FROM_LEFT_1ST_BUTTON_PRESSED)
{
PostEvent (DFM_LEFT_BUTTON,
ir.Event.MouseEvent.dwMousePosition.X,
ir.Event.MouseEvent.dwMousePosition.Y);
}
else if (ir.Event.MouseEvent.dwButtonState ==
RIGHTMOST_BUTTON_PRESSED)
{
PostEvent (DFM_RIGHT_BUTTON,
ir.Event.MouseEvent.dwMousePosition.X,
ir.Event.MouseEvent.dwMousePosition.Y);
}
else if (ir.Event.MouseEvent.dwButtonState == 0)
{
PostEvent (DFM_BUTTON_RELEASED,
ir.Event.MouseEvent.dwMousePosition.X,
ir.Event.MouseEvent.dwMousePosition.Y);
}
}
}
}
/* ----- post a message and parameters to msg queue ---- */
void DfPostMessage(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
{
if (msg == DFM_ENDDIALOG)
{
msg++;
--msg;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -