Win API - EnumDisplayMonitors [erledigt²]

Übersicht BlitzMax, BlitzMax NG Beginners-Corner

Neue Antwort erstellen

d-bug

Betreff: Win API - EnumDisplayMonitors [erledigt²]

BeitragFr, März 23, 2007 19:53
Antworten mit Zitat
Benutzer-Profile anzeigen
Hallo,

ich gestehe, dass ich der totale API Versager bin. Ich versuche gerade
EnumDisplayMonitors ans laufen zu bekommen, stehe aber völlig auf dem
Schlauch.

Code: [AUSKLAPPEN]
Type TRect
   Field rLeft:Int
   Field rRight:Int
   Field rTop:Int
   Field rBottom:Int
End Type


Extern "win32"
   Function EnumDisplayMonitors (hdc:Int, lprcClip:Int, lpfnEnum:Int, dwData:Byte Ptr)
End Extern


Function EnumMonitors (lpRect:TRect)
   Print "~n------------------------"
   Print lpRect.rLeft
   Print lpRect.rRight
   Print lpRect.rTop
   Print lpRect.rBottom
End Function

Print EnumDisplayMonitors (0,1,EnumMonitors(New TRect),Null)


Ich weiß ehrlich gesagt nicht mal ob das auch nur ansatzweise richtig ist.
zumindest gibt mit EnimDisplayMonitors schonmal keine Fehlermeldungen aus, dafür füllt es aber auch das Rect nicht aus.

Ich nehme mal an, dass ich hdc und lprcClip auch füllen muss, aber ich habe keine Ahnung woher ich die Daten bekommen soll. Außerdem bezweifle ich stark, dass ich ein Type überhaupt so übergeben kann.

Wäre nett, wenn sich jemand erbarmen könnte mir zu helfen.

der bug
  • Zuletzt bearbeitet von d-bug am Sa, März 24, 2007 18:38, insgesamt 3-mal bearbeitet

Markus2

BeitragFr, März 23, 2007 20:56
Antworten mit Zitat
Benutzer-Profile anzeigen
So wie du das gemacht hast bekommt
EnumDisplayMonitors den rückgabewert deiner EnumMonitors Funktion .
So wie ich das in dem VB Beispiel sehe wird die Adresse einer Funk.
angegeben die dann durch EnumDisplayMonitors angesprungen wird (callback function ).

Und die Deklaration stimmt bei dir nicht , siehe ByVal,ByRef
ByRef müßte sowas wie "var" in BMax sein .

Ließ dir die MSDN nochmal durch
Parameters
hdc
[in] Handle to a display device context that defines the visible region of interest.
If this parameter is NULL, the hdcMonitor parameter passed to the callback function will be NULL, and the visible region of interest is the virtual screen that encompasses all the displays on the desktop.

lprcClip
[in] Pointer to a RECT structure that specifies a clipping rectangle. The region of interest is the intersection of the clipping rectangle with the visible region specified by hdc.
If hdc is non-NULL, the coordinates of the clipping rectangle are relative to the origin of the hdc. If hdc is NULL, the coordinates are virtual-screen coordinates.

This parameter can be NULL if you don't want to clip the region specified by hdc.

lpfnEnum
[in] Pointer to a MonitorEnumProc application-defined callback function.
dwData
[in] Application-defined data that EnumDisplayMonitors passes directly to the MonitorEnumProc function.



VB6
Code: [AUSKLAPPEN]

'In a form (Form1)
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@allapi.net
    'set the graphics mode of this form to persistent
    Me.AutoRedraw = True
    'start the enumeration
    EnumDisplayMonitors ByVal 0&, ByVal 0&, AddressOf MonitorEnumProc, ByVal 0&
End Sub

'In a module
Public Const MONITORINFOF_PRIMARY = &H1
Public Const MONITOR_DEFAULTTONEAREST = &H2
Public Const MONITOR_DEFAULTTONULL = &H0
Public Const MONITOR_DEFAULTTOPRIMARY = &H1
Public Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Public Type MONITORINFO
    cbSize As Long
    rcMonitor As RECT
    rcWork As RECT
    dwFlags As Long
