Skip to content

Commit

Permalink
adds suffix to window title
Browse files Browse the repository at this point in the history
  • Loading branch information
sptls committed Sep 28, 2022
1 parent 06d84ba commit d0a305b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.exe
35 changes: 25 additions & 10 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#include <stdio.h>
#include <windows.h>

void *MainThread(void *vargp);
#define MAX_TITLE_LEN 256

void* MainThread(void *arg);
void SetTitle(HWND hwnd);
void RestoreTitle(HWND hwnd);

int main(int argc, char** argv)
{
MainThread(NULL);
return 0;
}

void *MainThread(void *vargp)
void* MainThread(void *arg)
{
BOOL bWasPressed = FALSE;
char title[256];
int totalWindows = 1;
int *winList = malloc(totalWindows);
winList[0] = 0;
Expand Down Expand Up @@ -47,28 +49,25 @@ void *MainThread(void *vargp)
winList = newList;
totalWindows--;

RestoreTitle(hwnd);
SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 1000, 800, SWP_NOMOVE | SWP_NOSIZE);
GetWindowTextA(hwnd, title, 256);
printf("Window \"%s\", unset from TOP\n", title);
fflush(stdout);
}
}
if(addNew == TRUE)
{
GetWindowTextA(hwnd, title, 256);
printf("Window \"%s\" set ONTOP\n", title);
fflush(stdout);
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 1000, 800, SWP_NOMOVE | SWP_NOSIZE);
if(totalWindows == 1)
{
winList[0] = GetWindowThreadProcessId(hwnd, NULL);
totalWindows++;
SetTitle(hwnd);
}
else
{
winList = realloc(winList, totalWindows + 1);
winList[totalWindows] = GetWindowThreadProcessId(hwnd, NULL);
totalWindows++;
SetTitle(hwnd);
}
}
bWasPressed = FALSE;
Expand All @@ -77,4 +76,20 @@ void *MainThread(void *vargp)
bWasPressed = TRUE;
}
free(winList);
}

void SetTitle(HWND hwnd)
{
char title[MAX_TITLE_LEN];
GetWindowTextA(hwnd, title, MAX_TITLE_LEN);
strncat(title, " (ONTOP)", MAX_TITLE_LEN - 1);
SetWindowTextA(hwnd, title);
}

void RestoreTitle(HWND hwnd)
{
char title[MAX_TITLE_LEN];
GetWindowTextA(hwnd, title, MAX_TITLE_LEN);
title[strlen(title) - strlen(" (ONTOP") - 1] = '\0';
SetWindowTextA(hwnd, title);
}

0 comments on commit d0a305b

Please sign in to comment.