Dialog-Fenster nachträglich positionieren

Fehlerberichte, Hilfe und Anregungen zu BasicMaker 2016 für Windows

Moderator: SoftMaker Team

Antworten
GodYa
Beiträge: 11
Registriert: 28.04.2015 18:30:29

Dialog-Fenster nachträglich positionieren

Beitrag von GodYa » 04.06.2015 14:46:08

Ein Lösungsansatz zum nachträglichen positionieren eines benutzerdefinierten Dialog-Fensters (Zentrieren):

Code: Alles auswählen

Type RECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type

Declare Function SetWindowPos Lib "user32.dll" _
        (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _
        ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
        (ByVal lpClassName As Long, ByVal lpWindowName As String) As Long 
Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As Long, ByRef lpRect As RECT) As Long
Declare Function GetSystemMetrics Lib "user32.dll" (ByVal index As Long) As Long

Const SM_CXSCREEN = 0
Const SM_CYSCREEN = 1

Dim sWidth As Long
Dim sHeight As Long

sWidth = GetSystemMetrics(SM_CXSCREEN)
sHeight = GetSystemMetrics(SM_CYSCREEN)

Begin Dialog TestDialog 50, 160, 400, 300, "Test-Dialog", .TestDialogFn
  OKButton 158, 280, 40, 14
  CancelButton 202, 280, 40, 14
End Dialog
Dim DlgDef As TestDialog
rc% = Dialog(DlgDef)

Function TestDialogFn(ControlID$, Action%, SuppValue%)
  Select Case Action%
    Case 1
      Dim hwnd As Long
      Dim res As Long
      Dim wrs As Long
      Dim rec As RECT
      Dim xPos As Long
      Dim yPos As Long
      Dim wWidth As Long
      Dim wHeight As Long
      hwnd = FindWindow(0, "Test-Dialog")
      res = GetWindowRect(hwnd, rec)
      wWidth = (rec.Right - rec.Left)
      wHeight = (rec.Bottom - rec.Top)
      xPos = (sWidth / 2) - (wWidth / 2)
      yPos = (sHeight / 2) - (wHeight / 2)
      wrs = SetWindowPos(hwnd, HWND_TOP, xPos, yPos, wWidth, wHeight, SWP_ASYNCWINDOWPOS)
    Case 2
      'Print onClick
    Case Else
  End Select
End Function

Antworten

Zurück zu „BasicMaker 2016 für Windows“