Avatar billede krismort Nybegynder
06. marts 2001 - 15:22 Der er 3 kommentarer og
1 løsning

GetPixel

Jeg har lavet et lille program der ser sådan her ud:

\'---------- modul: ---------------------
Public Declare Function WindowFromPoint Lib \"user32\" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Public Declare Function GetCursorPos Lib \"user32\" (lpPoint As POINTAPI) As Long
Public Declare Function GetPixel Lib \"gdi32\" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Public Declare Function GetWindowDC Lib \"user32\" (ByVal wnd As Long) As Long

Public Type POINTAPI
x As Long
y As Long
End Type

public P as pointapi
public tmpVal as long
\'---------form-----------------------

Private Sub Timer1_Timer() \'interval = 1

tmpval = GetCursorPos(P)

tmpval = GetPixel(GetWindowDC(WindowFromPoint(P.x, P.y)), P.x, P.y)

Label1.Caption = tmpval

End Sub

Programmet skulle (hvis det virkede) vise hvilken farve pixel musen befinder sig over dette skulle være noteret i label1.caption

hvad der sker er at -1 noteres istedet..-1 er imidlertidig error return værdien for getpixel...

Hvordan for jeg det til at fungere så de rigtige værdier for pixlerne angives?

På forhånd tak
Kristian
Avatar billede hoejrup Nybegynder
06. marts 2001 - 15:27 #1
Har du husket at lave en

Declare Function GetCursorPos Lib \"user32\"

GetCursorPos() is a Windows procedure, not a Visual Basic procedure

/per
Avatar billede hoejrup Nybegynder
06. marts 2001 - 15:28 #2
Du skal faktisk også huske at skrive

[ccc](lpPoint As POINTAPI) As Long

/per
Avatar billede krismort Nybegynder
06. marts 2001 - 16:01 #3
hmm...hoejrup jeg ved ikke hvad du snakker om ;) (se koden)
Det er jo osse getpixel som var problemet men nu har jeg selv fundet en løsning :)
Her kommer koden hvis andre for brug/har for den:

\'-------modul---------
Public Declare Function WindowFromPoint Lib \"user32\" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Public Declare Function GetCursorPos Lib \"user32\" (lpPoint As POINTAPI) As Long
Public Declare Function GetPixel Lib \"gdi32\" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Public Declare Function GetWindowDC Lib \"user32\" (ByVal wnd As Long) As Long
Public Declare Function GetWindowRect Lib \"user32.dll\" (ByVal hwnd As Long, lpRect As RECT) As Long

Public Type POINTAPI
x As Long
y As Long
End Type

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


\'--------form---------
Private Sub Timer1_Timer()
Dim tmpval As Long
Dim r As RECT
Dim retval As Long

Dim P As POINTAPI
k$ = GetCursorPos(P)
j$ = WindowFromPoint(P.x, P.y)

wnd = GetForegroundWindow
dc = GetWindowDC(wnd)


retval = GetWindowRect((WindowFromPoint(P.x, P.y)), r)
Label5.Caption = \"hwnd_W: \" & (r.Right - r.Left)
Label6.Caption = \"hwnd_H: \" & (r.Bottom - r.Top)
Label7.Caption = \"hwnd musX: \" & P.x - r.Left
Label8.Caption = \"hwnd musY: \" & P.y - r.Top

Label4.Caption = \"hDC: \" & GetWindowDC(WindowFromPoint(P.x, P.y))
tmpval = GetPixel(GetWindowDC(WindowFromPoint(P.x, P.y)), (P.x - r.Left), (P.y - r.Top))

Label1.Caption = k$
Label2.Caption = j$
Label3.Caption = tmpval

End Sub

Den retunerer rpg værdien for ethvert område i skærmen nu

Kristian Mortensen
Avatar billede krismort Nybegynder
06. marts 2001 - 16:02 #4
->Jeg snupper lige pointene igen :)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester