 |
|
 |
Hi. Is it possible to show the splash screen before creating CMainFrame? Cause my CMainFrame creation can take a few seconds and i would like the splash screen to appear before, so users could see that the program is doing something and that they dont double click again in the file their opening...
dfgsd
|
|
|
|
 |
|
 |
Seems like everyone is cool about using a large bitmap file? Well, I need to keep my EXE small and therefore was interested in embedding a small JPG or GIF file and use this as my splash image. I made the following modifications to this very helpfull class to accomplish such a task. Hope this helps someone out there.
----- Add to SplashWnd.h ------
static HBITMAP CSplashWnd::ConvertImage(UINT uResourceID, LPCTSTR szType = _T(""));
---- Change this ----
static BOOL ShowSplashScreen(UINT uTimeOut, UINT uBitmapID, CWnd* pParentWnd = NULL);
---- To this --------
static BOOL ShowSplashScreen(UINT uTimeOut, UINT uBitmapID, CWnd* pParentWnd = NULL, LPCTSTR szType = _T(""));
----- Add to SplashWnd.cpp ----
HBITMAP CSplashWnd::ConvertImage(UINT uResourceID, LPCTSTR szType)
{
HRSRC pRes = FindResource(NULL, MAKEINTRESOURCE(uResourceID), szType);
if (!pRes)
return NULL;
HGLOBAL hGlobal = GlobalAlloc(0, SizeofResource(NULL, pRes));
memcpy( hGlobal,
LoadResource(NULL, pRes),
SizeofResource(NULL, pRes) );
if (!hGlobal)
return NULL;
IPicture* pPicture;
IStream* pStream;
//IPersistStream* pPersistStream; // what is this for???
CreateStreamOnHGlobal(hGlobal, FALSE, &pStream);
if (!pStream) {
GlobalFree(hGlobal);
return NULL;
}
OleLoadPicture(pStream, 0, FALSE, IID_IPicture, (void**)&pPicture);
if (!pPicture) {
pStream->Release();
GlobalFree(hGlobal);
return NULL;
}
pStream->Release();
GlobalFree(hGlobal);
HBITMAP hBMP = 0;
pPicture->get_Handle((unsigned int*)&hBMP);
HBITMAP hBMPcopy = (HBITMAP)CopyImage(hBMP,IMAGE_BITMAP,0,0,LR_COPYRETURNORG);
pPicture->Release();
return hBMPcopy;
}
---- Change this in ShowSplashScreen() ----
if (!m_pSplashWnd->m_bitmap.LoadBitmap(uBitmapID)) {
return FALSE;
}
---- to this ------------------------------
HBITMAP hBitmap = 0;
if ( (lstrcmp(pszType, "JPG")==0) ||
(lstrcmp(pszType, "GIF")==0) ) {
hBitmap = m_pSplashWnd->ConvertImage(uBitmapID, pszType);
if (hBitmap) {
if(!m_pSplashWnd->m_bitmap.Attach(hBitmap))
return FALSE;
}
} else {
if (!m_pSplashWnd->m_bitmap.LoadBitmap(uBitmapID)) {
return FALSE;
}
}
---- Don't forget to modify the function too add this ----
LPCTSTR szType = _T("")
---- Also include the following in the cpp file ----------
#include
#include
-----------------------------------------------------------------------
Now for an explination. Sorry I didn't doco my code much. Anyways, it works just as before for BMP images, but if you wish to use a JPG or GIF then you can do the following:
1. Add the resource to your project by inserting it as a custom type JPG || GIF
2. When you call the ShowSplashScreen() then simply append _T("JPG") || _T("GIF") depending on which type of resource your are passing in this function.
3. Test it out
This worked really well for me, but I only tested it with a GIF image. I'm not sure if JPG actually works. If you add PNG || TIF formats, I'm not certain about these either.
Last note, I'm assuming that you are embedding your image into an EXE otherwise for a DLL the FindResource && LoadResource functions will need your module handle instead of NULL.
Good luck!
Arvin
|
|
|
|
 |
|
 |
thanks
it works with JPG file.
|
|
|
|
 |
|
 |
you say : "Feel free to use any of the source code found in this article without restriction.", but on the same line, you explicitely show a copyright advert (the top most sentence of the article)...
what is to do actually ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
 |
|
 |
The copyright has nothing to do with the license. If it is licensed without restriction then you can use it without restriction, but that doesn't make it your code as far as the copyright is concerned.
|
|
|
|
 |
|
 |
Perhaps I missed this, but I would like to get the splash screen to close when the program reaches a particular point, not simply based on the number of milliseconds. Is there a simple way to do this?
Thanks for the excellent article.
Dick Males
|
|
|
|
 |
|
 |
