Home > Software engineering >  VC in the desktop window display images, image before disappearing
VC in the desktop window display images, image before disappearing

Time:02-10

Do you want to be a software startup, is before the program window display, shows a few (such as 3) pictures, use CImage class, for the PNG image format,
Hope to get the effect is: first, according to delay, disappear; According to the second, time delay, and then disappeared, show 3 pieces, latency, then disappear,
Can the actual effect is: the front image is always present, don't disappear,
The first display is normal, the back of the picture, it still exists before the image, don't disappear, so the final show to 3, is on the table at the same time shows the 3 images overlap,

Hope ace to give directions, where did the problem, thank you very much!


The main code is as follows:

 void welcomestart (const float & amp; SecondsTimeout=1) 
{
//float secondsTimeout: images show the length of every week, unit: s

CWindowDC dc (CWnd: : GetDesktopWindow ());
//get the size of the screen,
Cx=int GetSystemMetrics (SM_CXSCREEN);
Int cy=GetSystemMetrics (SM_CYSCREEN);
////resource handle
HRSRC HRSRC=https://bbs.csdn.net/topics/NULL;
//display the number of images, each time to display the 3 picture
Int cout_show=0;
While (cout_show & lt; 3)
{
//count + 1
Cout_show + +;
Int temp_i=0;
Temp_i=cout_show % 2;
//according to random number, loading pictures of different resources
BOOL res1=FALSE;
The switch (temp_i)
{
Case 0:
{
//load the picture
1HRsrc=https://bbs.csdn.net/topics/::FindResource (AfxGetResourceHandle (), MAKEINTRESOURCE (IDB_PNG1), _T (" PNG "));
break;
}
Case 1:
{
//load the picture
2HRsrc=https://bbs.csdn.net/topics/::FindResource (AfxGetResourceHandle (), MAKEINTRESOURCE (IDB_PNG2), _T (" PNG "));
break;
}
Case 2:
{
//load the third picture
HRsrc=https://bbs.csdn.net/topics/::FindResource (AfxGetResourceHandle (), MAKEINTRESOURCE (IDB_PNG1), _T (" PNG "));
break;
}
}
//find resources
If (hRsrc=NULL https://bbs.csdn.net/topics/=
return;
//load resources
HGLOBAL hImgData=https://bbs.csdn.net/topics/::LoadResource (AfxGetResourceHandle (), hRsrc);
If (hImgData=NULL https://bbs.csdn.net/topics/=
{
: : FreeResource (hImgData);
return;
}
//lock specified resource in memory
LPVOID LPVOID=: : LockResource (hImgData);
DWORD dwSize=: : SizeofResource (AfxGetResourceHandle (), hRsrc);
HGLOBAL hNew=: : GlobalAlloc (GHND dwSize);
LPBYTE LPBYTE=(LPBYTE) : : GlobalLock (hNew);
: : memcpy (lpVoid lpByte, dwSize);
//remove the specified resource in memory
: : GlobalUnlock (hNew);
LPSTREAM pStream=nullptr;
CImage image2Display;
//create stream objects from the specified memory
HRESULT ht=: : CreateStreamOnHGlobal (hNew, TRUE, & amp; PStream);
If (ht!=S_OK)
{
GlobalFree (hNew);
}
The else
{
//load the picture
Image2Display. Load (pStream);
GlobalFree (hNew);
}
//release resources
: : FreeResource (hImgData);
//////////////////////////////////////////////////////
If (image2Display. GetBPP ()==32)//confirm the image contains Alpha channel
{
int i;
Int j;
For (I=0; I & lt; Image2Display. GetWidth (); I++)
{
For (j=0; J & lt; Image2Display. GetHeight (); J++)
{
Byte * pByte=(byte *) image2Display GetPixelAddress (I, j);
PByte [0]=pByte pByte [0] * [3]/255;
PByte [1]=pByte pByte [1] * [3]/255;
PByte [2]=pByte * pByte [2] [3]/255;
PByte=nullptr;
}
}
}
if (! Image2Display. The IsNull ())
{

//get the image size, so that the middle shows
Int image_width=image2Display. GetWidth ();
Int image_height=image2Display. GetHeight ();
//transparent display picture
Image2Display. AlphaBlend function (dc m_hDC, cx - image_width ()/2, (cy - image_height)/2);
Int nElapse=secondsTimeout * 1000;
//picture shows the length: unit: ms
Sleep (nElapse);
Cx - image_width CRect rectPic (()/2, (cy - image_height)/2, (cx + image_width)/2, (cy + image_height)/2);
//# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
//$$$$$$$$$$$$$3 lines of code, the following can eradicate have shown pictures of $$$$$$$$$$$$$$$$$$$$$$$
//: : InvalidateRect (GetDesktopWindow (), rectPic, TRUE);
//: : RedrawWindow (GetDesktopWindow (), & amp; RectPic, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_NOCHILDREN);
//: : UpdateWindow (GetDesktopWindow ());
//# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
}
//destroyed images
Image2Display. Destroy ();
HRsrc=https://bbs.csdn.net/topics/NULL;
HImgData=https://bbs.csdn.net/topics/NULL;
LpVoid=nullptr;
HNew=NULL;
LpByte=nullptr;
PStream=nullptr;
}
}
  • Related