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

  • The latest release of SugarCRM's flagship product gives users new tools to build extraordinary customer relationships. Read an in-depth analysis of SugarCRM's enhanced ability to help companies execute their customer-facing initiatives from Ovum, a leading technology research firm.

  • The impact of a data loss event can be significant. Real-time data is essential to remaining competitive. Many companies can no longer afford to rely on a truck arriving each day to take backup tapes offsite. For most companies, a cloud backup and recovery solution will eliminate, or significantly reduce, IT resources related to the mundane task of backup and allow your resources to be redeployed to more strategic projects. The cloud - can now be comfortable for you – with 100% recovery from anywhere all …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds