Open StdAfx.h and window size/move

Here is one to open the stdafx.h of the current project.

Sub stdafx()
	'DESCRIPTION: Opens the stdafx.h file of the current project.

	proj_path = ActiveProject.fullname
	ext = ""
	pos = len (proj_path)
	Do While ext <> "\"
	ext = Mid(proj_path, pos, 1)
	pos = pos -1
	proj_dir = left(proj_path, pos+1) & "stdafx.h" proj_dir
End Sub

Something else I found a pain was having to change from the keyboard to the mouse because the MDI window wasn't in the correct place or the wrong size. I wrote the following one-liners and associated them with the numeric keypad arrows and ctrl and alt to move/resize the windows. ie Ctrl + Alt and 6 to widen the window. Its not the code more the idea I find it relieves RSI type strain when using the mouse to often.

Sub WidenWindow()
ActiveWindow.Width = ActiveWindow.Width + 100
End Sub

Sub ShrinkWindow()
ActiveWindow.Width = ActiveWindow.Width - 100
End Sub

Sub MoveWindowLeft()
ActiveWindow.Left = ActiveWindow.Left -30
End Sub

Sub MoveWindowRight()
ActiveWindow.Left = ActiveWindow.Left +30
End Sub

Sub MoveWindowUp()
'DESCRIPTION: Hmmm... I wonder what this does
ActiveWindow.Top = ActiveWindow.Top -30
End Sub

Sub MoveWindowDown()
ActiveWindow.Top = ActiveWindow.Top +30
End Sub

Sub IncreaseWindowHeight()
ActiveWindow.Height = ActiveWindow.Height +30
End Sub

Sub DecreaseWindowHeight()
ActiveWindow.Height = ActiveWindow.Height -30
End Sub

Sub MoveNW()
ActiveWindow.Left = 0
ActiveWindow.Top = 0
End Sub


  • Moving/Sizing Windows

    Posted by Legacy on 10/04/1999 12:00am

    Originally posted by: Frank J. Lagattuta

    Your code to move/size windows is cool, but what really
    gets me is that the window opens with some semi-random
    size/position when I open a document. I always have to
    reposition and resize my document windows to where I like
    on the screen.

    Your article gave me an idea. With a little digging I
    found that you can add a Macro handler for the open
    document event. In my personal macro file I defined
    the following subroutine:

    ' Subroutine : Application_DocumentOpen
    ' Description : Handles the document open event in MS Dev Studio. This subrtn
    ' is called by MSDev after a document has been opened to allow
    ' the user to do any custom handling desired. Here we reposition
    ' and resize the window to our liking.
    ' Parameters : doc - the document opened
    Dim posRight

    Sub Application_DocumentOpen(doc)

    Dim wnd
    Set wnd = doc.ActiveWindow

    ' Set window size
    wnd.Width = 612
    wnd.Height = 797

    ' Get the file extension - .c or .cpp (or .cxx ...)
    ext = ActiveDocument.Name
    pos = Instr(ext, ".")
    If pos > 0 then
    Do While pos <> 1
    ext = Mid(ext, pos, Len(ext) - pos + 1)
    pos = Instr(ext, ".")
    ext = LCase(ext)
    End If

    ' Place the header doc windows slightly higher and to the left
    If ext = ".h" Or ext = ".hpp" Then
    wnd.Left = 0
    wnd.Top = 0
    wnd.Left = 24
    wnd.Top = 20
    End If

    ' Position window to right if needed
    If posRight = 1 Then
    wnd.Left = wnd.Left + 612
    posRight = 0
    posRight = 1
    End If

    End Sub

    With this, my document windows get placed where I want
    them with the desired size without me having to do


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

Top White Papers and Webcasts

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date