개발은 하는건가..

VC++ 윈도우 알파값 적용 본문

C, C++, MFC

VC++ 윈도우 알파값 적용

수동애비 2018. 10. 31. 16:35
반응형

#ifndef WS_EX_LAYERED

#define WS_EX_LAYERED           0x00080000

#define LWA_COLORKEY            0x00000001

#define LWA_ALPHA               0x00000002

#endif // ndef WS_EX_LAYERED

 

Then some declarations in the header-file:

 

// Preparation for the function we want to import from USER32.DLL

typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd,

                                  COLORREF crKey, BYTE bAlpha, DWORD dwFlags);

 

lpfnSetLayeredWindowAttributes m_pSetLayeredWindowAttributes

 

That is all for the header file, now to the implementation!

 

// Here we import the function from USER32.DLL

HMODULE hUser32 = GetModuleHandle(_T("USER32.DLL"));

m_pSetLayeredWindowAttributes =

                       (lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32,

                       "SetLayeredWindowAttributes");

 

// If the import did not succeed, make sure your app can handle it!

if (NULL == m_pSetLayeredWindowAttributes)

    return FALSE; //Bail out!!!

 

If the function was imported correctly we must set the dialog we want to make transparent into "transparent-mode". E.G. Set the style for the dialog so that it can be transparent, and that is done with the flag WS_EX_LAYERED defined earlier.

 

// Check the current state of the dialog, and then add the

// WS_EX_LAYERED attribute

SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd, GWL_EXSTYLE)

              | WS_EX_LAYERED);

 

// Sets the window to 70% visibility.

m_pSetLayeredWindowAttributes(m_hWnd, 0, (255 / 70) * 100, LWA_ALPHA);

Comments