Blitting to the screen in WinAPI

From Computernewb Wiki
Jump to navigation Jump to search

In Windows it is possible to blit to the entire screen using BitBlt() and other GDI functions.

Example C source code:

// Sample for Wiki Article  
// Forever until killed keeps inverting the screen.
// Tested on mingw-w64 i686, using the following compile command
// i686-w64-mingw-gcc wiki-dc.c -o wiki-dc -lgdi32 -mwindows 

#include <windows.h>

void DCFuckThrd(){
        int w = GetDeviceCaps(GetDC(NULL), HORZRES);
        int h = GetDeviceCaps(GetDC(NULL), VERTRES);
                BitBlt(GetDC(NULL), 0, 0, w, h, GetDC(NULL), 0, 0, NOTSRCCOPY);

int main() {
        DWORD tid;
        HANDLE a = CreateThread(NULL, 0, DCFuckThrd, NULL, 0, &tid);
        WaitForSingleObject(a, INFINITE);