INT_PTR CMessageForwarder::ForwardMessage(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
	m_hwnd = hwnd;
	m_uMsg = uMsg;
	m_wParam = wParam;
	m_lParam = lParam;

	/* Private message? */
	if(uMsg > WM_APP && uMsg < 0xBFFF)
	{
		return OnPrivateMessage(uMsg,wParam,lParam);
	}

	switch(uMsg)
	{
		case WM_INITDIALOG:
			return OnInitDialog();
			break;

		case WM_CTLCOLORSTATIC:
			return OnCtlColorStatic(reinterpret_cast<HWND>(lParam),
				reinterpret_cast<HDC>(wParam));
			break;

		case WM_CTLCOLOREDIT:
			return OnCtlColorEdit(reinterpret_cast<HWND>(lParam),
				reinterpret_cast<HDC>(wParam));
			break;

		case WM_HSCROLL:
			return OnHScroll(reinterpret_cast<HWND>(lParam));
			break;

		case WM_APPCOMMAND:
			return OnAppCommand(reinterpret_cast<HWND>(wParam),
				GET_APPCOMMAND_LPARAM(lParam),
				GET_DEVICE_LPARAM(lParam),
				GET_KEYSTATE_LPARAM(lParam));
			break;

		case WM_TIMER:
			return OnTimer(static_cast<int>(wParam));
			break;

		case WM_MBUTTONUP:
			return OnMButtonUp(&MAKEPOINTS(lParam));
			break;

		case WM_COMMAND:
			return OnCommand(wParam,lParam);
			break;

		case WM_NOTIFY:
			return OnNotify(reinterpret_cast<LPNMHDR>(lParam));
			break;

		case WM_GETMINMAXINFO:
			return OnGetMinMaxInfo(reinterpret_cast<LPMINMAXINFO>(lParam));
			break;

		case WM_SIZE:
			return OnSize(static_cast<int>(wParam),
				LOWORD(lParam),HIWORD(lParam));
			break;

		case WM_CLOSE:
			return OnClose();
			break;

		case WM_DESTROY:
			return OnDestroy();
			break;

		case WM_NCDESTROY:
			return OnNcDestroy();
			break;


		case EM_SETSEL:
			OnEMSetSel(wParam,lParam);
			break;
	}

	return GetDefaultReturnValue(hwnd,uMsg,wParam,lParam);
}
Example #2
0
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
    switch(uMsg){
    
    case WM_KEYDOWN:
        printf("[WM_KEYDOWN] key = %u, lParam = %lu\n", wParam, lParam);
        return 0;
    case WM_KEYUP:
        printf("[WM_KEYUP] key = %u, lParam = %lu\n", wParam, lParam);
        return 0;
    case WM_CHAR:
        printf("[WM_CHAR] key = %u, lParam = %lu\n", wParam, lParam);
        return 0;
    case WM_DEADCHAR:
        printf("[WM_DEADCHAR] key = %u, lParam = %lu\n", wParam, lParam);
        return 0;
    case WM_SYSKEYDOWN:
        printf("[WM_SYSKEYDOWN] key = %u, lParam = %lu\n", wParam, lParam);
        return 0;
    case WM_SYSKEYUP:
        printf("[WM_SYSKEYUP] key = %u, lParam = %lu\n", wParam, lParam);
        return 0;
    case WM_SYSDEADCHAR:
        printf("[WM_SYSDEADCHAR] key = %u, lParam = %lu\n", wParam, lParam);
        return 0;
    case WM_HOTKEY:
        printf("[WM_HOTKEY] keys1 = %u, keys2 = %lu\n", wParam, lParam);
        return 0;
    case WM_APPCOMMAND:
        printf("[WM_APPCOMMAND] cmd = %u, device = %u, keys = %u\n", GET_APPCOMMAND_LPARAM(lParam), GET_DEVICE_LPARAM(lParam), GET_KEYSTATE_LPARAM(lParam));
        return 0;

    case WM_CLOSE:
        PostQuitMessage(0);
        return 0;

    }
    
    printf("Received message %u with wParam = %u, lParam = %lu\n", uMsg, wParam, lParam);
    return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
