Home > Back-end >  Why use MemDC or solve the problem of no splash screen
Why use MemDC or solve the problem of no splash screen

Time:10-03

Internet use MemDC all say can solve the problem of the splash screen, but tried it on and don't want to,
Have a great god can explain what reason be?



 void CMy555Dlg: : OnPaint () 
{
If (IsIconic ())
{
CPaintDC dc (this);//device context for painting

SendMessage (WM_ICONERASEBKGND, (WPARAM) dc. GetSafeHdc (), 0).

//Center icon in the client rectangle
Int cxIcon=GetSystemMetrics (SM_CXICON);
Int cyIcon=GetSystemMetrics (SM_CYICON);
CRect the rect.
GetClientRect (& amp; The rect);
Int x=(the rect. Width () - cxIcon + 1)/2;
Int y=(the rect. Height () - cyIcon + 1)/2;

//Draw the icon
Dc. DrawIcon (x, y, m_hIcon);
}
The else
{
CDialog: : OnPaint ();
}


The CDC * pDC=GetDC ();/////////////black back
The CDC MemDC;//define a first display device object
CBitmap MemBitmap;//define a bitmap object

//then establish a compatible with screen display memory display device
MemDC. CreateCompatibleDC (NULL);
//can't drawing at this moment, because there is no place to paint ^_^
//below to create a compatible with screen display bitmap, as to the size of the bitmap, can use the size of the window
MemBitmap. CreateCompatibleBitmap (pDC, 400400);

//will be chosen bitmap into memory display device in the
//only the memory for the bitmap display device is drawing, painting on the specified bitmap
CBitmap * pOldBit=MemDC. SelectObject (& amp; MemBitmap);

//use the background color first bitmap clean, here I was using a white background as a
//you can also use you should use the color of the
MemDC. FillSolidRect (0,0,400,400 BLACK_BRUSH);


(BLACK_BRUSH MemDC. SelectStockObject ());
MemDC. A Rectangle (0,0,574,250);
Crect. Top=0 + I;
Crect. Bottom=30 + I;
Crect. Left=20,
Crect. Right=50;


MemDC. SelectStockObject (WHITE_BRUSH);
MemDC. A Rectangle (crect);
//copies a figure from a memory to the screen for display

PDC - & gt; BitBlt (0,0,400,400, & amp; MemDC, 0, 0, SRCCOPY);

//the drawing after completion of cleaning
MemBitmap. DeleteObject ();
MemDC. DeleteDC ();

}

//The system calls this to obtain The cursor to display while The user drags
//the minimized window.
HCURSOR CMy555Dlg: : OnQueryDragIcon ()
{
Return (HCURSOR) m_hIcon;
}

Void CMy555Dlg: : OnTimer (UINT nIDEvent)
{
I=I + 1;
Invalidate ().

//TODO: Add your message handler code here and/or call the default

CDialog: : OnTimer (nIDEvent);
}

CodePudding user response:

refer to the original poster ningan1431110367 response:
Internet use MemDC all say can solve the problem of the splash screen, but tried it on and don't want to,
Have a great god can explain what reason be?



 void CMy555Dlg: : OnPaint () 
{
If (IsIconic ())
{
CPaintDC dc (this);//device context for painting

SendMessage (WM_ICONERASEBKGND, (WPARAM) dc. GetSafeHdc (), 0).

//Center icon in the client rectangle
Int cxIcon=GetSystemMetrics (SM_CXICON);
Int cyIcon=GetSystemMetrics (SM_CYICON);
CRect the rect.
GetClientRect (& amp; The rect);
Int x=(the rect. Width () - cxIcon + 1)/2;
Int y=(the rect. Height () - cyIcon + 1)/2;

//Draw the icon
Dc. DrawIcon (x, y, m_hIcon);
}
The else
{
CDialog: : OnPaint ();
}


The CDC * pDC=GetDC ();/////////////black back
The CDC MemDC;//define a first display device object
CBitmap MemBitmap;//define a bitmap object

//then establish a compatible with screen display memory display device
MemDC. CreateCompatibleDC (NULL);
//can't drawing at this moment, because there is no place to paint ^_^
//below to create a compatible with screen display bitmap, as to the size of the bitmap, can use the size of the window
MemBitmap. CreateCompatibleBitmap (pDC, 400400);

//will be chosen bitmap into memory display device in the
//only the memory for the bitmap display device is drawing, painting on the specified bitmap
CBitmap * pOldBit=MemDC. SelectObject (& amp; MemBitmap);

//use the background color first bitmap clean, here I was using a white background as a
//you can also use you should use the color of the
MemDC. FillSolidRect (0,0,400,400 BLACK_BRUSH);


(BLACK_BRUSH MemDC. SelectStockObject ());
MemDC. A Rectangle (0,0,574,250);
Crect. Top=0 + I;
Crect. Bottom=30 + I;
Crect. Left=20,
Crect. Right=50;


MemDC. SelectStockObject (WHITE_BRUSH);
MemDC. A Rectangle (crect);
//copies a figure from a memory to the screen for display

PDC - & gt; BitBlt (0,0,400,400, & amp; MemDC, 0, 0, SRCCOPY);

//the drawing after completion of cleaning
MemBitmap. DeleteObject ();
MemDC. DeleteDC ();

}

//The system calls this to obtain The cursor to display while The user drags
//the minimized window.
HCURSOR CMy555Dlg: : OnQueryDragIcon ()
{
Return (HCURSOR) m_hIcon;
}

Void CMy555Dlg: : OnTimer (UINT nIDEvent)
{
I=I + 1;
Invalidate ().

//TODO: Add your message handler code here and/or call the default

CDialog: : OnTimer (nIDEvent);
}

Look,

CodePudding user response:

watch, also have the same problem
  • Related