From 2ff87bd38f38eca0732c65666dee825b6795029a Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Tue, 1 Apr 2014 21:11:18 +0200 Subject: GetClientRect instead of WM_SIZE --- test/.gitignore | 1 + test/Makefile | 10 ++++++++-- test/layered.c | 58 ++++++++++++++++++++++++++++++--------------------------- test/layered.rc | 3 +++ test/manifest | 13 +++++++++++++ 5 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 test/layered.rc create mode 100644 test/manifest diff --git a/test/.gitignore b/test/.gitignore index b883f1f..774f008 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1 +1,2 @@ *.exe +*.o diff --git a/test/Makefile b/test/Makefile index 78ae707..de20a97 100644 --- a/test/Makefile +++ b/test/Makefile @@ -2,5 +2,11 @@ CC=i686-w64-mingw32-gcc CFLAGS=-static-libgcc -static-libstdc++ -I.. LIBS=-lopengl32 -lgdi32 -lkernel32 -layered.exe: layered.c - $(CC) $(CFLAGS) -o layered.exe layered.c ../wglarb.c $(LIBS) +WINDRES=i686-w64-mingw32-windres + +layered.exe: layered.c layered.rc.o + $(CC) $(CFLAGS) -o layered.exe layered.c layered.rc.o ../wglarb.c $(LIBS) -Wl,--subsystem,windows + + +layered.rc.o: layered.rc + $(WINDRES) --input layered.rc --output layered.rc.o diff --git a/test/layered.c b/test/layered.c index 41a7127..3260a06 100644 --- a/test/layered.c +++ b/test/layered.c @@ -12,11 +12,8 @@ LRESULT CALLBACK ViewProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam); -void reshape(int w,int h); -void display(); +void display(HWND hWnd); -HWND hWnd = NULL; -HDC hDC = NULL; HGLRC hRC = NULL; HMODULE hDwmAPI_DLL = NULL; @@ -63,10 +60,10 @@ BOOL OpenGLWindowCreate( RegisterClass(&wc); fprintf(stderr, "creating proper window...\n"); - hWnd = CreateWindowEx( dwExStyle, + HWND hWnd = CreateWindowEx( dwExStyle, wc.lpszClassName, lpszWindowName, - dwStyle | WS_CLIPSIBLINGS|WS_CLIPCHILDREN, + dwStyle, 240,240,640,640, NULL,NULL, hInstance, @@ -79,7 +76,7 @@ BOOL OpenGLWindowCreate( SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)ViewProc); fprintf(stderr, "retrieving proper DC...\n"); - hDC = GetDC(hWnd); + HDC hDC = GetDC(hWnd); if(!hDC) { fprintf(stderr, "error retrieving proper DC\n"); DestroyWindow(hWnd); @@ -148,10 +145,9 @@ BOOL OpenGLWindowCreate( return FALSE; } + ReleaseDC(hWnd, hDC); - /* Finally we can bind the proper OpenGL context to our window */ - wglMakeCurrent(hDC, hRC); - +#if 1 if( hDwmAPI_DLL ) { if( impl_DwmEnableBlurBehindWindow ) { DWM_BLURBEHIND bb = {0}; @@ -169,6 +165,7 @@ BOOL OpenGLWindowCreate( else { SetLayeredWindowAttributes(hWnd, 0, 0xff, LWA_ALPHA); } +#endif UpdateWindow(hWnd); ShowWindow(hWnd, SW_SHOW); @@ -190,7 +187,6 @@ void OnOpenGLWindowDestroy() { wglMakeCurrent(NULL,NULL); wglDeleteContext(hRC); - ReleaseDC(hWnd,hDC); PostQuitMessage(0); } @@ -217,12 +213,9 @@ LRESULT CALLBACK ViewProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam) break; case WM_PAINT: - display(); + display(hWnd); break; - case WM_SIZE: - reshape(LOWORD(lParam),HIWORD(lParam)); - break; default: break; } @@ -230,21 +223,20 @@ LRESULT CALLBACK ViewProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam) } -void reshape(int w,int h) +void display(HWND hWnd) { - win_width = w; - win_height = h; -} + HDC hDC = GetDC(hWnd); + RECT rect; + GetClientRect(hWnd, &rect); + wglMakeCurrent(hDC, hRC); -void display() -{ - float const ratio = (float)win_width/(float)win_height; + float const ratio = (float)rect.right/(float)rect.bottom; glViewport( 0, 0, - win_width, - win_height); + rect.right, + rect.bottom); glClearColor(0., 0., 0., 0.); glClearDepth(1.); @@ -279,14 +271,23 @@ void display() SwapBuffers(hDC); glFinish(); + + wglMakeCurrent(NULL, NULL); + ReleaseDC(hWnd, hDC); } +#if 1 int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { +#else +int main(int argc, char *argv[]) +{ + HINSTANCE hInstance = GetModuleHandle(NULL); +#endif MSG msg; BOOL bRet; @@ -305,8 +306,12 @@ int CALLBACK WinMain( "Test", "TestWnd", ViewProc, hInstance, - WS_OVERLAPPEDWINDOW, - WS_EX_APPWINDOW) ) { +#if 0 + WS_OVERLAPPEDWINDOW +#else + WS_POPUP +#endif + , WS_EX_APPWINDOW) ) { return -1; } @@ -318,7 +323,6 @@ int CALLBACK WinMain( TranslateMessage(&msg); DispatchMessage(&msg); } - display(); } return msg.wParam; } diff --git a/test/layered.rc b/test/layered.rc new file mode 100644 index 0000000..187387c --- /dev/null +++ b/test/layered.rc @@ -0,0 +1,3 @@ +#include "winuser.h" +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST manifest + diff --git a/test/manifest b/test/manifest new file mode 100644 index 0000000..3f616a1 --- /dev/null +++ b/test/manifest @@ -0,0 +1,13 @@ + + + + + + + + + + + + + -- cgit v1.2.3