Red de conocimiento informático - Material del sitio web - Cómo dibujar el contenido del portapapeles en la ventana de programación VC win32

Cómo dibujar el contenido del portapapeles en la ventana de programación VC win32

OpenClipboard abre el portapapeles

GetClipboardData obtiene el contenido del portapapeles

CloseClipboard cierra el portapapeles

Dibujo BitBlt

#include lt;windows.hgt;

#include lt;tchar.hgt;

#define ID_DRAW 50

HMENU CreateMenuBar() { p>

HMENU hMenu = CreateMenu();

AppendMenu(hMenu, MF_STRING, ID_DRAW, _T("Draw"));

return hMenu; >

}

LLAMADA DE RESULTADO WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {

HANDLE hBit

HDC hDC, hMemDC

RECT rc;

cambiar (uMsg) {

caso WM_COMMAND:

cambiar (LOWORD(wParam)) {

caso ID_DRAW:

if (OpenClipboard(hwnd)) {

hBit = GetClipboardData(CF_BITMAP);

CloseClipboard();

if (hBit) {

hDC = GetDC(hwnd);

hMemDC = CreateCompatibleDC(NULL);

hBit = SelectObject(hMemDC); , hBit );

GetClientRect(hwnd, amp; rc

BitBlt(hDC, 0, 0, rc.right, rc.bottom, hMemDC, 0, 0, SRCCOPY);

SeleccionarObjeto(hMemDC, hBit);

EliminarDC(hMemDC);

LiberarDC(hwnd, hDC);

}

}

MessageBox(hwnd, _T("Datos no válidos."), _T("Error"), MB_ICONERROR);

}

descanso;

caso WM_DESTROY: PostQuitMessage(0);

valor predeterminado: devolver DefWindowProc(hwnd, uMsg, wParam, lParam

}

re

girar 0

}

INT WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, INT nCmdShow) {

MSG msg; p> WNDCLASS wnd = { 0 };

wnd.lpfnWndProc = WndProc;

wnd.hInstance = hInstance

wnd.hCursor = LoadCursor(NULL, IDC_ARROW);

wnd.hbrBackground = (HBRUSH)COLOR_WINDOW;

wnd.lpszClassName = _T("prueba");

RegisterClass(amp; wnd) ;

if (!CreateWindow(_T("prueba"), _T("prueba"), WS_OVERLAPPEDWINDOW | WS_VISIBLE,

CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,

NULL, CreateMenuBar(), hInstance, NULL)) devuelve 0

while (GetMessage(amp; msg, NULL, 0, 0)) {

TranslateMessage(amp; ;msg);

DispatchMessage(amp;msg);

}

return msg.wParam;

}