#define WM_CUSTOM_THREAD_GONE (WM_APP + 2)
DWORD WINAPI SplashScreen(LPVOID param)
{
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
/*GetModuleHandle(NULL)*/ appInst, NULL, NULL, NULL,
MAKEINTRESOURCE( IDR_MENU1 ),
"MyApp", NULL };
RegisterClassEx( &wc );
// Create the application's window.
hWnd = CreateWindow( "MyApp", "MyApp",
WS_OVERLAPPEDWINDOW, 100, 100, 600, 600,
GetDesktopWindow(), NULL, wc.hInstance,
NULL );
hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)SplashScreen, NULL,
0, &threadID);
InitialiseDirectX8(hWnd);
ready = true;
ShowWindow(hWnd, SW_HIDE);
UpdateWindow(hWnd);
MSG msg;
while(1)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return(msg.wParam);
}
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_CUSTOM_THREAD_GONE:
MessageBeep(1);
MessageBox(hWnd, "Eureka!","",MB_OK);
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
visible = true;
SetTimer(hWnd, THE_TIMER, 1000, NULL);
break;
}
}
DWORD WINAPI SplashScreen(LPVOID param)
{
WNDCLASSEX splashWC = { sizeof(WNDCLASSEX), CS_CLASSDC, SplashProc, 0L,
0L,
appInst, NULL, NULL, (HBRUSH)COLOR_WINDOW, NULL,
"Splash", NULL };
RegisterClassEx( &splashWC );
hSplashScreen = CreateWindow( "Splash", "Splash",
0, 100, 100, 600, 600,
hWnd, NULL, splashWC.hInstance, NULL );
ShowWindow(hSplashScreen, SW_SHOW);
UpdateWindow(hSplashScreen);
// The message loop.
MSG msg;
while(1)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return(msg.wParam);
}
LRESULT WINAPI SplashProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM
lParam )
{
switch( msg )
{
case WM_DESTROY:
PostMessage(GetParent(hSplashScreen), WM_CUSTOM_THREAD_GONE,
0,0);
SetForegroundWindow(hWnd);
PostQuitMessage(0);
return 0;
case WM_CREATE:
SetTimer(hWnd, SPLASH_TIMER, 5000, NULL);
return 0;
case WM_PAINT:
ValidateRect( hWnd, NULL );
return 0;
case WM_TIMER:
switch(wParam) {
case SPLASH_TIMER:
SendMessage(hSplashScreen, WM_DESTROY, 0, 0);
break;
}
break;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
Allow me to disagree with your logic. An application *really*
seldom has to have more than one message loop and, even more
seldom, more than one GUI thread. I have a similar code, with
the (big) difference that I create splash in WinMain and create
a *worker* thread (no windows, no message loop, just
loading&processing data). Before that thread dies, it sends
a custom message to the main frame to hide splash and enable all
GUI stuff (in the meantime, it also updates a progress bar
on the splash). In this way, splash screen is visible only as long
as the data are really loading, no bloody timer.
Your code could probably be fixed but, again, I dislike the
approach. Possibly the problem is that for SendMessage() to
work accross threads, the other thread's message loop has to
be active, but it's still initializing so it won't reach
the parent. Furthermore, you're creating a splash window
with hWnd as parent but 0 (WS_OVERLAPPED) as style, while
the parent is in another thread??? Maybe it works but it's
odd at best.
Jugoslav
________________________
www.geocities.com/jdujic
"Jugoslav Dujic" <jdu...@yahoo.com> wrote in message
news:a2451c$uessg$1...@ID-106075.news.dfncis.de...