|

Introduction
This dialog is derived from CDialog. A bitmap is loaded from
a file and a region created based on a transparent colour. The bitmap
is then used to paint the dialog. This demo also demonstrates dragging
the dialog by clicking anywhere on a visible portion of the dialog, timer
events and a button on the transparent dialog.
It is perfect to be used as a splash screen or similar application or as a skeleton
application for non rectangular windows that are shaped by a supplied bitmap.
The code
You should be able to use this demo as a skeleton application for your own
project.
A standard CDialog MFC EXE application was created with the wizard and apart
from the standard supplied code, the following functions were overridden.
void OnClose() |
Used to clean up some resources on exit. |
void OnPaint() |
Used to paint the bimap into the region. |
void OnSize(UINT nType, int cx, int cy) |
Used to create the region and position and resize the dialog. |
void OnLButtonDown(UINT nFlags, CPoint point) |
To allow the dialog to be dragged by clicking anywhere. |
A button was created to allow the user to close the dialog. A timer was
created to demonstrate auto closing after a period of time.
The image is a normal bmp file that is loaded by the app and used to paint
the dialog. TRANSPARENTCOLOR is defined in the dialog class header as
bright purple (RGB(255, 0, 255), but this could be changed to any colour
you like.
The dialog window is auto sized to the size of the loaded bitmap then a
region created based on the transparent colour. The dialog is then positioned in
the centre of the current screen. This was done as an example for those who want
to use this application as a splash windows.
An example of using this class is as follows:
CTransparentDialogDlg dlg;
int nResponse = dlg.DoModal();
The button serves no real purpose and was made a close button simply to
demonstrate using a button.
History
V1.0 initial release 27th November 2002
| You must Sign In to use this message board. |
|
| | Msgs 1 to 18 of 18 (Total in Forum: 18) (Refresh) | FirstPrevNext |
|
|
 |
|
|
its wonderful sir...i m new to development.and i m very much interested in MFC.can u give me any links or articles...i'll be thankful to u sir....
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks.
I'm looking for a splash implementation that is similar to that of Photoshop. The main function I need is to change the text on the splash is changeable at runtime.
After a while, I realized that a correct way to this is an implementation based on a dialog. It's what I need.
One question here:
I'm using it in a Doc/View program instead of a dialog program, so I don't want the program to exit, as the demo program, on the timer message, but just close the transparent dialog, I change the code in CTransparentDialogDlg::OnTimer(UINT nIDEvent) from
KillTimer(1); PostQuitMessage(0); CDialog::OnTimer(nIDEvent);
to KillTimer(1); OnClose(); CDialog::OnTimer(nIDEvent);
but the splash just don't close as anticipated. Why?
Thanks again.
max
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
As a step further, how can I keep showing the splash and, meanwhile, do the data initializing and updating a progress bar on the splash dialog?
Thanks for any hints from anybody.
Max
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, while I am running the application I am getting a message box "Error loading Bitmap".
what shd I do to solve this..???
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
The app looks in the same directory (folder) that the .exe file is started in. The author put the image.bmp file in the Release dir, so if you set run the project in release mode, it will find it. If you want to run in debug mode, copy image.bmp into the Debug dir.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I tried to use it with ws_child, but it didn't work, is it possible? can u give me a simple sample code? thanks,
give a hand,have a heart
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I have a problem like this.i have hooked WM_CREATE message and whenewer application window is created i just takes it HWND and passes user Defined message to another application that application handles userdefined message(This application is also my application).In that message handlers i have kept delay of 100 ms and capture the image and then hide it. That is work but when i hide window in WM_CREATE hook procedure then pass Userdefined message to my application then it can`t be captured insted it capures only active window`s GUI of Size of my hiden application window.
I think that to capture any window it is requred to be visible. but is it possible that by copying memory content of Windows Gui we can also capture the image of window ?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I tried to move my transparent window modifying iX e iY values in the demo, but the window is always centered, why?
//iX = (GetSystemMetrics(SM_CXSCREEN)) / 2 - (m_Bitmap.bmWidth / 2); //iY = (GetSystemMetrics(SM_CYSCREEN)) / 2 - (m_Bitmap.bmHeight / 2); iX=800; iY=400; SetWindowPos(&wndTopMost,iX, iY, m_Bitmap.bmWidth, m_Bitmap.bmHeight, NULL);
PS: i was able to move the window using: SetWindowPos(&wndTopMost,iX,iY,m_Bitmap.bmWidth,m_Bitmap.bmHeight, SWP_SHOWWINDOW) ; but, in this way, i lose my bitmap, and i have only a gray mask of the window
|
| Sign In·View Thread·PermaLink | 3.50/5 (2 votes) |
|
|
|
 |
|
|
Not transparent, but i like it...
void CMyDialogClass::OnPaint() { CPaintDC dc(this); // device context for painting
PaintDesktop(dc); // Desktop wallpaper background }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
I'm learning VC++ so, I might sound lil stupid but is it possible to have a bmp file with single color and then make it transparent so the dialog box not at all appears on the screen and you see the desktop through dialog?
|
| Sign In·View Thread·PermaLink | 1.25/5 (4 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
It's a nice way to easily generate resource files for transparent dialog applications! Here is some code to perform serialization:
void Serialize(CArchive& ar, CRgn* pRgn) { if( ar.IsStoring() ) { // store window region int nCount = pRgn->GetRegionData(NULL, 1); if( nCount>0 ) { LPBYTE pbuffer = new BYTE[nCount]; memset(pbuffer, 0, nCount); int nRet = pRgn->GetRegionData((LPRGNDATA)pbuffer, nCount); ar << nCount; ar.Write(pbuffer, nCount); delete[] pbuffer; } } else { // load and create window region int nCount = 0; ar >> nCount; LPBYTE pbuffer = new BYTE[nCount]; memset(pbuffer, 0, nCount); ar.Read(pbuffer, nCount); if( pRgn->m_hObject ) pRgn->DeleteObject(); pRgn->CreateFromData(NULL, nCount, (LPRGNDATA)pbuffer); delete[] pbuffer; } }
--- Manolis from Crete ---
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Add the following functions in the header file of the dialog:
void SaveData(CRgn* pRgn); BOOL LoadData(CRgn* pRgn); void Serialize(CArchive& ar, CRgn* pRgn);
The implementation is:
void CTransparentDialogDlg::Serialize(CArchive& ar, CRgn* pRgn) { if( ar.IsStoring() ) { // storing code
int nCount = pRgn->GetRegionData(NULL, 1); if( nCount>0 ) { LPBYTE pbuffer = new BYTE[nCount]; memset(pbuffer, 0, nCount); int nRet = pRgn->GetRegionData((LPRGNDATA)pbuffer, nCount); switch( nRet ) { case COMPLEXREGION: TRACE("New region has overlapping borders.\n"); break;
case ERROR: TRACE("No new region created.\n"); break;
case NULLREGION: TRACE("New region is empty.\n"); break;
case SIMPLEREGION: TRACE("New region has no overlapping borders.\n"); break; } ar << nCount; ar.Write(pbuffer, nCount); delete[] pbuffer; } } else { // loading code int nCount = 0; ar >> nCount; LPBYTE pbuffer = new BYTE[nCount]; memset(pbuffer, 0, nCount); ar.Read(pbuffer, nCount); if( pRgn->m_hObject ) pRgn->DeleteObject(); pRgn->CreateFromData(NULL, nCount, (LPRGNDATA)pbuffer); delete[] pbuffer; } }
void CTransparentDialogDlg::SaveData(CRgn* pRgn) { CFile ff; CFileException e; if( ff.Open("MyRgn.set", CFile::modeCreate | CFile::modeWrite | CFile::shareExclusive, &e) ) { CArchive ar(&ff, CArchive::store, 4096, NULL); try { Serialize( ar, pRgn ); } catch(CFileException* e) { e->ReportError(); e->Delete(); }
ar.Close(); ff.Close(); } }
BOOL CTransparentDialogDlg::LoadData(CRgn* pRgn) { CFile ff; CFileException e; if( ff.Open("MyRgn.set", CFile::modeRead, &e) ) { CArchive ar(&ff, CArchive::load, 4096, NULL);
try { Serialize( ar, pRgn ); } catch(CFileException* e) { e->ReportError(); e->Delete(); }
ar.Close(); ff.Close();
return TRUE; }
return FALSE; }
Call LoadData inside the OnInitDialog and SaveData before you close the dialog.
good luck.
Manolis from Crete 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|