'bmp'에 해당되는 글 1건

  1. 2019.04.18 dev cpp에서 바탕에 이미지를 그리는 소스

파일을 읽어서 이미지에 넣고 그린다

'''

#include

#include

#include <windows.h>

using namespace std;

/* This is where all the input to the window goes to */
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch(Message) {

    /* Upon destruction, tell the main thread to stop */
    case WM_DESTROY: {
        PostQuitMessage(0);
        break;
    }

    /* All other messages (a lot of them) are processed using default procedures */
    default:
        return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;

}

/* The 'main' function of Win32 GUI programs: this is where execution starts /
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASSEX wc; /
A properties struct of our window /
HWND hwnd; /
A 'HANDLE', hence the H, or a pointer to our window /
MSG msg; /
A temporary location for all messages */

/* zero out the struct and set the stuff we want to modify */
memset(&wc,0,sizeof(wc));
wc.cbSize         = sizeof(WNDCLASSEX);
wc.lpfnWndProc     = WndProc; /* This is where we will send messages to */
wc.hInstance     = hInstance;
wc.hCursor         = LoadCursor(NULL, IDC_ARROW);

/* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = "WindowClass";
wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */
wc.hIconSm         = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */

if(!RegisterClassEx(&wc)) {
    MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
    return 0;
}
 hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Fake Virus for Pentest",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, /* x */
    CW_USEDEFAULT, /* y */
    640, /* width */
    480, /* height */
    NULL,NULL,hInstance,NULL);

if(hwnd == NULL) {
    MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
    return 0;
}

HBITMAP hBitmap;

// From File:
//hBitmap = (HBITMAP)LoadImage(hInstance, "a.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);

std::ifstream is;
is.open("a.bmp", std::ios::binary);
is.seekg (0, std::ios::end);
int length = is.tellg();
is.seekg (0, std::ios::beg);
char * pBuffer = new char [length];
is.read (pBuffer,length);
is.close();

tagBITMAPFILEHEADER bfh = (tagBITMAPFILEHEADER)pBuffer;
tagBITMAPINFOHEADER bih = (tagBITMAPINFOHEADER)(pBuffer+sizeof(tagBITMAPFILEHEADER));
RGBQUAD rgb = (RGBQUAD)(pBuffer+sizeof(tagBITMAPFILEHEADER)+sizeof(tagBITMAPINFOHEADER));

BITMAPINFO bi;
bi.bmiColors[0] = rgb;
bi.bmiHeader = bih;

char* pPixels = (pBuffer+bfh.bfOffBits);

char* ppvBits;

hBitmap = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, (void**) &ppvBits, NULL, 0);
SetDIBits(NULL, hBitmap, 0, bih.biHeight, pPixels, &bi, DIB_RGB_COLORS);

//GetObject(hBitmap, sizeof(BITMAP), &cBitmap);

// From Resource:
//hBitmap = LoadBitmap(MAKEINTRESOURCE(IDB_MYBMP));

BITMAP BMP;
GetObject(hBitmap, sizeof(BMP), &BMP); // Here we get the BMP header info.

HDC BMPDC = CreateCompatibleDC(NULL); // This will hold the BMP image itself.

HDC hDC = GetDC(hwnd);
SelectObject(BMPDC, hBitmap); // Put the image into the DC.

BitBlt(hDC, 0, 0, BMP.bmWidth, BMP.bmHeight, BMPDC, 0, 0, SRCCOPY); // Finally, Draw it

ReleaseDC(hwnd, hDC);

// Don't forget to clean up!
DeleteDC(BMPDC);
DeleteObject(hBitmap);

/*
    This is the heart of our program where all input is processed and 
    sent to WndProc. Note that GetMessage blocks code flow until it receives something, so
    this loop will not produce unreasonably high CPU usage
*/
while(GetMessage(&msg, NULL, 0, 0) > 0) { /* If no error is received... */
    TranslateMessage(&msg); /* Translate key codes to chars if present */

''' DispatchMessage(&msg); /* Send i
t to WndProc */
}
return msg.wParam;
}
```

Posted by goldpapa
,