vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Schützen Sie Ihre Software vor Software-Piraterie - mit sevLock 1.0 DLL!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Ein- und Umsteiger
Re: Anwendung ohne Fokus als Bildschirmtastatur 
Autor: FrankyHH
Datum: 22.05.13 20:21

Hi

Ich hab mir schon mal so eine Bildschirmtastatur geschrieben. Allerdings noch unter VBC (VB6) und nur für den Ziffernblock. Ich verwende nur eine Form und keine weiteren Controls auf der Form. Für die Tasten verwende ich ein Bild das auf die Form gezeichnet wird. Damit die Bildschirmtastatur nicht den Focus bekommt, fange ich die Windowsmessages WM_ACTIVATE und WM_ACTIVATEAPP ab und setze per API SetWindowPos eine neue Position mit den Styles HWND_TOPMOST, SWP_NOSIZE, SWP_NOMOVE und SWP_NOACTIVATE. Das ganze muss man so ähnlich für die Windowsmessage WM_MOVING machen.

Hier mal der VBC Code den ich verwende damit die Bildschirmtastatur nicht den Focus bekommt wenn ein anderes Fenster den Focus hat.
Option Explicit
 
Private Const WS_EX_TOPMOST As Long = &H8&
Private Const WS_EX_NOACTIVATE As Long = &H8000000
Private Const GWL_EXSTYLE As Long = -20&
Private Const GWL_WNDPROC As Long = -4&
Private Const HWND_TOPMOST As Long = -1&
Private Const SWP_NOSIZE As Long = &H1&
Private Const SWP_NOMOVE As Long = &H2&
Private Const SWP_NOACTIVATE As Long = &H10&
Private Const SW_SHOWNOACTIVATE As Long = 4&
Private Const WM_MOVING As Long = &H216&
Private Const WM_ACTIVATE As Long = &H6&
Private Const WM_ACTIVATEAPP As Long = &H1C&
 
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
 
Private Declare Function CallWindowProc Lib "user32" _
                         Alias "CallWindowProcA" ( _
                         ByVal lpPrevWndFunc As Long, _
                         ByVal hwnd As Long, _
                         ByVal Msg As Long, _
                         ByVal wParam As Long, _
                         ByVal lParam As Long) As Long
 
Private Declare Function SetWindowLong Lib "user32" _
                         Alias "SetWindowLongA" ( _
                         ByVal hwnd As Long, _
                         ByVal nIndex As Long, _
                         ByVal dwNewLong As Long) As Long
 
Private Declare Function GetWindowLong Lib "user32" _
                         Alias "GetWindowLongA" ( _
                         ByVal hwnd As Long, _
                         ByVal nIndex As Long) As Long
 
Private Declare Sub SetWindowPos Lib "user32" ( _
                    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)
 
Private Declare Function ShowWindow Lib "user32" ( _
                         ByVal hwnd As Long, _
                         ByVal nCmdShow As Long) As Long
 
Private Declare Sub CopyMemory Lib "kernel32" _
                    Alias "RtlMoveMemory" ( _
                    ByRef Destination As Any, _
                    ByRef Source As Any, _
                    ByVal Length As Long)
 
Private tRect As RECT
Private lngStyle As Long
Private hFrmHwnd As Long
Private lngOldWndProc As Long
 
Sub Main()
 
    Load frmOSK
    hFrmHwnd = frmOSK.hwnd
 
    Call ShowWindow(hFrmHwnd, SW_SHOWNOACTIVATE)
 
    lngStyle = GetWindowLong(hFrmHwnd, GWL_EXSTYLE)
    lngStyle = lngStyle Or WS_EX_NOACTIVATE Or WS_EX_TOPMOST
 
    Call SetWindowLong(hFrmHwnd, GWL_EXSTYLE, lngStyle)
 
    Call SetWindowPos(hFrmHwnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, SWP_NOSIZE Or _
        SWP_NOMOVE Or SWP_NOACTIVATE)
 
    lngOldWndProc = SetWindowLong(hFrmHwnd, GWL_WNDPROC, AddressOf WindowProc)
 
End Sub
 
Public Sub Unhook()
 
    Call SetWindowLong(hFrmHwnd, GWL_WNDPROC, lngOldWndProc)
 
End Sub
 
Private Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal _
  wParam As _
    Long, ByVal lParam As Long) As Long
 
    If uMsg = WM_MOVING Then
 
        Call CopyMemory(tRect, ByVal lParam, LenB(tRect))
 
        Call SetWindowPos(hFrmHwnd, -1, tRect.Left, tRect.Top, tRect.Right - _
            tRect.Left, tRect.Bottom - tRect.Top, 0&)
 
        WindowProc = True
 
        Exit Function
 
    End If
 
    If uMsg = WM_ACTIVATE Or uMsg = WM_ACTIVATEAPP Then
 
        Call SetWindowPos(hFrmHwnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, SWP_NOSIZE Or _
            SWP_NOMOVE Or SWP_NOACTIVATE)
 
    End If
 
    WindowProc = CallWindowProc(lngOldWndProc, hwnd, uMsg, wParam, lParam)
 
End Function
Das komplette VBC Beispiel findest Du hier: http://www.activevb.de/cgi-bin/upload/download.pl?id=3186
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Anwendung ohne Fokus als Bildschirmtastatur1.555Novatlan22.05.13 18:20
Re: Anwendung ohne Fokus als Bildschirmtastatur1.299FrankyHH22.05.13 20:21
Re: Anwendung ohne Fokus als Bildschirmtastatur1.076GPM22.05.13 20:46

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel