Note that there are some explanatory texts on larger screens.

plurals
  1. POGDIplus flickering
    text
    copied!<p>I'm trying to draw with GDIplus on an transparent window and experiencing a lot of flickering. I've read plenty of threads that suggest implementing double-buffering or rendering to offscreen surface would help, which I've done but to no avail.</p> <p>Any idea what I've done wrong and how to fix it? Thanks.</p> <pre><code>#include &lt;Windows.h&gt; #include &lt;stdio.h&gt; #include &lt;time.h&gt; #include &lt;GdiPlus.h&gt; #pragma comment(lib, "GdiPlus.lib") HWND hWnd = NULL; WNDCLASSEX wcex; HDC hdc = NULL; PAINTSTRUCT ps; HGDIOBJ hfDefault; MSG msg; COLORREF transKey = RGB(37,14,103); ULONG_PTR m_gdiplusToken; char window_title[9] = "testings"; char window_class[9] = "testings"; int window_width = GetSystemMetrics(SM_CXSCREEN); int window_height = GetSystemMetrics(SM_CYSCREEN); DWORD MainThread(LPVOID lpArgs) { while(1) { RECT rc = {0,0,window_width,window_height}; InvalidateRect(hWnd, &amp;rc, false); UpdateWindow(hWnd); Sleep(50); } } LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { if(msg == WM_CREATE) { hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT); Gdiplus::GdiplusStartupInput gdiplusStartupInput; Gdiplus::GdiplusStartup(&amp;m_gdiplusToken, &amp;gdiplusStartupInput, NULL); SetLayeredWindowAttributes(hWnd, transKey, 128, LWA_COLORKEY); } else if(msg == WM_PAINT) { hdc = BeginPaint(hWnd, &amp;ps); Gdiplus::Graphics g(hdc); g.Clear(Gdiplus::Color(37,14,103)); Gdiplus::Bitmap* curBitmap = new Gdiplus::Bitmap(window_width, window_height); Gdiplus::Graphics* g1 = g.FromImage(curBitmap); static int x=1,y=1; // x += 3; y += 2; Gdiplus::Pen pen(Gdiplus::Color(255, 255, 0, 255)); g1-&gt;DrawLine(&amp;pen, x, y, window_width/2, window_height/2); g.DrawImage(curBitmap, 0, 0); EndPaint(hWnd, &amp;ps); } else if(msg == WM_CLOSE) { DestroyWindow(hWnd); } else if(msg == WM_DESTROY) { PostQuitMessage(0); } else { return DefWindowProc(hWnd, msg, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HBRUSH hbrBackground = CreateSolidBrush(transKey); wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = hbrBackground; wcex.lpszMenuName = NULL; wcex.lpszClassName = window_class; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); if(!RegisterClassEx(&amp;wcex)) return 1; hWnd = CreateWindowEx( WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST, window_class, window_title, WS_POPUP, 0, 0, window_width, window_height, NULL, NULL, hInstance, NULL ); if(!hWnd) return 1; ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)MainThread, NULL, NULL, NULL); while(GetMessage(&amp;msg, NULL, 0, 0) &gt; 0) { TranslateMessage(&amp;msg); DispatchMessage(&amp;msg); } Gdiplus::GdiplusShutdown(m_gdiplusToken); return msg.wParam; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload