Solved

Loading a Form with the no activate option

Posted on 2004-10-06
16
425 Views
Last Modified: 2011-10-03
Hi

I have a touchscreen and i have created an onscreen keyboard that works. And to keep the focus on the previous application i use a timer to detect what is the current foreground application and detect when it changes.

But you can see the thing flicker on every focus change (when each key is pressed). Plus it might crash under certain conditions.

The windows onscreen keyboard (osk.exe) just doesnt activate when pressed. This is what I want my program to do.

I have heard of a loading a form with a no_activate command, but information on it is very rare.

Does anyone know how to do it

Thanks
Adam
0
Comment
Question by:adam_pedley
  • 8
  • 8
16 Comments
 
LVL 4

Author Comment

by:adam_pedley
ID: 12255342
Hi

I have found two similar posts that might help someone find the answer

http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20666636.html
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20872370.html

But i would need the delphi code converted to vb, if anyone know how to do it

Any help will be greatly appreciated

Thanks
Adam
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12283301
Does anyone out know how to do it

I'm willing to open multiple questions to give the person as many points as they want, as this obviously seems like a very difficult question
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12283420
Hi adam_pedley,

I have studied the links you posted and searched EE as well the Net for a solution.  They all seem to suggest the same method but it just doesn't work in VB.  I wonder if it is a limitation of the forms created by Visual Basic.

~IM
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12283477
hmm, i thought it would of been an API function call that could do it quite easily. Just load a form with a no_activate call.

I suppose its in the way the form is loaded, its probably in the parmeters that vb uses to load the form, yet i wouldnt know how to get to them
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12283603
Finally found the right combination!

The following produced an AlwaysOnTop form that doesn't Activate.  I had NotePad open and maximized.  My app with the one button stays on top.  When I push the button, the form does not activate and the letter "a" was sent to NotePad each time I pressed it.

The form does react a little slower when you drag it around the screen (at least it was on my system).

Regards,

Idle_Mind

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 Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, Y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE

Private Const WS_EX_NOACTIVATE = &H8000000
Private Const GWL_EXSTYLE = (-20)

Private Sub Form_Load()
    Call SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS)
    Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_NOACTIVATE)
End Sub

Private Sub Command1_Click()
    SendKeys "a"
End Sub
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12283621
hi

one quick question before i can test this code

it says me.hwnd is not a member of (myform)

do i need to import something or anything else
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12283628
Sorry, I gave you a VB6 solution.

I need to convert it to VB.Net.

Gimme a couple minutes...

