| 发表于:2007-07-18 21:22:452楼 得分:40 |
this is impossible mission! http://community.csdn.net/expert/topicview3.asp?id=5648720 http://community.csdn.net/expert/topicview3.asp?id=5646744 重申: (不考虑win9x,因为更复杂)对于xp英文/中文系统,如果你的non-unicode设定是english, sendmessage 根本就不可能得到中文.但如果non-unicode设定是chinese (prc),上面的编码可以取得中文。原因在于sendmessage有经过unicode到ansi/dbcs的几次转换,造成unicode的丢失。 我挣扎多年都没成功!!!不信你们将你的non-unicode设定为english!!! control panel --> language and region options --> advance tab ---> english as non-unicode 'richedit getline function from vbadvisor public type textrange chrg as charrange lpstrtext as long end type public function getlinetext(byval hwnd as long,byval linenum as long) as string dim linecount as long dim lc as long, j as long dim charfrom as long dim charend as long dim cr as charrange dim tr as textrange linecount = sendmessagelong(hwnd, em_getlinecount, byval 0&, byval 0&) if linenum > linecount then getlinetext = vbnullstring exit function end if charfrom = sendmessagelong(hwnd, em_lineindex, linenum, byval 0&) lc = sendmessagelong(hwnd, em_linelength, byval charfrom, byval 0&) if lc = 0 then getlinetext = vbnullstring exit function end if getlinetext = textinrange(charfrom, charfrom + lc) end function public sub textinrange(byval hwnd as long,byval lstart as long, byval lend as long) dim tr as textrange dim stext as string dim lr as long dim b() as byte tr.chrg.cpmin = lstart tr.chrg.cpmax = lend ' vb won 't do the terminating null for you! stext = string$(lend - lstart + 1, 0) b = stext redim preserve b(0 to (lend - lstart + 1)) as byte tr.lpstrtext = varptr(b(0)) lr = sendmessagelong(hwnd, em_gettextrange, 0, varptr(tr)) if (lr > 0) then ' lstrlen assumes that lpstring is a null-terminated string !!! copymemory byval stext, byval tr.lpstrtext, lr textinrange = left$(stext, lr) end if end sub 'textbox getline function from vbadvisor public function getline(byval hwnd as long,byval whichline as long) as string dim nlen as long, barr() as byte, barr2() as byte, lreturn as long lreturn = sendmessage(hwnd , em_lineindex, whichline, byval 0&) nlen = sendmessage(hwnd , em_linelength, lreturn, byval 0&) if nlen > 0 then redim barr(2 * nlen + 1) as byte, barr2(2 * nlen - 1) as byte call copymemory(barr(0), 2 * nlen, 2) call sendmessage(hwnd , em_getline, whichline, barr(0)) call copymemory(barr2(0), barr(0), 2 * nlen) getline = string$(ubound(barr2) + 1, vbnullchar) copymemory byval getlinestring, barr2(0), ubound(barr) + 1 else getline = vbnullstring end if end function | | |
|