End Type
Public Type POINT
    x As Long
    y As Long
End Type
Public Declare Function GetMonitorInfo Lib "user32.dll" Alias "GetMonitorInfoA" (ByVal hMonitor As Long, ByRef lpmi As MONITORINFO) As Long
Public Declare Function MonitorFromPoint Lib "user32.dll" (ByVal x As Long, ByVal y As Long, ByVal dwFlags As Long) As Long
Public Declare Function MonitorFromRect Lib "user32.dll" (ByRef lprc As RECT, ByVal dwFlags As Long) As Long
Public Declare Function MonitorFromWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal dwFlags As Long) As Long
Public Declare Function EnumDisplayMonitors Lib "user32.dll" (ByVal hdc As Long, ByRef lprcClip As Any, ByVal lpfnEnum As Long, ByVal dwData As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Function MonitorEnumProc(ByVal hMonitor As Long, ByVal hdcMonitor As Long, lprcMonitor As RECT, ByVal dwData As Long) As Long
    Dim MI As MONITORINFO, R As RECT
    Debug.Print "Moitor handle: " + CStr(hMonitor)
    'initialize the MONITORINFO structure
    MI.cbSize = Len(MI)
    'Get the monitor information of the specified monitor
    GetMonitorInfo hMonitor, MI
    'write some information on teh debug window
    Debug.Print "Monitor Width/Height: " + CStr(MI.rcMonitor.Right - MI.rcMonitor.Left) + "x" + CStr(MI.rcMonitor.Bottom - MI.rcMonitor.Top)
    Debug.Print "Primary monitor: " + CStr(CBool(MI.dwFlags = MONITORINFOF_PRIMARY))
    'check whether Form1 is located on this monitor
    If MonitorFromWindow(Form1.hwnd, MONITOR_DEFAULTTONEAREST) = hMonitor Then
        Debug.Print "Form1 is located on this monitor"
    End If
    'heck whether the point (0, 0) lies within the bounds of this monitor
    If MonitorFromPoint(0, 0, MONITOR_DEFAULTTONEAREST) = hMonitor Then
        Debug.Print "The point (0, 0) lies wihthin the range of this monitor..."
    End If
    'check whether Form1 is located on this monitor
    GetWindowRect Form1.hwnd, R
    If MonitorFromRect(R, MONITOR_DEFAULTTONEAREST) = hMonitor Then
        Debug.Print "The rectangle of Form1 lies within this monitor"
    End If
    Debug.Print ""
    'Continue enumeration
    MonitorEnumProc = 1
End Function

 

klepto2

BeitragFr, März 23, 2007 21:03
Antworten mit Zitat
Benutzer-Profile anzeigen
Warum denn so kompliziert?

Code: [AUSKLAPPEN]

Type TRect
   Field rLeft:Int
   Field rRight:Int
   Field rTop:Int
   Field rBottom:Int
End Type


Extern "win32"
   Function EnumDisplayMonitors:Int(hdc:Int, lprcClip:Byte Ptr, lpfnEnum:Byte Ptr, dwData:Byte Ptr)
End Extern


Function EnumMonitors:Byte(hMonitor:Int,hdcMonitor:Int,lprcMonitor:TRect,dwData:Int)
    Print "~n------------------------"
    Print "MHandle:" + hmonitor
   Print "MHDC:" + hdcMonitor
    Print "L:"+lprcMonitor.rLeft
    Print "R:"+lprcMonitor.rRight
    Print "T:"+lprcMonitor.rTop
    Print "B:" + lprcMonitor.rBottom
   Return True
End Function

Print EnumDisplayMonitors (Null , Null, EnumMonitors , Null)



Wie Markus schon sagte stimmt deine Deklaration in der Funktion und für die Callback Funktion nicht ganz.
Matrix Screensaver
Console Modul für BlitzMax
KLPacker Modul für BlitzMax

HomePage : http://www.brsoftware.de.vu

d-bug

BeitragFr, März 23, 2007 23:12
Antworten mit Zitat
Benutzer-Profile anzeigen
Vielen Dank für eure Hilfe!

Speziell klepto2 hat mir mal wieder den Arsch gerettet. Wink

der bug

d-bug

BeitragSa, März 24, 2007 14:43
Antworten mit Zitat
Benutzer-Profile anzeigen
Okay, klepto2 rettete mir doch nur den halben Arsch. Anscheinend ist das übergebene Rect-Type nicht so ganz kompatibel.

Nach dem Sortieren der TRect Fields konnte ich immerhin schonmal 2 Werte
richtig bekommen:

Code: [AUSKLAPPEN]
Type TRect
   Field rRight:Int
   Field rBottom:Int
   Field rTop:Int
   Field rLeft:Int
End Type


Code: [AUSKLAPPEN]
Monitor1:
L      : 5363068  <-- sollte eigentlich 0 sein
T      : 0
R      : 1280
B      : 1024

Monitor2 rechts von Monitor1:
L      : 5363068  <-- sollte eigentlich 1280 sein
T      : 0
R      : 2560
B      : 1024


Code: [AUSKLAPPEN]
Monitor1:
L      : 5363068  <-- sollte eigentlich 0 sein
T      : 0
R      : 1280
B      : 1024

Monitor2 links von Monitor1:
L      : 5363068  <-- sollte eigentlich -1280 sein
T      : 0
R      : 0
B      : 1024


Code: [AUSKLAPPEN]
Monitor1:
L      : 5363068  <-- sollte eigentlich 0 sein
T      : 0
R      : 1280
B      : 1024

Monitor2 über Monitor1:
L      : 5363068  <-- sollte eigentlich 0 sein
T      : 0 <-- sollte eigentlich -1024 sein
R      : 1280
B      : 0


Code: [AUSKLAPPEN]
Monitor1:
L      : 5363068  <-- sollte eigentlich 0 sein
T      : 0
R      : 1280
B      : 1024

Monitor2 unter Monitor1:
L      : 5363068  <-- sollte eigentlich 0 sein
T      : 0 <-- sollte eigentlich 1024 sein
R      : 1280
B      : 2048


Wenn ich im TRect den Typ auf Short umstelle, ist wenigstens der der wert rLeft = 0. Alles in allem scheint es so, dass rLeft und rTop nicht korrekt ausgefüllt werden.

Ich glaube ich komme langsam zu dem Punkt, wo ich mir eingestehen sollte, dass ich doch lieber die Finger von der API lassen sollte, weil mir anscheinend jegliches Verständnis dafür fehlt.

cheers

Suco-X

Betreff: ....

BeitragSa, März 24, 2007 15:56
Antworten mit Zitat
Benutzer-Profile anzeigen
Vielleicht gehts so besser.
Code: [AUSKLAPPEN]

Type TRect
   Field rLeft:Int
   Field rTop:Int
   Field rRight:Int
   Field rBottom:Int
End Type


Extern "win32"
   Function EnumDisplayMonitors:Int(hdc:Int, lprcClip:Byte Ptr, lpfnEnum:Byte Ptr, dwData:Byte Ptr)
End Extern


Function EnumMonitors:Byte(hMonitor:Int,hdcMonitor:Int,lprcMonitor:Byte Ptr,dwData:Int)
   Local temp:TRect = New TRect
   MemCopy(Temp, lprcMonitor, SizeOf(Temp))
   
    Print "~n------------------------"
    Print "MHandle:" + hmonitor
   Print "MHDC:" + hdcMonitor
    Print "L:"+Temp.rLeft
    Print "T:"+Temp.rTop
    Print "R:"+Temp.rRight
    Print "B:" + Temp.rBottom
   Return True
End Function

Print EnumDisplayMonitors (Null , Null, EnumMonitors , Null)
Intel Core 2 Quad Q8300, 4× 2500 MHz, 4096 MB DDR2-Ram, GeForce 9600GT 512 MB

d-bug

BeitragSa, März 24, 2007 18:38
Antworten mit Zitat
Benutzer-Profile anzeigen
Danke Suco, genau das war das Heilmittel!

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group