用下面的方法在98或win me上没有问题,可是2000和xp上无法得到光标的列数,
请帮帮忙,谢谢!int LineIndex,LineNum,SelStar,ColNum;
LineNum = ::SendMessage(hFocus,EM_LINEFROMCHAR,(WPARAM)-1,0);
LineIndex = ::SendMessage(hFocus,EM_LINEINDEX,(WPARAM)LineNum,0);
SelStar = (int)LOWORD(::SendMessage(hFocus,EM_GETSEL,NULL,NULL));
ColNum = SelStar - LineIndex;
请帮帮忙,谢谢!int LineIndex,LineNum,SelStar,ColNum;
LineNum = ::SendMessage(hFocus,EM_LINEFROMCHAR,(WPARAM)-1,0);
LineIndex = ::SendMessage(hFocus,EM_LINEINDEX,(WPARAM)LineNum,0);
SelStar = (int)LOWORD(::SendMessage(hFocus,EM_GETSEL,NULL,NULL));
ColNum = SelStar - LineIndex;
SelStar = (int)LOWORD(::SendMessage(hFocus,EM_GETSEL,NULL,NULL));出了错,不知是怎么回事。
DWORD dwEnd;
SelStar = (int)LOWORD(::SendMessage(hFocus,EM_GETSEL,(WPARAM)&dwStart,(LPARAM)&dwEnd));=========================================================
EM_GETSEL
The EM_GETSEL message retrieves the starting and ending character positions of the current selection in an edit control. You can send this message to either an edit control or a rich edit control.To send this message, call the SendMessage function with the following parameters. SendMessage(
(HWND) hWnd, // handle to destination window
EM_GETSEL, // message to send
(WPARAM) wParam, // starting position (LPDWORD)
(LPARAM) lParam // ending position (LPDWORD)
);
Parameters
wParam
Pointer to a buffer that receives the starting position of the selection. This parameter can be NULL.
lParam
Pointer to a buffer that receives the position of the first nonselected character after the end of the selection. This parameter can be NULL.
Return Values
The return value is a zero-based value with the starting position of the selection in the low-order word and the position of the first character after the last selected character in the high-order word. If either of these values exceeds 65,535, the return value is –1.It is better to use the values returned in wParam and lParam because they are full 32-bit values.
EM_GETSEL消息中的这句:It is better to use the values returned in wParam and lParam because they are full 32-bit values
98下返回的index中汉字是2个字符,而2000、xp下返回的index中汉字是1个字符。
这可怎么办呀?
i = SendMessage(texthwnd, EM_GETSEL, wparam, lparam)
j = i / 2 ^ 16
'向文本框传递EM_LINEFROMCHAR消息根据获得的字符数确定光标所在行数
lineno = SendMessage(texthwnd, EM_LINEFROMCHAR, j, 0)
lineno = lineno + 1
'向文本框传递EM_LINEINDEX消息以获取所在列数
k = SendMessage(texthwnd, EM_LINEINDEX, -1, 0)
colno = j - k + 1
End Sub
{
long lTemp = 0, lTemp1 = 0, lTemp2 = 0;
long lLineX = 0,lLineY = 0;
long lNumberofLine = 0 ; lTemp = ::SendMessage(hWnd, EM_LINEINDEX, -1, 0);
lLineY = ::SendMessage(hWnd, EM_LINEFROMCHAR, lTemp, 0); //Col lNumberofLine =::SendMessage(hWnd,EM_LINELENGTH,0,0); GetSel(lTemp1,lTemp2);
lLineX = lTemp1 - lTemp; //LINE}
GetVersion
The GetVersion function returns the current version number of the operating system. Note This function has been superseded by GetVersionEx. New applications should use GetVersionEx or VerifyVersionInfo. DWORD GetVersion(VOID);
Parameters
This function has no parameters. Return Values
If the function succeeds, the return value is a DWORD value that contains the major and minor version numbers of the operating system in the low order word, and information about the operating system platform in the high order word. For all platforms, the low order word contains the version number of the operating system. The low-order byte of this word specifies the major version number, in hexadecimal notation. The high-order byte specifies the minor version (revision) number, in hexadecimal notation. To distinguish between operating system platforms, use the high order bit and the low order byte, as shown in the following table:Platform High-order bit Low-order byte (major version)
Windows NT/2000 0 3, 4, or 5
Windows 95/98 1 4
Win32s 1 3
Windows NT/2000: The remaining bits in the high-order word specify the build number. Windows 95/98: The remaining bits of the high-order word are reserved