본문 바로가기

Windows/MFC

Bring your frame window a shadow

Link : http://www.codeproject.com/dialog/FrameShadow.asp?df=100&forumid=358583&exp=0&select=1773460

윈도우에 그림자를 넣자 원래의 경우는 CWnd를 상속받아서 CreateEx로 생성 시키면되는데 여기 방식은 동일하다....
그런데 기본 윈도우가 있다면은 그 윈도우를 따라갈 수 있게 다이얼로그 밑에 깔아 놓는 방식으로 ... 했다... -_ - 머리 좋다... 잔머리..


Using the code
It is easy to utilize your frame window by a shadow, using my code. CWndShadow can be used in both MFC/ATL and non-MFC/ATL applications.

Add WndShadow.h and WndShadow.cpp to your project. Add:

#include "WndShadow.h"
to anywhere CWndShadow is used.

Call CWndShadow::Initialize() before any creation of a shadow. This function needs the handle to the instance of the application as a parameter. This is passed to the application as a parameter of WinMain(). If using MFC, this can be retrieved by calling AfxGetInstanceHandle(). Here is an example for MFC:
BOOL CYourApp::InitInstance()
{
    // CWndShadow::Initialize() could be also called anywhere else, just
    // before any call to CWndShadow::Create().
    // Here is only an example
    CWndShadow::Initialize(AfxGetInstanceHandle());
    
    // Other codes...
}
Declare an instance of CWndShadow for each frame window that you want to have a shadow.
CWndShadow WndShadow;

Remember, this object should not be destructed before the frame window is destroyed. For example, you can make it global, or, if using MFC, a member of the MFC class for that window.

Call the CWndShadow object's Create() with the handle to the frame window, to create a shadow. If using MFC, do remember, Create() must be called after the frame window has actually been created, for instance, in OnCreate() for a regular window, or in OnInitDialog() for a dialog. The MFC code may look like this:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    // Other code of CMainFrame::OnCreate()
    
    // assume CWndShadow CMainFrame::m_Shadow;
    m_Shadow.Create(GetSafeHwnd());
    
    return 0;
}
Now your frame window should have the shadow. Enjoy.

Advanced control of the shadow