winlivebg_test1
changeset 0:d6d791557330
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 17 Oct 2019 02:54:07 +0300 |
parents | |
children | aa6a9521b088 |
files | .hgignore Makefile src/main.c |
diffstat | 3 files changed, 205 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/.hgignore Thu Oct 17 02:54:07 2019 +0300 1.3 @@ -0,0 +1,4 @@ 1.4 +\.swp 1.5 +\.d 1.6 +\.o 1.7 +\.exe
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/Makefile Thu Oct 17 02:54:07 2019 +0300 2.3 @@ -0,0 +1,13 @@ 2.4 +src = $(wildcard src/*.c) 2.5 +obj = $(src:.c=.o) 2.6 +bin = test.exe 2.7 + 2.8 +CFLAGS = -pedantic -Wall -g 2.9 +LDFLAGS = -mwindows -lopengl32 -lwinmm 2.10 + 2.11 +$(bin): $(obj) 2.12 + $(CC) -o $@ $(obj) $(LDFLAGS) 2.13 + 2.14 +.PHONY: clean 2.15 +clean: 2.16 + rm -f $(obj) $(bin)
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/src/main.c Thu Oct 17 02:54:07 2019 +0300 3.3 @@ -0,0 +1,188 @@ 3.4 +#include <stdio.h> 3.5 +#include <string.h> 3.6 +#include <windows.h> 3.7 +#include <GL/gl.h> 3.8 + 3.9 +#define WCNAME "livebg_test" 3.10 + 3.11 +void draw(void); 3.12 +HWND create_window(int width, int height); 3.13 +int init_gl(void); 3.14 +long CALLBACK handle_events(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam); 3.15 + 3.16 +HWND win; 3.17 +HDC dc; 3.18 +HGLRC ctx; 3.19 +int wcreg, quit; 3.20 +unsigned long start_time; 3.21 + 3.22 +int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, char *cmdline, int cmdshow) 3.23 +{ 3.24 + MSG msg; 3.25 + 3.26 + if(!(win = create_window(400, 300))) { 3.27 + return 1; 3.28 + } 3.29 + if(init_gl() == -1) { 3.30 + DestroyWindow(win); 3.31 + return 1; 3.32 + } 3.33 + 3.34 + start_time = timeGetTime(); 3.35 + 3.36 + for(;;) { 3.37 + while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { 3.38 + TranslateMessage(&msg); 3.39 + DispatchMessage(&msg); 3.40 + 3.41 + if(quit) goto done; 3.42 + } 3.43 + 3.44 + draw(); 3.45 + Sleep(10); 3.46 + } 3.47 +done: 3.48 + 3.49 + if(wcreg) { 3.50 + UnregisterClass(WCNAME, hinst); 3.51 + } 3.52 + return 0; 3.53 +} 3.54 + 3.55 +void draw(void) 3.56 +{ 3.57 + float tm = (timeGetTime() - start_time) / 1000.0f; 3.58 + glClearColor(0.1, 0.1, 0.1, 1); 3.59 + glClear(GL_COLOR_BUFFER_BIT); 3.60 + 3.61 + glMatrixMode(GL_MODELVIEW); 3.62 + glLoadIdentity(); 3.63 + glRotatef(tm * 10.0f, 0, 0, 1); 3.64 + 3.65 + glBegin(GL_TRIANGLES); 3.66 + glColor3f(1, 0, 0); 3.67 + glVertex2f(-0.5, -0.5); 3.68 + glColor3f(0, 1, 0); 3.69 + glVertex2f(0.5, -0.5); 3.70 + glColor3f(0, 0, 1); 3.71 + glVertex2f(0, 0.68); 3.72 + glEnd(); 3.73 + 3.74 + SwapBuffers(dc); 3.75 +} 3.76 + 3.77 +HWND fadewin; 3.78 + 3.79 +int CALLBACK match_win(HWND win, LPARAM lparam) 3.80 +{ 3.81 + HWND shwin = FindWindowEx(win, 0, "SHELLDLL_DefView", 0); 3.82 + if(shwin) { 3.83 + fadewin = FindWindowEx(0, shwin, "WorkerW", 0); 3.84 + } 3.85 + return 1; 3.86 +} 3.87 + 3.88 +HWND create_window(int width, int height) 3.89 +{ 3.90 + HINSTANCE hinst; 3.91 + HWND win, parent = 0; 3.92 + HWND pgman_win; 3.93 + unsigned int style; 3.94 + RECT rect; 3.95 + 3.96 + hinst = GetModuleHandle(0); 3.97 + 3.98 + if(!wcreg) { 3.99 + WNDCLASSEX wc; 3.100 + memset(&wc, 0, sizeof wc); 3.101 + wc.cbSize = sizeof wc; 3.102 + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; 3.103 + wc.lpfnWndProc = handle_events; 3.104 + wc.hInstance = hinst; 3.105 + wc.hIcon = wc.hIconSm = LoadIcon(0, IDI_APPLICATION); 3.106 + wc.hCursor = LoadCursor(0, IDC_ARROW); 3.107 + wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); 3.108 + wc.lpszClassName = WCNAME; 3.109 + RegisterClassEx(&wc); 3.110 + wcreg = 1; 3.111 + } 3.112 + 3.113 + if((pgman_win = FindWindow("Progman", 0))) { 3.114 + parent = pgman_win; 3.115 + GetWindowRect(pgman_win, &rect); 3.116 + //width = rect.right - rect.left; 3.117 + //height = rect.bottom - rect.top; 3.118 + 3.119 + /* 3.120 + SendMessage(pgman_win, 0x52c, 0, 0); 3.121 + 3.122 + fadewin = 0; 3.123 + EnumWindows(match_win, 0); 3.124 + if(fadewin) { 3.125 + //ShowWindow(fadewin, 0); 3.126 + } 3.127 + */ 3.128 + } 3.129 + 3.130 + style = parent ? WS_CHILD : WS_POPUP; 3.131 + if(!(win = CreateWindow(WCNAME, WCNAME, style | WS_VISIBLE, 0, 0, width, height, 3.132 + parent, 0, hinst, 0))) { 3.133 + fprintf(stderr, "failed to create window\n"); 3.134 + return 0; 3.135 + } 3.136 + dc = GetDC(win); 3.137 + return win; 3.138 +} 3.139 + 3.140 +int init_gl(void) 3.141 +{ 3.142 + int pixfmt; 3.143 + PIXELFORMATDESCRIPTOR pfd; 3.144 + 3.145 + memset(&pfd, 0, sizeof pfd); 3.146 + pfd.nSize = sizeof pfd; 3.147 + pfd.nVersion = 1; 3.148 + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; 3.149 + pfd.iPixelType = PFD_TYPE_RGBA; 3.150 + pfd.cColorBits = 24; 3.151 + pfd.cDepthBits = 32; 3.152 + pfd.iLayerType = PFD_MAIN_PLANE; 3.153 + 3.154 + if(!(pixfmt = ChoosePixelFormat(dc, &pfd))) { 3.155 + fprintf(stderr, "failed to find a suitable pixel format\n"); 3.156 + return -1; 3.157 + } 3.158 + SetPixelFormat(dc, pixfmt, &pfd); 3.159 + 3.160 + if(!(ctx = wglCreateContext(dc))) { 3.161 + fprintf(stderr, "failed to create an OpenGL context\n"); 3.162 + return -1; 3.163 + } 3.164 + wglMakeCurrent(dc, ctx); 3.165 + return 0; 3.166 +} 3.167 + 3.168 +long CALLBACK handle_events(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam) 3.169 +{ 3.170 + switch(msg) { 3.171 + case WM_PAINT: 3.172 + ValidateRect(win, 0); 3.173 + break; 3.174 + 3.175 + case WM_CLOSE: 3.176 + DestroyWindow(win); 3.177 + break; 3.178 + 3.179 + case WM_DESTROY: 3.180 + PostQuitMessage(0); 3.181 + break; 3.182 + 3.183 + case WM_QUIT: 3.184 + quit = 1; 3.185 + break; 3.186 + 3.187 + default: 3.188 + return DefWindowProc(win, msg, wparam, lparam); 3.189 + } 3.190 + return 0; 3.191 +}