Yes, I just did this. I added a protected variable (m_nTimerID) that holds the return value from SetTimer. I then added a static public routine called CSplashWnd::KillSplashScreen( void ):
void CSplashWnd::KillSplashScreen( void )
{
if( m_pSplashWnd == NULL ) return;
if( m_nTimerID ) m_pSplashWnd->KillTimer( m_nTimerID );
m_nTimerID = 0;
m_pSplashWnd->HideSplashScreen();
}
and, just to be safe, changed the destructor:
CSplashWnd::~CSplashWnd()
{
// Kill the screen if it's still active
if( m_pSplashWnd ) HideSplashScreen();
// Clear the static window pointer.
ASSERT(m_pSplashWnd == this);
m_pSplashWnd = NULL;
// Kill the timer
if( m_nTimerID != 0 ) KillTimer( m_nTimerID );
}
Now, the splash screen will disappear when the user does some sort of input action (clicks the mouse, presses a key, etc.), or the timer expires, or the invoking program calls KillSplashScreen(). As somebody else here has noted, if you don't override PreTranslateMessage(), user input won't cause the splash screen to disappear.
Regards,
Robert Thompson
|
|
|
|
 |
|
 |
Hi. Is it possible to show the splash screen before creating CMainFrame? Cause my CMainFrame creation can take a few seconds and i would like the splash screen to appear before, so users could see that the program is doing something and that they dont double click again in the file their opening...
Thanks in advance
|
|
|
|
 |
|
 |
Hi All,
How would one go about creating a dynamic splash screen? The bitmap in this example has 'licensed to' text in it. I want to be able to draw/paste/paint the name of an arbitrary registered user before displaying the splash screen.
Any ideas anyone?
Thanks!
C.
|
|
|
|
 |
|
 |
Have You found a way to do this? I want to do the same.
|
|
|
|
 |
|
 |
It's very easy
I need to insert only three strings in CSplashWnd::OnPaint():
if (dcImage.CreateCompatibleDC(&dc))
{
BITMAP bm;
m_bitmap.GetBitmap(&bm);
// Paint the image.
CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);
dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
dcImage.SelectObject(pOldBitmap);
//my text
char buf[128];
sprintf(buf,"Licenzed to me!");
dc.TextOut(10,10,buf,strlen(buf));
}
|
|
|
|
 |
|
 |
Thank You!
That was almost too easy to be true
|
|
|
|
 |
|
 |
If you want your splash screen to be visible for as long as you have choosen wihtout the user beeing able to close it by clicking on it with the mouse then don't override PreTranslateMessage.
Just skip that step and it will be a really annoying splash sceen that hte user must look at as long as you want them to
|
|
|
|
 |
|
 |
Good stuff here
I do have a suggestion when the splash screen does show up you can still view the dialog in the background is there a way where you can only view the dialog after the splash screen has timed out???
Kindest Regards
Matt
|
|
|
|
 |
|
 |
Yes, that is possible!
I did it like this:
Change the time to 1 ms. Then add Sleep (3000) and your application shows the splash screen but waits 3 seconds before it shows the dialog.
CSplashWnd::ShowSplashScreen(1, IDB_SPLASH, this);
Sleep (3000);
|
|
|
|
 |
|
 |
Hi,
I also faced the same problem.Now it is resolved.Thanks for the same.I like to show one dialog itself as a splash screen.I have followed the steps mentioned in this article "How to insert a splash screen in a dialog-based application by using Visual C++ .NET or Visual C++ 2005" in msdn website http://support.microsoft.com/kb/817372 .But Main dialog window also appears in the background.Could you please suggest me hot to shoew only splash window before main window starts?suggest me if I have done anything wrong?Expecting your reply soon.Thanks in advance.
--
Vijay.S
|
|
|
|
 |
|
 |
thunx alot for this totrials..its very nice.
God With You
|
|
|
|
 |
|
 |
Just a few hours ago I came across just that problem--you can't add a splash screen to a dialog. Haven't tried this yet, but it looks great!
If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
 |
|
 |
When I change the file you use in your application it gives me an error that that file is not in format 3.So how can I change it?
<html>Mazy</html>
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
 |
|
 |
I have found this man is ad here for his commerce product,so it not welcome and we should kick it out codeproject.
|
|
|
|
 |
|
 |
I don't think so - CodeJock sponsors Codeproject so people like me and you can enjoy a site like this FREE !!!
Plus this article is FREE with excellent source code that will be useful to many people.
|
|
|
|
 |
|
 |
Looking at the codejock stuff and being a Win32 UI programmer myself, I'd say this was cool.
Now all you idiots you keep kicking people in the teeth because your code isn't handed to on a plate... Go and find another career - Programming is for people who have the tolorence to spend time looking at code and making it work.
Normski. - the next bit of code is self modifying ... jmp 0xCODE
|
|
|
|
 |
|
 |
Kirk,
Just want to say I agree with Norm's comments. I have never agreed with many ratings. It seams like the luck of the draw, if the first few people like it others just jump on board and if the reverse is true tough luck.
To be conscious that you are ignorant of the facts is a great step towards Knowledge. Benjamin Disraeli
|
|
|
|
 |
|
 |
Lighten up, man. Geez. Some people...
MT
http://www.teddev.com
|
|
|
|
 |
|
 |
Try changing line in Splash.h (and corresponding one in Splash.cpp)
from: static virtual BOOL PreTranslateAppMessage(MSG *pMsg);
to: virtual BOOL PreTranslateMessage(MSG *pMsg);
and the splash window will be closed on mouse & keyboard events as it seems to have been purpose..
Otherwise, a good tutorial on how to make a simple splash screen easily!
|
|
|
|
 |