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 에서도 작동 하도록 변경해봤다.
사용 방법은 다음과 같다.
1. 위 소스를 복사
2. Visual Studio 에서 도구 -> 매크로 -> 매크로 편집
3. visual Studio Macros 창이 뜨면 프로젝트 -> 모듈 추가
4. 모듈을 선택 하고 이름은 AutoT 로 하자
5. 추가 하면 아래와 같은 코드가 만들어 지는것을 볼 수 있다.
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Public Module AutoT
' 여기에 위에서 복사한 소스를 붙여넣기 하자
End Module
6. 표시한 곳에 소스를 붙여넣기 한다.
7. 단축키로 등록하여 준다.
도구 -> 사용자 지정 -> 키보드 버튼을 클릭하면 다음과 같은 창이 뜬다.
단축키를 설정하려는 매크로 UnderscoreT 매크로를 선택 한 다음
바로 가기 키 누르기(P) 텍스트 박스에서 원하는 단축키를 누른다.
필자는 Ctrl + Q 로 할당 하였다.
텍스트 에디터에서만 사용을 할 것이므로 새 바로 가기 사용 위치는 전역 -> 텍스트 편집기 로 바꿔준다.
이제 "문자열" 형태로 된 코드에서 단축키를 눌러보자.
_T("문자열") 형태로 변경 되는것을 볼 수 있다.
'Programming > Visual Studio' 카테고리의 다른 글
| Visual Studio 유용한 확장 도구 (0) | 2014.05.26 |
|---|---|
| Visual Studio Macro 작동 (0) | 2014.02.20 |
| devdenv 또는 MSBuild 로 빌드시 프로젝트 종속성 무시 (0) | 2013.10.17 |
| Visual Studio 에서 빌드 후 이벤트의 매크로 이용 (0) | 2013.03.29 |
| Windows 7 64bit 시스템에서 Visual C++ 6.0 사용하기 (14) | 2012.02.09 |
| visual studio 정규식 (0) | 2011.09.05 |
| _T() 를 자동으로.. (0) | 2010.10.29 |
| visual studio 2010 - Restart Manager (0) | 2009.02.24 |