www.pudn.com > GdiPlusMacro.zip > gdiplus.dsm


'GdiPlus macro 
'Written by PJ Arends 
' 
'Adds the neccesary stuff to VC6 MFC files to enable the use of GDI+ 
' 
'- Place in stdafx.h 
' 
'#include  
'using namespace Gdiplus; 
'#pragma comment (lib, "Gdiplus.lib") 
' 
' 
' 
'- Add to App class 
' 
'protected: 
'   ULONG_PTR m_gdiplusToken; 
' 
' 
' 
'- Place in App's InitInstance() function 
' 
'    // Initialize GDI+ 
'    GdiplusStartupInput gdiplusstartupinput; 
'    GdiplusStartup (&m_gdiplusToken, &gdiplusstartupinput, NULL); 
' 
' 
' 
'- Place in App's ExitInstance() function ( add function if needed ) 
' 
'    GdiplusShutdown(m_gdiplusToken); 
' 
'*/ 
 
 
Sub GdiPlus() 
'Add the GdiPlus startup and cleanup code to the app 
    Dim FileName 
    Dim ExitInstance 
    FileName = "StdAfx.h" 
 
    Documents.Open ( FileName ), "Text", False 
 
    if ActiveDocument.Selection.FindText ("// GdiPlus -- Added by the GdiPlus macro",  dsMatchForward + dsMatchFromStart + dsMatchCase) then 
        MsgAnswer = MsgBox ("The GdiPlus macro has already been run on this project." & Chr(13) & Chr(10) &_ 
                            "Do you want to run it again?", vbYesNo, "GdiPlus Macro") 
        if MsgAnswer = vbNo  then   
            Exit Sub 
        end if 
    end if 
 
    'Update the Stdafx.h file 
    ActiveDocument.Selection.FindText "//{{AFX_INSERT_LOCATION}}", dsMatchForward + dsMatchFromStart + dsMatchCase 
    ActiveDocument.Selection.StartOfLine 
    ActiveDocument.Selection = "// GdiPlus -- Added by the GdiPlus macro" 
    ActiveDocument.Selection.NewLine 
    ActiveDocument.Selection = "#include " 
    ActiveDocument.Selection.NewLine 
    ActiveDocument.Selection = "using namespace Gdiplus;" 
    ActiveDocument.Selection.NewLine 
    ActiveDocument.Selection = "#pragma comment (lib, ""Gdiplus.lib"")" 
    ActiveDocument.Selection.NewLine 
    ActiveDocument.Selection.NewLine 
 
    'Update Application class header file 
    FileName = ActiveProject.Name + ".h" 
    Documents.Open ( FileName ), "Text", False 
 
    ActiveDocument.Selection.FindText "public CWinApp", dsMatchForward + dsMatchFromStart + dsMatchCase 
    if ActiveDocument.Selection.FindText ("ExitInstance()") then 
        ExitInstance = True 
    else 
        ExitInstance = False 
    end if 
 
    if False = ExitInstance then 
        ActiveDocument.Selection.FindText "public CWinApp", dsMatchForward + dsMatchFromStart + dsMatchCase 
        ActiveDocument.Selection.FindText "//}}AFX_VIRTUAL" 
        ActiveDocument.Selection.StartOfLine 
        ActiveDocument.Selection.NewLine 
        ActiveDocument.Selection = "// GdiPlus -- Added by the GdiPlus macro" 
        ActiveDocument.Selection.NewLine 
        ActiveDocument.Selection = "public:" 
        ActiveDocument.Selection.NewLine 
        ActiveDocument.Selection.Unindent 
        ActiveDocument.Selection = "virtual int ExitInstance();" 
        ActiveDocument.Selection.NewLine 
        ActiveDocument.Selection.FindText "public CWinApp", dsMatchForward + dsMatchFromStart + dsMatchCase 
    end if 
 
    ActiveDocument.Selection.FindText "};", dsMatchForward 
    ActiveDocument.Selection.StartOfLine 
    ActiveDocument.Selection.NewLine 
    ActiveDocument.Selection = "// GdiPlus -- Added by the GdiPlus macro" 
    ActiveDocument.Selection.NewLine 
    ActiveDocument.Selection = "protected:" 
    ActiveDocument.Selection.NewLine 
    ActiveDocument.Selection = "    ULONG_PTR m_gdiplusToken;" 
    ActiveDocument.Selection.NewLine 
 
    'Update Application class source file 
    FileName = ActiveProject.Name + ".cpp" 
    Documents.Open ( FileName ), "Text", False 
 
    ActiveDocument.Selection.FindText "App::InitInstance()", dsMatchForward + dsMatchFromStart + dsMatchCase 
    ActiveDocument.Selection.FindText "{" 
    ActiveDocument.Selection.LineDown 
    ActiveDocument.Selection.StartOfLine 
    ActiveDocument.Selection = "// GdiPlus -- Added by the GdiPlus macro" 
    ActiveDocument.Selection.NewLine 
    ActiveDocument.Selection = "GdiplusStartupInput gdiplusstartupinput;" 
    ActiveDocument.Selection.NewLine 
    ActiveDocument.Selection = "GdiplusStartup (&m_gdiplusToken, &gdiplusstartupinput, NULL);" 
    ActiveDocument.Selection.NewLine 
    ActiveDocument.Selection.NewLine 
 
    if False = ExitInstance then ' Add ExitInstance() function 
        ActiveDocument.Selection.EndOfDocument 
        ActiveDocument.Selection.NewLine 
        ActiveDocument.Selection = "// GdiPlus -- Added by the GdiPlus macro" 
        ActiveDocument.Selection.NewLine 
        ActiveDocument.Selection = ActiveProject.Name 
        ActiveDocument.Selection.SelectLine 
'       ActiveDocument.Selection.ChangeCase dsCapitalize 
        ActiveDocument.Selection.StartOfLine 
        ActiveDocument.Selection = "int C" 
        ActiveDocument.Selection.EndOfLine 
        ActiveDocument.Selection = "App::ExitInstance()" 
        ActiveDocument.Selection.NewLine 
        ActiveDocument.Selection = "{" 
        ActiveDocument.Selection.NewLine 
    else 
        ActiveDocument.Selection.FindText "App::ExitInstance()", dsMatchForward + dsMatchFromStart + dsMatchCase 
        ActiveDocument.Selection.FindText "{" 
        ActiveDocument.Selection.LineDown 
        ActiveDocument.Selection = "// GdiPlus -- Added by the GdiPlus macro" 
        ActiveDocument.Selection.NewLine 
    end if 
    ActiveDocument.Selection = "GdiplusShutdown(m_gdiplusToken);" 
    ActiveDocument.Selection.NewLine 
    if False = ExitInstance then 
        ActiveDocument.Selection = "return CWinApp::ExitInstance();" 
        ActiveDocument.Selection.NewLine 
        ActiveDocument.Selection.Unindent 
        ActiveDocument.Selection = "}" 
        ActiveDocument.Selection.NewLine 
    end if 
End Sub