Прозрачность под win2k & winxp (взято из api-guide):
Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
'param description:
· hwnd [in] Handle to the layered window. A layered window is created by specifying WS_EX_LAYERED when creating the window with the CreateWindowEx function or by setting WS_EX_LAYERED via SetWindowLong after the window has been created.
· crKey [in] Pointer to a COLORREF value that specifies the transparency color key to be used when composing the layered window. All pixels painted by the window in this color will be transparent. To generate a COLORREF, use the RGB macro.
· bAlpha [in] Alpha value used to describe the opacity of the layered window. Similar to the SourceConstantAlpha member of the BLENDFUNCTION structure. When bAlpha is 0, the window is completely transparent. When bAlpha is 255, the window is opaque.
· dwFlags [in] Specifies an action to take. This parameter can be one or more of the following values. LWA_COLORKEY Use crKey as the transparency color. LWA_ALPHA Use bAlpha to determine the opacity of the layered window..
'example:
Const
LWA_COLORKEY = &H1
Const
LWA_ALPHA = &H2
Const
GWL_EXSTYLE = (-20)
Const
WS_EX_LAYERED = &H80000
Private
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private
Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private
Sub Form_Load()'KPD-Team 2000 'URL: http://www.allapi.net/ 'E-Mail: KPDTeam@Allapi.net Dim Ret As Long 'Set the window style to 'Layered'
If Src = Dest Then Recode = Char Exit Function End If
Dim t As String, i As Long, tt As String, a As Long, ss As String, ch As String If Src = Win Then t = Char Else Select Case Src Case Koi: ss = wKoi Case Dos: ss = wDos Case Iso: ss = wIso End Select For i = 1 To Len(Char) ch = Mid(Char, i, 1) If Asc(ch) < 128 Then t = t & ch Else a = InStr(1, ss, ch, vbBinaryCompare) If a = 0 Then t = t & NotRecodedChar Else t = t & Mid$(wWin, a, 1) End If End If Next i End If
If Dest = Win Then Recode = t Else Select Case Dest Case Koi: ss = wKoi Case Dos: ss = wDos Case Iso: ss = wIso End Select For i = 1 To Len(Char) ch = Mid(t, i, 1) If Asc(ch) < 128 Then tt = tt & ch Else a = InStr(1, wWin, ch, vbBinaryCompare) If a = 0 Then tt = tt & NotRecodedChar Else tt = tt & Mid$(ss, a, 1) End If End If Next i Recode = tt End If End Function
...и пример определения кодировки:
'пpовеpяем тип кодиpовки ANSI или ASCII
'беpем пеpвые 1000 байт еcли это возможно. Hевозможно - меньше.
l& = Len(rtbView.Text)
If l& > 1000 Then l& = 1000
'копиpyем yчаcток текcта из RichTextBox в пеpеменнyю, иначе тоpмоз обеcпечен
s$ = Left$(rtbView.Text, l&
'обнyляем флажки
fdo% = 0
fwo% = 0
'пpоcматpиваем кycок текcта
For n% = 1 To l&
'вытаcкиваем очеpедной cимвол
c$ = Mid$(s$, n%, 1)
'еcли это pyccкая "о" в DOS кодиpовке то инкpементиpyем cчетчик
Public Declare Function FindText Lib "comdlg32.dll" Alias "FindTextA" ( _ pFindreplace As FINDREPLACE) As Long
Public Declare Function ReplaceText Lib "comdlg32.dll" Alias "ReplaceTextA" ( _ pFindreplace As FINDREPLACE) As Long
Type FINDREPLACE lStructSize As Long ' size of this struct 0x20 hwndOwner As Long ' handle to owner's window hInstance As Long ' stance handle of.EXE that ' contains cust. dlg. template flags As Long ' one or more of the FR_?? lpstrFindWhat As String ' ptr. to search string lpstrReplaceWith As String ' ptr. to replace string wFindWhatLen As Integer ' size of find buffer wReplaceWithLen As Integer ' size of replace buffer lCustData As Long ' data passed to hook fn. lpfnHook As Long ' ptr. to hook fn. or NULL lpTemplateName As String ' custom template name End Type
2 Padre: вот перекодировка намного быстрее и лучше:
'===================Перекодировка символов=========== Public Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, _ ByVal lpWideCharStr As String, ByVal cchWideChar As Long, ByVal lpMultiByteStr As String, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long Public Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As String, ByVal cchMultiByte As Long, ByVal lpWideCharStr As String, ByVal cchWideChar As Long) As Long
Public Const MB_PRECOMPOSED = &H1 ' use precomposed chars
'=============Функция перекодировки=================== Public Function Convert(ByVal strSrc As String, ByVal nFromCP As Long, ByVal nToCP As Long) As String Dim nLen As Long Dim strDst As String Dim strRet As String Dim nRet As Long nLen = Len(strSrc) strDst = String(nLen * 2, Chr(0)) strRet = String(nLen * 2, Chr(0)) nRet = MultiByteToWideChar(nFromCP, MB_PRECOMPOSED, strSrc, nLen, strDst, nLen) nRet = WideCharToMultiByte(nToCP, 0, strDst, nRet, strRet, nLen * 2, ByVal 0, 0) Convert = Left(strRet, nRet) End Function
Вызывай функцию Convert. Ей передаёшь исходную строку, исходную кодировку (например, 1251) и кодировку, которую надо получить (например, 866).
В .NET для перекодировки надо юзать класс System.Text.Encoding. То есть создаём один Encoding для исходной кодировки, другой - для получаемой кодировки. Потом в первом юзаем GetBytes, полученный байтовый массив закидываем в метод второго Encoding'а - GetString.