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
	Loop
	proj_dir = left(proj_path, pos+1) & "stdafx.h"
	documents.open 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()
'DESCRIPTION: Guess
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


Comments

  • 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, ".")
    Loop
    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
    Else
    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
    Else
    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
    anything.

    -Frank

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Due to internal controls and regulations, the amount of long term archival data is increasing every year. Since magnetic tape does not need to be periodically operated or connected to a power source, there will be no data loss because of performance degradation due to the drive actuator. Read this white paper to learn about a series of tests that determined magnetic tape is a reliable long-term storage solution for up to 30 years.

Most Popular Programming Stories

More for Developers

RSS Feeds