[VB.NET] Findwindow declaration

Pagina: 1
Acties:

  • MuggenHor
  • Registratie: Juli 2003
  • Laatst online: 11-05 22:42
Ik probeer met behulp van de FindWindow function de hwnd van winamp te achterhalen maar het lukt nietzo, kan iemand mij helpen

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
Public Class Form1
    Inherits System.Windows.Forms.Form
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim hWndWinamp As Long

'{ Windows Form Designer generated code }

    Private Sub Label1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.Click
        hWndWinamp = FindWindow("Winamp v1.x", vbNullString)
        Label1.Text = "&H" & Hex(hWndWinamp) & " " & CStr(hWndWinamp)
    End Sub
End Class


Volgens mij ligt het probleem aan het declareren ofso. want ik krijg er geen 0 als hwnd uit maar een telkens veranderende handle (hwnd=window handle)

[ Voor 15% gewijzigd door MuggenHor op 03-03-2004 19:16 ]

Waarheid is pas waarheid als het tegendeel ook waarheid is.


  • MuggenHor
  • Registratie: Juli 2003
  • Laatst online: 11-05 22:42
Ik heb de code nu ff in vb6 geknipt en geplakt, en nu werkt ie perfect. Dus nu snap ik er helemaal nx meer van

vb6code
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Private hWndWinamp As Long

'Key Constants
Private Const VK_AUDIO_NEXT = &HB0
Private Const VK_AUDIO_PREV = &HB1
Private Const VK_AUDIO_STOP = &HB2
Private Const VK_AUDIO_PLAYPAUSE = &HB3
Private Const VK_AUDIO_MEDIA = &HB5
'Window message constants
Private Const WM_COMMAND = &H111
Private Const WM_USER = &H400