~IM
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 12283726
Here you go...

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents Button4 As System.Windows.Forms.Button
    Friend WithEvents Button5 As System.Windows.Forms.Button
    Friend WithEvents Button6 As System.Windows.Forms.Button
    Friend WithEvents Button7 As System.Windows.Forms.Button
    Friend WithEvents Button8 As System.Windows.Forms.Button
    Friend WithEvents Button9 As System.Windows.Forms.Button
    Friend WithEvents Button10 As System.Windows.Forms.Button
    Friend WithEvents Button11 As System.Windows.Forms.Button
    Friend WithEvents Button12 As System.Windows.Forms.Button
    Friend WithEvents Button13 As System.Windows.Forms.Button
    Friend WithEvents Button15 As System.Windows.Forms.Button
    Friend WithEvents Button16 As System.Windows.Forms.Button
    Friend WithEvents Button17 As System.Windows.Forms.Button
    Friend WithEvents Button18 As System.Windows.Forms.Button
    Friend WithEvents Button19 As System.Windows.Forms.Button
    Friend WithEvents Button20 As System.Windows.Forms.Button
    Friend WithEvents Button21 As System.Windows.Forms.Button
    Friend WithEvents Button22 As System.Windows.Forms.Button
    Friend WithEvents Button23 As System.Windows.Forms.Button
    Friend WithEvents Button24 As System.Windows.Forms.Button
    Friend WithEvents Button25 As System.Windows.Forms.Button
    Friend WithEvents Button26 As System.Windows.Forms.Button
    Friend WithEvents Button29 As System.Windows.Forms.Button
    Friend WithEvents Button30 As System.Windows.Forms.Button
    Friend WithEvents Button31 As System.Windows.Forms.Button
    Friend WithEvents Button32 As System.Windows.Forms.Button
    Friend WithEvents Button33 As System.Windows.Forms.Button
    Friend WithEvents Button34 As System.Windows.Forms.Button
    Friend WithEvents Button35 As System.Windows.Forms.Button
    Friend WithEvents Button36 As System.Windows.Forms.Button
    Friend WithEvents Button37 As System.Windows.Forms.Button
    Friend WithEvents Button38 As System.Windows.Forms.Button
    Friend WithEvents Button14 As System.Windows.Forms.Button
    Friend WithEvents Button28 As System.Windows.Forms.Button
    Friend WithEvents Button39 As System.Windows.Forms.Button
    Friend WithEvents Button40 As System.Windows.Forms.Button
    Friend WithEvents Button41 As System.Windows.Forms.Button
    Friend WithEvents Button42 As System.Windows.Forms.Button
    Friend WithEvents Button43 As System.Windows.Forms.Button
    Friend WithEvents Button44 As System.Windows.Forms.Button
    Friend WithEvents Button45 As System.Windows.Forms.Button
    Friend WithEvents Button46 As System.Windows.Forms.Button
    Friend WithEvents Button47 As System.Windows.Forms.Button
    Friend WithEvents Button48 As System.Windows.Forms.Button
    Friend WithEvents Button49 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button3 = New System.Windows.Forms.Button
        Me.Button4 = New System.Windows.Forms.Button
        Me.Button5 = New System.Windows.Forms.Button
        Me.Button6 = New System.Windows.Forms.Button
        Me.Button7 = New System.Windows.Forms.Button
        Me.Button8 = New System.Windows.Forms.Button
        Me.Button9 = New System.Windows.Forms.Button
        Me.Button10 = New System.Windows.Forms.Button
        Me.Button11 = New System.Windows.Forms.Button
        Me.Button12 = New System.Windows.Forms.Button
        Me.Button13 = New System.Windows.Forms.Button
        Me.Button15 = New System.Windows.Forms.Button
        Me.Button16 = New System.Windows.Forms.Button
        Me.Button17 = New System.Windows.Forms.Button
        Me.Button18 = New System.Windows.Forms.Button
        Me.Button19 = New System.Windows.Forms.Button
        Me.Button20 = New System.Windows.Forms.Button
        Me.Button21 = New System.Windows.Forms.Button
        Me.Button22 = New System.Windows.Forms.Button
        Me.Button23 = New System.Windows.Forms.Button
        Me.Button24 = New System.Windows.Forms.Button
        Me.Button25 = New System.Windows.Forms.Button
        Me.Button26 = New System.Windows.Forms.Button
        Me.Button29 = New System.Windows.Forms.Button
        Me.Button30 = New System.Windows.Forms.Button
        Me.Button31 = New System.Windows.Forms.Button
        Me.Button32 = New System.Windows.Forms.Button
        Me.Button33 = New System.Windows.Forms.Button
        Me.Button34 = New System.Windows.Forms.Button
        Me.Button35 = New System.Windows.Forms.Button
        Me.Button36 = New System.Windows.Forms.Button
        Me.Button37 = New System.Windows.Forms.Button
        Me.Button38 = New System.Windows.Forms.Button
        Me.Button14 = New System.Windows.Forms.Button
        Me.Button28 = New System.Windows.Forms.Button
        Me.Button39 = New System.Windows.Forms.Button
        Me.Button40 = New System.Windows.Forms.Button
        Me.Button41 = New System.Windows.Forms.Button
        Me.Button42 = New System.Windows.Forms.Button
        Me.Button43 = New System.Windows.Forms.Button
        Me.Button44 = New System.Windows.Forms.Button
        Me.Button45 = New System.Windows.Forms.Button
        Me.Button46 = New System.Windows.Forms.Button
        Me.Button47 = New System.Windows.Forms.Button
        Me.Button48 = New System.Windows.Forms.Button
        Me.Button49 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(16, 32)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(24, 24)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Q"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(40, 32)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(24, 24)
        Me.Button2.TabIndex = 1
        Me.Button2.Text = "W"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(64, 32)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(24, 24)
        Me.Button3.TabIndex = 2
        Me.Button3.Text = "E"
        '
        'Button4
        '
        Me.Button4.Location = New System.Drawing.Point(88, 32)
        Me.Button4.Name = "Button4"
        Me.Button4.Size = New System.Drawing.Size(24, 24)
        Me.Button4.TabIndex = 3
        Me.Button4.Text = "R"
        '
        'Button5
        '
        Me.Button5.Location = New System.Drawing.Point(112, 32)
        Me.Button5.Name = "Button5"
        Me.Button5.Size = New System.Drawing.Size(24, 24)
        Me.Button5.TabIndex = 4
        Me.Button5.Text = "T"
        '
        'Button6
        '
        Me.Button6.Location = New System.Drawing.Point(136, 32)
        Me.Button6.Name = "Button6"
        Me.Button6.Size = New System.Drawing.Size(24, 24)
        Me.Button6.TabIndex = 5
        Me.Button6.Text = "Y"
        '
        'Button7
        '
        Me.Button7.Location = New System.Drawing.Point(160, 32)
        Me.Button7.Name = "Button7"
        Me.Button7.Size = New System.Drawing.Size(24, 24)
        Me.Button7.TabIndex = 6
        Me.Button7.Text = "U"
        '
        'Button8
        '
        Me.Button8.Location = New System.Drawing.Point(184, 32)
        Me.Button8.Name = "Button8"
        Me.Button8.Size = New System.Drawing.Size(24, 24)
        Me.Button8.TabIndex = 7
        Me.Button8.Text = "I"
        '
        'Button9
        '
        Me.Button9.Location = New System.Drawing.Point(208, 32)
        Me.Button9.Name = "Button9"
        Me.Button9.Size = New System.Drawing.Size(24, 24)
        Me.Button9.TabIndex = 8
        Me.Button9.Text = "O"
        '
        'Button10
        '
        Me.Button10.Location = New System.Drawing.Point(232, 32)
        Me.Button10.Name = "Button10"
        Me.Button10.Size = New System.Drawing.Size(24, 24)
        Me.Button10.TabIndex = 9
        Me.Button10.Text = "P"
        '
        'Button11
        '
        Me.Button11.Location = New System.Drawing.Point(256, 32)
        Me.Button11.Name = "Button11"
        Me.Button11.Size = New System.Drawing.Size(24, 24)
        Me.Button11.TabIndex = 10
        Me.Button11.Text = "["
        '
        'Button12
        '
        Me.Button12.Location = New System.Drawing.Point(280, 32)
        Me.Button12.Name = "Button12"
        Me.Button12.Size = New System.Drawing.Size(24, 24)
        Me.Button12.TabIndex = 11
        Me.Button12.Text = "]"
        '
        'Button13
        '
        Me.Button13.Location = New System.Drawing.Point(304, 32)
        Me.Button13.Name = "Button13"
        Me.Button13.Size = New System.Drawing.Size(24, 24)
        Me.Button13.TabIndex = 12
        Me.Button13.Text = "\"
        '
        'Button15
        '
        Me.Button15.Location = New System.Drawing.Point(288, 56)
        Me.Button15.Name = "Button15"
        Me.Button15.Size = New System.Drawing.Size(40, 24)
        Me.Button15.TabIndex = 24
        Me.Button15.Text = "Enter"
        '
        'Button16
        '
        Me.Button16.Location = New System.Drawing.Point(264, 56)
        Me.Button16.Name = "Button16"
        Me.Button16.Size = New System.Drawing.Size(24, 24)
        Me.Button16.TabIndex = 23
        Me.Button16.Text = "'"
        '
        'Button17
        '
        Me.Button17.Location = New System.Drawing.Point(240, 56)
        Me.Button17.Name = "Button17"
        Me.Button17.Size = New System.Drawing.Size(24, 24)
        Me.Button17.TabIndex = 22
        Me.Button17.Text = ";"
        '
        'Button18
        '
        Me.Button18.Location = New System.Drawing.Point(216, 56)
        Me.Button18.Name = "Button18"
        Me.Button18.Size = New System.Drawing.Size(24, 24)
        Me.Button18.TabIndex = 21
        Me.Button18.Text = "L"
        '
        'Button19
        '
        Me.Button19.Location = New System.Drawing.Point(192, 56)
        Me.Button19.Name = "Button19"
        Me.Button19.Size = New System.Drawing.Size(24, 24)
        Me.Button19.TabIndex = 20
        Me.Button19.Text = "K"
        '
        'Button20
        '
        Me.Button20.Location = New System.Drawing.Point(168, 56)
        Me.Button20.Name = "Button20"
        Me.Button20.Size = New System.Drawing.Size(24, 24)
        Me.Button20.TabIndex = 19
        Me.Button20.Text = "J"
        '
        'Button21
        '
        Me.Button21.Location = New System.Drawing.Point(144, 56)
        Me.Button21.Name = "Button21"
        Me.Button21.Size = New System.Drawing.Size(24, 24)
        Me.Button21.TabIndex = 18
        Me.Button21.Text = "H"
        '
        'Button22
        '
        Me.Button22.Location = New System.Drawing.Point(120, 56)
        Me.Button22.Name = "Button22"
        Me.Button22.Size = New System.Drawing.Size(24, 24)
        Me.Button22.TabIndex = 17
        Me.Button22.Text = "G"
        '
        'Button23
        '
        Me.Button23.Location = New System.Drawing.Point(96, 56)
        Me.Button23.Name = "Button23"
        Me.Button23.Size = New System.Drawing.Size(24, 24)
        Me.Button23.TabIndex = 16
        Me.Button23.Text = "F"
        '
        'Button24
        '
        Me.Button24.Location = New System.Drawing.Point(72, 56)
        Me.Button24.Name = "Button24"
        Me.Button24.Size = New System.Drawing.Size(24, 24)
        Me.Button24.TabIndex = 15
        Me.Button24.Text = "D"
        '
        'Button25
        '
        Me.Button25.Location = New System.Drawing.Point(48, 56)
        Me.Button25.Name = "Button25"
        Me.Button25.Size = New System.Drawing.Size(24, 24)
        Me.Button25.TabIndex = 14
        Me.Button25.Text = "S"
        '
        'Button26
        '
        Me.Button26.Location = New System.Drawing.Point(24, 56)
        Me.Button26.Name = "Button26"
        Me.Button26.Size = New System.Drawing.Size(24, 24)
        Me.Button26.TabIndex = 13
        Me.Button26.Text = "A"
        '
        'Button29
        '
        Me.Button29.Location = New System.Drawing.Point(248, 80)
        Me.Button29.Name = "Button29"
        Me.Button29.Size = New System.Drawing.Size(24, 24)
        Me.Button29.TabIndex = 34
        Me.Button29.Text = "/"
        '
        'Button30
        '
        Me.Button30.Location = New System.Drawing.Point(224, 80)
        Me.Button30.Name = "Button30"
        Me.Button30.Size = New System.Drawing.Size(24, 24)
        Me.Button30.TabIndex = 33
        Me.Button30.Text = "."
        '
        'Button31
        '
        Me.Button31.Location = New System.Drawing.Point(200, 80)
        Me.Button31.Name = "Button31"
        Me.Button31.Size = New System.Drawing.Size(24, 24)
        Me.Button31.TabIndex = 32
        Me.Button31.Text = ","
        '
        'Button32
        '
        Me.Button32.Location = New System.Drawing.Point(176, 80)
        Me.Button32.Name = "Button32"
        Me.Button32.Size = New System.Drawing.Size(24, 24)
        Me.Button32.TabIndex = 31
        Me.Button32.Text = "M"
        '
        'Button33
        '
        Me.Button33.Location = New System.Drawing.Point(152, 80)
        Me.Button33.Name = "Button33"
        Me.Button33.Size = New System.Drawing.Size(24, 24)
        Me.Button33.TabIndex = 30
        Me.Button33.Text = "N"
        '
        'Button34
        '
        Me.Button34.Location = New System.Drawing.Point(128, 80)
        Me.Button34.Name = "Button34"
        Me.Button34.Size = New System.Drawing.Size(24, 24)
        Me.Button34.TabIndex = 29
        Me.Button34.Text = "B"
        '
        'Button35
        '
        Me.Button35.Location = New System.Drawing.Point(104, 80)
        Me.Button35.Name = "Button35"
        Me.Button35.Size = New System.Drawing.Size(24, 24)
        Me.Button35.TabIndex = 28
        Me.Button35.Text = "V"
        '
        'Button36
        '
        Me.Button36.Location = New System.Drawing.Point(80, 80)
        Me.Button36.Name = "Button36"
        Me.Button36.Size = New System.Drawing.Size(24, 24)
        Me.Button36.TabIndex = 27
        Me.Button36.Text = "C"
        '
        'Button37
        '
        Me.Button37.Location = New System.Drawing.Point(56, 80)
        Me.Button37.Name = "Button37"
        Me.Button37.Size = New System.Drawing.Size(24, 24)
        Me.Button37.TabIndex = 26
        Me.Button37.Text = "X"
        '
        'Button38
        '
        Me.Button38.Location = New System.Drawing.Point(32, 80)
        Me.Button38.Name = "Button38"
        Me.Button38.Size = New System.Drawing.Size(24, 24)
        Me.Button38.TabIndex = 25
        Me.Button38.Text = "Z"
        '
        'Button14
        '
        Me.Button14.Location = New System.Drawing.Point(64, 104)
        Me.Button14.Name = "Button14"
        Me.Button14.Size = New System.Drawing.Size(152, 24)
        Me.Button14.TabIndex = 35
        Me.Button14.Text = "Space"
        '
        'Button28
        '
        Me.Button28.Location = New System.Drawing.Point(272, 8)
        Me.Button28.Name = "Button28"
        Me.Button28.Size = New System.Drawing.Size(56, 24)
        Me.Button28.TabIndex = 47
        Me.Button28.Text = "Back"
        '
        'Button39
        '
        Me.Button39.Location = New System.Drawing.Point(248, 8)
        Me.Button39.Name = "Button39"
        Me.Button39.Size = New System.Drawing.Size(24, 24)
        Me.Button39.TabIndex = 46
        Me.Button39.Text = "="
        '
        'Button40
        '
        Me.Button40.Location = New System.Drawing.Point(224, 8)
        Me.Button40.Name = "Button40"
        Me.Button40.Size = New System.Drawing.Size(24, 24)
        Me.Button40.TabIndex = 45
        Me.Button40.Text = "-"
        '
        'Button41
        '
        Me.Button41.Location = New System.Drawing.Point(200, 8)
        Me.Button41.Name = "Button41"
        Me.Button41.Size = New System.Drawing.Size(24, 24)
        Me.Button41.TabIndex = 44
        Me.Button41.Text = "9"
        '
        'Button42
        '
        Me.Button42.Location = New System.Drawing.Point(176, 8)
        Me.Button42.Name = "Button42"
        Me.Button42.Size = New System.Drawing.Size(24, 24)
        Me.Button42.TabIndex = 43
        Me.Button42.Text = "8"
        '
        'Button43
        '
        Me.Button43.Location = New System.Drawing.Point(152, 8)
        Me.Button43.Name = "Button43"
        Me.Button43.Size = New System.Drawing.Size(24, 24)
        Me.Button43.TabIndex = 42
        Me.Button43.Text = "7"
        '
        'Button44
        '
        Me.Button44.Location = New System.Drawing.Point(128, 8)
        Me.Button44.Name = "Button44"
        Me.Button44.Size = New System.Drawing.Size(24, 24)
        Me.Button44.TabIndex = 41
        Me.Button44.Text = "6"
        '
        'Button45
        '
        Me.Button45.Location = New System.Drawing.Point(104, 8)
        Me.Button45.Name = "Button45"
        Me.Button45.Size = New System.Drawing.Size(24, 24)
        Me.Button45.TabIndex = 40
        Me.Button45.Text = "5"
        '
        'Button46
        '
        Me.Button46.Location = New System.Drawing.Point(80, 8)
        Me.Button46.Name = "Button46"
        Me.Button46.Size = New System.Drawing.Size(24, 24)
        Me.Button46.TabIndex = 39
        Me.Button46.Text = "4"
        '
        'Button47
        '
        Me.Button47.Location = New System.Drawing.Point(56, 8)
        Me.Button47.Name = "Button47"
        Me.Button47.Size = New System.Drawing.Size(24, 24)
        Me.Button47.TabIndex = 38
        Me.Button47.Text = "3"
        '
        'Button48
        '
        Me.Button48.Location = New System.Drawing.Point(32, 8)
        Me.Button48.Name = "Button48"
        Me.Button48.Size = New System.Drawing.Size(24, 24)
        Me.Button48.TabIndex = 37
        Me.Button48.Text = "2"
        '
        'Button49
        '
        Me.Button49.Location = New System.Drawing.Point(8, 8)
        Me.Button49.Name = "Button49"
        Me.Button49.Size = New System.Drawing.Size(24, 24)
        Me.Button49.TabIndex = 36
        Me.Button49.Text = "1"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(336, 134)
        Me.Controls.Add(Me.Button28)
        Me.Controls.Add(Me.Button39)
        Me.Controls.Add(Me.Button40)
        Me.Controls.Add(Me.Button41)
        Me.Controls.Add(Me.Button42)
        Me.Controls.Add(Me.Button43)
        Me.Controls.Add(Me.Button44)
        Me.Controls.Add(Me.Button45)
        Me.Controls.Add(Me.Button46)
        Me.Controls.Add(Me.Button47)
        Me.Controls.Add(Me.Button48)
        Me.Controls.Add(Me.Button49)
        Me.Controls.Add(Me.Button14)
        Me.Controls.Add(Me.Button29)
        Me.Controls.Add(Me.Button30)
        Me.Controls.Add(Me.Button31)
        Me.Controls.Add(Me.Button32)
        Me.Controls.Add(Me.Button33)
        Me.Controls.Add(Me.Button34)
        Me.Controls.Add(Me.Button35)
        Me.Controls.Add(Me.Button36)
        Me.Controls.Add(Me.Button37)
        Me.Controls.Add(Me.Button38)
        Me.Controls.Add(Me.Button15)
        Me.Controls.Add(Me.Button16)
        Me.Controls.Add(Me.Button17)
        Me.Controls.Add(Me.Button18)
        Me.Controls.Add(Me.Button19)
        Me.Controls.Add(Me.Button20)
        Me.Controls.Add(Me.Button21)
        Me.Controls.Add(Me.Button22)
        Me.Controls.Add(Me.Button23)
        Me.Controls.Add(Me.Button24)
        Me.Controls.Add(Me.Button25)
        Me.Controls.Add(Me.Button26)
        Me.Controls.Add(Me.Button13)
        Me.Controls.Add(Me.Button12)
        Me.Controls.Add(Me.Button11)
        Me.Controls.Add(Me.Button10)
        Me.Controls.Add(Me.Button9)
        Me.Controls.Add(Me.Button8)
        Me.Controls.Add(Me.Button7)
        Me.Controls.Add(Me.Button6)
        Me.Controls.Add(Me.Button5)
        Me.Controls.Add(Me.Button4)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.TopMost = True
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Integer

    Private Const WS_EX_NOACTIVATE = &H8000000
    Private Const GWL_EXSTYLE = (-20)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call SetWindowLong(Me.Handle.ToInt32, GWL_EXSTYLE, GetWindowLong(Me.Handle.ToInt32, GWL_EXSTYLE) Or WS_EX_NOACTIVATE)

        Dim c As Control
        Dim b As Button
        For Each c In Me.Controls
            If TypeOf c Is Button Then
                b = CType(c, Button)
                AddHandler b.Click, AddressOf Me.Button_Click
            End If
        Next
    End Sub

    Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim t As String = sender.text
        If t = "Back" Then
            SendKeys.Send("{BACKSPACE}")
        ElseIf t = "Enter" Then
            SendKeys.Send("{ENTER}")
        ElseIf t = "Space" Then
            SendKeys.Send(" ")
        Else
            SendKeys.Send(t)
        End If
    End Sub

