⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autorun.c

📁 C:Documents and SettingsAdministrator桌面VC++多媒体特效制作百例CHAR23Autorun
💻 C
📖 第 1 页 / 共 2 页
字号:
	static  HFONT hfontDlg;		// Font for dialog text
	static	HFONT hFinePrint;	// Font for 'fine print' in dialog
	DWORD   dwVerInfoSize;		// Size of version information block
	LPSTR   lpVersion;			// String pointer to 'version' text
	DWORD   dwVerHnd=0;			// An 'ignored' parameter, always '0'
	UINT    uVersionLen;
	WORD    wRootLen;
	BOOL    bRetCode;
	int     i;
	char    szFullPath[256];
	char    szResult[256];
	char    szGetName[256];
	DWORD	dwVersion;
	char	szVersion[40];
	DWORD	dwResult;

	switch (message) {
		case WM_INITDIALOG:
			ShowWindow (hDlg, SW_HIDE);
			hfontDlg = GetStockObject (ANSI_VAR_FONT);
			hFinePrint = CreateFont(11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				VARIABLE_PITCH | FF_SWISS, "");
			CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
			GetModuleFileName (hInst, szFullPath, sizeof(szFullPath));

			// Now lets dive in and pull out the version information:
			dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
			if (dwVerInfoSize) {
				LPSTR   lpstrVffInfo = (LPVOID)LocalAlloc (LPTR, dwVerInfoSize);
				GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpstrVffInfo);
				// The below 'hex' value looks a little confusing, but
				// essentially what it is, is the hexidecimal representation
				// of a couple different values that represent the language
				// and character set that we are wanting string values for.
				// 040904E4 is a very common one, because it means:
				//   US English, Windows MultiLingual characterset
				// Or to pull it all apart:
				// 04------        = SUBLANG_ENGLISH_USA
				// --09----        = LANG_ENGLISH
				// ----04E4 = 1252 = Codepage for Windows:Multilingual
				lstrcpy(szGetName, "\\StringFileInfo\\040904E4\\");	 
				wRootLen = lstrlen(szGetName); // Save this position
			
				// Set the title of the dialog:
				lstrcat (szGetName, "ProductName");
				bRetCode = VerQueryValue((LPVOID)lpstrVffInfo,
					(LPSTR)szGetName,
					(LPVOID)&lpVersion,
					(UINT *)&uVersionLen);
				lstrcpy(szResult, "About ");
				lstrcat(szResult, lpVersion);
				SetWindowText (hDlg, szResult);

				// Walk through the dialog items that we want to replace:
				for (i = DLG_VERFIRST; i <= DLG_VERLAST; i++) {
					GetDlgItemText(hDlg, i, szResult, sizeof(szResult));
					szGetName[wRootLen] = (char)0;
					lstrcat (szGetName, szResult);
					uVersionLen   = 0;
					lpVersion     = NULL;
					bRetCode      =  VerQueryValue((LPVOID)lpstrVffInfo,
						(LPSTR)szGetName,
						(LPVOID)&lpVersion,
						(UINT *)&uVersionLen);

					if ( bRetCode && uVersionLen && lpVersion) {
					// Replace dialog item text with version info
						lstrcpy(szResult, lpVersion);
						SetDlgItemText(hDlg, i, szResult);
					} else {
						dwResult = GetLastError();
						wsprintf (szResult, "Error %lu", dwResult);
						SetDlgItemText (hDlg, i, szResult);
					}
					SendMessage (GetDlgItem (hDlg, i), WM_SETFONT, 
						(UINT)((i==DLG_VERLAST)?hFinePrint:hfontDlg),
						TRUE);
				} // for (i = DLG_VERFIRST; i <= DLG_VERLAST; i++)
				LocalFree ((HLOCAL)lpstrVffInfo);

			} else {
				// No version information available.
			} // if (dwVerInfoSize)

			SendMessage (GetDlgItem (hDlg, IDC_LABEL), WM_SETFONT, (WPARAM)hfontDlg,(LPARAM)TRUE);

			// We are  using GetVersion rather then GetVersionEx
			// because earlier versions of Windows NT and Win32s
			// didn't include GetVersionEx:
			dwVersion = GetVersion();

			if (dwVersion < 0x80000000) {
				// Windows NT
				wsprintf (szVersion, "Microsoft Windows NT %u.%u (Build: %u)",
					(DWORD)(LOBYTE(LOWORD(dwVersion))),
					(DWORD)(HIBYTE(LOWORD(dwVersion))),
					(DWORD)(HIWORD(dwVersion)) );
			} else if (LOBYTE(LOWORD(dwVersion))<4) {
				// Win32s
				wsprintf (szVersion, "Microsoft Win32s %u.%u (Build: %u)",
					(DWORD)(LOBYTE(LOWORD(dwVersion))),
					(DWORD)(HIBYTE(LOWORD(dwVersion))),
					(DWORD)(HIWORD(dwVersion) & ~0x8000) );
			} else {
				// Windows 95
				wsprintf (szVersion, "Microsoft Windows 95 (osv:%u.%u)",
					(DWORD)(LOBYTE(LOWORD(dwVersion))),
					(DWORD)(HIBYTE(LOWORD(dwVersion))) );
			}

			SetWindowText (GetDlgItem(hDlg, IDC_OSVERSION), szVersion);
			ShowWindow (hDlg, SW_SHOW);
			return (TRUE);

		case WM_COMMAND:
			if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
				EndDialog(hDlg, TRUE);
				return (TRUE);
			}
			break;

		case WM_DESTROY:
			DeleteObject (hFinePrint);
			break;			
	}

	return FALSE;
}