Private Sub tmrKeyScan_Timer()
    Dim nRet As Integer, nChar As Integer, LWinKey As Integer, RWinKey As Integer, WinKey As Integer
    LWinKey = GetAsyncKeyState(&H5B)
    RWinKey = GetAsyncKeyState(&H5C)
    WinKey = LWinKey Or RWinKey
    For nChar = 1 To 255
        nRet = GetAsyncKeyState(nChar)
        If nRet = -32767 Then
            Select Case nChar
                Case VK_AUDIO_PREV
                    If Not (Not hWndWinamp) Then
                        If WinKey = -32767 Then
                            'Windows key has been pressed in combination with the audio previous button,
                            'so let's toggle repeat by emulating the repeat button being pressed
                            nRet = SendMessage(hWndWinamp, WM_COMMAND, 0, 40022)
                        Else
                            'Emulates the previous button being pressed
                            nRet = SendMessage(hWndWinamp, WM_COMMAND, 0, 40044)
                        End If
                    End If
                Case VK_AUDIO_PLAYPAUSE
                    If Not (Not hWndWinamp) Then
                        'Check's if Winamp is playing or not ( first bit of nRet indicates that
                        'winamp is playing, second that winamp is paussed )
                        nRet = SendMessage(hWndWinamp, WM_USER, 0, 104)
                        If nRet And 1 Then
                            'Winamp is NOT stopped but playing or paused
                            'So we emulate the pause button being pressed
                            nRet = SendMessage(hWndWinamp, WM_COMMAND, 0, 40046)
                        Else
                            'Winamp is stopped so we emulate the play button begin pressed
                            nRet = SendMessage(hWndWinamp, WM_COMMAND, 0, 40045)
                        End If
                    End If
                Case VK_AUDIO_STOP
                    If Not (Not hWndWinamp) Then
                        'Check if one of the windows keys is pressed
                        If WinKey = -32767 Then
                            'Windows key has been pressed in combination with the audio stop button,
                            'so let's close winamp
                            nRet = SendMessage(hWndWinamp, WM_COMMAND, 0, 40001)
                        Else
                            'Emulates the stop button being pressed
                            nRet = SendMessage(hWndWinamp, WM_COMMAND, 0, 40047)
                        End If
                    End If
                Case VK_AUDIO_NEXT
                    If Not (Not hWndWinamp) Then
                        If WinKey = -32767 Then
                            'Windows key has been pressed in combination with the audio next button,
                            'so let's toggle shuffle by emulating the shuffle button being pressed
                            nRet = SendMessage(hWndWinamp, WM_COMMAND, 0, 40023)
                        Else
                            'Emulates the next button being pressed
                            nRet = SendMessage(hWndWinamp, WM_COMMAND, 0, 40048)
                        End If
                    End If
                Case VK_AUDIO_MEDIA
                    'Let's start winamp
                    Shell "C:\Program Files\Winamp\winamp.exe", vbNormalFocus
            End Select
        End If
    Next nChar
End Sub

Private Sub tmrWinampAlive_Timer()
    hWndWinamp = FindWindow("Winamp v1.x", vbNullString)
End Sub

Waarheid is pas waarheid als het tegendeel ook waarheid is.


  • MuggenHor
  • Registratie: Juli 2003
  • Laatst online: 11-05 22:42
werkt vb.net misschien anders met declarations ofsow of hoe zit dat?

Waarheid is pas waarheid als het tegendeel ook waarheid is.


Verwijderd

Je gebruikt VB6 code in .NET, dat gaat al niet goed. En het is niet zozeer de declaratie maar de functies die jij gebruikt.

Wat geeft je compiler terug voor warnings/errors?

/me heeft verder niet echt naar je code gekeken

[ Voor 19% gewijzigd door Verwijderd op 03-03-2004 23:51 ]


  • MuggenHor
  • Registratie: Juli 2003
  • Laatst online: 11-05 22:42
Verwijderd schreef op 03 maart 2004 @ 23:49:
Je gebruikt VB6 code in .NET, dat gaat al niet goed. En het is niet zozeer de declaratie maar de functies die jij gebruikt.

Wat geeft je compiler terug voor warnings/errors?

/me heeft verder niet echt naar je code gekeken
ik krijg geen enkele warning of error dat is het probleem zo weet ik niet waar de fout zit

Waarheid is pas waarheid als het tegendeel ook waarheid is.


  • whoami
  • Registratie: December 2000
  • Laatst online: 00:40
Verwijderd schreef op 03 maart 2004 @ 23:49:
Je gebruikt VB6 code in .NET, dat gaat al niet goed. En het is niet zozeer de declaratie maar de functies die jij gebruikt.

Wat geeft je compiler terug voor warnings/errors?

/me heeft verder niet echt naar je code gekeken
Je kan in .NET wel een call doen naar 'unmanaged' functions, zoals API functies enzo.
Ik doe geen VB6 of VB.NET, maar ik denk wel dat het dat is wat hij hier doet. Dat zou dus normaal gezien wel werken.

https://fgheysels.github.io/


  • Markieman
  • Registratie: December 2001
  • Laatst online: 15-05 12:16
Beetje offtopic:

Maar, wat is dit voor een raar statement?
code:
1
If Not (Not hWndWinamp) Then


Is dat niet hetzelfde als:
code:
1
If hWndWinamp Then

You do not fear them? - The Wraith? Naah. Now *clowns*, that's another story.


  • MuggenHor
  • Registratie: Juli 2003
  • Laatst online: 11-05 22:42
Markieman schreef op 15 maart 2004 @ 09:36:
Beetje offtopic:

Maar, wat is dit voor een raar statement?
code:
1
If Not (Not hWndWinamp) Then


Is dat niet hetzelfde als:
code:
1
If hWndWinamp Then
hmmm, ik zie het ja, tsjah ik was denk ik ff in een wazige bui ofsow.

Waarheid is pas waarheid als het tegendeel ook waarheid is.


  • MuggenHor
  • Registratie: Juli 2003
  • Laatst online: 11-05 22:42
Verwijderd schreef op 03 maart 2004 @ 23:49:
Je gebruikt VB6 code in .NET, dat gaat al niet goed. En het is niet zozeer de declaratie maar de functies die jij gebruikt.

Wat geeft je compiler terug voor warnings/errors?

/me heeft verder niet echt naar je code gekeken
nee, ik heb deze 2e codelisting aangepast aan vb6 en daardoor is die listing een vb6 listing

Waarheid is pas waarheid als het tegendeel ook waarheid is.

Pagina: 1