# HG changeset patch # User John Tsiombikas # Date 1571270047 -10800 # Node ID d6d7915573306cd8eeed8602b935b3d8f592817d initial commit diff -r 000000000000 -r d6d791557330 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Thu Oct 17 02:54:07 2019 +0300 @@ -0,0 +1,4 @@ +\.swp +\.d +\.o +\.exe diff -r 000000000000 -r d6d791557330 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Thu Oct 17 02:54:07 2019 +0300 @@ -0,0 +1,13 @@ +src = $(wildcard src/*.c) +obj = $(src:.c=.o) +bin = test.exe + +CFLAGS = -pedantic -Wall -g +LDFLAGS = -mwindows -lopengl32 -lwinmm + +$(bin): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + +.PHONY: clean +clean: + rm -f $(obj) $(bin) diff -r 000000000000 -r d6d791557330 src/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main.c Thu Oct 17 02:54:07 2019 +0300 @@ -0,0 +1,188 @@ +#include +#include +#include +#include + +#define WCNAME "livebg_test" + +void draw(void); +HWND create_window(int width, int height); +int init_gl(void); +long CALLBACK handle_events(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam); + +HWND win; +HDC dc; +HGLRC ctx; +int wcreg, quit; +unsigned long start_time; + +int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, char *cmdline, int cmdshow) +{ + MSG msg; + + if(!(win = create_window(400, 300))) { + return 1; + } + if(init_gl() == -1) { + DestroyWindow(win); + return 1; + } + + start_time = timeGetTime(); + + for(;;) { + while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + + if(quit) goto done; + } + + draw(); + Sleep(10); + } +done: + + if(wcreg) { + UnregisterClass(WCNAME, hinst); + } + return 0; +} + +void draw(void) +{ + float tm = (timeGetTime() - start_time) / 1000.0f; + glClearColor(0.1, 0.1, 0.1, 1); + glClear(GL_COLOR_BUFFER_BIT); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glRotatef(tm * 10.0f, 0, 0, 1); + + glBegin(GL_TRIANGLES); + glColor3f(1, 0, 0); + glVertex2f(-0.5, -0.5); + glColor3f(0, 1, 0); + glVertex2f(0.5, -0.5); + glColor3f(0, 0, 1); + glVertex2f(0, 0.68); + glEnd(); + + SwapBuffers(dc); +} + +HWND fadewin; + +int CALLBACK match_win(HWND win, LPARAM lparam) +{ + HWND shwin = FindWindowEx(win, 0, "SHELLDLL_DefView", 0); + if(shwin) { + fadewin = FindWindowEx(0, shwin, "WorkerW", 0); + } + return 1; +} + +HWND create_window(int width, int height) +{ + HINSTANCE hinst; + HWND win, parent = 0; + HWND pgman_win; + unsigned int style; + RECT rect; + + hinst = GetModuleHandle(0); + + if(!wcreg) { + WNDCLASSEX wc; + memset(&wc, 0, sizeof wc); + wc.cbSize = sizeof wc; + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + wc.lpfnWndProc = handle_events; + wc.hInstance = hinst; + wc.hIcon = wc.hIconSm = LoadIcon(0, IDI_APPLICATION); + wc.hCursor = LoadCursor(0, IDC_ARROW); + wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); + wc.lpszClassName = WCNAME; + RegisterClassEx(&wc); + wcreg = 1; + } + + if((pgman_win = FindWindow("Progman", 0))) { + parent = pgman_win; + GetWindowRect(pgman_win, &rect); + //width = rect.right - rect.left; + //height = rect.bottom - rect.top; + + /* + SendMessage(pgman_win, 0x52c, 0, 0); + + fadewin = 0; + EnumWindows(match_win, 0); + if(fadewin) { + //ShowWindow(fadewin, 0); + } + */ + } + + style = parent ? WS_CHILD : WS_POPUP; + if(!(win = CreateWindow(WCNAME, WCNAME, style | WS_VISIBLE, 0, 0, width, height, + parent, 0, hinst, 0))) { + fprintf(stderr, "failed to create window\n"); + return 0; + } + dc = GetDC(win); + return win; +} + +int init_gl(void) +{ + int pixfmt; + PIXELFORMATDESCRIPTOR pfd; + + memset(&pfd, 0, sizeof pfd); + pfd.nSize = sizeof pfd; + pfd.nVersion = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.cColorBits = 24; + pfd.cDepthBits = 32; + pfd.iLayerType = PFD_MAIN_PLANE; + + if(!(pixfmt = ChoosePixelFormat(dc, &pfd))) { + fprintf(stderr, "failed to find a suitable pixel format\n"); + return -1; + } + SetPixelFormat(dc, pixfmt, &pfd); + + if(!(ctx = wglCreateContext(dc))) { + fprintf(stderr, "failed to create an OpenGL context\n"); + return -1; + } + wglMakeCurrent(dc, ctx); + return 0; +} + +long CALLBACK handle_events(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam) +{ + switch(msg) { + case WM_PAINT: + ValidateRect(win, 0); + break; + + case WM_CLOSE: + DestroyWindow(win); + break; + + case WM_DESTROY: + PostQuitMessage(0); + break; + + case WM_QUIT: + quit = 1; + break; + + default: + return DefWindowProc(win, msg, wparam, lparam); + } + return 0; +}