/* SplashStart Copyleft 2003 Brett McNamara, brett@chaingang.org (a.k.a. Baavgai) -------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. See http://www.gnu.org for further information. -------------------------------------------------------------------------------- */ #include #include #if defined(CUSTOM_ICON) #include "resource.h" #endif #define TIMER_LAUNCH 100 #define TIMER_ALL 101 LPCSTR iniFile = ".\\start.ini"; char *className="SplashStart"; // globals struct { TCHAR bmpFileName[MAX_PATH]; TCHAR executePath[MAX_PATH]; TCHAR startupPath[MAX_PATH]; TCHAR parameters[MAX_PATH]; int delayLaunch; int delayTotal; } gConfig; struct { HDC hDc; // Storing a resource, we must remember to give it back HBITMAP hBitmap; SIZE size; } gBmp; struct { HWND hWnd; POINT top; SIZE size; DWORD style; } gWin; void LoadConfigFile(void) { GetPrivateProfileString(className, "ExecutePath", "", gConfig.executePath, MAX_PATH, iniFile ); GetPrivateProfileString(className, "Parameters", NULL, gConfig.parameters, MAX_PATH, iniFile ); GetPrivateProfileString(className, "StartupPath", NULL, gConfig.startupPath, MAX_PATH, iniFile ); GetPrivateProfileString(className, "ImageFile", "start.bmp", gConfig.bmpFileName, MAX_PATH, iniFile ); gConfig.delayTotal = GetPrivateProfileInt(className, "Delay", 3000, iniFile ); gConfig.delayLaunch = GetPrivateProfileInt(className, "DelayLaunch", 1000, iniFile ); } void StartProgram(void) { ShellExecute( (HWND)NULL, (LPCTSTR)"open", // lpOperation (LPCTSTR)gConfig.executePath, // lpFile (LPCTSTR)gConfig.parameters, //lpParameters (LPCTSTR)gConfig.startupPath, //lpDirectory (INT)SW_SHOWNORMAL | SW_RESTORE ); } void LoadSplashFile() { BITMAP bmp; RECT r; gWin.style = WS_OVERLAPPEDWINDOW & (~WS_MAXIMIZEBOX) & (~WS_THICKFRAME); gBmp.hDc = CreateCompatibleDC(0); gBmp.hBitmap=(HBITMAP)LoadImage(NULL, gConfig.bmpFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE ); SelectObject(gBmp.hDc,gBmp.hBitmap); GetObject(gBmp.hBitmap,sizeof(BITMAP),&bmp); gBmp.size.cx = bmp.bmWidth; gBmp.size.cy = bmp.bmHeight; r.left=r.top=0; r.right=bmp.bmWidth; r.bottom=bmp.bmHeight; AdjustWindowRect(&r, gWin.style, FALSE); gWin.size.cx= r.right-r.left; gWin.size.cy = r.bottom-r.top; gWin.top.x = (GetSystemMetrics(SM_CXSCREEN)-gWin.size.cx)/2; gWin.top.y = (GetSystemMetrics(SM_CYSCREEN)-gWin.size.cy)/2; } long CALLBACK MainWndProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam) { static HANDLE hTimer; HDC hdc; PAINTSTRUCT ps; switch (message) { case WM_CREATE: hTimer=(HANDLE)SetTimer(hwnd, TIMER_LAUNCH, gConfig.delayLaunch, (TIMERPROC) NULL); hTimer=(HANDLE)SetTimer(hwnd, TIMER_ALL, gConfig.delayTotal, (TIMERPROC) NULL); return 0; case WM_PAINT: hdc = BeginPaint(hwnd,&ps); BitBlt(hdc, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right-ps.rcPaint.left, ps.rcPaint.bottom-ps.rcPaint.top, gBmp.hDc, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY ); EndPaint(hwnd,&ps); break; case WM_TIMER: if (wparam==TIMER_LAUNCH) { KillTimer(hwnd, TIMER_LAUNCH); StartProgram(); return 0; } if (wparam==TIMER_ALL) { KillTimer(hwnd, TIMER_ALL); PostMessage(hwnd,WM_CLOSE,0,0); return 0; } PostMessage(hwnd,WM_CLOSE,0,0); break; case WM_DESTROY: DeleteDC(gBmp.hDc); DeleteObject(gBmp.hBitmap); PostQuitMessage(0); return 0; } return DefWindowProc(hwnd,message,wparam,lparam); } int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevious, LPSTR cmdline, int cmdshow) { int retVal=-1; WNDCLASSEX wc; HWND hWnd; MSG msg; DWORD dwStyle; LoadConfigFile(); wc.cbSize=sizeof(WNDCLASSEX); wc.style=CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc=(WNDPROC)MainWndProc; wc.cbClsExtra=0; wc.cbWndExtra=0; wc.hInstance=hinstance; wc.hCursor=LoadCursor(NULL,IDC_ARROW); wc.hbrBackground=GetStockObject( WHITE_BRUSH ); wc.lpszMenuName=(LPCSTR)NULL; wc.lpszClassName=className; #if defined(CUSTOM_ICON) wc.hIcon=LoadIcon(hinstance, (LPCTSTR)IDI_APP); wc.hIconSm=LoadIcon(hinstance, (LPCTSTR)IDI_APP) ; #else wc.hIcon=NULL; wc.hIconSm=NULL; #endif if (!RegisterClassEx(&wc)) return retVal; LoadSplashFile(); hWnd = CreateWindow( className, className, gWin.style, gWin.top.x, gWin.top.y, gWin.size.cx, gWin.size.cy, NULL, NULL, hinstance, NULL ); dwStyle = GetWindowLong(hWnd, GWL_STYLE); dwStyle &= ~(WS_CAPTION|WS_SIZEBOX); SetWindowLong(hWnd, GWL_STYLE, dwStyle); gWin.style = dwStyle; SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, gBmp.size.cx, gBmp.size.cy, SWP_NOMOVE ); ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd); while (GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } retVal=msg.wParam; return retVal; }