|
-
Mar 31st, 2001, 06:52 PM
#1
Thread Starter
PowerPoster
Ok, I'm just messing around with subclassing. How would I subclass a text boxes keydown event so if a user presses a key, the key is canceled so nothing gets entered into the textbox. thanks
-
Mar 31st, 2001, 07:03 PM
#2
Hyperactive Member
Let me check that one out
Hi Paul,
There is already an intrinsic event on that in VB. Textbox_keydown event.
But if you want the Windows Message, I will have to get back to you on that
William T
Software Architect / Chief Software Developer
Softwaremaker.Net Pte Ltd
http://www.Softwaremaker.net
*** Things are always the darkest before they go pitch black ***
-
Mar 31st, 2001, 07:05 PM
#3
Thread Starter
PowerPoster
Yeah, I know there is an intrinsic keypress event for the textbox, but I'm just Messing around with subclassing. Oh by the way, my name isn't Paul My Name is Marco
-
Mar 31st, 2001, 07:07 PM
#4
That's correct, you don't event need subclasing, but if you want it, here it is:
Add to a Module
Code:
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
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
Const GWL_WNDPROC = (-4)
Const WM_CHAR = &H102
Global WndProcOld As Long
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = WM_KEYDOWN Then Exit Function
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
Sub SubClassWnd(hwnd As Long)
WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
End Sub
Sub UnSubclassWnd(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
WndProcOld& = 0
End Sub
Add to a Form
Code:
Private Sub Form_Load()
SubClassWnd Text1.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd Text1.hwnd
End Sub
-
Mar 31st, 2001, 07:09 PM
#5
Hyperactive Member
to answer
Ok Paul,
The windows message you want is the constant WM_KeyDown = &H100
When you reveive this message from the default windows, exit the function (therefore it does nothing). Any other messages, you HAVE to pass along to the new window.
Remember to unhook the function once you have finished or your VB will crash !!!
William T
Software Architect / Chief Software Developer
Softwaremaker.Net Pte Ltd
http://www.Softwaremaker.net
*** Things are always the darkest before they go pitch black ***
-
Mar 31st, 2001, 07:10 PM
#6
Thread Starter
PowerPoster
Thanks Megatron, I know there was an event already...
I just wanted to see an example used with subclassing,
just to get my feet wet so to speak...
-
Mar 31st, 2001, 07:11 PM
#7
Hyperactive Member
Hi guys
Hi Guys,
Sorry Marco....
Hi Megatron, I am still working in the scrollable forms you have helped me with. Dont you ever sleep...
William T
Software Architect / Chief Software Developer
Softwaremaker.Net Pte Ltd
http://www.Softwaremaker.net
*** Things are always the darkest before they go pitch black ***
-
Mar 31st, 2001, 07:17 PM
#8
Thread Starter
PowerPoster
No problem about the Paul thing....My name always get pronouned backwards 
Megatron, I tried your code and vb crashed so I added the WM_KeyDown constant and when I entered something into the text box, nothing happened. Am I missing something. thanks, I'm new to subclassing
-
Mar 31st, 2001, 07:23 PM
#9
Hyperactive Member
Hi Lethal
Nothing happened, because you have already subclassed that message...meaning your textbox will not receive anything once it receives the Keydown event.
William T
Software Architect / Chief Software Developer
Softwaremaker.Net Pte Ltd
http://www.Softwaremaker.net
*** Things are always the darkest before they go pitch black ***
-
Mar 31st, 2001, 07:26 PM
#10
Thread Starter
PowerPoster
No No...I mean that text was still able to be entered, the whole point of the subclassing the textbox is so that
nothing will be entered.
-
Mar 31st, 2001, 07:36 PM
#11
Thread Starter
PowerPoster
Anyone?? I just hate putting topics to rest before I know what is going on.
-
Mar 31st, 2001, 07:45 PM
#12
Hyperactive Member
Hi Marco
I am still trying to find the correct message.
Megatronic's Codes works fine. But I think Windows recieves a message before the WM_keyDown event and I am still trying to figure out what it is...
William T
Software Architect / Chief Software Developer
Softwaremaker.Net Pte Ltd
http://www.Softwaremaker.net
*** Things are always the darkest before they go pitch black ***
-
Mar 31st, 2001, 07:49 PM
#13
Use the X in the corner instead of the Stop button in the VB IDE. If you don't, then it will crash.
-
Mar 31st, 2001, 07:51 PM
#14
SoftwareMaker: There is no message before WM_KEYDOWN. This is the first message, but the TextBox ignores it, and processes the WM_CHAR message instead.
My code works fine, but whenever you subclass in VB, you need to make sure tht you close it with the X in the corner (rather than the stop button), otherwise it will crash.
-
Mar 31st, 2001, 07:53 PM
#15
Thread Starter
PowerPoster
Ok, I figured it out. Megatron, you used KeyDown instead of WM_Char. Thank You once again
-
Mar 31st, 2001, 08:00 PM
#16
Hyperactive Member
Ummmm...
Sorry Guys,
I tried out Megatronics Codes as it is...and Textbox still receives the messages.
Why is that so ? Sorry for the stupid question
William T
Software Architect / Chief Software Developer
Softwaremaker.Net Pte Ltd
http://www.Softwaremaker.net
*** Things are always the darkest before they go pitch black ***
-
Mar 31st, 2001, 08:01 PM
#17
Thread Starter
PowerPoster
Change the code in the form module to this:
Code:
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = WM_CHAR Then
End If
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
-
Mar 31st, 2001, 08:03 PM
#18
Hyperactive Member
OK I Got it
OK, I got it....Oops.. Syntax Error....
William T
Software Architect / Chief Software Developer
Softwaremaker.Net Pte Ltd
http://www.Softwaremaker.net
*** Things are always the darkest before they go pitch black ***
-
Mar 31st, 2001, 08:06 PM
#19
Hyperactive Member
Hi Megatron
Hi Megatron,
Did you figure out the scrollable forms you helped me with.
The form scrolls perfectly and from right to left when I move the scrollBar from left to right BUT when I scroll the bar the other way around, the form STILL scrolls from left to right and all the controls disappears into the left.
William T
Software Architect / Chief Software Developer
Softwaremaker.Net Pte Ltd
http://www.Softwaremaker.net
*** Things are always the darkest before they go pitch black ***
-
Mar 31st, 2001, 08:28 PM
#20
Hyperactive Member
Hi Megatronics
Hi M,
I have tweaked it so that now the controls can move accordingly to the directions I scrolled.
All I did was to check for descending or ascending Hscroll values and then if it was descending value, move the controls to the left...If it was ascending, move it to the right.
Thanks for all your help. I really appreciate it very much.
William T
Software Architect / Chief Software Developer
Softwaremaker.Net Pte Ltd
http://www.Softwaremaker.net
*** Things are always the darkest before they go pitch black ***
-
Mar 31st, 2001, 08:33 PM
#21
Thread Starter
PowerPoster
Hey Software, just out of curiosity, how did you find out my name. Doesn't matter to me, just wondering
-
Mar 31st, 2001, 08:39 PM
#22
Hyperactive Member
Hi Lethal
You gave me your email a couple of weeks back when I ask for it if I ever needed help. I just kinda gather your name (the wrong one...obviously) from your email...
I remembered you said that its OK to ask you questions as it keeps you on your toes.
Did I refresh your memory now ?
William T
Software Architect / Chief Software Developer
Softwaremaker.Net Pte Ltd
http://www.Softwaremaker.net
*** Things are always the darkest before they go pitch black ***
-
Mar 31st, 2001, 08:41 PM
#23
Thread Starter
PowerPoster
heheh...yes you did. I remember now.
-
Mar 31st, 2001, 08:53 PM
#24
Hyperactive Member
Thanks Marco
Thanks for all your help Marco. I appreciate it.
William T
Software Architect / Chief Software Developer
Softwaremaker.Net Pte Ltd
http://www.Softwaremaker.net
*** Things are always the darkest before they go pitch black ***
-
Apr 1st, 2001, 11:54 AM
#25
Ack, I just saw my mistake now, I declared WM_CHAR, but I used WM_KEYDOWN in my code.
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
|