• Win7 Noborder Script
    10 replies, posted
When I used Windows XP, I was able to use the following AutoHotkey script: [code] #NoEnv WinGet,pid,PID,A WinWaitNotActive,ahk_pid %pid% MsgBox,3,Confirm,%pid% IfMsgBox No { ExitApp } WinSet,Style,-0xC00000,A ;WS_CAPTION WinSet,Style,-0x40000,A ;WS_SIZEBOX WinMove,A,,0,0,1680,1050 WinSet,AlwaysOnTop,ON,A [/code] (or AutoIt equivalent) to set a Window's style similar to that of Team Fortress 2 with the -noborder option. This worked for almost [i]every[/i] windowed application, including Notepad. Unfortunately, this no longer works in Windows 7. How would I go about writing a program to accomplish the same thing in Windows 7?
Did you try switching to the Windows Classic theme and then testing it?
That doesn't work either, thanks.
Still looking for a solution...any ideas?
I noticed that EVEMon removes the border for EVE in Windows 7 correctly. Here is the specific method: [code] /// <summary> /// Position the window on the target screen. /// </summary> /// <param name="hWnd">EVE instance to be moved</param> /// <param name="targetScreen">Screen to be moved to</param> public static void Relocate(IntPtr hWnd, int targetScreen) { Rectangle ncr = GetWindowRect(hWnd); Rectangle cr = GetClientRectInScreenCoords(hWnd); int wDiff = ncr.Width - cr.Width; int hDiff = ncr.Height - cr.Height; Screen sc = Screen.AllScreens[targetScreen]; // Null guard? Could in any case sc be null? if (sc == null) return; // Grab the current window style long oldStyle = NativeMethods.GetWindowLong(hWnd, NativeMethods.GWL_STYLE); // Turn off dialog frame and border long newStyle = oldStyle & ~(NativeMethods.WS_DLGFRAME | NativeMethods.WS_BORDER); NativeMethods.SetWindowLong(hWnd, NativeMethods.GWL_STYLE, newStyle); NativeMethods.MoveWindow(hWnd, sc.Bounds.X, sc.Bounds.Y, cr.Width, cr.Height, true); } [/code] (trunk/EVEMon/Relocator.cs) Obtained from the SVN here: [url]http://evemon.battleclinic.com/source_code.php[/url] I'm intent on figuring this out unless someone beats me to the punch. [b]Edit:[/b] Now that I know what the Windows API method is called, I found this: [url]http://stackoverflow.com/questions/2398746/removing-window-border[/url]
So this removes the window chrome from the program?
It removes the window's borders and positions the window as if it were running in fullscreen. [editline]05:14PM[/editline] Got a rough sketch of code: [code] #include <windows.h> #include <tchar.h> #include <iostream> const int maxWindows = 10; HWND hwndTarget[maxWindows]; unsigned long hwndTargets = 0; bool CALLBACK EnumWindowsProcFoo(HWND hwnd, LPARAM lParam){ // Prevent buffer overflow for people that like to run maxWindows+1 instances simultaneously if (hwndTargets > maxWindows) return false; // Get window title TCHAR szTitle[127]; GetWindowText(hwnd, szTitle, sizeof(szTitle)); // Check window title for match if (_tcscmp(szTitle, _T("Dwarf Fortress")) != 0){ return true; } // Check window size WINDOWINFO wi; GetWindowInfo(hwnd, &wi); DWORD dwW = wi.rcWindow.right - wi.rcWindow.left; DWORD dwH = wi.rcWindow.bottom - wi.rcWindow.top; // Print prompt _tprintf(_T(" %i: %s\n"),hwndTargets,szTitle); _tprintf(_T(" %i x %i\n"),dwW,dwH); hwndTarget[hwndTargets++] = hwnd; // Prevent buffer overflow for people that like to run maxWindows+1 instances simultaneously if (hwndTargets > maxWindows) return false; return true; } int promptForWindow(){ std::cout << "Select a window:\n"; EnumDesktopWindows(NULL,(WNDENUMPROC)EnumWindowsProcFoo,NULL); std::cout << "Choice: "; int a; std::cin >> a; if (a >= (int)hwndTargets || a < 0) { return -1; }; return a; } int main(){ //Prompt for the window int iWin = promptForWindow(); if (iWin == -1){ std::cout << "No action will be taken.\n"; system("pause"); return 0; } HWND hwnd = hwndTarget[iWin]; // Set the new style of chosen window long lStyle = GetWindowLong(hwnd, GWL_STYLE); lStyle = lStyle & ~(WS_DLGFRAME | WS_BORDER | WS_CAPTION | WS_SIZEBOX); SetWindowLong(hwnd, GWL_STYLE, lStyle); // Move to (0,0) RECT lpRect; GetWindowRect(hwnd,&lpRect); SetWindowPos(hwnd,HWND_TOP,0,0,lpRect.right - lpRect.left,lpRect.bottom - lpRect.top, SWP_NOSIZE | SWP_SHOWWINDOW ); system("pause"); return 0; } [/code] Now I just need to set coordinates, and I'm in business. [b]Edit:[/b] Code should reposition to (0,0) now.
[b]Release:[/b] [url=http://eagle.undo.it:8083/download/?id=12&act=url][img]http://eagle.undo.it:8083/download/?id=12&act=img[/img][/url] [b]Usage:[/b] Put the application you want on the correct monitor, launch the program, then click on the application you want to be no-borderized. [b]How it works:[/b] The application waits for the active window to change. When the active window is changed, it gets which monitor the cursor is on. The active window is then stripped of the border and resized/repositioned to that monitor. [b]Source:[/b] [code] #include <windows.h> #include <tchar.h> #include <time.h> #include <iostream> #include <math.h> #include <list> const int maxWindows = 10; HWND hwndTarget[maxWindows]; unsigned long hwndTargets = 0; bool CALLBACK EnumWindowsProcFoo(HWND hwnd, LPARAM lParam){ // Prevent buffer overflow for people that like to run maxWindows+1 instances simultaneously if (hwndTargets > maxWindows) return false; // Get window title TCHAR szTitle[127]; GetWindowText(hwnd, szTitle, sizeof(szTitle)); // Check window title for match if (_tcscmp(szTitle, _T("Dwarf Fortress")) != 0){ return true; } // Check window size WINDOWINFO wi; GetWindowInfo(hwnd, &wi); DWORD dwW = wi.rcWindow.right - wi.rcWindow.left; DWORD dwH = wi.rcWindow.bottom - wi.rcWindow.top; // Print prompt _tprintf(_T(" %i: %s\n"),hwndTargets,szTitle); _tprintf(_T(" %i x %i\n"),dwW,dwH); hwndTarget[hwndTargets++] = hwnd; // Prevent buffer overflow for people that like to run maxWindows+1 instances simultaneously if (hwndTargets > maxWindows) return false; return true; } int promptForWindow(){ std::cout << "Select a window:\n"; EnumDesktopWindows(NULL,(WNDENUMPROC)EnumWindowsProcFoo,NULL); std::cout << "Choice: "; int a; std::cin >> a; if (a >= (int)hwndTargets || a < 0) { return -1; }; return a; } //Automatic method void sleep(int ctTimeDelay_ms){ clock_t ctTimeCurrent = clock(); clock_t ctTimeTarget = ctTimeCurrent + (ctTimeDelay_ms * CLOCKS_PER_SEC / 1000); while (clock() < ctTimeTarget){ } } int getActiveWindow(){ std::cout << "Waiting for active window change..."; HWND hCur = GetForegroundWindow(); while (hwndTargets == 0){ sleep(100); std::cout << "."; HWND hProc = GetForegroundWindow(); if (hCur != hProc){ // Get window title TCHAR szTitle[127]; GetWindowText(hProc, szTitle, sizeof(szTitle)); _tprintf(_T("%s\n"),szTitle); // Return window hwndTarget[hwndTargets] = hProc; return hwndTargets++; } } return -1; } //Get monitors std::list<DISPLAY_DEVICE> iterateMonitors(){ std::list<DISPLAY_DEVICE> mons; bool done = false; for (int i=0;!done;++i){ DISPLAY_DEVICE mon; mon.cb = sizeof(DISPLAY_DEVICE); done = !EnumDisplayDevices(NULL, i, &mon, EDD_GET_DEVICE_INTERFACE_NAME); if (!done){ mons.push_back(mon); } } return mons; } //Get monitors' resolutions struct RESOLUTION{ int x; int y; int w; int h; int cx; int cy; }; std::list<RESOLUTION> iterateMonitorsResolutions(){ std::list<DISPLAY_DEVICE> lstMons = iterateMonitors(); std::list<RESOLUTION> lstResolutions; for (std::list<DISPLAY_DEVICE>::iterator iterMon = lstMons.begin(); iterMon != lstMons.end(); iterMon++) { DISPLAY_DEVICE ddMon = *iterMon; wprintf(L"%s:%s\n\n",ddMon.DeviceName,ddMon.DeviceString); DEVMODE dmMon; dmMon.dmSize = sizeof(DEVMODE); dmMon.dmDriverExtra = 64; if (EnumDisplaySettings(ddMon.DeviceName, ENUM_CURRENT_SETTINGS, &dmMon)){ printf("\tx:%i\n\ty:%i\n",dmMon.dmPosition.x,dmMon.dmPosition.y); printf("\tw:%i\n\th:%i\n",dmMon.dmPelsWidth,dmMon.dmPelsHeight); RESOLUTION res; res.x = dmMon.dmPosition.x; res.y = dmMon.dmPosition.y; res.w = dmMon.dmPelsWidth; res.h = dmMon.dmPelsHeight; res.cx = res.x + res.w; res.cy = res.y + res.h; lstResolutions.push_back(res); } } return lstResolutions; } int main(){ //Get the window //int iWin = promptForWindow(); int iWin = getActiveWindow(); //Process the window if (iWin == -1){ std::cout << "No action will be taken.\n"; system("pause"); return 0; } HWND hwnd = hwndTarget[iWin]; // Get window information RECT lpRect; GetWindowRect(hwnd,&lpRect); RESOLUTION victim; victim.x = lpRect.left; victim.y = lpRect.top; victim.cx = lpRect.right; victim.cy = lpRect.bottom; victim.w = victim.cx - victim.x; victim.h = victim.cy - victim.y; //Iterate monitors and determine which monitor to place on std::list<RESOLUTION> lstRes = iterateMonitorsResolutions(); //Vars for finding best monitor bool bGood = false; RESOLUTION rBest; /* int iTolerence = -1; RESOLUTION rBest; //Find best monitor by width for (std::list<RESOLUTION>::iterator iterRes = lstRes.begin(); iterRes != lstRes.end(); iterRes++) { RESOLUTION check = *iterRes; bool hit = false; int iDifference = abs(check.w - victim.w); if (iTolerence == -1){ hit = true; } else if (iDifference < iTolerence){ hit = true; } if (hit){ iTolerence = iDifference; rBest = check; } } if (iTolerence >= 0) bGood = true; */ //Find best monitor by mouse position POINT cursorPos; GetCursorPos(&cursorPos); for (std::list<RESOLUTION>::iterator iterRes = lstRes.begin(); iterRes != lstRes.end(); iterRes++) { RESOLUTION check = *iterRes; if (cursorPos.x > check.x && cursorPos.y > check.y && cursorPos.x < check.cx && cursorPos.y < check.cy) { rBest = check; bGood = true; break; } } //If we hit, execute if (bGood) { // Set the new style of chosen window long lStyle = GetWindowLong(hwnd, GWL_STYLE); lStyle = lStyle & ~(WS_DLGFRAME | WS_BORDER | WS_CAPTION | WS_SIZEBOX); SetWindowLong(hwnd, GWL_STYLE, lStyle); SetWindowPos(hwnd,HWND_TOP,rBest.x,rBest.y,rBest.w,rBest.h, SWP_SHOWWINDOW ); } return 0; } [/code] Pardon the mess, I did it in a hurry. Google search keys: [code] windows noborder fullscreen like team fortress 2 -fullscreen -noborder [/code]
Doesn't work for me on windows 7 32bit, anything needed for it to work?
Forgot to set to release build. (Release build now up) Did you try compiling it? Note that you cannot click the taskbar to select the window.
Go to any Source game's launch properties and add -noborder, make sure game is set to windowed mode, and there you go!
Sorry, you need to Log In to post a reply to this thread.