Sub UnderscoreT() 'DESCRIPTION: This macro will automatically put "_T( )" around ' your strings, Author: Orin Walker, 1999, Version 1.1 ' Last change - Acidpop(http://acidpop.tistory.com) (2012.09.07) ' Supported Visual Studio 2010 Macro Dim iCount As Integer Dim bFoundAQuote As Boolean Dim strTemp As String Dim strStuffAtEnd As String Dim bDone As Boolean Dim str As String Dim strBuildString As String Dim Selection As TextSelection Dim win win = ActiveWindow 'If win.type <> "Text" Then ' MsgBox("This macro can only be run when a text editor" + _ ' " window is active.") 'Else iCount = 0 bFoundAQuote = False ActiveDocument.Selection.SelectLine() strTemp = ActiveDocument.Selection.Text Selection = ActiveDocument.Selection strStuffAtEnd = "" While bDone <> True str = ParseString(strTemp, bFoundAQuote, strStuffAtEnd) strBuildString = strBuildString + str If bFoundAQuote = True Then strTemp = strStuffAtEnd Else bDone = True 'ActiveDocument.Selection.Delete() 'ActiveDocument.Selection = strBuildString Selection.Text = strBuildString End If iCount = iCount + 1 If iCount > 100 Then ' safety valve bDone = True End If End While 'End If End Sub Function ParseString(ByVal strTemp, ByRef bFoundAQuote, _ ByRef strStuffAtEnd) Dim strSpace As String Dim iLen As Integer Dim iPos As Integer Dim x As Integer Dim strCheck As String Dim iUnderscoreTPos As Integer Dim strBeforeFirstQuote As String Dim strNewTempStr As String Dim strRemaining As String Dim strStuffInQuotes As String 'DESCRIPTION: This is a helper function for the UnderscoreT macro, ' Author: Orin Walker, 1999, Version 1.1 ' Comment in/out whatever style you prefer strSpace = "" ' NO space before or after "_T(" 'strSpace = " " ' Add a space before and after "_T(" iLen = Len(strTemp) bFoundAQuote = False ' Get the position of the first quote on the line iPos = InStr(strTemp, Chr(34)) If iPos > 0 Then 'a quote was found ' Go back and see if we have an existing ' _T( defined for this quote x = iPos - 5 ' Go back up to 5 characters If x <= 0 Then ' If we have reached the ' beginning of our string x = 1 ' Set x to start at the first character End If strCheck = Mid(strTemp, x, iPos) iUnderscoreTPos = InStr(strCheck, "_T(") ' If we found one grab everything before the first quote strBeforeFirstQuote = Mid(strTemp, 1, iPos - 1) If iUnderscoreTPos > 0 Then ' we found an "_T(" ' Do NOT add the "_T(" to our temporary string strNewTempStr = strBeforeFirstQuote Else ' Now create our new temporary string and append "_T(" strNewTempStr = strBeforeFirstQuote + "_T(" + strSpace End If ' Get the remaining string strRemaining = Mid(strTemp, iPos + 1, iLen) iLen = Len(strRemaining) ' Now find the second quote iPos = InStr(strRemaining, Chr(34)) If iPos > 0 Then ' If we found one save the stuff in quotes strStuffInQuotes = Chr(34) + Mid(strRemaining, 1, iPos) ' And grab the stuff after the quotes strStuffAtEnd = Mid(strRemaining, iPos + 1, iLen) If iUnderscoreTPos > 0 Then ' we found an _T( ' Do NOT add the final ")" to our parsed string, ' because it alreasy exists ParseString = strNewTempStr + strStuffInQuotes Else ' Create our parsed string ParseString = strNewTempStr + strStuffInQuotes + _ strSpace + ")" End If bFoundAQuote = True Else ' No SECOND quote was found so just return ' what was passed in ParseString = strTemp End If Else ' No quote was found so just return what was passed in ParseString = strTemp End If End Function
http://acidpop.tistory.com/52 위 글에 올려놨던 _T 자동 입력 매크로이나 Visual c++ 6.0 에서만 작동하던 녀석을 Visual 2010 에서도 작동 하도록 변경해봤다.
사용 방법은 다음과 같다.
Imports System Imports EnvDTE Imports EnvDTE80 Imports EnvDTE90 Imports EnvDTE90a Imports EnvDTE100 Imports System.Diagnostics Public Module AutoT ' 여기에 위에서 복사한 소스를 붙여넣기 하자 End Module