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

📄 message.c

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

	if (MsgQueueCtr != DF_MAXMESSAGES)
	{
		MsgQueue[MsgQueueOnCtr].wnd = wnd;
		MsgQueue[MsgQueueOnCtr].msg = msg;
		MsgQueue[MsgQueueOnCtr].p1 = p1;
		MsgQueue[MsgQueueOnCtr].p2 = p2;
		if (++MsgQueueOnCtr == DF_MAXMESSAGES)
			MsgQueueOnCtr = 0;
		MsgQueueCtr++;
	}
}

/* --------- send a message to a window ----------- */
int DfSendMessage(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
{
    int rtn = TRUE, x, y;

#ifdef INCLUDE_LOGGING
	DfLogMessages(wnd, msg, p1, p2);
#endif
    if (wnd != NULL)
        switch (msg)    {
            case DFM_PAINT:
            case DFM_BORDER:
                /* ------- don't send these messages unless the
                    window is visible -------- */
                if (DfIsVisible(wnd))
	                rtn = (*wnd->wndproc)(wnd, msg, p1, p2);
                break;
            case DFM_RIGHT_BUTTON:
            case DFM_LEFT_BUTTON:
            case DOUBLE_CLICK:
            case DFM_BUTTON_RELEASED:
                /* --- don't send these messages unless the
                    window is visible or has captured the mouse -- */
                if (DfIsVisible(wnd) || wnd == DfCaptureMouse)
	                rtn = (*wnd->wndproc)(wnd, msg, p1, p2);
                break;
            case DFM_KEYBOARD:
            case DFM_SHIFT_CHANGED:
                /* ------- don't send these messages unless the
                    window is visible or has captured the keyboard -- */
                if (!(DfIsVisible(wnd) || wnd == DfCaptureKeyboard))
	                break;
            default:
                rtn = (*wnd->wndproc)(wnd, msg, p1, p2);
                break;
        }
    /* ----- window processor returned true or the message was sent
        to no window at all (NULL) ----- */
    if (rtn != FALSE)    {
        /* --------- process messages that a window sends to the
            system itself ---------- */
        switch (msg)    {
            case DFM_STOP:
				StopMsg();
                break;
            /* ------- clock messages --------- */
            case DFM_CAPTURE_CLOCK:
                Cwnd = wnd;
                DfSetTimer(clocktimer, 0);
                break;
            case DFM_RELEASE_CLOCK:
                Cwnd = NULL;
                DfDisableTimer(clocktimer);
                break;
            /* -------- keyboard messages ------- */
            case DFM_KEYBOARD_CURSOR:
                if (wnd == NULL)
                    DfCursor((int)p1, (int)p2);
                else if (wnd == DfInFocus)
                    DfCursor(DfGetClientLeft(wnd)+(int)p1,
                                DfGetClientTop(wnd)+(int)p2);
                break;
            case DFM_CAPTURE_KEYBOARD:
                if (p2)
                    ((DFWINDOW)p2)->PrevKeyboard=DfCaptureKeyboard;
                else
                    wnd->PrevKeyboard = DfCaptureKeyboard;
                DfCaptureKeyboard = wnd;
                NoChildCaptureKeyboard = (int)p1;
                break;
			case DFM_RELEASE_KEYBOARD:
				if (wnd != NULL)
				{
					if (DfCaptureKeyboard == wnd || (int)p1)
						DfCaptureKeyboard = wnd->PrevKeyboard;
					else
					{
						DFWINDOW twnd = DfCaptureKeyboard;
						while (twnd != NULL)
						{
							if (twnd->PrevKeyboard == wnd)
							{
								twnd->PrevKeyboard = wnd->PrevKeyboard;
								break;
							}
							twnd = twnd->PrevKeyboard;
						}
						if (twnd == NULL)
							DfCaptureKeyboard = NULL;
					}
					wnd->PrevKeyboard = NULL;
				}
				else
					DfCaptureKeyboard = NULL;
				NoChildCaptureKeyboard = FALSE;
				break;
            case DFM_CURRENT_KEYBOARD_CURSOR:
                DfCurrCursor(&x, &y);
                *(int*)p1 = x;
                *(int*)p2 = y;
                break;
            case DFM_SAVE_CURSOR:
                DfSaveCursor();
                break;
            case DFM_RESTORE_CURSOR:
                DfRestoreCursor();
                break;
            case DFM_HIDE_CURSOR:
                DfNormalCursor();
                DfHideCursor();
                break;
            case DFM_SHOW_CURSOR:
                if (p1)
                    DfSetCursorSize(100);
                else
                    DfSetCursorSize(5);
                DfUnhideCursor();
                break;

			case DFM_CAPTURE_MOUSE:
				if (p2)
					((DFWINDOW)p2)->PrevMouse = DfCaptureMouse;
				else
					wnd->PrevMouse = DfCaptureMouse;
				DfCaptureMouse = wnd;
				NoChildCaptureMouse = (int)p1;
				break;

			case DFM_RELEASE_MOUSE:
				if (wnd != NULL)
				{
					if (DfCaptureMouse == wnd || (int)p1)
						DfCaptureMouse = wnd->PrevMouse;
					else
					{
						DFWINDOW twnd = DfCaptureMouse;
						while (twnd != NULL)
						{
							if (twnd->PrevMouse == wnd)
							{
								twnd->PrevMouse = wnd->PrevMouse;
								break;
							}
							twnd = twnd->PrevMouse;
						}
						if (twnd == NULL)
							DfCaptureMouse = NULL;
					}
					wnd->PrevMouse = NULL;
				}
				else
					DfCaptureMouse = NULL;
				NoChildCaptureMouse = FALSE;
				break;

			default:
				break;
		}
	}
	return rtn;
}

static DFRECT VisibleRect(DFWINDOW wnd)
{
	DFRECT rc = DfWindowRect(wnd);
	if (!DfTestAttribute(wnd, DF_NOCLIP))
	{
		DFWINDOW pwnd = DfGetParent(wnd);
		DFRECT prc;
		prc = DfClientRect(pwnd);
		while (pwnd != NULL)
		{
			if (DfTestAttribute(pwnd, DF_NOCLIP))
				break;
			rc = DfSubRectangle(rc, prc);
			if (!DfValidRect(rc))
				break;
			if ((pwnd = DfGetParent(pwnd)) != NULL)
				prc = DfClientRect(pwnd);
		}
	}
	return rc;
}

/* ----- find window that mouse coordinates are in --- */
static DFWINDOW inWindow(DFWINDOW wnd, int x, int y)
{
	DFWINDOW Hit = NULL;
	while (wnd != NULL)	{
		if (DfIsVisible(wnd))	{
			DFWINDOW wnd1;
			DFRECT rc = VisibleRect(wnd);
			if (DfInsideRect(x, y, rc))
				Hit = wnd;
			if ((wnd1 = inWindow(DfLastWindow(wnd), x, y)) != NULL)
				Hit = wnd1;
			if (Hit != NULL)
				break;
		}
		wnd = DfPrevWindow(wnd);
	}
	return Hit;
}

static DFWINDOW MouseWindow(int x, int y)
{
	/* get the window in which a mouse event occurred */
	DFWINDOW Mwnd = inWindow(DfApplicationWindow, x, y);

	/* ---- process mouse captures ----- */
	if (DfCaptureMouse != NULL)
	{
		if (NoChildCaptureMouse ||
		    Mwnd == NULL 	||
		    !DfIsAncestor(Mwnd, DfCaptureMouse))
			Mwnd = DfCaptureMouse;
	}
	return Mwnd;
}


void DfHandshake(void)
{
	handshaking++;
	DfDispatchMessage ();
	--handshaking;
}


/* ---- dispatch messages to the message proc function ---- */
BOOL DfDispatchMessage (void)
{
	DFWINDOW Mwnd, Kwnd;

	/* -------- collect mouse and keyboard events ------- */
	collect_events();

	/* --------- dequeue and process events -------- */
	while (EventQueueCtr > 0)
	{
		struct events ev;

		ev = EventQueue[EventQueueOffCtr];
		if (++EventQueueOffCtr == DF_MAXMESSAGES)
			EventQueueOffCtr = 0;
		--EventQueueCtr;

		/* get the window in which a keyboard event occurred */
		Kwnd = DfInFocus;

		/* process keyboard captures */
		if (DfCaptureKeyboard != NULL)
		{
			if (Kwnd == NULL ||
			    NoChildCaptureKeyboard ||
			    !DfIsAncestor(Kwnd, DfCaptureKeyboard))
				Kwnd = DfCaptureKeyboard;
		}

		/* send mouse and keyboard messages to the
		   window that should get them */
		switch (ev.event)
		{
			case DFM_SHIFT_CHANGED:
			case DFM_KEYBOARD:
				if (!handshaking)
					DfSendMessage(Kwnd, ev.event, ev.mx, ev.my);
				break;

			case DFM_LEFT_BUTTON:
				if (!handshaking)
				{
					Mwnd = MouseWindow(ev.mx, ev.my);
					if (!DfCaptureMouse ||
					    (!NoChildCaptureMouse &&
					     DfIsAncestor(Mwnd, DfCaptureMouse)))
					{
						if (Mwnd != DfInFocus)
							DfSendMessage(Mwnd, DFM_SETFOCUS, TRUE, 0);
						DfSendMessage(Mwnd, DFM_LEFT_BUTTON, ev.mx, ev.my);
					}
				}
				break;

			case DFM_BUTTON_RELEASED:
			case DOUBLE_CLICK:
			case DFM_RIGHT_BUTTON:
				if (handshaking)
					break;

			case MOUSE_MOVED:
				Mwnd = MouseWindow(ev.mx, ev.my);
				DfSendMessage(Mwnd, ev.event, ev.mx, ev.my);
				break;

			case DFM_CLOCKTICK:
				DfSendMessage(Cwnd, ev.event, ev.mx, ev.my);
				break;

			default:
				break;
		}
	}

	/* ------ dequeue and process messages ----- */
	while (MsgQueueCtr > 0)
	{
		struct msgs mq;

		mq = MsgQueue[MsgQueueOffCtr];

		if (++MsgQueueOffCtr == DF_MAXMESSAGES)
			MsgQueueOffCtr = 0;
		--MsgQueueCtr;

		DfSendMessage (mq.wnd, mq.msg, mq.p1, mq.p2);
		if (mq.msg == DFM_ENDDIALOG)
			return FALSE;

		if (mq.msg == DFM_STOP)
			return FALSE;
	}

	return TRUE;
}

/* EOF */

⌨️ 快捷键说明

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