Skip to content

Commit

Permalink
Merge pull request #2 from mattias-symphony/SDA-1637_SDA-1638
Browse files Browse the repository at this point in the history
fix: Fixes for SDA-1637 and SDA-1638
  • Loading branch information
mattias-symphony authored Dec 19, 2019
2 parents 4bd0f9b + 97f7a0e commit b018f7b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
19 changes: 15 additions & 4 deletions MakeAnnotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ HBITMAP WINAPI penIcon( Gdiplus::Pen* pen ) {
}


int makeAnnotations( HBITMAP snippet, RECT bounds, int lang ) {
int makeAnnotations( HMONITOR monitor, HBITMAP snippet, RECT bounds, int lang ) {
// Register window class
WNDCLASSW wc = {
CS_OWNDC | CS_HREDRAW | CS_VREDRAW, // style
Expand All @@ -324,11 +324,22 @@ int makeAnnotations( HBITMAP snippet, RECT bounds, int lang ) {
WINDOW_CLASS_NAME // lpszClassName
};
RegisterClassW( &wc );



// Calculate window size from snippet bounds. Add some extra space and a min size to fit buttons
int width = max(600, bounds.right - bounds.left) + 50;
int height = bounds.bottom - bounds.top + 150;

// Determine position on requested monitor
MONITORINFO info;
info.cbSize = sizeof( info );
GetMonitorInfo( monitor, &info );
int x = info.rcWork.left + max( 0, ( ( info.rcWork.right - info.rcWork.left ) - width ) / 2 );
int y = info.rcWork.top + max( 0, ( ( info.rcWork.bottom - info.rcWork.top ) - height ) / 2 );

// Create window
HWND hwnd = CreateWindowExW( WS_EX_TOPMOST, wc.lpszClassName,
localization[ lang ].title, WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
max( 600, bounds.right - bounds.left ) + 50 , bounds.bottom - bounds.top + 150, // Add some extra space and a min size
localization[ lang ].title, WS_VISIBLE | WS_OVERLAPPEDWINDOW, x, y, width, height,
NULL, NULL, GetModuleHandleW( NULL ), 0 );

// GDI+ instances of all available pens
Expand Down
12 changes: 11 additions & 1 deletion ScreenSnippet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,18 @@ static BOOL CALLBACK closeExistingInstance( HWND hwnd, LPARAM lparam ) {
int main( int argc, char* argv[] ) {
SetProcessDPIAware(); // Avoid DPI scaling affecting the resolution of the grabbed snippet

HWND foregroundWindow = GetForegroundWindow();

HMONITOR monitor = MonitorFromWindow( foregroundWindow, MONITOR_DEFAULTTOPRIMARY );

// Cancel screen snippet in progress
EnumWindows( closeExistingInstance, 0 );

// If no command line parameters, this was a request to cancel in-progress snippet tool
if( argc < 2 ) {
if( foregroundWindow ) {
SetForegroundWindow( foregroundWindow );
}
return EXIT_SUCCESS;
}

Expand Down Expand Up @@ -129,7 +136,7 @@ int main( int argc, char* argv[] ) {

// Let the user annotate the screen snippet with drawings
RECT bounds = { 0, 0, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y };
int result = makeAnnotations( snippet, bounds, lang );
int result = makeAnnotations( monitor, snippet, bounds, lang );
if( result == EXIT_SUCCESS ) {
// Save annotated bitmap
Gdiplus::Bitmap bmp( snippet, (HPALETTE)0 );
Expand All @@ -147,6 +154,9 @@ int main( int argc, char* argv[] ) {
}

Gdiplus::GdiplusShutdown( gdiplusToken );
if( foregroundWindow ) {
SetForegroundWindow( foregroundWindow );
}
return EXIT_SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "screen-snippet",
"version": "1.0.0",
"version": "1.0.1",
"description": "screen snippet util for windows, new version",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down

0 comments on commit b018f7b

Please sign in to comment.