'2008/07'에 해당되는 글 5건
- 2008/07/22 IWebBrowser2를 이용해서 브라우저를 띄울 때, 브라우저를 다르게 해보자.
- 2008/07/21 CString -> LPWSTR, LPWSTR -> CString
- 2008/07/08 MessageBox의 디폴트 아이콘 변경하기
- 2008/07/08 윈도우를 반투명하게...
- 2008/07/02 CTextProgressCtrl. 텍스트가 들어가있는 프로그레스바
우선 IWebBrowser2를 선언. 그 외 변수들 선언
IWebBrowser2* pWebBrowser = NULL;
BSTR bstrURL = NULL;
BSTR bstrHeader = NULL;
VARIANT vtPostData = {0};
VARIANT vtEmpty;
VARIANT vtHeader;
bstrURL하고, bstrHeader는 필요한 값으로 채우고...(Navigate 할 때 필요)
그 다음 생성.
hr = ::CoCreateInstance( __uuidof(InternetExplorer), NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
__uuidof(IWebBrowser2), reinterpret_cast<LPVOID *>(&pWebBrowser) );
띄울 웹 브라우저의 크기를 설정
pWebBrowser->put_Left(200);
pWebBrowser->put_Top(300);
pWebBrowser->put_Width(578);
pWebBrowser->put_Height(298);
다른 값들도 설정 혹은 디폴트로 놓고 사용.
VariantInit( &vtEmpty );
VariantInit( &vtPostData );
VariantInit( &vtHeader );
V_VT( &vtHeader ) = VT_BSTR;
V_BSTR( &vtHeader ) = bstrHeader;
그 다음 브라우저에서 필요없는 것들 삭제.
pWebBrowser->put_ToolBar(VARIANT_FALSE); // 익스플로어 툴바 없앰
pWebBrowser->put_MenuBar(VARIANT_FALSE); // 메뉴바 없앰
pWebBrowser->put_AddressBar(VARIANT_FALSE); // 주소창 없앰
pWebBrowser->put_StatusBar(VARIANT_FALSE); // 상태바 없앰
pWebBrowser->put_Resizable(VARIANT_FALSE); //리사이즈 불가
pWebBrowser->put_Visible ( (VARIANT_BOOL) TRUE );
이렇게 하고 Navigate
hr = pWebBrowser->Navigate( bstrURL, &vtEmpty, &vtEmpty, &vtPostData, &vtHeader );
위 처럼 하면 툴바도 없고, 메뉴바도 없고, 주소창도 없고, 상태바도 없고, 리사이즈도 않되는 브라우저가 뜬다.
마지막으로...
HWND hIE;
hr=pWebBrowser->get_HWND((long *)&hIE);
::SetWindowPos(hIE, HWND_TOPMOST, 0, 0,0 ,0 , SWP_NOMOVE | SWP_NOSIZE);
위 코드는 방금 전에 띄운 브라우저를 최상단에 띄우게 하는 코드이다.
먼저..LPWSTR을 CString으로 변환하는 것은....그냥 (CString) 이렇게 캐스팅 해주면 된다.
그리고 CString을 LPWSTR로 캐스팅 하는 것은...
CString strString = "aa";
BSTR bstrString = strString.AllocSysString();
LPWSTR pwstr = (LPWSTR)bstrString;
SysFreeString(bstrString); //메모리 해제.
이렇게 해주면 된다.
|
원본글은 데브피아의 김동진님이 작성하신 글입니다.(http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=51&MAEULNO=20&no=8123&page=1) 이 글은 김동진님에게 저작권이 있습니다~개인 소장용으로 간직하기 위해 퍼왔습니다~ MessageBox에서는 기본적으로 MB_ICONSTOP...
등의 ICON이 지정되는데 임의로 아이콘을 세팅하시려면 아래와 같이 설정하시면 됩니다.
------------ typedef struct { UINT cbSize; HWND hwndOwner; HINSTANCE hInstance; LPCTSTR lpszText; LPCTSTR lpszCaption; DWORD dwStyle; LPCTSTR lpszIcon; DWORD_PTR dwContextHelpId; MSGBOXCALLBACK lpfnMsgBoxCallback; DWORD dwLanguageId; } MSGBOXPARAMS, *PMSGBOXPARAMS;
[Example] StartFragment MSGBOXPARAMS m_MsgParam = {0,}; m_MsgParam.cbSize = sizeof(m_MsgParam); m_MsgParam.dwStyle = MB_USERICON | MB_OK m_MsgParam.lpszIcon = MAKEINTRESOURCE(IDI_ICON1); m_MsgParam.hInstance = GetModuleHandle(NULL); m_MsgParam.hwndOwner = NULL m_MsgParam.lpszCaption = TEXT("This is User Icon MessageBox"); m_MsgParam.lpszText = TEXT("User Icon MessageBox Test"); MessageBoxIndirect(&m_MsgParam); |
우선 반투명 효과는 윈도우2000 이상에서만 지원된다는 것을 알아두길 바란다. 윈도우98에서 한다고 에러가 나진 않지만, 반투명효과는 나오지 않는다.
::SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd, GWL_EXSTYLE) ^ WS_EX_LAYERED);
::SetLayeredWindowAttributes( m_hWnd, 0, (255 * 70) / 100, LWA_ALPHA);
원래는 위와 같이 하면 된다고 하는데...vc6에서는 안되나? 아무튼 SetLayeredWindowAttributes 요놈이 없다고 하면서 안된다면 USER32.DLL에서 불러오면 된다고 한다.
typedef BOOL (WINAPI* pSLWA)(HWND, COLORREF, BYTE, DWORD);
pSLWA pSetLayeredWindowAttributes = NULL;
// "user32.dll"을 로드해서 SetLayeredWindowAttributes를 찾는다.
HINSTANCE hmodUSER32 = LoadLibrary("USER32.DLL");
pSetLayeredWindowAttributes = (pSLWA)GetProcAddress(hmodUSER32, "SetLayeredWindowAttributes");
::SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd, GWL_EXSTYLE) ^ WS_EX_LAYERED);
pSetLayeredWindowAttributes( m_hWnd, 0, (255 * 70) / 100, LWA_ALPHA);
위와 같이 해주면 된다. 이 때, LWA_ALPHA와 GWL_EXSTYLE이 없다고 나오면...선언해주자.
#define WS_EX_LAYERED 0x00080000 //확장 스타일
#define LWA_COLORKEY 0x00000001 //투명색상 지정
#define LWA_ALPHA 0x00000002 //반투명 정도 지정
#define ULW_COLORKEY 0x00000001
#define ULW_ALPHA 0x00000002
#define ULW_OPAQUE 0x00000004
위와 같이 해주면 된다.
위 함수에서 핸들은..투명하게 하고자 하는 윈도우의 값이다. 프로그램 시작부터 투명하게 하려면..Initinstance()에서 위의 처리를 해주면 된다~
///////////////////////////////////////////
//반투명 윈도우로 만듭니다.
SLWA pSetLayeredWindowAttributes = NULL;
HINSTANCE hmodUSER32 = LoadLibrary("USER32.DLL"); //라이브러리를 불러와서
pSetLayeredWindowAttributes=(SLWA)GetProcAddress(hmodUSER32,"SetLayeredWindowAttributes"); //함수포인터를 가져오고.
SetWindowLong(m_pMainWnd->m_hWnd, GWL_EXSTYLE,GetWindowLong(m_pMainWnd->m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED); //윈도우 스타일을 변경.
pSetLayeredWindowAttributes(m_pMainWnd->m_hWnd, 0, (255 * 70) / 100, LWA_ALPHA); //윈도우 투명도를 조절한다.
//////////////////////////////////////////데브피아 참고.
추가로 윈도우가 움직이거나, 사이즈가 조절될 때, 반투명하게 만들고 싶으면..아래와 같이 하면 된다.
메시지맵에 아래를 추가한다.
ON_MESSAGE(WM_ENTERSIZEMOVE, OnEnterSizeMove)
ON_MESSAGE(WM_EXITSIZEMOVE, OnExitSizeMove)
헤더파일에 위의 두개의 함수를 추가해준다.
afx_msg LRESULT OnEnterSizeMove(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnExitSizeMove(WPARAM wParam, LPARAM lParam);
그리고 각각의 함수에서, 아래와 같이 해준다.
::SetLayeredWindowAttributes( m_hWnd, 0, (255 * 100) / 100, LWA_ALPHA);
::SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd, GWL_EXSTYLE) &~WS_EX_LAYERED);
return 0L;
물론 SetLayeredWindowAttributes 요놈이 없다고 나오면 맨 위에 설명해준 것 처럼 하면 된다~
This is a simple CProgressCtrl derived class that allows text to be displayed on top of the progress bar in much the same way as many "Setup" programs display the progress of long operations.
The control is extremely simple and allows the same operations as a standard CProgressCtrl, as well as:
void SetShowText(BOOL bShow); |
Specifies whether or not the text for the control will be displayed during updates |
COLORREF SetBarColor(COLORREF crBarClr = CLR_DEFAULT); |
Specifies the colour of the progress control bar, and returns the previous colour. If the colour is set as CLR_DEFAULT then the Windows default colour is used. |
COLORREF GetBarColor(); |
Returns the colour of the progress control bar, or CLR_DEFAULT if the default Windows colours are being used. |
COLORREF SetBarBkColor(COLORREF crBarClr = CLR_DEFAULT); |
Specifies the colour for the control's background, and returns the previous background colour. If the colour is set as CLR_DEFAULT then the Windows default colour is used. |
COLORREF GetBarBkColor(); |
Returns the colour of the control's background, or CLR_DEFAULT if the default Windows colours are being used. |
COLORREF SetTextColor(COLORREF crBarClr = CLR_DEFAULT); |
Specifies the colour of the text, and returns the previous colour. If the colour is set as CLR_DEFAULT then the Windows default colour is used. |
COLORREF GetTextColor(); |
Returns the colour of the text, or CLR_DEFAULT if the default Windows colours are being used. |
COLORREF SetTextBkColor(COLORREF crBarClr = CLR_DEFAULT); |
Specifies the background colour of the text, and returns the previous background colour. If the colour is set as CLR_DEFAULT then the Windows default colour is used. |
COLORREF GetTextBkColor(); |
Returns the background colour of the text, or CLR_DEFAULT if the default Windows colours are being used. |
BOOL SetShowPercent(BOOL bShow) |
Sets whether or not to show the percentage value of the bar, and returns the old value |
DWORD AlignText(DWORD dwAlignment = DT_CENTER) |
Sets the text alignment and returns the old value |
BOOL SetMarquee(BOOL bOn, UINT uMsecBetweenUpdate) |
Sets whether or not the progress control is in marquee mode, as well as the interval in milliseconds between steps of the marquee block |
int SetMarqueeOptions(int nBarSize) |
Sets the size of the marquee as a percentage of the total control width |
To set the text to be displayed use the standard CWnd::SetWindowText. If you call SetShowText(TRUE) but do not specify any window text using CWnd::SetWindowText, then the percentage fraction of progress will be displayed as default.
To use the control, just include a CProgressCtrl in your app as per usual (either dynamically or by using a dialog template) and change the variable type from CProgressCtrl to CTextProgressCtrl. (Make sure you include TextProgressCtrl.h)
At present the progress is only displayed as a smooth bar, and colours are strictly windows default colours. (These may be changed in the future versions.)
Acknowledgements
Thanks to Keith Rule for his CMemDC class.
Updates
Pete Arends went to town on the code. His updates:
- Set the font used to the parent window font
- Added
SetTextColour()andGetTextColour()functions - Added a bunch of message handlers, so the control now responds to the standard progress bar
PBM_*messages. It is now possible to control the text progress control by sending messages to it. (works great from a worker thread). - Added 2 new messages
PBM_SETSHOWTEXTandPBM_SETTEXTCOLOR. - Added an
OnGetPos()handler. The functionGetPos()now works!!
Thanks Pete!
3 Jan 05: Kriz has also extended the code with two basic methods that allow switching between the three alignment styles LEFT, CENTER and RIGHT - even on the fly if that's needed.
Changes to the code
- Created a protected
DWORDmemberm_dwTextStyle - Disabled all
dwTextStylevariables inOnPaintor replaced them bym_dwTextStyle - Added two methods called
AlignTextandAlignTextInvalidate
Syntax
BOOL AlignText(DWORD aligment = DT_CENTER); BOOL AlignTextInvalidate(DWORD aligment = DT_CENTER);
Params/Return:
"alignment" can be DT_LEFT, DT_CENTER (default) or DT_RIGHT. Using the invalidating version forces the control to repaint itself automatically. Both methods will return FALSE if a wrong alignment flag was given, otherwise they will return TRUE to the caller.
Thank you Kriz!
I've also updated the code so it compiles in VC7.X.
9 mar 06: Tony Bommarito has updated the code to include more settings for colours, made corrections to vertical text mode and added a new marquee mode.
26 Feb 07: Tony Mommarito has provided further updates:
- Fixed bug where outside edge of progress bar wasn't drawn on XP when using an application manifest.
- Added complete turn-off of marquee mode in a slightly different manner than that suggested in Robert Pickford message.
- Fixed Unicode compile bug reported in dev75040 message.
- Added three SLN and VCPROJ file sets; one each for VS2002, VS2003 and VS2005. By removing the VS… extension from the proper set, any of the three IDEs can be used.

이올린에 북마크하기
textprogressctrl_demo.zip
Prev
Rss Feed