Home > Back-end >  Using UpdateLayeredWindow window can not display.
Using UpdateLayeredWindow window can not display.

Time:11-12

UpdateLayeredWindow after the last parameter instead ULW_ALPHA cannot display window, win10 were tried, and 7 what I use is png32 pictures, have the alpha channel, but is transparent, lend. AlphaFormat not set AC_SRC_ALPHA this parameter can be translucent, but is not what I want according to the alpha channel and flexible implementation of transparent effect, know the great spirit show just a little, see a day also didn't set,

#include
#include
//this code is used to establish special shape window
# pragma comment (lib, "GdiPlus. Lib")

Using the namespace Gdiplus;

LRESULT a CALLBACK WndProc (HWND HWND, UINT MSG, WPARAM WPARAM, LPARAM LPARAM);
Int WINAPI WinMain (HINSTANCE HINSTANCE, HINSTANCE hPrevInstance, LPSTR szCmdLine, int

NCmdShow)
{
TCHAR szAppName []=TEXT (" Windows programming ");
Modifed WNDCLASSEX wndClass;
MSG MSG.
The HWND HWND;
ULONG_PTR token;
The GdiplusStartupInput gin;
WndClass. CbSize=sizeof (modifed WNDCLASSEX);
WndClass. CbClsExtra=0;
WndClass. CbWndExtra=0;
WndClass. HbrBackground=(HBRUSH) GetStockObject (WHITE_BRUSH);
WndClass. HCursor=LoadCursor (NULL, IDC_ARROW);
WndClass. HIcon=LoadIcon (NULL, IDI_APPLICATION);
WndClass. HIconSm=NULL;
WndClass. HInstance=hInstance;
WndClass. LpszClassName=TEXT (" AppTest ");
WndClass. LpszMenuName=NULL;
WndClass. LpfnWndProc=WndProc;
WndClass. Style=CS_HREDRAW | CS_VREDRAW | CS_IME | CS_DBLCLKS;

GdiplusStartup (& amp; Token, & amp; Gin, NULL);
RegisterClassEx (& amp; WndClass);
HWND=CreateWindowEx (WS_EX_LAYERED, TEXT (" AppTest "), szAppName, WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP/* */no border style
, 0, 0, 100, 100,
NULL, NULL, hInstance, NULL);
//set the window for layered window support transparent
//layered window without the WM_PAINT message
ShowWindow (HWND, SW_SHOW);
UpdateWindow (HWND);
While (GetMessage (& amp; MSG, NULL, 0, 0))
{
TranslateMessage (& amp; MSG);
DispatchMessage (& amp; MSG);
}
GdiplusShutdown (token);
return 0;
}
Void CreateRoundRectangle (the Rect rc, int Round, GraphicsPath * gp)
{
Gp - & gt; AddArc (0, 0, Round, Round, 180, 90);
Gp - & gt; AddLine (Round, 0, rc. Width - Round, 0).
Gp - & gt; AddArc (rc. The Width - Round, 0, Round, Round, 270, 90);
Gp - & gt; AddLine (rc) Width, Round, rc. Width, rc, Height - Round).
Gp - & gt; AddArc (rc) Width - Round, rc, Height - Round, Round, Round, 0, 90);
Gp - & gt; AddLine (rc) Width - Round, rc, Height, Round, rc, Height);
Gp - & gt; AddArc (0, rc. Height - Round, Round, Round, 90, 90);
}
LRESULT a CALLBACK WndProc (HWND HWND, UINT MSG, WPARAM WPARAM, LPARAM LPARAM)
{
The static BOOL ldown;
The static POINT TheFirstPoint;
Static int cxClient cyClient;

The switch (MSG)
{
Case WM_SIZE:
CxClient=LOWORD (lParam);
CyClient=HIWORD (lParam);
break;
Case WM_LBUTTONDOWN:
Ldown=TRUE;
SetCapture (HWND);//this code fault-tolerant processing can be done, who knows the window response speed is slow, you don't believe it? '-_ -' try to remove this code
TheFirstPoint. X=LOWORD (lParam);
TheFirstPoint. Y=HIWORD (lParam);
break;
Case WM_LBUTTONUP:
Ldown=FALSE;
ReleaseCapture ();
break;
Case WM_MOUSEMOVE:
If (ldown)
{
POINT pt;
The GetCursorPos (& amp; Pt);
Pt. X=TheFirstPoint. X;
Pt. - y=TheFirstPoint. Y;
SetWindowPos (HWND, NULL, pt. X, pt. J y, NULL, NULL, SWP_NOREDRAW |

SWP_NOSIZE | SWP_NOZORDER);
}
break;
Case WM_LBUTTONDBLCLK:
The DestroyWindow (HWND);
Case WM_CREATE message handler:
{
Image Image, TEXT (" bianping - Christmas - 2014-12. PNG "));
//load the window graphics
Int iWidth=image. GetWidth ();
Int iHeight=image. GetHeight ();
HDC hdcScreen=GetDC (NULL);
HDC hdcMem=CreateCompatibleDC (hdcScreen);
HBITMAP HBITMAP=CreateCompatibleBitmap (hdcScreen, iWidth, iHeight);
HBITMAP hBitmapOld=(HBITMAP) SelectObject (hdcMem HBITMAP);
Graphics gp (hdcMem);
//here to establish a window graphics, can use the code to generate the
GraphicsPath GraphicsPath;
SolidBrush brush (Color (255, 175, 0, 0));
CreateRoundRectangle (the Rect (0, 0, iWidth, iHeight), 20, & amp; Graphicspath);//create a rounded rectangle path
//gp. FillPath (& amp; Brush, & amp; Graphicspath);//fill path - remove the annotation view effect
Gp. DrawImage (& amp; Image, 5, 5, 90, 90);//the PNG image map to the backend DC

BLENDFUNCTION blend={0};
Blend. BlendOp=AC_SRC_OVER;
Blend. SourceConstantAlpha=255;
Blend. AlphaFormat=AC_SRC_ALPHA;//according to the channel mixed
POINT pPos={0, 0};
POINT pSrc=https://bbs.csdn.net/topics/{0, 0};
The SIZE sizeWnd={iWidth, iHeight};
UpdateLayeredWindow (HWND hdcScreen, & amp; PPos, & amp; SizeWnd hdcMem, & amp; PSrc, NULL, & amp; Blend, ULW_ALPHA);//update the layered window
//finishing the cleanup
SelectObject (hdcMem hBitmapOld);
DeleteObject (hBitmap);
DeleteDC (hdcMem);
ReleaseDC (HWND, hdcScreen);
}
break;
In case the WM_PAINT:
MessageBox (NULL, NULL, NULL, NULL);
break;
Case WM_DESTROY:
The PostQuitMessage (0);
break;
}
Return DefWindowProc (HWND, MSG, wParam, lParam);
}

CodePudding user response:




You can!
  • Related