WIN API не работает TransparentBlt

Выдаёт ошибку изза функции TransparentBlt, при попытке скомпилировать и запустить выдаёт unable to start program... и 2 ошибки которые не показует.

Вот код, Visual studio 2019, строчка, которая вызывает ошибку выделена отдельно.

#ifndef UNICODE
#define UNICODE
#endif

#include <iostream>
#include <windows.h>
#include <thread>
#include "functions.h"
using namespace std;
int count_size(int);
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
bool issetup = false;
HBITMAP border = (HBITMAP)LoadImage(NULL, L"C:\\bitmap.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HBITMAP red = (HBITMAP)LoadImage(NULL, L"C:\\Red.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HBITMAP snake = (HBITMAP)LoadImage(NULL, L"C:\\snake.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HBITMAP apple = (HBITMAP)LoadImage(NULL, L"C:\\apple.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HBITMAP game_over = (HBITMAP)LoadImage(NULL, L"C:\\GAME OVER.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HBITMAP memorybitmap = NULL;
PAINTSTRUCT ps;
HDC hdc = NULL;
HDC bmpdc = NULL;
HFONT hfont = NULL;
const int block_size = 20;
int board_width;
int board_height;
RECT clrect;
int border_side;
int border_top;
int frametime;
int headx;
int heady;
HWND hwnd;
int counter = 0;
void upwin();
HDC memoryDC = NULL;
int buffx;
int buffy;
HDC snakedc;
int taillen = 0;
int* tailx = new int[taillen];
int* taily = new int[taillen];
bool isapplecrt = false;
int applex;
int appley;
int eatenaplle = 0;
short int way;
short int buffway;
TEXTMETRIC textmetric;

bool issnake(int, int);


int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
    // Register the window class.
    const wchar_t CLASS_NAME[] = L"Sample Window Class";
    AllocConsole();
    freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
    WNDCLASS wc = { };

    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.lpszClassName = CLASS_NAME;

    RegisterClass(&wc);

    // Create the window.

        hwnd = CreateWindowEx(
        0,                              // Optional window styles.
        CLASS_NAME,                     // Window class
        L"Learn to Program Windows",    // Window text
        WS_POPUP,            // Window style

        // Size and position
        0, 0, 800, 800,

        NULL,       // Parent window    
        NULL,       // Menu
        hInstance,  // Instance handle
        NULL        // Additional application data
    );

    if (hwnd == NULL)
    {
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    //ShowWindow(hwnd, WS_MAXIMIZE);

    // Run the message loop.
    MSG msg = { };
    std::thread th(upwin);
    SetForegroundWindow(hwnd);
    while(true )
    {
        GetMessage(&msg, NULL, 0, 0);
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    th.detach();

    return 0;

}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{   
    //cout << "wndproc" << endl;
    switch (uMsg)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;

    case WM_PAINT:
        if (issetup == false)
    {
            hdc = BeginPaint(hwnd, &ps);
            std::cout << "setup!" << std::endl;

        bmpdc = CreateCompatibleDC(hdc);
        memoryDC = CreateCompatibleDC(hdc);
        SelectObject(bmpdc, border);
        GetClientRect(hwnd, &clrect);
        board_width = count_size(clrect.right);
        board_height = count_size(clrect.bottom);
        border_side = (clrect.right - count_size(clrect.right)) / 2;
        border_top = (clrect.bottom - count_size(clrect.bottom)) / 2;

        // drawing border

        headx = block_size + border_side;
        heady = block_size + border_top;
        FillRect(hdc, &clrect, (HBRUSH)(COLOR_WINDOW + 1));
        for (int i = 0; i < board_width / block_size; i++)
            StretchBlt(hdc, clrect.left + border_side + i * block_size, clrect.top + border_top, block_size, block_size, bmpdc, 0, 0, 10, 10, SRCCOPY);
        for (int i = 0; i < board_width / block_size; i++)
            StretchBlt(hdc, clrect.left + border_side + i * block_size, clrect.bottom - border_top - block_size, block_size, block_size, bmpdc, 0, 0, 10, 10, SRCCOPY);
        for (int i = 0; i < board_height / block_size; i++)
            StretchBlt(hdc, clrect.left + border_side, clrect.top + border_top + i * block_size, block_size, block_size, bmpdc, 0, 0, 10, 10, SRCCOPY);
        for (int i = 0; i < board_height / block_size; i++)
            StretchBlt(hdc, clrect.right - border_side - block_size, clrect.top + border_top + i * block_size, block_size, block_size, bmpdc, 0, 0, 10, 10, SRCCOPY);
        // filling borad

        SelectObject(bmpdc, red);
        for (int i = 0; i < board_width / block_size - 2; i++)
            for (int j = 0; j < board_height / block_size - 2; j++)
                StretchBlt(hdc, clrect.left + border_side + block_size + block_size * i, clrect.top + border_top + j * block_size + block_size, block_size, block_size, bmpdc, 0, 0, 10, 10, SRCCOPY);
        issetup = true;
    }
        long long unsigned int timer = clock();

        SelectObject(bmpdc, red);

        // add snake lenght
        if (taillen > eatenaplle)
        {
            taillen--;
            buffx = tailx[taillen-1];
            buffy = taily[taillen-1];
            dell_back(tailx, taillen);
            dell_back(taily, taillen);

        }
        pull_start(tailx, taillen, headx);
        pull_start(taily, taillen, heady);
        // end add snake lenght

        GetAsyncKeyState('W') ? buffway = way, way = 1 : GetAsyncKeyState('D') ? buffway = way, way = 2 : GetAsyncKeyState('S') ? buffway = way, way = 3 : GetAsyncKeyState('A') ? buffway = way, way = 4 : true;


        // move snake
        if (((buffway == 1) && (way == 3)) || ((buffway == 3) && (way == 1)) || ((buffway == 2) && (way == 4) || ((buffway == 4) && (way == 2))))
            way = buffway;

        switch (way)
        {
        case 1:
            heady -= block_size;
            break;
        case 2:
            headx += block_size;
            break;
        case 3:
            heady += block_size;
            break;
        case 4:
            headx -= block_size;
            break;
        default:
            break;
        }
        // end move snake

        // creating apple
        if (!isapplecrt)
        {
            link:
            applex = (count_size(rand() % (board_width - border_side*2 - block_size*2 ) + (border_side) + block_size)) + border_side;
            appley = (count_size(rand() % (board_height - border_top*2 - block_size*2) + (border_top) + block_size)) + border_top;
            if (((applex == headx) && (appley == heady))||(issnake(applex,appley)))
                goto link;
            SelectObject(bmpdc, apple);
            StretchBlt(hdc, applex, appley, block_size, block_size, bmpdc, 0, 0, 10, 10, SRCCOPY);
            eatenaplle++;
            isapplecrt = true;
        }
        // end creating apple

        // checking for collision with apple
        if ((applex == headx) && (appley == heady))
        {
            taillen++;
            isapplecrt = false;
        }
        // end checking for collision with apple

        // painting snake tail
        SelectObject(bmpdc, snake);
            StretchBlt(hdc,headx, heady, block_size, block_size, bmpdc, 0, 0, 10, 10, SRCCOPY);
        for(int i = 0; i < taillen; i++)
            StretchBlt(hdc, tailx[i], taily[i], block_size, block_size, bmpdc, 0, 0, 10, 10, SRCCOPY);
        taillen++;
        // end painting snake tail

        // clean board
        SelectObject(bmpdc, red);
        if (((headx != buffx) || (heady != buffy))&&(buffx != 0))
            StretchBlt(hdc, tailx[taillen-2], taily[taillen-2], block_size, block_size, bmpdc, 0, 0, 10, 10, SRCCOPY);
        // end clean board

        // check for colision with head
        if ((issnake(headx, heady) == true) && (taillen > 1))
        {
            cout << "snake!" << endl;
            SelectObject(bmpdc, game_over);
        **TransparentBlt(hdc, 0, 0, 100, 100, bmpdc, 10, 0, 10, 10, RGB(0, 0, 0));**
            frametime = clock() - timer;
        }// end check for colision with head
    }

    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
int count_size(int a)
{
    int b = 0;
    for (int i = 0; true; i++)
    {
        if (block_size * i > a)
        {
            return b;
        }
        else
            b = block_size * i;
    }
}
void upwin()
{
    while (true)
    {
        InvalidateRect(hwnd, NULL, TRUE);
        Sleep(100 - frametime);
        cout << "framerate = " << 100 - frametime << endl;
    }
}
bool issnake(int x, int y)
{
    for (int i = 0; i < taillen; i++)
    {
        if ((tailx[i] == x) && (taily[i] == y))
            return true;
    }
    return false;
}

Ответы (0 шт):