VSMacro/ TCHAR 매크로

개발 2009/09/03 09:05 김성민

C 문자열 주위를 _T() 매크로로 감싸주는 Visual Studio 매크로다.

"Some String" ---> _T("Some String")

매크로 IDE(ALT+F11)에서 붙여넣고, 단축키 등록해 준 다음 쓰면 된다. 문자열을 선택한 다음 실행해도 되고, 문자열 가운데 아무데서나 그냥 실행해도 된다.

Sub WrapStringWithTcharMacro()
  Dim objRanges As TextRanges
  Dim objStartPt As EditPoint
  Dim objEndPt As EditPoint

  objRanges = ActiveDocument().Selection.TextRanges
  objStartPt = objRanges.Item(1).StartPoint.CreateEditPoint()
  objEndPt = objRanges.Item(objRanges.Count).EndPoint.CreateEditPoint()

  ' 문자열의 처음을 찾는다.
  While objStartPt.GetText(-1) <> """" Or objStartPt.GetText(-2) = "\"""
       objStartPt.CharLeft(1)
  End While
  objStartPt.CharLeft(1)

  ' 문자열의 끝을 찾는다.
  While objEndPt.GetText(1) <> """" Or objEndPt.GetText(-1) = "\"
       objEndPt.CharRight(1)
  End While
  objEndPt.CharRight(1)

  ' 이미 _T 매크로로 감싸여 있는 문자열이 아니라면 감싸준다.
  If objStartPt.GetText(-3) <> "_T(" Then
       objStartPt.Insert("_T(")
       objEndPt.Insert(")")
  End If
End Sub
2009/09/03 09:05 2009/09/03 09:05
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://serious-code.net/tc/rss/response/8

댓글+트랙백 ATOM :: http://serious-code.net/tc/atom/response/8

트랙백 주소 :: http://serious-code.net/tc/trackback/8

트랙백 RSS :: http://serious-code.net/tc/rss/trackback/8

트랙백 ATOM :: http://serious-code.net/tc/atom/trackback/8

댓글을 달아 주세요

댓글 RSS 주소 : http://serious-code.net/tc/rss/comment/8
댓글 ATOM 주소 : http://serious-code.net/tc/atom/comment/8
[로그인][오픈아이디란?]