| 发表于:2007-10-24 13:30:43 楼主 |
我在vb程序中向c#程序发送消息,用sendmessage函数时c#程序可以收到,但改成postmessage时c#程序就收不到 vb发出的消息。vb的代码如下,请大家看看可能是什么原因 '\\ declarations private declare function postmessagelong lib "user32" alias "postmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long private declare sub copymemory lib "kernel32" alias "rtlmovememory" (byref hpvdest as any, byref hpvsource as any, byval cbcopy as long) private declare function findwindow lib "user32" alias "findwindowa" (byval lpclassname as string, byval lpwindowname as string) as long private sub command1_click() dim sstring as string dim lhwnd as long dim cds as copydatastruct dim buf(255) as byte sstring = "string to send" if sstring = "" then exit sub ' ' get the handle of the target application's visible window. ' lhwnd = findwindow(vbnullstring, cwindow_title) if lhwnd then ' ' copy the string into a byte array, ' converting it to ascii. assign lpdata ' the address of the byte array. ' call copymemory(buf(1), byval sstring, lenb(strconv(sstring, vbfromunicode))) with cds .dwdata = 3 .cbdata = lenb(strconv(sstring, vbfromunicode)) + 1 .lpdata = varptr(buf(1)) end with msgbox (cds.cbdata) ' ' send the string. ' call postmessagelong(lhwnd, wm_copydata, me.hwnd, cds) end if end sub |
|
|
|
|