计算机网络实验指导书(详细版) 下载本文

计算机网络实验指导书

; 处理 窗口关闭 消息,退出时关闭全部连接

;******************************************************************** ;用户关闭连接

.elseif eax == WM_CLOSE ;关闭服务器的套接字

invoke closesocket,hSocket ;找到客户连接登记表stTable

xor ebx,ebx mov esi,offset stTable cld ;关闭所有与服务器连接的客户套接字 .while ebx < MAX_SOCKET lodsd .if eax invoke closesocket,eax .endif inc ebx .endw ;卸载WinSock库

invoke WSACleanup ;关闭窗口hWinMain

invoke EndDialog,hWinMain,NULL

;******************************************************************** ; 处理 窗口初始化 消息

;******************************************************************** ;窗口被激活时,马上要运行的窗口初始化程序

.elseif eax == WM_INITDIALOG ;hWnd和hWinMain保存窗口句柄

push hWnd

pop hWinMain ;调用初始化函数_Init call _Init

;******************************************************************** .else ;消息处理失败,返回 mov eax,FALSE ret .endif ;消息处理成功,返回 mov eax,TRUE ret

_ProcDlgMain endp

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

第 61 页 共 64 页

计算机网络实验指导书

; 程序开始

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

start: ;创建进程,获得进程句柄eax

invoke GetModuleHandle,NULL

;激活资源文件定义的主窗口DLG_MAIN,执行主窗口程序_ProcDlgMain invoke DialogBoxParam,eax,DLG_MAIN,NULL,offset _ProcDlgMain,0 ;用户关闭主窗口,退出进程

invoke ExitProcess,NULL

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

end start

第 62 页 共 64 页

计算机网络实验指导书

附录五 常用系统资源汇集

1、 对话框中的编辑风格-Edit Styles

? ES_AUTOHSCROLL Automatically scrolls text to the right by 10

characters when the user types a character at the end of the line. When the user presses the ENTER key, the control scrolls all text back to position 0.

? ES_AUTOVSCROLL Automatically scrolls text up one page when the user presses ENTER on the last line.

? ES_CENTER Centers text in a single-line or multiline edit control. ? ES_LEFT Left-aligns text in a single-line or multiline edit control.

? ES_LOWERCASE Converts all characters to lowercase as they are typed into the edit control.

? ES_MULTILINE Designates a multiple-line edit control. (The default is single line.) If the ES_AUTOVSCROLL style is specified, the edit control shows as many lines as possible and scrolls vertically when the user presses the ENTER key. If ES_AUTOVSCROLL is not given, the edit control shows as many lines as possible and beeps if ENTER is pressed when no more lines can be displayed. If the ES_AUTOHSCROLL style is specified, the multiple-line edit control

automatically scrolls horizontally when the caret goes past the right edge of the control. To start a new line, the user must press ENTER. If ES_AUTOHSCROLL is not given, the control automatically wraps words to the beginning of the next line when necessary; a new line is also started if ENTER is pressed. The position of the wordwrap is determined by the window size. If the window size changes, the wordwrap position changes and the text is redisplayed. Multiple-line edit controls can have scroll bars. An edit control with scroll bars processes its own scroll-bar messages. Edit controls without scroll bars scroll as described above and process any scroll messages sent by the parent window.

? ES_NOHIDESEL Normally, an edit control hides the selection when the control loses the input focus and inverts the selection when the control receives the input focus. Specifying ES_NOHIDESEL deletes this default action. ? ES_NUMBER Allows only digits to be entered into the edit control.

? ES_OEMCONVERT Text entered in the edit control is converted from the ANSI character set to the OEM character set and then back to ANSI. This

ensures proper character conversion when the application calls the AnsiToOem Windows function to convert an ANSI string in the edit control to OEM

characters. This style is most useful for edit controls that contain filenames. ? ES_PASSWORD Displays all characters as an asterisk (*) as they are typed into the edit control. An application can use the SetPasswordChar member function to change the character that is displayed.

? ES_READONLY Prevents the user from entering or editing text in the edit control.

? ES_RIGHT Right-aligns text in a single-line or multiline edit control.

? ES_UPPERCASE Converts all characters to uppercase as they are typed into the edit control.

? ES_WANTRETURN Specifies that a carriage return be inserted when the user presses the ENTER key while entering text into a multiple-line edit control in a dialog box. Without this style, pressing the ENTER key has the same effect as pressing the dialog boxs default pushbutton. This style has no effect on a single-line edit control.

第 63 页 共 64 页

计算机网络实验指导书

2、WINDOWS中WM_SOCKET类消息

CASyncSocket::Socket

Allocates a socket handle.

BOOL Socket(

int nSocketType = SOCK_STREAM,

long lEvent = FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE,

int nProtocolType = 0,

int nAddressFormat = PF_INET );

Parameters

nSocketType

Specifies SOCK_STREAM or SOCK_DGRAM.

lEvent

A bitmask that specifies a combination of network events in which the application is interested.

? FD_READ: Want to receive notification of readiness for reading. ? FD_WRITE: Want to receive notification of readiness for writing. ? FD_OOB: Want to receive notification of the arrival of out-of-band

data.

? FD_ACCEPT: Want to receive notification of incoming connections. ? FD_CONNECT: Want to receive notification of completed

connection.

? FD_CLOSE: Want to receive notification of socket closure.

nProtocolType

Protocol to be used with the socket that is specific to the indicated address family. nAddressFormat

Address family specification.

Return Value

Returns TRUE on success, FALSE on failure. Remarks

This method allocates a socket handle. It does not call CAsyncSocket::Bind to bind the socket to a specified address, so you need to call Bind later to bind the socket to a specified address. You can use CAsyncSocket::SetSockOpt to set the socket option before it is bound.

3、常见的WM_消息类

例如:

WM_SETCURSOR,WM_MOUSEMOVE,WM_PAINT,WM_TIMER,WM_VKEYTOITEM,

WM_KEYDOWN,WM_GETDLGCODE,WM_SYSCHAR,WM_CHARVSCROLL, WM_LBUTTONUP,WM_CONTEXTMENU, WM_COMMAND,WM_SIZE,

WM_ HOOKRCRESULT,WM_ CTLCOLOR,WM_KEYUP,WM_KEYDOWN等等。

第 64 页 共 64 页