SCRIPT Move cc files

This commit is contained in:
PJ Reiniger
2025-11-07 19:55:39 -05:00
committed by Peter Johnson
parent 10b4a0c971
commit 7ca1be9bae
1197 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <windows.h>
#include <functional>
#include <thread>
namespace cs {
class WindowsMessagePump {
public:
explicit WindowsMessagePump(
std::function<LRESULT(HWND, UINT, WPARAM, LPARAM)> callback);
~WindowsMessagePump();
friend LRESULT CALLBACK pWndProc(HWND hwnd, UINT uiMsg, WPARAM wParam,
LPARAM lParam);
template <typename RetVal = LRESULT, typename FirstParam = WPARAM,
typename SecondParam = LPARAM>
RetVal SendWindowMessage(UINT msg, FirstParam wParam, SecondParam lParam) {
static_assert(sizeof(FirstParam) <= sizeof(WPARAM),
"First Parameter Does Not Fit");
static_assert(sizeof(SecondParam) <= sizeof(LPARAM),
"Second Parameter Does Not Fit");
static_assert(sizeof(RetVal) <= sizeof(LRESULT),
"Return Value Does Not Fit");
WPARAM firstToSend = 0;
LPARAM secondToSend = 0;
std::memcpy(&firstToSend, &wParam, sizeof(FirstParam));
std::memcpy(&secondToSend, &lParam, sizeof(SecondParam));
LRESULT result = SendMessage(hwnd, msg, firstToSend, secondToSend);
RetVal toReturn;
std::memset(&toReturn, 0, sizeof(RetVal));
std::memcpy(&toReturn, &result, sizeof(RetVal));
return toReturn;
}
template <typename FirstParam = WPARAM, typename SecondParam = LPARAM>
BOOL PostWindowMessage(UINT msg, FirstParam wParam, SecondParam lParam) {
static_assert(sizeof(FirstParam) <= sizeof(WPARAM),
"First Parameter Does Not Fit");
static_assert(sizeof(SecondParam) <= sizeof(LPARAM),
"Second Parameter Does Not Fit");
WPARAM firstToSend = 0;
LPARAM secondToSend = 0;
std::memcpy(&firstToSend, &wParam, sizeof(FirstParam));
std::memcpy(&secondToSend, &lParam, sizeof(SecondParam));
return PostMessage(hwnd, msg, firstToSend, secondToSend);
}
private:
void ThreadMain(HANDLE eventHandle);
HWND hwnd;
std::function<LRESULT(HWND, UINT, WPARAM, LPARAM)> m_callback;
std::thread m_mainThread;
};
} // namespace cs