效果
代码
#include <windows.h>
#pragma comment(linker, "/subsystem:windows /entry:WinMainCRTStartup")
#if(_MSC_VER == 1200)
#define WS_EX_LAYERED 0x00080000
#define LWA_COLORKEY 1
#define LWA_ALPHA 2
int SetLayeredWindowAttributes(HWND hwnd, COLORREF crKey,
BYTE bAlpha, DWORD dwFlags)
{
typedef int (WINAPI *Func)( HWND hwnd, COLORREF crKey,
BYTE bAlpha, DWORD dwFlags);
Func func;
if(func = (Func)GetProcAddress(GetModuleHandle(TEXT("user32.dll")),
TEXT("SetLayeredWindowAttributes")))
return func(hwnd, crKey, bAlpha, dwFlags);
return 0;
}
#endif
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR pCmdLine,
int nCmdShow)
{
static TCHAR szAppName[] = TEXT("HelloWin");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.lpszClassName = szAppName;
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
RegisterClass(&wndclass);
hwnd = CreateWindowEx(WS_EX_LAYERED,
szAppName,
TEXT("Title"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
SetLayeredWindowAttributes(hwnd, 0, 200, LWA_ALPHA);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}