bool MyApplication::winEventFilter(MSG * msg, long * result) {
	//qDebug() << "MyApplication::winEventFilter" << msg->message << "lParam:" << msg->lParam;

	static uint last_appcommand = 0;
	
	if (msg->message == WM_KEYDOWN) {
		//qDebug("MyApplication::winEventFilter: WM_KEYDOWN: %X", msg->wParam);
		bool eat_key = false;
		if ((last_appcommand == APPCOMMAND_MEDIA_NEXTTRACK) && (msg->wParam == VK_MEDIA_NEXT_TRACK)) eat_key = true;
		else
		if ((last_appcommand == APPCOMMAND_MEDIA_PREVIOUSTRACK) && (msg->wParam == VK_MEDIA_PREV_TRACK)) eat_key = true;
		else
		if ((last_appcommand == APPCOMMAND_MEDIA_PLAY_PAUSE) && (msg->wParam == VK_MEDIA_PLAY_PAUSE)) eat_key = true;
		else
		if ((last_appcommand == APPCOMMAND_MEDIA_STOP) && (msg->wParam == VK_MEDIA_STOP)) eat_key = true;
		
		if (eat_key) { 
			qDebug("MyApplication::winEventFilter: ignoring key %X", msg->wParam);
			last_appcommand = 0; 
			*result = true; 
			return true; 
		}
	}
	else
	if (msg->message == WM_APPCOMMAND) {
		/*
		QKeySequence k(Qt::Key_MediaTogglePlayPause);
		qDebug() << "MyApplication::winEventFilter" << k.toString();
		*/

		//qDebug() << "MyApplication::winEventFilter" << msg->message << "lParam:" << msg->lParam;
		uint cmd  = GET_APPCOMMAND_LPARAM(msg->lParam);
		uint uDevice = GET_DEVICE_LPARAM(msg->lParam);
		uint dwKeys = GET_KEYSTATE_LPARAM(msg->lParam);
		qDebug() << "MyApplication::winEventFilter: cmd:" << cmd <<"uDevice:" << uDevice << "dwKeys:" << dwKeys;

		//if (uDevice == FAPPCOMMAND_KEY) {
			int key = 0;
			Qt::KeyboardModifiers modifier = Qt::NoModifier;
			QString name;
			
			switch (cmd) {
				case APPCOMMAND_MEDIA_PAUSE: key = Qt::Key_MediaPause; name = "Media Pause"; break;
				case APPCOMMAND_MEDIA_PLAY: key = Qt::Key_MediaPlay; name = "Media Play"; break;
				case APPCOMMAND_MEDIA_STOP: key = Qt::Key_MediaStop; name = "Media Stop"; break;
				case APPCOMMAND_MEDIA_PLAY_PAUSE: key = Qt::Key_MediaTogglePlayPause; name = "Toggle Media Play/Pause"; break;
			
				case APPCOMMAND_MEDIA_NEXTTRACK: key = Qt::Key_MediaNext; name = "Media Next"; break;
				case APPCOMMAND_MEDIA_PREVIOUSTRACK: key = Qt::Key_MediaPrevious; name = "Media Previous"; break;

				case APPCOMMAND_MEDIA_FAST_FORWARD: key = Qt::Key_F; modifier = Qt::ShiftModifier | Qt::ControlModifier; break;
				case APPCOMMAND_MEDIA_REWIND: key = Qt::Key_B; modifier = Qt::ShiftModifier | Qt::ControlModifier; break;
			}
			
			if (key != 0) {
				last_appcommand = cmd;
				
				QKeyEvent event(QEvent::KeyPress, key, modifier, name);
				QWidget * w = QApplication::focusWidget();
				if (w) QCoreApplication::sendEvent(w, &event);
				*result = true;
				return true;
			}
		//}
	}

	return false;
}