Splash window (was Newera Qusetion)
Posted in 1996
Topics: Stored Procedures & SPL
Here's the code for a Newera splash window. I've modified it slightly for public consumption. Here's how to use it. MAIN CALL splashOpen("MyBitmap") LET myWin = NEW myWindow() CALL myWin.open() CALL splashClose() END MAIN 1. You must link with the toolhelp.lib library that comes with VC++. (simply put 'toolhelp' in the library section of the AppBuilder) 2. You must pass the resource name of the bitmap to the splashOpen function (I believe its case-sensitive). You'll probably want to create you own .rc file for this and include it in the project. 3. If your application might display an error message anytime while the splash window is showning, you need to call splashClose() first or the error window will be hidden behind the splash screen and it will appear that your app in hung. Good luck! Kristopher Sarpolis Concepts Dynamic, Inc. kriss@conceptsdyn.com -------------------------------------------------------------------- BEGIN_C #include <toolhelp.h> static HBITMAP NE_SVARDEF hBitmap = NULL; static HINSTANCE NE_SVARDEF hLibInst = NULL; static HWND NE_SVARDEF hwndSplash = NULL; static BOOL NE_SVARDEF alreadyOpened = FALSE; long FAR PASCAL SplashWndProc(HWND hWnd, UINT message, WORD wParam, LONG lParam); long FAR PASCAL SplashWndProc(HWND hWnd, UINT message, WORD wParam, LONG lParam) { PAINTSTRUCT ps; HBITMAP hOldBmp; BITMAP bm; HDC hMemDC; switch(message) { case WM_PAINT: // // Display the bitmap in the splash window // BeginPaint(hWnd, &ps); hMemDC = CreateCompatibleDC(ps.hdc); hOldBmp = SelectObject(hMemDC, hBitmap); GetObject(hBitmap, sizeof(BITMAP), &bm); BitBlt(ps.hdc, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY); SelectObject(hMemDC, hOldBmp); DeleteDC(hMemDC); EndPaint(hWnd, &ps); return 0L; default: return DefWindowProc(hWnd, message, wParam, lParam); } } END_C ############################################################################## FUNCTION splashOpen(bitmapName CHAR(*)) ############################################################################## BEGIN_C TASKENTRY te; BITMAP bm; WNDCLASS wc; HTASK hTask; BOOL success; int screenWidth, screenHeight; int splashWidth, splashHeight; int top, left; if (alreadyOpened == TRUE) return 0; alreadyOpened = TRUE; // // Get a handle to instance for this task // hTask = GetCurrentTask(); te.dwSize = sizeof(TASKENTRY); success = TaskFindHandle(&te, hTask); if (!success) return 0; hLibInst = te.hInst; if (!hLibInst) return 0; hBitmap = LoadBitmap(hLibInst, (LPCSTR) bitmapname); if (!hBitmap) return 0; GetObject(hBitmap, sizeof(BITMAP), &bm); splashWidth = bm.bmWidth; splashHeight = bm.bmHeight; // // Center the bitmap on the screen // screenWidth = GetSystemMetrics(SM_CXSCREEN); screenHeight = GetSystemMetrics(SM_CYSCREEN); top = (screenHeight - splashHeight)/2; left = (screenWidth - splashWidth)/2; wc.style = 0; wc.lpfnWndProc = (WNDPROC) SplashWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = te.hInst; wc.hIcon = NULL; wc.hCursor = NULL; wc.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE + 1); wc.lpszMenuName = (LPCSTR) NULL; wc.lpszClassName = (LPSTR) "NewEraSplash"; RegisterClass(&wc); hwndSplash = CreateWindowEx(WS_EX_TOPMOST, "NewEraSplash", "", WS_POPUP | WS_VISIBLE, left, top, splashWidth, splashHeight, NULL, NULL, te.hInst, NULL); UpdateWindow(hwndSplash); END_C END FUNCTION ############################################################################## FUNCTION splashClose() ############################################################################## BEGIN_C if (hBitmap) { DeleteObject(hBitmap); hBitmap = NULL; } if (hwndSplash) { DestroyWindow(hwndSplash); hwndSplash = NULL; } END_C END FUNCTION