c++请问如何用updatelayeredwindow函数使窗口半透明,或者说setayeredwindow也可以 50
#include<windows.h>//#include"resource.h"ATOMMyRegisterClass(HINSTANCE);LRESULTCALLBA...
#include <windows.h>
//#include "resource.h"
ATOM MyRegisterClass(HINSTANCE);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND hwNd;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
if (!MyRegisterClass(hInstance))
{
MessageBox(NULL, TEXT("窗口注册失败"), TEXT("提示信息"), MB_OK);
return 0;
}
int cx = GetSystemMetrics(SM_CXSCREEN);
int cy = GetSystemMetrics(SM_CYSCREEN);
HWND hwnd = CreateWindowEx(
WS_EX_LAYERED | WS_EX_TOOLWINDOW|WS_EX_TOPMOST,
TEXT("SCREENC"),
TEXT("screen"),
/*WS_POPUP |*/ WS_VISIBLE ,
300,300, 700, 500,
NULL,
NULL,
hInstance,
NULL);
hwnd = hwNd;
ShowWindow(hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);
//SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
while (GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra =0;//SetWindowLong(hwNd, GWL_STYLE, GetWindowLong(hwNd, GWL_STYLE) | WS_EX_LAYERED);;
wc.hbrBackground =(HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
wc.hInstance = hInstance;
wc.lpfnWndProc =(WNDPROC) WndProc;
wc.lpszClassName = TEXT("SCREENC");
wc.lpszMenuName = NULL;
wc.style= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
return RegisterClass(&wc);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//SetLayeredWindowAttributes(hWnd, RGB(0, 0, 0), 100, LWA_ALPHA | LWA_COLORKEY); //LWA_ALPHA | LWA_COLORKE
BLENDFUNCTION bl;
bl.SourceConstantAlpha = 100;
bl.BlendOp = 0; //theonlyBlendOpdefinedinWindows2000
bl.BlendFlags=0; //nothingelseisspecial...
bl.AlphaFormat=1; //...
switch (uMsg)
{
/*case WM_LBUTTONDOWN:
MessageBeep(0);
SetLayeredWindowAttributes(hWnd, RGB(0, 0, 0), 150, LWA_ALPHA | LWA_COLORKEY);
break;*/
case WM_RBUTTONDOWN:
MessageBeep(0);
UpdateLayeredWindow(hWnd,NULL,NULL,NULL,NULL,NULL,RGB(100,100,100),&bl,NULL);
break;
case WM_LBUTTONDBLCLK:
PostQuitMessage(0);
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
} 展开
//#include "resource.h"
ATOM MyRegisterClass(HINSTANCE);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND hwNd;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
if (!MyRegisterClass(hInstance))
{
MessageBox(NULL, TEXT("窗口注册失败"), TEXT("提示信息"), MB_OK);
return 0;
}
int cx = GetSystemMetrics(SM_CXSCREEN);
int cy = GetSystemMetrics(SM_CYSCREEN);
HWND hwnd = CreateWindowEx(
WS_EX_LAYERED | WS_EX_TOOLWINDOW|WS_EX_TOPMOST,
TEXT("SCREENC"),
TEXT("screen"),
/*WS_POPUP |*/ WS_VISIBLE ,
300,300, 700, 500,
NULL,
NULL,
hInstance,
NULL);
hwnd = hwNd;
ShowWindow(hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);
//SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
while (GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra =0;//SetWindowLong(hwNd, GWL_STYLE, GetWindowLong(hwNd, GWL_STYLE) | WS_EX_LAYERED);;
wc.hbrBackground =(HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
wc.hInstance = hInstance;
wc.lpfnWndProc =(WNDPROC) WndProc;
wc.lpszClassName = TEXT("SCREENC");
wc.lpszMenuName = NULL;
wc.style= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
return RegisterClass(&wc);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//SetLayeredWindowAttributes(hWnd, RGB(0, 0, 0), 100, LWA_ALPHA | LWA_COLORKEY); //LWA_ALPHA | LWA_COLORKE
BLENDFUNCTION bl;
bl.SourceConstantAlpha = 100;
bl.BlendOp = 0; //theonlyBlendOpdefinedinWindows2000
bl.BlendFlags=0; //nothingelseisspecial...
bl.AlphaFormat=1; //...
switch (uMsg)
{
/*case WM_LBUTTONDOWN:
MessageBeep(0);
SetLayeredWindowAttributes(hWnd, RGB(0, 0, 0), 150, LWA_ALPHA | LWA_COLORKEY);
break;*/
case WM_RBUTTONDOWN:
MessageBeep(0);
UpdateLayeredWindow(hWnd,NULL,NULL,NULL,NULL,NULL,RGB(100,100,100),&bl,NULL);
break;
case WM_LBUTTONDBLCLK:
PostQuitMessage(0);
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询