⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 message.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 2 页
字号:
/* --------- message.c ---------- */

#include "dflat32/dflat.h"
#include "dflat32/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[MAXMESSAGES];

/* ---------- message queue --------- */
static struct msgs
{
	DFWINDOW wnd;
	DFMESSAGE msg;
	PARAM p1;
	PARAM p2;
} MsgQueue[MAXMESSAGES];

static int EventQueueOnCtr;
static int EventQueueOffCtr;
static int EventQueueCtr;

static int MsgQueueOnCtr;
static int MsgQueueOffCtr;
static int MsgQueueCtr;


DFWINDOW CaptureMouse;
DFWINDOW CaptureKeyboard;
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)
{
	ClearClipboard();
	ClearDialogBoxes();
	restorecursor();
	unhidecursor();
}

SHORT DfGetScreenHeight (void)
{
	return sScreenHeight;
}

SHORT DfGetScreenWidth (void)
{
	return sScreenWidth;
}

/* ------------ 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 */
	hInput = GetStdHandle (STD_INPUT_HANDLE);
	hOutput = GetStdHandle (STD_OUTPUT_HANDLE);

	/* get screen size */
	GetConsoleScreenBufferInfo (hOutput, &csbi);
	sScreenHeight = (csbi.srWindow.Bottom - csbi.srWindow.Top) + 1;
	sScreenWidth = (csbi.srWindow.Right - csbi.srWindow.Left) + 1;

	/* enable mouse events */
	SetConsoleMode (hInput, ENABLE_MOUSE_INPUT);

	savecursor();
	hidecursor();

	CaptureMouse = NULL;
	CaptureKeyboard = 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 != MAXMESSAGES)    {
        EventQueue[EventQueueOnCtr].event = event;
        EventQueue[EventQueueOnCtr].mx = p1;
        EventQueue[EventQueueOnCtr].my = p2;
        if (++EventQueueOnCtr == 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 hInput = GetStdHandle (STD_INPUT_HANDLE);
	INPUT_RECORD ir;
	DWORD dwRead;
	int c;

#ifdef TIMER_AVAILABLE
    /* -------- test for a clock event (one/second) ------- */
    if (timed_out(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 -------- */
        set_timer(clocktimer, 1);
        /* -------- post the clock event -------- */
        PostEvent(CLOCKTICK, (PARAM)timestr, 0);
    }
#endif

//	WaitForSingleObject (hInput, INFINITE);
	ReadConsoleInput (hInput, &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 |= ALTKEY;
		}
		if (ir.Event.KeyEvent.dwControlKeyState &
		    (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
		{
			sk |= CTRLKEY;
		}
		if (ir.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED)
		{
			sk |= LEFTSHIFT + RIGHTSHIFT;
		}

		if (sk != OldShiftKeys)
		{
			OldShiftKeys = sk;
			/* the shift status changed */
			PostEvent(SHIFT_CHANGED, sk, 0);
#if 0
			if (sk & ALTKEY)
				AltDown = TRUE;
			else
				AltDown = FALSE;
#endif
		}

		if (ir.Event.KeyEvent.uChar.AsciiChar == 0)
		{
			switch (ir.Event.KeyEvent.wVirtualKeyCode)
			{
				case VK_F1:
					c = F1;
					break;

				case VK_F4:
					if (sk & ALTKEY)
						c = ALT_F4;
					else if (sk & CTRLKEY)
						c = CTRL_F4;
					else
						c = F4;

				case VK_F10:
					c = F10;
					break;

				case VK_UP:
					c = UP;
					break;

				case VK_DOWN:
					c = DN;
					break;

				case VK_LEFT:
					c = BS;
					break;

				case VK_RIGHT:
					c = FWD;
					break;

				case VK_INSERT:
					c = INS;
					break;

				case VK_DELETE:
					c = DEL;
					break;

				case VK_HOME:
					c = HOME;
					break;

				case VK_END:
					c = END;
					break;

				case VK_PRIOR:
					c = PGUP;
					break;

				case VK_NEXT:
					c = 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 = SHIFT_HT;
			else
				c = ir.Event.KeyEvent.uChar.AsciiChar;
		}

		PostEvent (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 (LEFT_BUTTON,
				           ir.Event.MouseEvent.dwMousePosition.X,
				           ir.Event.MouseEvent.dwMousePosition.Y);
			}
			else if (ir.Event.MouseEvent.dwButtonState ==
			         RIGHTMOST_BUTTON_PRESSED)
			{
				PostEvent (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, PARAM p1, PARAM p2)
{
	if (msg == ENDDIALOG)
	{
		msg++;
		--msg;
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -