📄 cpp1.cpp
字号:
BOOL PasteImageClip(VOID)
{
HCURSOR hcurOld;
INT cxClip;
INT cyClip;
INT cxTarget;
INT cyTarget;
INT cxSource;
INT cySource;
DWORD rgbClipScreen;
BOOL fIEFormatFound;
HANDLE hClipData;
LPSTR lpClipData;
BITMAP bmClip;
HDC hdcClip;
HBITMAP hbmClip;
HBITMAP hbmClipOld;
HDC hdcClipAND;
HBITMAP hbmClipAND;
HBITMAP hbmClipANDOld;
HDC hdcClipAND16;
HBITMAP hbmClipAND16;
HBITMAP hbmClipAND16Old;
HDC hdcTarget;
HBITMAP hbmTarget;
HBITMAP hbmTargetOld;
HDC hdcTargetAND16;
HBITMAP hbmTargetAND16;
HBITMAP hbmTargetAND16Old;
HDC hdcTargetAND;
HBITMAP hbmTargetAND;
HBITMAP hbmTargetANDOld;
hcurOld = SetCursor(hcurWait);
if (!OpenClipboard(ghwndMain)) {
Message(MSG_NOCLIPBOARD);
goto Error1;
}
if (!(hbmClip = GetClipboardData(CF_BITMAP))) {
Message(MSG_NOCLIPBOARDFORMAT);
goto Error2;
}
GetObject(hbmClip, sizeof(BITMAP), (LPSTR)&bmClip);
cxClip = (INT)bmClip.bmWidth;
cyClip = (INT)bmClip.bmHeight;
/*
* If the dimensions of the current pick rectangle don't match
* the bitmap being pasted, ask the user if they want to stretch
* or clip the pasted image.
*/
cxTarget = gcxPick;
cyTarget = gcyPick;
cxSource = cxClip;
cySource = cyClip;
if (gcxPick != cxClip || gcyPick != cyClip) {
if (DlgBox(DID_PASTEOPTIONS, (WNDPROC)PasteOptionsDlgProc) == IDCANCEL) {
goto Error2;
}
/*
* If clipping and the clipboard dimensions differ from the
* selected pick rectangle, then either the target dimensions
* or the source dimensions need to be sized down.
*/
if (!fStretchClipboardData) {
if (cxClip < gcxPick)
cxTarget = cxClip;
else
cxSource = gcxPick;
if (cyClip < gcyPick)
cyTarget = cyClip;
else
cySource = gcyPick;
}
}
/*
* Update the undo buffer now that we are committed to the paste.
*/
ImageUpdateUndo();
/*
* Determine if the private ImagEdit clipboard format is available.
*/
fIEFormatFound = IsClipboardFormatAvailable(ClipboardFormat);
if (giType != FT_BITMAP && fIEFormatFound) {
/*
* Get the AND mask bitmap and the old screen color out of
* the private format.
*/
hClipData = GetClipboardData(ClipboardFormat);
lpClipData = (LPSTR)GlobalLock(hClipData);
rgbClipScreen = *((DWORD FAR *)lpClipData);
hdcClipAND = CreateCompatibleDC(ghdcImage);
hbmClipAND = CreateBitmap(cxClip, cyClip, (BYTE)1, (BYTE)1,
(LPSTR)lpClipData + sizeof(DWORD));
hbmClipANDOld = SelectObject(hdcClipAND, hbmClipAND);
/*
* Create a color bitmap for temporary use.
*/
hdcClipAND16 = CreateCompatibleDC(ghdcImage);
hbmClipAND16 = MyCreateBitmap(ghdcImage, cxSource, cySource, 16);
hbmClipAND16Old = SelectObject(hdcClipAND16, hbmClipAND16);
/*
* Blt the AND mask onto the color bitmap.
*/
BitBlt(hdcClipAND16, 0, 0, cxSource, cySource, hdcClipAND,
0, 0, SRCCOPY);
/*
* Create the color target AND mask bitmap.
*/
hdcTargetAND16 = CreateCompatibleDC(ghdcImage);
hbmTargetAND16 = MyCreateBitmap(ghdcImage, cxTarget, cyTarget, 16);
hbmTargetAND16Old = SelectObject(hdcTargetAND16, hbmTargetAND16);
/*
* StretchBlt from the color AND mask bitmap to the color target
* AND mask bitmap. The blt must be done from a color bitmap to
* a color bitmap, and the stretch blt mode must be set to
* COLORONCOLOR. All this is necessary so that the AND mask
* stays exactly in sync with the stretch blt of the color
* (XOR) mask. If these steps are not done correctly, shrinking
* an image with screen colored pixels in it can cause problems,
* because the stretch blt will use a slightly different
* algorithm to compress the monochrome AND mask and the color
* XOR mask.
*/
SetStretchBltMode(hdcTargetAND16, COLORONCOLOR);
SetStretchBltMode(hdcClipAND16, COLORONCOLOR); //
StretchBlt(hdcTargetAND16, 0, 0, cxTarget, cyTarget, hdcClipAND16,
0, 0, cxSource, cySource, SRCCOPY);
/*
* Create the monochrome target AND mask bitmap.
*/
hdcTargetAND = CreateCompatibleDC(ghdcImage);
hbmTargetAND = MyCreateBitmap(ghdcImage, cxTarget, cyTarget, 2);
hbmTargetANDOld = SelectObject(hdcTargetAND, hbmTargetAND);
/*
* Blt the color AND mask onto the monochrome AND mask.
* The monochrome AND mask is the one that we will use
* later. It must be monochrome or the ImageDCSeparate
* and ImageDCCombine functions will not work properly.
*/
BitBlt(hdcTargetAND, 0, 0, cxTarget, cyTarget, hdcTargetAND16,
0, 0, SRCCOPY);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -