Open Primary .rc File As Text

The following macro opens the primary .rc file as text.
Sub OpenRCFile()
'DESCRIPTION: Opens the primary .rc file as text
'NOTE: If the resource file is already open within the
'      resource editor, you may be asked if you wish to
'      close it.

	' Simply strip the project filename of its extension...
	' ...and replace it with "rc"
	If Projects.Count = 0 Then
		MsgBox "Load a project first."
		Exit Sub
	End If
	PathName = ActiveProject.fullname
	PathName = Left(PathName, Len(PathName)-3)
	PathName = PathName + "rc"
	Documents.Open PathName, "Text"
End Sub



Comments

  • Enhanced toggle macro: *.h/*.cpp file & open mode (*.rc/ or as txt)

    Posted by Legacy on 05/17/2001 12:00am

    Originally posted by: Feng Zhou

    This is enhanced version based all the published macros.

    Sub ToggleFile()
    'DESCRIPTION:
    ' -- #1. Opens the .cpp or .h file for the current document.
    ' Toggles between the .cpp & .h file
    ' -- #2 Toggles rc file: open as a text file or resource file

    Dim doctype, baseFile, attribute
    baseFile = ActiveDocument.FullName
    doctype = ActiveDocument.Type

    DocName = UCase(baseFile)

    '#1. 'rc' files
    If Right(DocName,3) = ".RC" Then
    Dim closeStatus
    closeStatus = ActiveDocument.Close (dsSaveChangesNo)

    If doctype = "Generic" Then
    Documents.Open baseFile, "Text", FALSE
    Else
    Documents.Open baseFile, "Auto", FALSE
    End If

    Exit Sub
    End If

    '#2. Generic CPP/H file
    If Right(DocName,4) = ".CPP" Then
    fn = left(DocName, Len(DocName)-3) & "h"
    ElseIf Right(DocName,2) = ".H" Then
    fn = Left(DocName, Len(DocName)-1) & "cpp"
    ElseIf Right(DocName,4) = ".HPP" Then
    fn = Left(DocName, Len(DocName)-3) & "cpp"
    ElseIf Right(DocName,4) = ".INL" Then
    fn = Left(DocName, Len(DocName)-3) & "h"
    ElseIf Right(DocName,4) = ".TLI" Then
    fn = Left(DocName, Len(DocName)-3) & "tlh"
    ElseIf Right(DocName,4) = ".TLH" Then
    fn = Left(DocName, Len(DocName)-3) & "tli"
    Else
    fn = DocName + ".CPP"
    End If

    fn = HandleMFC(fn) 'To handle some MFC files that are just not matched this way

    on error resume next
    Documents.Open (fn)

    End Sub


    Function HandleMFC(fn)
    'MFC Specific Handling
    baseFile = UCase(ActiveDocument.Name)
    'strMFCInclude = "C:\Program Files\Microsoft Visual Studio\VC98\MFC\Include\"

    If baseFile = "DLGDATA.CPP" Then
    HandleMFC = strMFCInclude + "AFXWIN.H"
    ElseIf DocName = "" Then
    HandleMFC = fn
    Else
    HandleMFC = fn
    End If

    End Function

    Reply
  • A much simpler approach - just a single line

    Posted by Legacy on 09/23/1999 12:00am

    Originally posted by: Stefan Tzanev

    Sub OpenRCFileAsText()
    
    'DESCRIPTION: Opens project's RC resource file in text mode for manual editing.

    Documents.Open (ActiveProject.Name + ".rc"), "Text"
    End Sub

    Reply
  • What if the .RC file doesn't exist?

    Posted by Legacy on 01/29/1999 12:00am

    Originally posted by: Bob Paksi

    Great time saver of macro. However, I have a project that creates a library and doesn't have an associated .RC file. If this project is active and I use this macro (which I mapped to a button on the tool bar)DevStudio crashes. It seems that Documents.Open <PathName> crashes if the <PathName> doesn't exist. I did a search of DevStudio's object modal but didn't find any Exists() method. Any ideas?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

  • A modern mobile IT strategy is no longer an option, it is an absolute business necessity. Today's most productive employees are not tied to a desk, an office, or a location. They are mobile. And your company's IT strategy has to be ready to support them with easy, reliable, 24/7 access to the business information they need, from anywhere in the world, across a broad range of communication devices. Here's how some of the nation's most progressive corporations are meeting the many needs of their mobile workers …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds