|
-
May 12th, 2003, 11:09 AM
#1
Thread Starter
Member
problem with api-call
hi... i've a problem with an api-call
the class should prevent the ExtCombobox from opening the dropdown-box.
Code:
Public Class ExtComboBox
Inherits ComboBox
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public 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 GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, ByVal lpRect As RECT) As Long
Private Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Structure rect
Dim Left As Long
Dim Top As Long
Dim Right As Long
Dim Botton As Long
End Structure
Private Const GWL_WNDPROC = (-4)
Private Const WM_CTLCOLORLISTBOX = &H134
Private lbRect As rect
Private hWndLB As Long
Private OldWndPrg As Long
' Subclassing einschalten
Public Sub ChangeWndPrg(ByVal hwnd As Long)
OldWndPrg = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WndPrg)
End Sub
' Subclassing ausschalten
Public Sub ResetWndPrg(ByVal hwnd As Long)
SetWindowLong(hwnd, GWL_WNDPROC, OldWndPrg)
End Sub
Public Function WndPrg(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
If uMsg = WM_CTLCOLORLISTBOX Then
' lParam = Handler für Listbox-Window
hWndLB = lParam
' Ausmasse des Windows ermitteln, das erzeugt wird
GetWindowRect(hWndLB, lbRect)
' Wir verhindern damit, dass die Listbox aufgeklappt wird
' Parameter: SW_Hidde = 0&
ShowWindow(hWndLB, 0&)
End If
' Alle Nachrichten an die Fensterprozedur weiterleiten
Return CallWindowProc(OldWndPrg, hwnd, uMsg, wParam, lParam)
End Function
End Class
The compiler doesn't accept this code because in ChangeWndPrg the AdressOf-instruction doesn't return a long value.
has andybody an idea how to solve this problem?
thanks
robert
-
May 12th, 2003, 11:33 AM
#2
Sleep mode
Change the long to interger and see if that's the problem !
-
Oct 23rd, 2003, 03:39 PM
#3
Hyperactive Member
You must add a delegate for the AddressOf operator, and change the parameter of the function declaration to the Delegate type.
See the following topic in the online MSDN Library:
http://msdn.microsoft.com/library/en...l/vbup1048.asp
-
Oct 23rd, 2003, 04:54 PM
#4
Hyperactive Member
I have a problem with the API call GetWindowLong in regard to the AddressOf operator though.
Does anyone know how to use the GetWindowLong API call in VB.NET using the GWL_WNDPROC constant as the last parameter, and then use the return value to point to a delegate using the AddressOf operator? Yes it's probably easier said than done. But take a look at this scenario:
I have a class named CFoo, okay. It has a Public variable named lpPrevWndFunc, another called frm of type Windows.Forms.Form, and another variable called hwnd of type Long.
I have an instance of the CFoo class called Foo. Okay, now... in a public module SubClass.vb:
VB Code:
Module modSubclass
Delegate Function SubClassProcDelegate(ByVal hwnd As Integer, _
ByVal msg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As Integer
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Integer, _
ByVal hwnd As Integer, _
ByVal msgWinMessage As Integer, _
ByVal wParam As Integer, _
ByRef lParam As Integer) As Integer
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"
(ByVal hwnd As Integer, _
ByVal nIndex As Integer, _
ByVal dwNewLong As SubClassProcDelegate) As Integer
Private Function SubclassWndProc(ByVal hwnd As Integer, _
ByVal msgWinMessage As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As Integer
' code hidden ;oP
End Function
Public Sub DoSubclass(ByRef frm As Windows.Forms.Form)
Dim Foo As New CFoo
' Create the object as a form
Foo.frm = frm
Foo.hwnd = frm.Handle.ToInt32
Foo.lpPrevWndFunc = GetWindowLong(frm.Handle.ToInt32, GWL_WNDPROC)
' Replace the basic window procedure of the
' form calling this procedure
Call SetWindowLong(frm.Handle.ToInt32, _
GWL_WNDPROC, _
AddressOf SubclassWndProc)
End Sub
Public Sub UnSubClass(ByRef frm As Windows.Forms.Form)
Dim hHelp As New HTMLHelp
' Release the subclassed form
Call SetWindowLong(frm.Handle.ToInt32, _
GWL_WNDPROC, _
Foo.lpPrevWndFunc)
End Sub
End Module
My real question is... of what type should the class member lpPrevWndFunc be in the class CFoo? Can it be of Type AppName.modSubClass.SubClassProcDelegate? Because if it can then the GetWindowLong returns a value of the wrong type. I would get the error:
Value of type 'Integer' cannot be converted to 'AppName.modSubclass.SubClassProcDelegate'.
Thanks to anyone who makes effort in helping me out.
Last edited by jovton; Oct 24th, 2003 at 03:19 AM.
jovton
-
Oct 23rd, 2003, 08:52 PM
#5
try this link for an article on codeproject...
Subclassing in VB.Net
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Oct 23rd, 2003, 09:21 PM
#6
a simple example of subclassing controls , based on the above is this ....
VB Code:
[Color=Blue]Private[/COLOR] [Color=Blue]Const[/COLOR] WM_CTLCOLORLISTBOX [Color=Blue]As[/COLOR] [Color=Blue]Integer[/COLOR] = [Color=Blue]CInt[/COLOR](&H134)
[Color=Blue]Private[/COLOR] [Color=Blue]Declare[/COLOR] [Color=Blue]Function[/COLOR] ShowWindow [Color=Blue]Lib[/COLOR] "user32.dll" ([Color=Blue]ByVal[/COLOR] hwnd [Color=Blue]As[/COLOR] [Color=Blue]Integer[/COLOR], [Color=Blue]ByVal[/COLOR] nCmdShow [Color=Blue]As[/COLOR] [Color=Blue]Integer[/COLOR]) [Color=Blue]As[/COLOR] [Color=Blue]Integer
[/COLOR] [Color=Blue]Private[/COLOR] [Color=Blue]WithEvents[/COLOR] sbclss [Color=Blue]As[/COLOR] SubClass
[Color=Blue]Private[/COLOR] [Color=Blue]Sub[/COLOR] Button1_Click([Color=Blue]ByVal[/COLOR] sender [Color=Blue]As[/COLOR] System.Object, [Color=Blue]ByVal[/COLOR] e [Color=Blue]As[/COLOR] System.EventArgs) [Color=Blue]Handles[/COLOR] Button1.Click
sbclss = [Color=Blue]New[/COLOR] SubClass(ComboBox1.Handle)
sbclss.IsSubClassed = [Color=Blue]True
[/COLOR] [Color=Blue]End[/COLOR] [Color=Blue]Sub
[/COLOR] [Color=Blue]Private[/COLOR] [Color=Blue]Sub[/COLOR] sbclss_Proc([Color=Blue]ByVal[/COLOR] m [Color=Blue]As[/COLOR] Message) [Color=Blue]Handles[/COLOR] sbclss.MyBaseProc
[Color=Blue]If[/COLOR] m.Msg = WM_CTLCOLORLISTBOX [Color=Blue]Then
[/COLOR] ShowWindow(m.HWnd.ToInt32, 0)
[Color=Blue]End[/COLOR] [Color=Blue]If
[/COLOR] [Color=Blue]End[/COLOR] [Color=Blue]Sub
End[/COLOR] [Color=Blue]Class
Public[/COLOR] [Color=Blue]Class[/COLOR] SubClass
[Color=Blue]Inherits[/COLOR] System.Windows.Forms.NativeWindow
[Color=Blue]Public[/COLOR] [Color=Blue]Event[/COLOR] MyBaseProc([Color=Blue]ByVal[/COLOR] m [Color=Blue]As[/COLOR] Message)
[Color=Blue]Public[/COLOR] IsSubClassed [Color=Blue]As[/COLOR] [Color=Blue]Boolean[/COLOR] = [Color=Blue]False
[/COLOR] [Color=Blue]Sub[/COLOR] [Color=Blue]New[/COLOR]([Color=Blue]ByVal[/COLOR] Handle [Color=Blue]As[/COLOR] IntPtr)
[Color=blue]MyBase[/color].AssignHandle(Handle)
[Color=Blue]End[/COLOR] [Color=Blue]Sub
[/COLOR] [Color=Blue]Protected[/COLOR] [Color=Blue]Overrides[/COLOR] [Color=Blue]Sub[/COLOR] WndProc([Color=Blue]ByRef[/COLOR] m [Color=Blue]As[/COLOR] System.Windows.Forms.Message)
[Color=Blue]If[/COLOR] IsSubClassed [Color=Blue]Then
[/COLOR] [Color=Blue]RaiseEvent[/COLOR] MyBaseProc(m)
[Color=Blue]End[/COLOR] [Color=Blue]If
[/COLOR] [Color=blue]MyBase[/color].WndProc(m)
[Color=Blue]End[/COLOR] [Color=Blue]Sub
End[/COLOR] [Color=Blue]Class[/COLOR]
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Oct 24th, 2003, 03:06 AM
#7
Hyperactive Member
Seeing that I'm in the early stages of the migration phase I would state that you my friend, are a lifesaver! Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|