End Class
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 4

Author Comment

by:adam_pedley
ID: 12283755
BRILLIANT!

Thanks heaps

how many points do you want

i can open up other questions (simple ones and give you more points)
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12283761
Regarding the drag and drop it looks like since it doesnt activate it doesnt select it before it moves so you just cant see the drag in motion
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12283765
No need for additional points.  The challenge of solving the problem was reward enough.  =)

Thanks for posting an interesting question!

~IM
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12283773
Thanks again :)
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12283774
Yeah...I'm testing to see if subclassing the form and intercepting the WM_MOVING message will allow me to move the form before the mouse is released.

~IM
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12283890
Add the following to your code and the form will move correctly as it is dragged:

' above the form code
Imports System.Runtime.InteropServices

    ' in the form code
    Private Const WM_MOVING = &H216
    Private Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
    End Structure

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = WM_MOVING Then
            Dim r As RECT
            r = DirectCast(Marshal.PtrToStructure(m.LParam, GetType(RECT)), RECT)
            Me.Location = New Point(r.Left, r.Top)
        End If

        MyBase.WndProc(m)
    End Sub
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12283915
BRILLIANT once again

works perfectly

I have started up another question still regarding the onscreen keyboard
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21164561.html

If you have time to help out again

Thanks
Adam
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12284576
After seeing the converted code in your other question on AppBars, I realized how to do the windows style conversion the .Net way (I'm still used to doing certain things the old VB6 way if you hadn't noticed):

