📄 clip.cpp
字号:
// transblt.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void OnPaint(HWND hWnd);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
//
// WinMain: Entry point for the application
//
int APIENTRY WinMain
(
HINSTANCE hInstance
,HINSTANCE /*hPrevInstance*/
,LPSTR /*pCmdLine*/
,int nCmdShow
)
{
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_CLIP, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_CLIP);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
//
// MyRegisterClass: registers the window class
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_CLIP);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_CLIP;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
//
// InitInstance: creates the window
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
BOOL bReturn(FALSE);
HWND hWnd;
// Store instance handle in our global variable
hInst = hInstance;
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (hWnd)
{
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
bReturn = TRUE;
}
return bReturn;
}
//
// WndProc: main window window procedure
//
LRESULT CALLBACK WndProc
(
HWND hWnd
,UINT message
,WPARAM wParam
,LPARAM lParam
)
{
int wmId, wmEvent;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
OnPaint(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
//
// OnPaint: handles the painting for the window
//
void OnPaint(HWND hWnd)
{
PAINTSTRUCT ps;
HBITMAP hBitmapOld(NULL);
HDC hDC = BeginPaint(hWnd, &ps);
// get the client rect
RECT rectClient;
GetClientRect(hWnd, &rectClient);
// load the transparent bitmap
HBITMAP hBitmapTransparent = LoadBitmap(
hInst, MAKEINTRESOURCE(IDB_TRANSPARENT));
// get the dimension of the transparent bitmap so we can
// center the window and create a clipping region
BITMAP bitmapTransparent;
GetObject(hBitmapTransparent,
sizeof(bitmapTransparent), &bitmapTransparent);
int nLeft =
(rectClient.right / 2) - (bitmapTransparent.bmWidth / 2);
int nTop =
(rectClient.bottom / 2) - (bitmapTransparent.bmHeight / 2);
// set the clipping region to the size and position of the
// transparent bitmap
HRGN hrgnClip = CreateRectRgn(
nLeft, nTop,
nLeft + bitmapTransparent.bmWidth,
nTop + bitmapTransparent.bmHeight);
// select the clip region
SelectClipRgn(hDC, hrgnClip);
// delete the region
DeleteObject(hrgnClip);
// create a compatible memory dc
HDC hDCMem = CreateCompatibleDC(hDC);
//
// draw an the background image in the middle of the screen
//
// load the background bitmap
HBITMAP hBitmapBackground = LoadBitmap(
hInst, MAKEINTRESOURCE(IDB_BACKGROUNDBITMAP));
// select the bitamp into the memory dc
hBitmapOld = (HBITMAP)SelectObject(
hDCMem, hBitmapBackground);
// get the dimension of the bitmap so we can center
// it in the window
BITMAP bitmapBackground;
GetObject(hBitmapBackground,
sizeof(bitmapBackground), &bitmapBackground);
int nLeftBackground =
(rectClient.right / 2) - (bitmapBackground.bmWidth / 2);
int nTopBackground =
(rectClient.bottom / 2) - (bitmapBackground.bmHeight / 2);
// draw the background bitmap
BitBlt(hDC, nLeftBackground, nTopBackground,
bitmapBackground.bmWidth, bitmapBackground.bmHeight,
hDCMem, 0, 0, SRCCOPY);
//
// Draw a transparent bitmap over the background bitmap
//
// select the transparentbitamp into the memory dc
SelectObject(hDCMem, hBitmapTransparent);
// draw the transparent bitmap
TransparentBlt(hDC, nLeft, nTop,
bitmapTransparent.bmWidth, bitmapTransparent.bmHeight,
hDCMem, 0, 0,
bitmapTransparent.bmWidth, bitmapTransparent.bmHeight,
RGB(0,0,255));
// Select the old bitmap
SelectObject(hDCMem, hBitmapOld);
DeleteObject(hBitmapBackground);
DeleteObject(hBitmapTransparent);
EndPaint(hWnd, &ps);
}
//
// Mesage handler for about box.
//
LRESULT CALLBACK About
(
HWND hDlg
,UINT message
,WPARAM wParam
,LPARAM /*lParam*/
)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -