VB.NET/VB declaring API functions to implement parent form functionality

Source: Internet
Author: User

Recalling the first knock on the computer room charges, I call the API function to implement the parent form and its sub-form to minimize the function, and now again encountered, they are thinking, can you continue to use the API function? The answer is of course the course!

Actually look at the two is not much difference, first see how to call in vb.net:

First, add a class module to encapsulate this API function:

<span style= "FONT-SIZE:14PX;" > Public Declare Function SetParent Lib "<span style=" color: #ff0000; " >user32</span> "(ByVal hwndchild As Integer, ByVal hwndnewparent as Integer) as integer</span>

And then call it directly in the form to meet your needs.

<span style= "FONT-SIZE:14PX;" >setparent (Frmregistercard.handle.toint<span style= "color: #ff0000;" >32</span>, Me.handle.toint<span style= "color: #ff0000;" >32</span>) </span>

Note: Although you have implemented the functionality that you want, the size of the self-sensing form also has to be more subforms from my modified:

             <span style= "FONT-SIZE:14PX;" >frmregistercard.width = me.clientrectangle.width-800        frmregistercard.height = Me.ClientRectangle.Height-        SetParent (FrmRegisterCard.Handle.ToInt32, Me.Handle.ToInt32)        frmregistercard.show () </span>
below to talk about the difference between the API function declaration with VB:

1, one of the main difference is that the data type defined in VB is a long, and in vb.net use an integer to replace long, because in vb.net, the integer type is 32 bits, and the same as the long type.

2, to pay attention to the use ByVal and ByRef

    • ByVal is a pass-through value, the source data is not modified, it can be used as its own local variable, (pass the parameter memory to the callee)
    • ByRef is the delivery address, and the source data may be modified. (Pass the parameter address to the callee)

3, in the main form call API function to pay attention to the use of "Handel.toint32", he is equivalent to the VB call process. hwnd

H:handle; Wnd: Variable object description, so-called form, so handel.toint32 is the meaning of the so-called window handle!


here is also just their own understanding, first put the understanding of the API here, for the re-learning to play a foundation!

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.