/************************************************************************\
 *    FUNCTION: OnCreate
\************************************************************************/
// This function will be called when the WM_CREATE message is processed
// by our application. This is where we will load the bitmap to be
// displayed, create a palette for the image, resize the window to fit
// the bitmap, and put in our control buttons that will allow the user
// to tell us how to proceed.

int OnCreate(HWND hWnd)
{
	HDC hdc;
	RECT rect;
	HFONT hfontBtn;
	HWND hwndBtnOk, hwndBtnExit;

	int i;
	LPBITMAPINFO lpbmi;

	LPVOID lpv;
	HRSRC hrsrc;
	DWORD dwSize;

	LOGPALETTE *plgpl;
	int cColors;
	LPVOID pimage;
	TEXTMETRIC tm;
	int iHeight, iWidth, x, y;

	BOOL fPalette = FALSE;
	BOOL fTrueColor = FALSE;

	char szString[20];

	hdc = GetDC(hWnd);

	hpal = NULL;

	fPalette = GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE;
	fTrueColor = ((GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES))>=32);

	// At this point, 'fPalette' will be true if we are running
	// on a display that supports (and -needs- to support) the
	// palette manager. 'fTrueColor' will be true if the display
	// we are running on can handle any color we can throw at
	// it, thus doesn't need to use the palette manager. If
	// either of these are true, then we can display our full
	// color image, otherwise, we need to shift down to our
	// 16 color version.

	if (fPalette || fTrueColor) {
		// Locate the resource:
		hrsrc = FindResource(hInst, "AUTORUN", RT_BITMAP);
		// Lock it down. This will give us a memory pointer:
		lpv = LockResource(LoadResource(hInst,hrsrc));
		// Find out how big the resource was:
		dwSize = SizeofResource(hInst,hrsrc);
		// Allocate enough memory:
		lpbmi = (LPBITMAPINFO)LocalAlloc (LPTR, dwSize);
		if (!lpbmi) return -1; // failure
		// And make our own private copy of the data:
		memcpy (lpbmi, lpv, dwSize);

		// How many colors does it use?:
		cColors = lpbmi->bmiHeader.biClrUsed;
		if (cColors == 0) {
			cColors = (1 << (int)(lpbmi)->bmiHeader.biBitCount);
		}

		// Use that to determine where the actual bitmap image starts:
		pimage = &(lpbmi->bmiColors[cColors]);

		// Now lets create a palette based on the image we loaded:
		plgpl = (LPVOID)LocalAlloc (LPTR, sizeof(LOGPALETTE) + (cColors-1)*sizeof(PALETTEENTRY));
		if (!plgpl) return -1; // failure

		plgpl->palVersion = 0x300;
		plgpl->palNumEntries = cColors;
		for (i=0; i<cColors; i++) {
			plgpl->palPalEntry[i].peRed   = lpbmi->bmiColors[i].rgbRed;
			plgpl->palPalEntry[i].peGreen = lpbmi->bmiColors[i].rgbGreen;
			plgpl->palPalEntry[i].peBlue  = lpbmi->bmiColors[i].rgbBlue;
			//plgpl->palPalEntry[i].peFlags = PC_NOCOLLAPSE; // is this needed?
		}
		hpal = CreatePalette(plgpl);

		// And free up the memory we allocated:
		LocalFree ((HLOCAL)plgpl);

		if (!hpal) return -1; // Fail on no palette

		// Now create a true DIBitmap from all of this:
		// First assign the palette to the DC:
		SelectPalette(hdc, hpal, FALSE);
		RealizePalette(hdc);

		// Now create a DIB based off the the DC with the bitmap image from the resource:
		hbmAutoRun = CreateDIBitmap (hdc, (BITMAPINFOHEADER *)lpbmi,
			CBM_INIT, pimage, lpbmi, DIB_RGB_COLORS);

		LocalFree (lpbmi);

	} else {
		// At this point, you know that the current display
		// device does not support palettes. So you may want
		// to keep track of this and later warn the user that
		// they may not get the full visual impact of your
		// application...
		hbmAutoRun = NULL; // just to make sure we force load the 16 color version
	}

	if (!hbmAutoRun) {
		hbmAutoRun = LoadBitmap (hInst, "AUTO16"); // whimpy 16 color version...
		if (!hbmAutoRun) {
			return -1;
		}
	}

	// And get the header data:
	GetObject (hbmAutoRun, sizeof(BITMAP), &bmAutoRun);

	SetWindowPos (hWnd, NULL, 0, 0, bmAutoRun.bmWidth, bmAutoRun.bmHeight,
		SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
	// Since what we really want to do is size the 'Client' window,
	// Lets find out how far off we were, adjust our values, and
	// try it again...
	GetClientRect (hWnd, &rect);
	x = bmAutoRun.bmWidth - (rect.right-rect.left);
	y = bmAutoRun.bmHeight - (rect.bottom-rect.top);
	SetWindowPos (hWnd, NULL, 0, 0, bmAutoRun.bmWidth+x,
		bmAutoRun.bmHeight+y, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

	CenterWindow (hWnd, GetDesktopWindow ());

	// Ok, our image is loaded, and our window properly sized
	// Lets add in some controls: The text to use for these
	// buttons is coming out of the resource of this app
	LoadString (hInst, IDM_CONTINUE, szString, sizeof(szString));
	hwndBtnOk = CreateWindow ("BUTTON", szString,
		WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON,
		0, 0, 0, 0,
		hWnd, (HMENU)IDM_CONTINUE, hInst, NULL);

	LoadString (hInst, IDM_EXIT, szString, sizeof(szString));
	hwndBtnExit = CreateWindow ("BUTTON", szString, 
		WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | BS_PUSHBUTTON,
		0, 0, 0, 0,
		hWnd, (HMENU)IDM_EXIT, hInst, NULL);

	hfontBtn = GetStockObject (ANSI_VAR_FONT);
	SendMessage (hwndBtnOk, WM_SETFONT, (WPARAM)hfontBtn,(LPARAM)TRUE);
	SendMessage (hwndBtnExit, WM_SETFONT, (WPARAM)hfontBtn, (LPARAM)TRUE);
	SelectObject (hdc, hfontBtn);
	GetTextMetrics (hdc, &tm);

	iHeight = (tm.tmHeight + tm.tmExternalLeading) * 2;
	iWidth = (bmAutoRun.bmWidth / 2) - (iHeight * 2);
			
	x = ((bmAutoRun.bmWidth/2) / 2) - (iWidth/2);
	y = bmAutoRun.bmHeight - iHeight - (iHeight/2);

	SetWindowPos (hwndBtnExit, NULL, x, y, iWidth, iHeight,
		SWP_NOZORDER | SWP_NOACTIVATE);

	x += bmAutoRun.bmWidth/2;
	SetWindowPos (hwndBtnOk, NULL, x, y, iWidth, iHeight,
		SWP_NOZORDER | SWP_NOACTIVATE);

	ShowWindow (hWnd, SW_SHOW);

	ReleaseDC (hWnd, hdc);

	return 0; // Sucess
	
}

/************************************************************************\
 *    FUNCTION: 
\************************************************************************/
// This function is called to launch the 'real' application when the
// user instructs us to. The name of the application to be run is coming
// out of the resource of this app.
BOOL LaunchApplication(void)
{
	char szCompany[40];
	char szImageName[40];
	char szCmdLine[40];

	STARTUPINFO         si;
	PROCESS_INFORMATION pi;

	LoadString (hInst, ID_COMPANY, szCompany, sizeof(szCompany));
	LoadString (hInst, ID_APPNAME, szImageName, sizeof(szImageName));
	strcat (szImageName, ".EXE");
	LoadString (hInst, ID_CMDLINE, szCmdLine, sizeof(szCmdLine));

	si.cb = sizeof(STARTUPINFO);
	// Yeah, this could be done with a 'memset', but this is more illustrative:
	si.lpReserved =
		si.lpDesktop =
		si.lpTitle	=
		si.dwX	=
		si.dwY =
		si.dwXSize	=
		si.dwYSize =
		si.dwXCountChars =
		si.dwYCountChars =
		si.dwFillAttribute =
		si.dwFlags =
		si.wShowWindow =
		si.cbReserved2 =
		si.lpReserved2 =
		si.hStdInput =
		si.hStdOutput =
		si.hStdError =
		NULL;

	return CreateProcess (szImageName, szCmdLine, NULL, NULL, FALSE,
		CREATE_NEW_PROCESS_GROUP, NULL, NULL, &si, &pi);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -