31

Is it possible to make the console window in Visual Studio show up in the same location on screen for each compile?

I always have to move it around whenever I compile because its starting location overlaps things.

4
  • Ehm, are you talking about the console window when you are debugging? Commented Nov 20, 2011 at 2:41
  • See stackoverflow.com/questions/1548838/… Commented Nov 20, 2011 at 2:41
  • David, that's a badass suggestion but it looks like I'll need to make a framework that manually allocates a console window for that. Is there any way to simply change it in my IDE settings? Commented Nov 20, 2011 at 2:49
  • @Aux no you don't, you just use the Win32 API. Commented Nov 20, 2011 at 2:57

2 Answers 2

44

By default you can change console window settings per application and windows will save them for the next time when this application is run. You may change the start location by clicking right button on the console title bar, then choosing Properties and Layout tab. Then uncheck the "Let system position window" checkbox and type the coordinates you would like.

Unfortunately Visual Studio when you run an application without the debugger (Ctrl + F5) will launch the cmd.exe /c <your app> command. So changing properties on this window will also change settings for all console sessions in the system.

This does not apply to the debug run as under the debugger VS launches just the application and so the settings apply only to its console windows.

Sign up to request clarification or add additional context in comments.

2 Comments

You made today at least someone happy. Thx.
Thank you! I was always on top of Visual Studio and now it it not.
2

I came here with the same problem, and was sure there must be an option in VS. I ended up writing a quick python script that runs in the background, searches for the window and sets its last position. Also optionally sets it to always on top, and persists the position in a file. Hopefully will help someone else out.

import win32api import win32gui import win32con import msvcrt import sys import time import threading import pywintypes import argparse import re import weakref import pickle def log_message(message,*args): print(("[%s]" % message).ljust(30) ," ... ",*(str(arg) for arg in args)) def make_file_name(arguments): return arguments.save_file_name or "window_" + re.sub("[^a-z]","_",arguments.title_text,flags=re.IGNORECASE) def update_proc(flags,arguments): found_pos = (0,0,500,500) found_hwnd = -1 if arguments.save_to_file and not arguments.reset: load_file_name = make_file_name(arguments) try: with open(load_file_name,"rb") as load_file: found_pos = pickle.load(load_file) except:pass while not flags.exit: try: hwnd = win32gui.FindWindow(arguments.class_text,arguments.title_text) if not hwnd: continue if hwnd != found_hwnd: log_message("new window found",hwnd) for _ in range(10): win32gui.SetWindowPos(hwnd,0 if not arguments.on_top else win32con.HWND_TOPMOST,*found_pos,0) time.sleep(0.01) log_message("setting window position",found_pos) found_hwnd = hwnd time.sleep(0.1) if win32gui.IsIconic(found_hwnd): continue rect = win32gui.GetWindowRect(found_hwnd) new_pos = (rect[0],rect[1],rect[2]-rect[0],rect[3]-rect[1]) #ignore negative pos if True in [ r < 0 for r in new_pos[0:2] ]: continue if new_pos == found_pos: continue if arguments.save_to_file: log_message("saving position",new_pos) save_file_name = make_file_name(arguments) try: with open(save_file_name,"wb") as save_file: pickle.dump(new_pos,save_file) except:pass else: log_message("updading stored position",new_pos) found_pos = new_pos except pywintypes.error:pass if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-s","--savetofile",help="Save window settings to a file",action="store_true",dest="save_to_file") parser.add_argument("-sfn","--savefilename",type=str,help="File name to use if --savetofile specified (or a default is generated)",dest="save_file_name") parser.add_argument("-ot","--ontop",help="Window Always Ontop",dest="on_top",action="store_true") parser.add_argument("-c","--class",type=str,help="Window Class Name",dest="class_text") parser.add_argument("-r","--reset",help="Reset Window Position",action="store_true") parser.add_argument("-t","--title",type=str,help="Window Title Text",required=True,dest="title_text") arguments = parser.parse_args() flags = type("", (), {"exit":False})() update_thread = threading.Thread(target=update_proc,args=[weakref.proxy(flags),arguments]) update_thread.start() if arguments.save_to_file: log_message("saving to file",make_file_name(arguments)) while True: if flags.exit: break key = msvcrt.getch() if key == b'q': flags.exit = True log_message("exiting") break update_thread.join() 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.