Use IP controls in Delphi

zhaozj2021-02-11  223

Use IP controls in Delphi

Xi'an Jiaotong University Liu Minghua

----- In the network program, we often encounter the case where you need the user to enter the IP address. However, Delphi does not provide us with controls that can be used to enter IP strings, so we have to use TEDIT controls (single line text box) to accept the IP string input by the user. However, using TEDIT to enter an IP string is not a good idea because it is very inconvenient to process. In fact, there is a Windows control specifically used to enter the IP string next to our side, which is shown. The IP control will reject the illegal IP string (only the number between 0,255); it allows you to easily get the IP value corresponding to the IP string in the control (32-bit integers), this The province has saved the trouble between IP strings and IP values; in addition, you can limit the range of IPs that can be entered in the IP control. In this article, I will introduce you how to use Windows IP controls in our Delphi program.

---- There are two very important dynamic linkages in Windows: CommCtrl.dll and ComctL32.dll, which are Windows Common Controls. The custom control library contains many common Windows controls, such as Statusbar, Coolbar, Hotkey, etc .; most of these controls have been packaged into visual controls in Delphi. After Microsoft launches Internet Explorer 3, some controls have been added to the custom control library, including the IP Address Edit Control.

---- Initializing Windows Custom Control Library

---- Windows provides two API functions, INITCOMMONCONTROLS, and INITCOMMONCONTROLSEX to initialize custom control libraries. From the name, we are not difficult to see the relationship between these two API functions: the latter is the enhancement of the former. If you want to use IP controls in the program, you must use INTCOMMONCONTROLSEX to complete the initialization of custom control libraries and classes. The prototype of the function initcommonControlsex is as follows (Pascal syntax):

---- ... ...

---- Create an IP control

---- ... ...

---- Use IP controls. In the program, we communicate with it by sending messages to the IP control. There are 6 messages that IP controls can respond, these messages and their meaning are shown in the table:

---- ... ...

---- If you want to get the IP value corresponding to the IP string in the IP control, you should send an IPM_GetadDress message to the IP control, and you need to put an address of a 32-bit integer as the last parameter of SendMessage.

---- ... ...

---- Notification message for IP control

---- When the IP string is changed or the input focus occurs, the IP control sends a notification message ipn_fieldchanged to its parent window. In most cases, we can ignore this notification message. The following is an example of the processing notification message IPN_FIELDCHANGED:

Procedure TFORM1.WNDPROC (VAR Msg: TMESSAGE);

VAR P: ​​pnmhdr;

Begin

inherited;

IF msg.msg = wm_notify

Then Begin

P: = Pointer (msg.lparam);

IF P ^ .code = ipn_fieldchanged

Then Begin

{...

IPN_FIELDCHANGED notification message for processing IP controls ...}

END;

END;

END;

转载请注明原文地址:https://www.9cbs.com/read-3913.html

New Post(0)