This commit is contained in:
yc S
2024-10-28 16:37:56 +08:00
parent 9a6c1b52ec
commit 3bfd924dc7
3 changed files with 165 additions and 27 deletions
+12 -10
View File
@@ -1,19 +1,21 @@
cmake_minimum_required(VERSION 3.5.0)
project(HighBloodPressure VERSION 0.1.0 LANGUAGES C CXX)
project(ProjectBase VERSION 0.1.0 LANGUAGES C CXX)
#add_definitions(-DUNICODE)
#add_definitions(-D_UNICODE)
#add_definitions(-DCINTERFACE)
#add_definitions(-D__CARLBEKS_CMAKE_VSCODE__)
add_compile_definitions(DUNICODE)
add_compile_definitions(_UNICODE)
add_compile_definitions(CINTERFACE)
add_compile_definitions(__CARLBEKS_CMAKE_VSCODE__)
add_definitions(-DUNICODE)
add_definitions(-D_UNICODE)
add_definitions(-DCINTERFACE)
add_definitions(-D__CARLBEKS_CMAKE_VSCODE__)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_WIN32_EXECUTABLE true)
#if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
#add_compile_options(${PROJECT_NAME} -Wno-microsoft-string-literal-from-predefined)
#endif()
#add_compile_options(${PROJECT_NAME} /utf-8)
include(CTest)
enable_testing()
add_executable(HighBloodPressure main.cpp)
add_executable(${PROJECT_NAME} main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
+26 -1
View File
@@ -1,2 +1,27 @@
#include "../CarlbeksLib/gxdef.h"
#include <Windows.h>
#include <winuser.h>
#include "../CarlbeksLib/gxdef.h"
#include "../CarlbeksLib/rgui.h"
#include "../CarlbeksLib/iwindows.h"
static HINSTANCE MainInstance;
static HWND MainWindowHandle;
static inline String ApplicationName = L"Project";
inline Carlbeks::UI::Main MainWindow;
inline Carlbeks::UI::TickThread MainTick{ &MainWindow };
inline void Initialize() noexcept {
Carlbeks::WindowsInterface::ShowConsoleIO();
MainWindow.setWindow(MainWindowHandle);
MainWindow.setDC(GetDC(MainWindowHandle));
MainTick.start();
}
inline void Finalize() noexcept {
MainTick.stopAndWait();
_wsystem(L"pause");
}
+127 -16
View File
@@ -1,29 +1,140 @@
#include <Windows.h>
#include <iostream>
#include <consoleapi.h>
#include <corecrt_wprocess.h>
#include <minwindef.h>
#include <windef.h>
#include <wingdi.h>
#include <winuser.h>
#include <Uxtheme.h>
#include <vssym32.h>
#include "../CarlbeksLib/gxdef.h"
#include "../CarlbeksLib/iwindows.h"
__stdcall int wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
// create window
#include "core.h"
LRESULT __stdcall WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
[[likely]] case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps); // Paint caption
MainWindow.fireRender();
EndPaint(hwnd, &ps);
break;
}
case WM_LBUTTONDOWN:
MainWindow.fireMouseDown(Carlbeks::UI::MA_LEFT);
MainWindow.fireRender();
break;
case WM_RBUTTONDOWN:
MainWindow.fireMouseDown(Carlbeks::UI::MA_RIGHT);
MainWindow.fireRender();
break;
case WM_LBUTTONUP:
MainWindow.fireMouseUp(Carlbeks::UI::MA_LEFT);
MainWindow.fireRender();
break;
case WM_RBUTTONUP:
MainWindow.fireMouseUp(Carlbeks::UI::MA_RIGHT);
MainWindow.fireRender();
break;
[[likely]] case WM_NCHITTEST: {
Carlbeks::UI::UIReturn ret = MainWindow.fireMouseMove();
MainWindow.fireRender();
if (ret & 0x20) return ret ^ 0x20;
return HTCLIENT;
LRESULT lr = 0;
BOOL r = DwmDefWindowProc(hwnd, uMsg, wParam, lParam, &lr);
return lr;
}
[[likely]] case WM_MOUSEMOVE: {
MainWindow.fireMouseMove();
// MainWindow.fireRender();
break;
}
[[unlikely]] case WM_MBUTTONDOWN:
MainWindow.fireMouseDown(Carlbeks::UI::MA_MID);
MainWindow.fireRender();
break;
[[unlikely]] case WM_MBUTTONUP:
MainWindow.fireMouseUp(Carlbeks::UI::MA_MID);
MainWindow.fireRender();
break;
[[unlikely]] case WM_COMMAND:
std::wcout << L"WM_COMMAND" << std::endl;
break;
case WM_DWMCOMPOSITIONCHANGED: {
MARGINS margins{
.cxLeftWidth = 0,
.cxRightWidth = 0,
.cyTopHeight = 0,
.cyBottomHeight = 0
};
HRESULT hr = Carlbeks::WindowsInterface::RemoveDefaultCaption(hwnd, &margins);
break;
}
case WM_NCCALCSIZE:
if (wParam == 1) {
NCCALCSIZE_PARAMS* pncsp = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);
pncsp->rgrc[0].left = pncsp->rgrc[0].left + 0;
pncsp->rgrc[0].top = pncsp->rgrc[0].top + 0;
pncsp->rgrc[0].right = pncsp->rgrc[0].right - 0;
pncsp->rgrc[0].bottom = pncsp->rgrc[0].bottom - 0;
return 0;
}
case WM_SIZE:
MainWindow.fireResize();
MainWindow.fireRender();
break;
case WM_ACTIVATE: {
MARGINS margins{
.cxLeftWidth = 0,
.cxRightWidth = 0,
.cyTopHeight = 0,
.cyBottomHeight = 0
};
HRESULT hr = Carlbeks::WindowsInterface::RemoveDefaultCaption(hwnd, &margins);
} break;
[[unlikely]] case WM_DESTROY:
PostQuitMessage(0);
return 0;
[[unlikely]] case WM_CREATE:
SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER); // Force post NCCALCSIZE
break;
default:
break;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
int __stdcall wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
WNDCLASSEX wc = { 0 };
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = DefWindowProc;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszClassName = L"HighBloodPressure";
RegisterClassEx(&wc);
HWND hwnd = CreateWindowEx(0, L"HighBloodPressure", L"High Blood Pressure", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = L"None";
wc.lpszClassName = ApplicationName.c_str();
if (!RegisterClassExW(&wc)) return FALSE;
MainInstance = hInstance;
MainWindowHandle = CreateWindowExW(0, wc.lpszClassName, wc.lpszClassName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
ShowWindow(MainWindowHandle, nCmdShow);
Initialize();
MainWindow.fireResize();
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(109));
MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
while (GetMessageW(&msg, NULL, 0, 0)) {
if (!TranslateAcceleratorW(msg.hwnd, hAccelTable, &msg)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
DestroyAcceleratorTable(hAccelTable);
Finalize();
return (int) msg.wParam;
}