Skip to content

Commit

Permalink
Merge pull request #7 from tmarenko/dpi_aware
Browse files Browse the repository at this point in the history
Fix #6: BitBlt and set DPI Awareness
  • Loading branch information
tmarenko authored Aug 26, 2022
2 parents c41f970 + 8432769 commit dadc3cf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ project(GenshinImpact_PaimonShutUp)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
set(MAIN_MANIFEST "main.manifest")
if(NOT TESSERACT_ENG_DATA)
set(TESSERACT_ENG_DATA "https://github.com/tesseract-ocr/tessdata/raw/3.04.00/eng.traineddata")
endif()
Expand All @@ -17,7 +19,6 @@ include_directories(${Leptonica_INCLUDE_DIRS})
include_directories(${Tesseract_INCLUDE_DIRS})

add_executable(${PROJECT_NAME} source/main.cpp source/tesseract.cpp source/tesseract.h appicon.rc)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS /MANIFESTUAC:"level='requireAdministrator' uiAccess='false'")

MESSAGE(STATUS "LINK LIBRARIES ${OpenCV_LIBS} ${Leptonica_LIBRARIES} ${Tesseract_LIBRARIES}")
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${Leptonica_LIBRARIES} libtesseract)
Expand All @@ -34,8 +35,14 @@ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMENT "Copying dependencies..."
COMMAND_EXPAND_LISTS)

add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/${MAIN_MANIFEST}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${MAIN_MANIFEST})

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND "mt.exe" -manifest "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}\\${PROJECT_NAME}.exe.manifest" -outputresource:"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}\\${PROJECT_NAME}.exe"
COMMAND ${CMAKE_COMMAND} -E remove -f "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}\\${PROJECT_NAME}.exe.manifest"
COMMAND "mt.exe" -manifest "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}\\${MAIN_MANIFEST}" -outputresource:"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}\\${PROJECT_NAME}.exe"
COMMAND ${CMAKE_COMMAND} -E remove -f "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}\\${MAIN_MANIFEST}"
COMMENT "Embedding manifest..."
COMMAND_EXPAND_LISTS)
18 changes: 18 additions & 0 deletions main.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
<application>
<windowsSettings>
<!-- legacy -->
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
<!-- falls back to pm if pmv2 is not available -->
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">permonitorv2,permonitor</dpiAwareness>
</windowsSettings>
</application>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level='requireAdministrator' uiAccess='false' />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
2 changes: 1 addition & 1 deletion source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void GetFrame(int screenWidth, int screenHeight) {
auto bitMap = CreateCompatibleBitmap(hwndDC, screenWidth, screenHeight);
SelectObject(saveDC, bitMap);

PrintWindow(genshinWindow, saveDC, PW_RENDERFULLCONTENT);
BitBlt(saveDC, 0, 0, screenWidth, screenHeight, hwndDC, 0, 0, SRCCOPY);
GetDIBits(saveDC, bitMap, 0, screenHeight - titleBarSize, frame.data, (BITMAPINFO *) &bi, DIB_RGB_COLORS);

DeleteObject(bitMap);
Expand Down

0 comments on commit dadc3cf

Please sign in to comment.