Imports System.Runtime.InteropServices

Public Class Form1
    Inherits System.Windows.Forms.Form

'   Windows Form Designer generated code

    Private Const WS_EX_NOACTIVATE = &H8000000
    Private Const WM_MOVING = &H216

    Private Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
    End Structure

    Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
        Get
            Dim cp As CreateParams = MyBase.CreateParams
            cp.ExStyle = cp.ExStyle Or WS_EX_NOACTIVATE
            Return cp
        End Get
    End Property

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = WM_MOVING Then
            Dim r As RECT
            r = DirectCast(Marshal.PtrToStructure(m.LParam, GetType(RECT)), RECT)
            Me.Location = New Point(r.Left, r.Top)
        End If

        MyBase.WndProc(m)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim c As Control
        Dim b As Button
        For Each c In Me.Controls
            If TypeOf c Is Button Then
                b = CType(c, Button)
                AddHandler b.Click, AddressOf Me.Button_Click
            End If
        Next
    End Sub

    Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim t As String = sender.text
        If t = "Back" Then
            SendKeys.Send("{BACKSPACE}")
        ElseIf t = "Enter" Then
            SendKeys.Send("{ENTER}")
        ElseIf t = "Space" Then
            SendKeys.Send(" ")
        Else
            SendKeys.Send(t)
        End If
    End Sub

End Class
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now