Subclassing window (URGENT!!!)

  • 15 years ago

    Hi all,
    For my client I have to build a onscreen keyboard just like the onscreen keyboard of win2000/xp.


    For this, I need implement the following features in a form/window-
    *Form will not be activated by mouse click in the client area (Below the title bar)
    Here, I also need to know on which button user clicked
    *But form can be activated by mouse click on the titlebar and can be moved
    *Form can be activated by alt/tab focusing


    I know this can be done by subclassing form, but never did that before. Can anybody tell me which


    window messages I need to check for and how to supress/block certain of them?Plz?


    Code examples will be most helpful for me.


    Thanks in advance for your kind help.


    Regards,
    MHasan

  • 15 years ago
    Could you not just use case statements?

    More info....

    I would return the cursor position
    Code:

    Public XCord, YCord As Double    
    Dim XYCord As System.Drawing.Point

    Code:

    Private Sub frmMain_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles frmMain.MouseClick
           'xcord is the x cordinate of the mouse cursor--checks to see when
           'the mouse is clicked
           XCord = e.X
           YCord = e.Y

    select case when xcord>=1 and xcord<=50 'this would be the value return when in the title bar
                     then frmKeyboard.showdialog 'this is the form you want to pull up
    end case

    End Sub

       

    Just an idea.    Hope this helps a little at least!
  • 15 years ago

    I forgot to say, I'm using VB6, not VB.net


    Now, this is what I've done to discard activating a form, but no luck!
    Can anybody figure out the bug?Or what else I should do?


    '*********
    'In  Form1
    Option Explicit


    Private Sub Form_Load()
     InitiateSubclass Me.hWnd
    End Sub


    Private Sub Form_Unload(Cancel As Integer)
     RemoveSubclass hWnd
    End Sub
    '*********



    'In Module1
    '*********
    Option Explicit


    Private mprocOld As Long
    Private Const GWL
    WNDPROC As Long = (-4&)
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&) As Long
    Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd&, ByVal wMsg&, ByVal wParam&, lParam As Any) As Long
    Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc&, ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&) As Long


    Public Const WMNCACTIVATE = &H86
    Public Const WM
    ACTIVATE = &H6
    Public Const WMACTIVATEAPP = &H1C
    Public Const WM
    MOUSEACTIVATE = &H21


    Public Function WindowProc(ByVal hWnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
       If iMsg = WMNCACTIVATE Or iMsg = WMACTIVATE Or iMsg = WMACTIVATEAPP Then
           If wParam = True Then
               WindowProc = 0
               Exit Function
           End If
       End If
       WindowProc = CallWindowProc(m
    procOld, hWnd, iMsg, wParam, lParam)
    End Function


    Public Sub InitiateSubclass(ByVal hWnd&)
       mprocOld = SetWindowLong(hWnd, GWLWNDPROC, AddressOf WindowProc)
    End Sub


    Public Sub RemoveSubclass(ByVal hWnd&)
       Call SetWindowLong(hWnd, GWLWNDPROC, mprocOld)
    End Sub
    '*********

  • 15 years ago
    Sorry--I've forgotten vb6, but you are in the vb6 forom--that was my fault.    Even so, does vb6 not have case statements or does it not have system.drawing.points?  I'm a bit rusty.  

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It works on my machine.” - Anonymous