원본 글 : http://www.codeproject.com/KB/wtl/CDialogRegionT.aspx
이 클래스는 WTL로 생성된 다이얼로그 클래스(CDialogImpl)에서 돌아간다. 우선 이 놈을 사용하려면, 헤더파일이 필요한데, WTL을 설치하면 나오는
#include <atlapp.h>
이놈을 추가시켜주자. 대부분의 atl관련 헤더파일이 stdafx.h 에 들어가 있으므로, 여기에 해주면 좋을 것 같다.
그 다음, 다이얼로그 클래스에 적용을 시켜야 하는데....
class CMainDlg : public CDialogImpl<CMainDlg>, public CUpdateUI<CMainDlg>,
public CMessageFilter, public CIdleHandler, public CDialogRegionT<CMainDlg>
{
위 처럼, CDialogRegionT를 추가시켜주고
BEGIN_MSG_MAP(CMainDlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
COMMAND_ID_HANDLER(IDOK, OnOK)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
CHAIN_MSG_MAP(CDialogRegionT<CMainDlg>)
END_MSG_MAP()
메시지 맵에 위에 파란색으로 된 놈을 추가시켜준다.
그 다음 원하는 곳에 가서 SetBitmap 함수를 불러주면 된다.
SetBitmap(IDB_BITMAP1); 또는 SetBitmap("Mybitmap.bmp"); 이런식으로
더 필요한 내용은 원본 글 주소로 들어가보라.
===============================================================================================
BEGIN_MSG_MAP(CMainDlg) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout) COMMAND_ID_HANDLER(IDOK, OnOK) COMMAND_ID_HANDLER(IDCANCEL, OnCancel) CHAIN_MSG_MAP(CDialogRegionT<CMainDlg>) END_MSG_MAP()
- Use
SetBkBitmap
method in theWM_INITDIALOG
routine to specify the skin file. SetBkBitmap is an overloaded function and takes the color which is to be set as transparent (RGB(255,0,255)
is default transparent color)- If you are providing a resource bitmap:
SetBKBitmap(IDB_BITMAP1);
HereIDB_BITMAP1
is the bitmap resource identifier. - In case you are providing a bitmap file:
SetBKBitmap("MyBitmap.bmp");
HereMyBitmap.bmp
is the name of bitmap file in the directory of the target executable generated.
- If you are providing a resource bitmap:
Things to note
In the background section I did not discuss the
WM_CTLCOLORSTATIC
message. The CDialogRegionT
template class uses this message to return the color for the static controls. In our case we will be using any color bitmap so the static controls needs to be drawn as transparent. So when the static controls are to be colored we set the background color as transparent and return hollow brush.LRESULT OnCtlColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam,
BOOL& bHandled)
{
// We handle this message only if we have set the region
bHandled = m_bIsRgnSet;
if(m_bIsRgnSet)
{
::SetBkMode((HDC)wParam, TRANSPARENT);
return (LRESULT) GetStockObject (HOLLOW_BRUSH);
}
return 0;
}
I came across one problem: if I add the manifest for common controls 6, the static controls are drawn black. So you have to ensure that you are not using the common controls 6 in your project. You can choose not to add common controls manifest when you are creating the project using the WTL project wizard. If you already have a WTL project and upon adding
CDialogRegionT
class make the static controls to be drawn black, you can remove the common controls manifest from the .rc file.
댓글 없음:
댓글 쓰기