Skip to content
This repository has been archived by the owner on Sep 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2 from superp00t/master
Browse files Browse the repository at this point in the history
prevent Windows 7 crash caused by no shcore.dll
  • Loading branch information
richardwilkes authored Jan 18, 2019
2 parents cb2055e + 57668bb commit e8f80e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
33 changes: 20 additions & 13 deletions internal/windows/displays_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@ func (d *driver) Displays() []*webapp.Display {
} else {
var dpiX, dpiY uint32
if err = GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY); err != nil {
jot.Error(err)
} else {
d.Bounds.X = float64(info.MonitorBounds.Left)
d.Bounds.Y = float64(info.MonitorBounds.Top)
d.Bounds.Width = float64(info.MonitorBounds.Right - info.MonitorBounds.Left)
d.Bounds.Height = float64(info.MonitorBounds.Bottom - info.MonitorBounds.Top)
d.UsableBounds.X = float64(info.WorkBounds.Left)
d.UsableBounds.Y = float64(info.WorkBounds.Top)
d.UsableBounds.Width = float64(info.WorkBounds.Right - info.WorkBounds.Left)
d.UsableBounds.Height = float64(info.WorkBounds.Bottom - info.WorkBounds.Top)
d.ScalingFactor = float64(dpiX) / 96
d.IsMain = info.Flags&MONITORINFOF_PRIMARY != 0
result = append(result, d)
// Windows 7 fallback
overallX := GetDeviceCaps(dc, LOGPIXELSX)
overallY := GetDeviceCaps(dc, LOGPIXELSY)

if overallX > 0 && overallY > 0 {
dpiX = uint32(overallX)
dpiY = uint32(overallY)
}
}

d.Bounds.X = float64(info.MonitorBounds.Left)
d.Bounds.Y = float64(info.MonitorBounds.Top)
d.Bounds.Width = float64(info.MonitorBounds.Right - info.MonitorBounds.Left)
d.Bounds.Height = float64(info.MonitorBounds.Bottom - info.MonitorBounds.Top)
d.UsableBounds.X = float64(info.WorkBounds.Left)
d.UsableBounds.Y = float64(info.WorkBounds.Top)
d.UsableBounds.Width = float64(info.WorkBounds.Right - info.WorkBounds.Left)
d.UsableBounds.Height = float64(info.WorkBounds.Bottom - info.WorkBounds.Top)
d.ScalingFactor = float64(dpiX) / 96
d.IsMain = info.Flags&MONITORINFOF_PRIMARY != 0
result = append(result, d)
}
return 1
}, 0); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions internal/windows/shcoredll_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ var (

// GetDpiForMonitor https://docs.microsoft.com/en-us/windows/desktop/api/libloaderapi/nf-libloaderapi-getmodulehandlew
func GetDpiForMonitor(monitor HMONITOR, dpiType int32, dpiX, dpiY *uint32) error {
err := getDpiForMonitor.Find()
if err != nil {
return errs.NewWithCause(getDpiForMonitor.Name, err)
}

ret, _, err := getDpiForMonitor.Call(uintptr(monitor), uintptr(dpiType), uintptr(unsafe.Pointer(dpiX)), uintptr(unsafe.Pointer(dpiY)))
if ret != 0 {
return errs.NewWithCause(getDpiForMonitor.Name, err)
Expand Down

0 comments on commit e8f80e7

Please sign in to comment.