关于API里WSAAsyncSelect的参数

liounzhou 2005-02-28 11:12:13
WSAAsyncSelect(RSocket,btnReceive->Handle,0x0202, FD_READ | FD_CLOSE);

小弟在书上的例子看到这个代码,不太明白的是0x0202代表的是什么。因为此例子中,是将SOCKET的读事件处理程序交给了btnReceive按钮中的MouseUp事件去处理。我想问的是,换成OnClick事件行不行?应该怎么换?我试了好像并不触发按钮的OnClick事件,是不是跟WSAAsyncSelect的参数有关?
...全文
334 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
liounzhou 2005-03-01
  • 打赏
  • 举报
回复
如果是写在DLL里的方法怎么解决?-_-|
3996906 2005-03-01
  • 打赏
  • 举报
回复
哪有没有办法指定一个自定义类中的方法?
-------------------------------------------------------

我就是用WM_USER+1000

然后在主窗口处理WM_USER+1000的消息。
-----------------------------------------------------------

所以是可以的,自己定义消息,在合适的窗口拦截,就执行自己的方法,从window的角度讲木问题,但是要试试
liounzhou 2005-03-01
  • 打赏
  • 举报
回复
早上上班顶一下
3996906 2005-03-01
  • 打赏
  • 举报
回复
发出消息和捕获消息都写在dll里就和应用程序中差不错
netsys2 2005-02-28
  • 打赏
  • 举报
回复
0x0202应该是btnReceive按钮中的MouseUp事件的消息句柄。

你如果要换成OnClick事件,把它的消息句柄找到并替换。

WSAAsyncSelect函数本身的用法是没有问题的,我就是那样用的,

只不过我是传给主窗口,然后在主窗口的消息处理函数中处理。
liounzhou 2005-02-28
  • 打赏
  • 举报
回复
netsys2(来电!) 贴的API帮助我也看了。
现在我的问题是,为什么不能指定OnClick事件,而只能指定MouseUp事件?
3996906 2005-02-28
  • 打赏
  • 举报
回复
这个我看大半天了

他那个消息反正在winsock.h和winsock2.h里都木看见~~~~~~~~~希望有牛人来,偶光看bcb的help没看很明白,估计楼主也是
netsys2 2005-02-28
  • 打赏
  • 举报
回复
0x0202:你自定义的消息号码

当发生读和关闭事件时,它会发一个消息给你的窗口(btnReceive->Handle),消息编号是0x0202。

The Windows Sockets WSAAsyncSelect function requests Windows message-based notification of network events for a socket.

int WSAAsyncSelect (

SOCKET s,
HWND hWnd,
unsigned int wMsg,
long lEvent
);


Parameters

s

[in] A descriptor identifying the socket for which event notification is required.

hWnd

[in] A handle identifying the window which should receive a message when a network event occurs.

wMsg

[in] The message to be received when a network event occurs.

lEvent

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



Remarks

This function is used to request that the Windows Sockets DLL should send a message to the window hWnd whenever it detects any of the network events specified by the lEvent parameter. The message which should be sent is specified by the wMsg parameter. The socket for which notification is required is identified by s.
This function automatically sets socket s to nonblocking mode, regardless of the value of lEvent. See ioctlsocket about how to set the nonoverlapped socket back to blocking mode.

The lEvent parameter is constructed by or'ing any of the values specified in the following list.

Value Meaning
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
FD_QOS Want to receive notification of socket Quality of Service (QOS) changes
FD_GROUP_QOS Want to receive notification of socket group Quality of Service (QOS) changes


Issuing a WSAAsyncSelect for a socket cancels any previous WSAAsyncSelect or WSAEventSelect for the same socket. For example, to receive notification for both reading and writing, the application must call WSAAsyncSelect with both FD_READ and FD_WRITE, as follows:

rc = WSAAsyncSelect(s, hWnd, wMsg, FD_READ|FD_WRITE);


It is not possible to specify different messages for different events. The following code will not work; the second call will cancel the effects of the first, and only FD_WRITE events will be reported with message wMsg2:

rc = WSAAsyncSelect(s, hWnd, wMsg1, FD_READ);
rc = WSAAsyncSelect(s, hWnd, wMsg2, FD_WRITE);


To cancel all notification (that is, to indicate that Windows Sockets should send no further messages related to network events on the socket) lEvent should be set to zero.

rc = WSAAsyncSelect(s, hWnd, 0, 0);
liounzhou 2005-02-28
  • 打赏
  • 举报
回复
哪有没有办法指定一个自定义类中的方法?
netsys2 2005-02-28
  • 打赏
  • 举报
回复
你换其他自定义的参数不就得了?

我就是用WM_USER+1000

然后在主窗口处理WM_USER+1000的消息。
liounzhou 2005-02-28
  • 打赏
  • 举报
回复
netsys2(来电!) 的猜测跟我相似。那么,如果0x0202这个参数不能解决的话,怎么指定特定的事件?总不能每次都指MouseUp事件吧?

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