diff --git a/WinDevice/Utils/CmdUtil.cpp b/WinDevice/Utils/CmdUtil.cpp index c72a679..4ed3b19 100644 --- a/WinDevice/Utils/CmdUtil.cpp +++ b/WinDevice/Utils/CmdUtil.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include "spdlog/spdlog.h" using namespace std; diff --git a/WinDevice/Utils/Log.cpp b/WinDevice/Utils/Log.cpp new file mode 100644 index 0000000..d67894f --- /dev/null +++ b/WinDevice/Utils/Log.cpp @@ -0,0 +1,19 @@ +#include "Log.h" +#include "spdlog/spdlog.h" + + +void Log::Init(LogLevel level, std::string fileName) +{ + +} + +void Log::Info(std::string format, std::string args...) +{ + spdlog::info(format, args); +} + +void Log::WInfo(std::wstring format, std::wstring args...) +{ + std::string s_format(format.begin(), format.end()); + +} \ No newline at end of file diff --git a/WinDevice/Utils/Log.h b/WinDevice/Utils/Log.h new file mode 100644 index 0000000..0493af9 --- /dev/null +++ b/WinDevice/Utils/Log.h @@ -0,0 +1,17 @@ +#pragma once +#include "spdlog/spdlog.h" + +enum LogLevel : int +{ + Debug = spdlog::level::debug, + Info = spdlog::level::info, +}; + +class Log +{ +public: + static void Init(LogLevel level, std::string fileName); + + static void Info(std::string format, std::string args...); + static void WInfo(std::wstring format, std::wstring args...); +}; diff --git a/WinDevice/Utils/StringUtil.h b/WinDevice/Utils/StringUtil.h new file mode 100644 index 0000000..1236658 --- /dev/null +++ b/WinDevice/Utils/StringUtil.h @@ -0,0 +1,24 @@ +#ifndef STRING_UTIL_H +#define STRING_UTIL_H + +#include +#include +#include + +template +To Convert(const From& input) { + std::wstring_convert, typename From::value_type> converter; + return converter.to_bytes(input); +} + +std::string Wstring2String(const std::wstring& input) { + return Convert(input); +} + +std::string Wchar2String(const WCHAR* input) { + std::wstring_convert> converter; + return converter.to_bytes(input); +} + + +#endif // STRING_CONVERSION_H \ No newline at end of file diff --git a/WinDevice/Utils/TimeUtil.cpp b/WinDevice/Utils/TimeUtil.cpp index 6a45c19..e4bfd5f 100644 --- a/WinDevice/Utils/TimeUtil.cpp +++ b/WinDevice/Utils/TimeUtil.cpp @@ -1,5 +1,5 @@ #include "TimeUtil.h" -#include +#include "spdlog/spdlog.h" template diff --git a/WinDevice/Video/ScreenManager.cpp b/WinDevice/Video/ScreenManager.cpp index fa0d943..6e0a619 100644 --- a/WinDevice/Video/ScreenManager.cpp +++ b/WinDevice/Video/ScreenManager.cpp @@ -1,15 +1,97 @@ #include "ScreenManager.h" +#include "spdlog/spdlog.h" +#include "spdlog/sinks/basic_file_sink.h" +#include "spdlog/sinks/stdout_color_sinks.h" +#include "Utils/StringUtil.h" void SceenManager::UpdateDisplayInfo() { - + _UpdateDisplayDeviceList(); + _UpdateMonitorInfoMap(); } void SceenManager::_UpdateDisplayDeviceList() { + spdlog::info("=====GetInfoByEnumDisplayDevices start====="); + DISPLAY_DEVICE displayDevice; + displayDevice.cb = sizeof(DISPLAY_DEVICE); + DWORD deviceIndex = 0; + + while (EnumDisplayDevices(nullptr, deviceIndex, &displayDevice, 0)) + { + spdlog::info("Display Device DeviceName:{0}, DeviceString:{1}, DeviceID:{2}, DeviceKey:{3}.", + Wstring2String(displayDevice.DeviceName), Wstring2String(displayDevice.DeviceString), + Wstring2String(displayDevice.DeviceID), Wstring2String(displayDevice.DeviceKey)); + _displayDeviceList.push_back(displayDevice); + deviceIndex++; + } + + spdlog::info("=====GetInfoByEnumDisplayDevices end====="); +} + +BOOL SceenManager::_EnumMonitorProc(HMONITOR hMonitor) +{ + MONITORINFOEX monitorInfo; + monitorInfo.cbSize = sizeof(MONITORINFOEX); + if (GetMonitorInfo(hMonitor, &monitorInfo)) + { + // Ѻ + spdlog::info("_UpdateMonitorInfoMap, szDevice:{0}, right:{1}, bottom:{2}", Wchar2String(monitorInfo.szDevice), + monitorInfo.rcMonitor.right, monitorInfo.rcMonitor.bottom); + } + auto it = SceenManager::_hMonitorInfoMap.find(hMonitor); + if (it != SceenManager::_hMonitorInfoMap.end()) + { + // Ѿڣʾظ + // ﴦظ + } + else + { + SceenManager::_hMonitorInfoMap.insert(std::make_pair(hMonitor, monitorInfo)); + // ڣʾûظ + // ﴦظ + } + + DISPLAYCONFIG_TARGET_DEVICE_NAME targetDeviceName = {}; + targetDeviceName.header.size = sizeof(targetDeviceName); + + // ȡָ HMONITOR Ŀ豸Ϣ + if (DisplayConfigGetDeviceInfo(&targetDeviceName.header) == ERROR_SUCCESS) + { + spdlog::info("_UpdateMonitorInfoMap, monitorDevicePath:{0}, monitorFriendlyDeviceName:{1}", + Wchar2String(targetDeviceName.monitorDevicePath), Wchar2String(targetDeviceName.monitorFriendlyDeviceName)); + + // ȡָ HMONITOR ķֱϢ + DEVMODE dm; + dm.dmSize = sizeof(DEVMODE); + dm.dmDriverExtra = 0; + + if (EnumDisplaySettings(targetDeviceName.monitorDevicePath, ENUM_CURRENT_SETTINGS, &dm) != 0) + { + spdlog::info("Resolution:{0}x{1}", dm.dmPelsWidth, dm.dmPelsHeight); + } + else + { + spdlog::info(L"Failed to get display resolution."); + } + } + else + { + spdlog::info("Failed to get display device info."); + } + return TRUE; +} + +BOOL CALLBACK SceenManager::EnumMonitorsProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) +{ + return ((SceenManager*)dwData)->_EnumMonitorProc(hMonitor); } void SceenManager::_UpdateMonitorInfoMap() { + spdlog::info("=====GetInfoByEnumDisplayMonitors start====="); + // öʾ + EnumDisplayMonitors(nullptr, nullptr, EnumMonitorsProc, reinterpret_cast(this)); + spdlog::info("=====GetInfoByEnumDisplayMonitors end====="); } diff --git a/WinDevice/Video/ScreenManager.h b/WinDevice/Video/ScreenManager.h index fea840d..1808524 100644 --- a/WinDevice/Video/ScreenManager.h +++ b/WinDevice/Video/ScreenManager.h @@ -7,11 +7,15 @@ class SceenManager { public: + SceenManager(); + ~SceenManager(); void UpdateDisplayInfo(); private: void _UpdateDisplayDeviceList(); void _UpdateMonitorInfoMap(); + static BOOL CALLBACK EnumMonitorsProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData); + BOOL _EnumMonitorProc(HMONITOR hMonitor); std::vector _displayDeviceList; std::map _hMonitorInfoMap; diff --git a/WinDevice/WinDevice.cpp b/WinDevice/WinDevice.cpp index 2047c6a..21955da 100644 --- a/WinDevice/WinDevice.cpp +++ b/WinDevice/WinDevice.cpp @@ -7,9 +7,10 @@ #include #include #include -#include +#include "spdlog/spdlog.h" #include "Utils/CmdUtil.h" +#include "Video/ScreenManager.h" using namespace std; @@ -17,7 +18,8 @@ int main() { const std::string command = "wmic desktopmonitor get PNPDeviceId,ScreenWidth,ScreenHeight"; const std::string command_output = CmdUtil::ExecuteCommand(command); - + SceenManager sceen_manager; + sceen_manager.UpdateDisplayInfo(); } // 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 diff --git a/WinDevice/WinDevice.vcxproj b/WinDevice/WinDevice.vcxproj index 747fa14..9c36d83 100644 --- a/WinDevice/WinDevice.vcxproj +++ b/WinDevice/WinDevice.vcxproj @@ -89,7 +89,7 @@ true WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(ProjectDir)include\third_lib\;$(ProjectDir)include\third_lib\spdlog\;. + $(ProjectDir)include\third_lib\;. Console @@ -147,6 +147,7 @@ + @@ -157,6 +158,8 @@ + + diff --git a/WinDevice/WinDevice.vcxproj.filters b/WinDevice/WinDevice.vcxproj.filters index 633b294..dacede8 100644 --- a/WinDevice/WinDevice.vcxproj.filters +++ b/WinDevice/WinDevice.vcxproj.filters @@ -33,6 +33,9 @@ 源文件 + + 源文件 + @@ -56,5 +59,11 @@ 头文件 + + 头文件 + + + 头文件 + \ No newline at end of file diff --git a/WinDevice/include/third_lib/spdlog.h b/WinDevice/include/third_lib/spdlog.h deleted file mode 100644 index fbfe5fb..0000000 --- a/WinDevice/include/third_lib/spdlog.h +++ /dev/null @@ -1,363 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -// spdlog main header file. -// see example.cpp for usage example - -#ifndef SPDLOG_H -#define SPDLOG_H - -#pragma once - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace spdlog { - -using default_factory = synchronous_factory; - -// Create and register a logger with a templated sink type -// The logger's level, formatter and flush level will be set according the -// global settings. -// -// Example: -// spdlog::create("logger_name", "dailylog_filename", 11, 59); -template -inline std::shared_ptr create(std::string logger_name, SinkArgs &&...sink_args) -{ - return default_factory::create(std::move(logger_name), std::forward(sink_args)...); -} - -// Initialize and register a logger, -// formatter and flush level will be set according the global settings. -// -// Useful for initializing manually created loggers with the global settings. -// -// Example: -// auto mylogger = std::make_shared("mylogger", ...); -// spdlog::initialize_logger(mylogger); -SPDLOG_API void initialize_logger(std::shared_ptr logger); - -// Return an existing logger or nullptr if a logger with such name doesn't -// exist. -// example: spdlog::get("my_logger")->info("hello {}", "world"); -SPDLOG_API std::shared_ptr get(const std::string &name); - -// Set global formatter. Each sink in each logger will get a clone of this object -SPDLOG_API void set_formatter(std::unique_ptr formatter); - -// Set global format string. -// example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v"); -SPDLOG_API void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local); - -// enable global backtrace support -SPDLOG_API void enable_backtrace(size_t n_messages); - -// disable global backtrace support -SPDLOG_API void disable_backtrace(); - -// call dump backtrace on default logger -SPDLOG_API void dump_backtrace(); - -// Get global logging level -SPDLOG_API level::level_enum get_level(); - -// Set global logging level -SPDLOG_API void set_level(level::level_enum log_level); - -// Determine whether the default logger should log messages with a certain level -SPDLOG_API bool should_log(level::level_enum lvl); - -// Set global flush level -SPDLOG_API void flush_on(level::level_enum log_level); - -// Start/Restart a periodic flusher thread -// Warning: Use only if all your loggers are thread safe! -template -inline void flush_every(std::chrono::duration interval) -{ - details::registry::instance().flush_every(interval); -} - -// Set global error handler -SPDLOG_API void set_error_handler(void (*handler)(const std::string &msg)); - -// Register the given logger with the given name -SPDLOG_API void register_logger(std::shared_ptr logger); - -// Apply a user defined function on all registered loggers -// Example: -// spdlog::apply_all([&](std::shared_ptr l) {l->flush();}); -SPDLOG_API void apply_all(const std::function)> &fun); - -// Drop the reference to the given logger -SPDLOG_API void drop(const std::string &name); - -// Drop all references from the registry -SPDLOG_API void drop_all(); - -// stop any running threads started by spdlog and clean registry loggers -SPDLOG_API void shutdown(); - -// Automatic registration of loggers when using spdlog::create() or spdlog::create_async -SPDLOG_API void set_automatic_registration(bool automatic_registration); - -// API for using default logger (stdout_color_mt), -// e.g: spdlog::info("Message {}", 1); -// -// The default logger object can be accessed using the spdlog::default_logger(): -// For example, to add another sink to it: -// spdlog::default_logger()->sinks().push_back(some_sink); -// -// The default logger can replaced using spdlog::set_default_logger(new_logger). -// For example, to replace it with a file logger. -// -// IMPORTANT: -// The default API is thread safe (for _mt loggers), but: -// set_default_logger() *should not* be used concurrently with the default API. -// e.g do not call set_default_logger() from one thread while calling spdlog::info() from another. - -SPDLOG_API std::shared_ptr default_logger(); - -SPDLOG_API spdlog::logger *default_logger_raw(); - -SPDLOG_API void set_default_logger(std::shared_ptr default_logger); - -// Initialize logger level based on environment configs. -// -// Useful for applying SPDLOG_LEVEL to manually created loggers. -// -// Example: -// auto mylogger = std::make_shared("mylogger", ...); -// spdlog::apply_logger_env_levels(mylogger); -SPDLOG_API void apply_logger_env_levels(std::shared_ptr logger); - -template -inline void log(source_loc source, level::level_enum lvl, format_string_t fmt, Args &&...args) -{ - default_logger_raw()->log(source, lvl, fmt, std::forward(args)...); -} - -template -inline void log(level::level_enum lvl, format_string_t fmt, Args &&...args) -{ - default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward(args)...); -} - -template -inline void trace(format_string_t fmt, Args &&...args) -{ - default_logger_raw()->trace(fmt, std::forward(args)...); -} - -template -inline void debug(format_string_t fmt, Args &&...args) -{ - default_logger_raw()->debug(fmt, std::forward(args)...); -} - -template -inline void info(format_string_t fmt, Args &&...args) -{ - default_logger_raw()->info(fmt, std::forward(args)...); -} - -template -inline void warn(format_string_t fmt, Args &&...args) -{ - default_logger_raw()->warn(fmt, std::forward(args)...); -} - -template -inline void error(format_string_t fmt, Args &&...args) -{ - default_logger_raw()->error(fmt, std::forward(args)...); -} - -template -inline void critical(format_string_t fmt, Args &&...args) -{ - default_logger_raw()->critical(fmt, std::forward(args)...); -} - -template -inline void log(source_loc source, level::level_enum lvl, const T &msg) -{ - default_logger_raw()->log(source, lvl, msg); -} - -template -inline void log(level::level_enum lvl, const T &msg) -{ - default_logger_raw()->log(lvl, msg); -} - -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT -template -inline void log(source_loc source, level::level_enum lvl, wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->log(source, lvl, fmt, std::forward(args)...); -} - -template -inline void log(level::level_enum lvl, wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward(args)...); -} - -template -inline void trace(wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->trace(fmt, std::forward(args)...); -} - -template -inline void debug(wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->debug(fmt, std::forward(args)...); -} - -template -inline void info(wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->info(fmt, std::forward(args)...); -} - -template -inline void warn(wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->warn(fmt, std::forward(args)...); -} - -template -inline void error(wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->error(fmt, std::forward(args)...); -} - -template -inline void critical(wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->critical(fmt, std::forward(args)...); -} -#endif - -template -inline void trace(const T &msg) -{ - default_logger_raw()->trace(msg); -} - -template -inline void debug(const T &msg) -{ - default_logger_raw()->debug(msg); -} - -template -inline void info(const T &msg) -{ - default_logger_raw()->info(msg); -} - -template -inline void warn(const T &msg) -{ - default_logger_raw()->warn(msg); -} - -template -inline void error(const T &msg) -{ - default_logger_raw()->error(msg); -} - -template -inline void critical(const T &msg) -{ - default_logger_raw()->critical(msg); -} - -} // namespace spdlog - -// -// enable/disable log calls at compile time according to global level. -// -// define SPDLOG_ACTIVE_LEVEL to one of those (before including spdlog.h): -// SPDLOG_LEVEL_TRACE, -// SPDLOG_LEVEL_DEBUG, -// SPDLOG_LEVEL_INFO, -// SPDLOG_LEVEL_WARN, -// SPDLOG_LEVEL_ERROR, -// SPDLOG_LEVEL_CRITICAL, -// SPDLOG_LEVEL_OFF -// - -#ifndef SPDLOG_NO_SOURCE_LOC -# define SPDLOG_LOGGER_CALL(logger, level, ...) \ - (logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__) -#else -# define SPDLOG_LOGGER_CALL(logger, level, ...) (logger)->log(spdlog::source_loc{}, level, __VA_ARGS__) -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE -# define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__) -# define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__) -#else -# define SPDLOG_LOGGER_TRACE(logger, ...) (void)0 -# define SPDLOG_TRACE(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG -# define SPDLOG_LOGGER_DEBUG(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__) -# define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__) -#else -# define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0 -# define SPDLOG_DEBUG(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO -# define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__) -# define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__) -#else -# define SPDLOG_LOGGER_INFO(logger, ...) (void)0 -# define SPDLOG_INFO(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN -# define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__) -# define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__) -#else -# define SPDLOG_LOGGER_WARN(logger, ...) (void)0 -# define SPDLOG_WARN(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR -# define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__) -# define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__) -#else -# define SPDLOG_LOGGER_ERROR(logger, ...) (void)0 -# define SPDLOG_ERROR(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL -# define SPDLOG_LOGGER_CRITICAL(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__) -# define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__) -#else -# define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0 -# define SPDLOG_CRITICAL(...) (void)0 -#endif - -#ifdef SPDLOG_HEADER_ONLY -# include "spdlog-inl.h" -#endif - -#endif // SPDLOG_H diff --git a/WinDevice/stdafx.h b/WinDevice/stdafx.h index 5208945..f1e0469 100644 --- a/WinDevice/stdafx.h +++ b/WinDevice/stdafx.h @@ -5,4 +5,5 @@ #include #include #include -#include \ No newline at end of file +#include +