n*****3 发帖数: 15 | 1 新手刚开始vb.net不到一年,event handler部分还很困惑。手头有一个project, 是一
个windowsCE版的application.我的工作是把它转成windows application will be
running on win 7 os, 所有程序都不用改,只是event handler process 要改, 因为
不同os系统。
app是这样的,main form只包括一些button, click the button to open secondary
level forms, these forms will handle the sanner event, and based on the data
input, 3rd level forms could be open from some point and handle scanner
event too.
main form will just initial scanner class, no data handler. the secondary
and third level form contain "Friend WithEvents" and a sub handles these
scanner data. every for has different way to process data.
当scanner event 发生,任何一个active的form(on the top)就要handle the scanned
data. event只能由scanner class to invoke a sub outside the scanner class to
raise.这部分只能这样不能改。原有的这个windowCE是work的,但是用的是Microsoft.
WindowsCE.Forms.MessageWindow, 转成windows app 就不能用了。我试过把scanner
event放在module里,在每个form里的sub form_load 加addhandler, 第一个form read
很好,但是这些forms开的多了,换来换去的,程序就因有太多激活的handler而死机。
所以这种方发不可行。
又试了写一个evntclass for raise the event, 用withevents和sub getdata()
handles evntclass.event 来handle.在scanner class里, 当scan发生,new一个
evntclass to raise this event, 但是在form class里根本接受不到这个event, 可能
是因为scannerclass new 的这个evntclass 和form里的evntclass是different copy
of evntclass, they cannot see each other. 这种方法只有raise event and handle
event方在一个class里才能work 是吗?
所以我又研究了一下原程序,他的方法用的是microsoft.WindowsCE.Forms.
MessageWindow来raise这个event,这样每个form都能看到这个event,从而可以handle
它.
每个form里有"Friend WithEvents event1 as new MsgWindow " 和 "sub getdata()
handles event1.raiseevent1".
in scanner class:
.....
if scan happens then
Dim msg As Microsoft.WindowsCE.Forms.Message = Microsoft.WindowsCE.Forms.
Message.Create(HWND_BROADCAST, WM_ManagedScan, IntPtr.Zero, IntPtr.Zero)
MessageWindow.SendMessage(msg)
end it
end class
----module for the event --------
Module modMessage
Public Class MsgWindow
Inherits microsoft.WindowsCE.Forms.MessageWindow
Public Event Event1(ByVal ScanData As String)
Protected Overrides Sub WndProc(ByRef msg As icrosoft.WindowsCE.
Forms.Message)
Select Case msg.Msg
RaiseEvent Event1(ScanData)
End Select
MyBase.WndProc(msg)
End Sub
End Class
我注意到他用create a msg and use MessageWindow.sendMessage(msg) method to
send it out to invoke Class MsgWindow's Overrides Sub WndProc, so the event
get to raised. that way, the event1 raised from messageWindow will be seeing
by every form in the app? why?
我的问提是:
1。这种方法raised的event就可以被所有form看到吗?为什么呢?
2。windows系统是否也有相似的功能?如果有,那么这部分code怎样转换成可以用于
windows app的呢?
请大侠们帮帮忙, 我这个新手实在想不出别的办法。网上搜索了很久了。万分感谢!! | v******n 发帖数: 421 | 2 ce 也是从 windows 移植过去的,WndProc 涉及到底层 win32 message处理了, 跟
VB 的 Event 不是一个概念
HWND_BROADCAST 给所有 top-level 窗口发消息
http://msdn.microsoft.com/en-us/library/windows/desktop/ms64495
我估计 System.Windows.Forms.Form 和你这里 CE 的 MessageWindow 对应
data
【在 n*****3 的大作中提到】 : 新手刚开始vb.net不到一年,event handler部分还很困惑。手头有一个project, 是一 : 个windowsCE版的application.我的工作是把它转成windows application will be : running on win 7 os, 所有程序都不用改,只是event handler process 要改, 因为 : 不同os系统。 : app是这样的,main form只包括一些button, click the button to open secondary : level forms, these forms will handle the sanner event, and based on the data : input, 3rd level forms could be open from some point and handle scanner : event too. : main form will just initial scanner class, no data handler. the secondary : and third level form contain "Friend WithEvents" and a sub handles these
| n*****3 发帖数: 15 | 3 新手刚开始vb.net不到一年,event handler部分还很困惑。手头有一个project, 是一
个windowsCE版的application.我的工作是把它转成windows application will be
running on win 7 os, 所有程序都不用改,只是event handler process 要改, 因为
不同os系统。
app是这样的,main form只包括一些button, click the button to open secondary
level forms, these forms will handle the sanner event, and based on the data
input, 3rd level forms could be open from some point and handle scanner
event too.
main form will just initial scanner class, no data handler. the secondary
and third level form contain "Friend WithEvents" and a sub handles these
scanner data. every for has different way to process data.
当scanner event 发生,任何一个active的form(on the top)就要handle the scanned
data. event只能由scanner class to invoke a sub outside the scanner class to
raise.这部分只能这样不能改。原有的这个windowCE是work的,但是用的是Microsoft.
WindowsCE.Forms.MessageWindow, 转成windows app 就不能用了。我试过把scanner
event放在module里,在每个form里的sub form_load 加addhandler, 第一个form read
很好,但是这些forms开的多了,换来换去的,程序就因有太多激活的handler而死机。
所以这种方发不可行。
又试了写一个evntclass for raise the event, 用withevents和sub getdata()
handles evntclass.event 来handle.在scanner class里, 当scan发生,new一个
evntclass to raise this event, 但是在form class里根本接受不到这个event, 可能
是因为scannerclass new 的这个evntclass 和form里的evntclass是different copy
of evntclass, they cannot see each other. 这种方法只有raise event and handle
event方在一个class里才能work 是吗?
所以我又研究了一下原程序,他的方法用的是microsoft.WindowsCE.Forms.
MessageWindow来raise这个event,这样每个form都能看到这个event,从而可以handle
它.
每个form里有"Friend WithEvents event1 as new MsgWindow " 和 "sub getdata()
handles event1.raiseevent1".
in scanner class:
.....
if scan happens then
Dim msg As Microsoft.WindowsCE.Forms.Message = Microsoft.WindowsCE.Forms.
Message.Create(HWND_BROADCAST, WM_ManagedScan, IntPtr.Zero, IntPtr.Zero)
MessageWindow.SendMessage(msg)
end it
end class
----module for the event --------
Module modMessage
Public Class MsgWindow
Inherits microsoft.WindowsCE.Forms.MessageWindow
Public Event Event1(ByVal ScanData As String)
Protected Overrides Sub WndProc(ByRef msg As icrosoft.WindowsCE.
Forms.Message)
Select Case msg.Msg
RaiseEvent Event1(ScanData)
End Select
MyBase.WndProc(msg)
End Sub
End Class
我注意到他用create a msg and use MessageWindow.sendMessage(msg) method to
send it out to invoke Class MsgWindow's Overrides Sub WndProc, so the event
get to raised. that way, the event1 raised from messageWindow will be seeing
by every form in the app? why?
我的问提是:
1。这种方法raised的event就可以被所有form看到吗?为什么呢?
2。windows系统是否也有相似的功能?如果有,那么这部分code怎样转换成可以用于
windows app的呢?
请大侠们帮帮忙, 我这个新手实在想不出别的办法。网上搜索了很久了。万分感谢!! | v******n 发帖数: 421 | 4 ce 也是从 windows 移植过去的,WndProc 涉及到底层 win32 message处理了, 跟
VB 的 Event 不是一个概念
HWND_BROADCAST 给所有 top-level 窗口发消息
http://msdn.microsoft.com/en-us/library/windows/desktop/ms64495
我估计 System.Windows.Forms.Form 和你这里 CE 的 MessageWindow 对应
data
【在 n*****3 的大作中提到】 : 新手刚开始vb.net不到一年,event handler部分还很困惑。手头有一个project, 是一 : 个windowsCE版的application.我的工作是把它转成windows application will be : running on win 7 os, 所有程序都不用改,只是event handler process 要改, 因为 : 不同os系统。 : app是这样的,main form只包括一些button, click the button to open secondary : level forms, these forms will handle the sanner event, and based on the data : input, 3rd level forms could be open from some point and handle scanner : event too. : main form will just initial scanner class, no data handler. the secondary : and third level form contain "Friend WithEvents" and a sub handles these
|
|