Dev Tool: garry.exe - Cure for the always-on-top problems with hl2.exe

As you may have noticed hl2.exe likes to become always on top with -window and -noborder parameters so I made a small application for those who are suffering from this “side-effect”.

Just throw it somewhere on your %PATH% (system32) and when the game is always on top you can just hit win+r and write garry.exe and curse a bit less.

SRC:



// Credits: I've got no idea. Not me though. I just assembled what I wanted to do with the snippet.
#define UNICODE
#define _UNICODE

#include <windows.h>
#include <Shellapi.h>
#include <tlhelp32.h>
#include <stdio.h>

#include <string.h>
#include <wchar.h>
#include <tchar.h>

#ifdef UNICODE

#define GETARGVT \
	LPTSTR * argvT; \
	int argcT; \
	argvT = CommandLineToArgvW(GetCommandLine(), &argcT); \
	if (argvT == NULL) return -1;

#define FREEARGVT \
	GlobalFree(argvT);


#else

#define GETARGVT
#define argcT argc
#define argvT argv
#define FREEARGVT

#endif


void forceBackground( HWND wnd )
{
	HDWP wnds = BeginDeferWindowPos( 10 );
	wnds = DeferWindowPos( wnds, wnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
	EndDeferWindowPos( wnds );
}


BOOL CALLBACK EnumWindowsProc(HWND hwnd, DWORD lParam)
{
    DWORD             pid = 0;

    if (!GetWindowThreadProcessId( hwnd, &pid )) {
        return TRUE;
    }

    if (lParam == pid) {
	forceBackground( hwnd );
    }
    return TRUE;
}





BOOL BGProc( DWORD dwProcessID, BOOL bSendClose )
{
	EnumWindows( EnumWindowsProc, (LPARAM) dwProcessID );
	return TRUE;

}


int main(int argc, char * argv[]) 
{ 
    HANDLE         hProcessSnap = NULL; 
    BOOL           bRet      = FALSE; 
    PROCESSENTRY32 pe32      = {0}; 
    long           lngTimeout = 1000; 
    LPTSTR         exeFile;

    GETARGVT;

    if (argcT < 2)
	exeFile = _T("hl2.exe");
	else
    exeFile = argvT[1];
    hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 

    if (hProcessSnap == INVALID_HANDLE_VALUE) return 0; 
 
    pe32.dwSize = sizeof(PROCESSENTRY32); 
    if (Process32First(hProcessSnap, &pe32)) 
    { 

        do 
        { 

		if (_tcsicmp( pe32.szExeFile, exeFile) == 0) {
			bRet = BGProc( pe32.th32ProcessID, TRUE );
		}


        } while (Process32Next(hProcessSnap, &pe32)); 
    } 
    CloseHandle (hProcessSnap); 
    FREEARGVT;
    return (bRet); 
}

Oh and the name came from the fact that I like to blame Valve or Garry when the game does that. Helps me remember.

This has been annoying me the past few days, thanks.

Same here. Thanks!

Never had this problem.

Thank you for this app.

You told me that you didn’t know c++ you bastard.

Awesome, thanks!

Silly Cubar!

Just used this to make myself a concommand to minimize, much easier than running garry.

Dual monitors ftw?

Do explain how a concommand can control the main window.

[editline]lol[/editline]

andrew mad so dumb rating for me :frowning:

Lua module

That, and I run Ubuntu so it’s no problem for me.

lua module popped on my mind too but I’m still afraid of the big daddy.

Using a Lua binary module to do this would require no hackery at all, since it wouldn’t be hooking into the engine’s internals.

you so cool

Thanks bro.

Awesome, I have been running in windowed mode and been having to put up with the border because there isnt much point in having windowed if it doesnt let you minimise :frowning:

If its not letting you minimize then open a window, such as chat or the console and it should let you without problem.

Doesn’t work.

Why question mark?