Object-oriented support for Visual Basic classes

Source: Internet
Author: User

The most common problem with VB is its object-oriented feature. In fact, VB is an object-based development tool. In VB
The created class supports inheritance. The following is an example:

Create a new project and add a new class module. Set the class name to baseclass.
Then add the following code to baseclass:

Public sub basesub () 'virtual feature, which is implemented in sub-classes

End sub

Add two class modules and set the class names to impclass and impclass2 respectively. Then, write the following in the code window of the class:
Implements baseclass
The above code indicates the class impclass and impclass2 implementation class baseclass.
Add the following code to the impclass window:
Private sub baseclass_basesub () 'implements the basesub method in the base class
Msgbox "hello. This is imp. inherited from baseclass"
End sub

Add the following code to impclass2:
Private sub baseclass_basesub ()
Msgbox "hello. This is imp2. inherited from baseclass"
End sub

After completing the above class code, open form1 and add a commandbutton on it. In the Click Event of the button
Write the following code:

Dim ximp as new impclass
Dim ximp2 as new impclass2
Dim xbase as baseclass

Set xbase = ximp
Xbase. basesub
Set xbase = ximp2
Xbase. basesub
Set xbase = nothing

Set ximp = nothing
Set ximp2 = nothing

Run the program and click commandbutton. The message box is displayed in impclass and impclass2.
Set the message.
From the code above, we can see how to implement object-oriented features in VB: inheritance, virtualization, and polymorphism. Only
Different from Java, C ++, and Object Pascal, VB hides many implementation details.

Q: How do I block the close button X in the form?
A: You can use the API function to gray out the close items in the form menu, because the menus are associated with the close button.
The button is also unavailable. The Code is as follows:

Option explicit

Private declare function getsystemmenu lib "USER32 "_
(Byval hwnd as long, byval brevert as long) as long
Private declare function removemenu lib "USER32 "_
(Byval hmenu as long, byval nposition as long ,_
Byval wflags as long) as long
Private declare function enablemenuitem lib "USER32 "_
(Byval hmenu as long, byval widenableitem as long ,_
Byval wenable as long) as long

Const SC _close = & hf060

Private sub form_load ()
Dim hmenu as long

Hmenu = getsystemmenu (Me. hwnd, 0)
Removemenu hmenu, & hf060, & h200 &
Debug. Print enablemenuitem (hmenu, SC _close, 1)
End sub

 

Www.applevb.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.