home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Loisirs 18
/
cd.iso
/
PLANETE
/
MUDWIN
/
SOURCE.ZIP
/
ABOUT.C
next >
Wrap
C/C++ Source or Header
|
1994-10-01
|
12KB
|
464 lines
//
// MODULE About.c
//
// PURPOSE Displays the "About" box
//
// EXPORTS AboutDialog
//
#include "defcon.h"
#include "global.h"
#pragma hdrstop
#include <ver.h>
#include <string.h>
/* note when we were last compiled */
TS(About)
short FAR CDECL MsgBox2(WORD, LPCSTR,...);
/* local info for marquee animation */
static BOOL fAnimate;
static BITMAP bm;
static RECT rCredits, rScroll;
static HBITMAP hbmpScroll, hbmpCredits;
static HRSRC hResource;
static HGLOBAL hDedicate;
static LPSTR lpszDedicate, lpszMsg;
static int nScan = 0;
static BOOL Marquee_Create(HWND, LPCSTR);
static VOID Marquee_Destroy(VOID);
static VOID Marquee_Paint(HDC);
static VOID Marquee_Animate(HWND);
BOOL
Marquee_Create(HWND hwnd, LPCSTR lpszRsrc)
{
HDC hdc = GetDC(hwnd);
HDC hdcMem = CreateCompatibleDC(hdc);
HWND h;
/* fetch the picture of myself */
hbmpCredits = LoadBitmap(hInst, lpszRsrc);
if (!hbmpCredits) return FALSE;
GetObject(hbmpCredits, sizeof(BITMAP), &bm);
/* figure out where the picture frame goes */
h = GetDlgItem(hwnd, IDD_ABOUT_COMPANY);
GetClientRect(h, &rCredits);
rCredits.bottom = bm.bmHeight;
MapWindowPoints(h, hwnd, (POINT FAR *) &rCredits, 2);
/* figure out where the text goes */
rScroll.left = rCredits.left + bm.bmWidth - CREDIT_BORDER;
rScroll.top = rCredits.top + CREDIT_BORDER;
rScroll.right = rCredits.right - CREDIT_BORDER;
rScroll.bottom = rCredits.bottom - CREDIT_BORDER;
/* create a (monochrome) place to draw */
hdcMem = CreateCompatibleDC(hdc);
hbmpScroll = CreateCompatibleBitmap(hdcMem,
rScroll.right - rScroll.left,
rScroll.bottom - rScroll.top);
DeleteDC(hdcMem);
if (!hbmpScroll) {
Marquee_Destroy();
return FALSE;
}
/* now get the words */
hResource = FindResource(hInst, lpszRsrc, RT_RCDATA);
hDedicate = LoadResource(hInst, hResource);
lpszDedicate = (LPSTR)LockResource(hDedicate);
if (!lpszDedicate) {
Marquee_Destroy();
return FALSE;
}
/* hide existing comments */
ShowWindow(GetDlgItem(hwnd, IDD_ABOUT_COMPANY), SW_HIDE);
ShowWindow(GetDlgItem(hwnd, IDD_ABOUT_PRODUCT), SW_HIDE);
ShowWindow(GetDlgItem(hwnd, IDD_ABOUT_VERSION), SW_HIDE);
ShowWindow(GetDlgItem(hwnd, IDD_ABOUT_COPYRITE), SW_HIDE);
Marquee_Paint(hdc);
/* where are we in the animation loop */
lpszMsg = lpszDedicate;
nScan = 0;
fAnimate = TRUE;
SetTimer(hwnd, 0, 111, NULL);
ReleaseDC(hwnd, hdc);
return TRUE;
}
VOID
Marquee_Destroy(VOID)
{
fAnimate = FALSE;
if (hbmpScroll) {
DeleteObject(hbmpScroll);
hbmpScroll = 0;
}
if (hbmpCredits) {
DeleteObject(hbmpCredits);
hbmpCredits = 0;
}
if (hDedicate) {
UnlockResource(hDedicate);
hDedicate = 0;
}
if (hResource) {
FreeResource(hResource);
hResource = 0;
}
}
VOID
Marquee_Paint(HDC hdc)
{
HDC hdcMem = CreateCompatibleDC(hdc);
RECT r;
HBRUSH hbr, hbrOld;
HBITMAP hbmpOld;
hbmpOld = SelectObject(hdcMem, hbmpCredits);
BitBlt(hdc, rCredits.left, rCredits.top,
bm.bmWidth-CREDIT_BORDER, bm.bmHeight,
hdcMem, 0, 0, SRCCOPY);
BitBlt(hdc, rCredits.right-CREDIT_BORDER, rCredits.top,
CREDIT_BORDER, bm.bmHeight,
hdcMem, bm.bmWidth-CREDIT_BORDER, 0, SRCCOPY);
/* establish common width */
r.left = rScroll.left;
r.right = rScroll.right;
/* draw black lines at top and bottom of the frame */
hbr = CreateSolidBrush(RGB(0,0,0));
hbrOld = SelectObject(hdc, hbr);
r.top = rCredits.top;
r.bottom = rCredits.top + 1;
FillRect(hdc, &r, hbr);
r.top = rCredits.bottom - 1;
r.bottom = rCredits.bottom;
FillRect(hdc, &r, hbr);
/* upper part of frame is in shadow */
hbr = CreateSolidBrush(CREDIT_SHADOW);
DeleteObject(SelectObject(hdc, hbr));
r.top = rCredits.top + 1;
r.bottom = rCredits.top + CREDIT_BORDER;
FillRect(hdc, &r, hbr);
/* lower part of frame is illuminated */
hbr = CreateSolidBrush(CREDIT_HIGHLIGHT);
DeleteObject(SelectObject(hdc, hbr));
r.top = rCredits.bottom - CREDIT_BORDER;
r.bottom = rCredits.bottom - 1;
FillRect(hdc, &r, hbr);
/* scrollable region starts off as blank background */
hbr = CreateSolidBrush(CREDIT_BACKGROUND);
DeleteObject(SelectObject(hdc, hbr));
FillRect(hdc, &rScroll, hbr);
DeleteObject(SelectObject(hdc, hbrOld));
DeleteObject(SelectObject(hdcMem, hbmpOld));
DeleteDC(hdcMem);
}
VOID
Marquee_Animate(HWND hwnd)
{
HDC hdc, hdcMem;
RECT r;
int len;
static int nMaxScan;
if (!fAnimate) return;
hdc = GetDC(hwnd);
hdcMem = CreateCompatibleDC(hdc);
SelectObject(hdcMem, hbmpScroll);
SelectObject(hdcMem, GetStockObject(ANSI_VAR_FONT));
SetRect(&r, 0, 0,
rScroll.right - rScroll.left,
rScroll.bottom - rScroll.top);
BitBlt(hdc, rScroll.left, rScroll.top, r.right, r.bottom - 1,
hdc, rScroll.left, rScroll.top + 1, SRCCOPY);
len = _fstrcspn(lpszMsg, "\r\n");
if (nScan == 0) {
int x;
DWORD dw;
dw = GetTextExtent(hdcMem, lpszMsg, len);
nMaxScan = HIWORD(dw);
if (*lpszMsg == '\\') {
lpszMsg++;
len -= 2;
switch (*lpszMsg++) {
case 'l':
case 'L':
x = 0;
break;
case 'r':
case 'R':
x = r.right - LOWORD(dw);
break;
default:
goto center;
}
} else {
center:
x = (r.right - LOWORD(dw)) / 2;
}
ExtTextOut(hdcMem, x, 0, ETO_OPAQUE, &r,
lpszMsg, len, NULL);
}
SetBkColor(hdc, CREDIT_BACKGROUND);
BitBlt(hdc, rScroll.left, rScroll.bottom - 1, r.right, 1,
hdcMem, 0, nScan, SRCCOPY);
if (++nScan >= nMaxScan) {
nScan = 0;
lpszMsg += len + 2;
if (*lpszMsg == 26) lpszMsg = lpszDedicate;
}
DeleteDC(hdcMem);
ReleaseDC(hwnd, hdc);
}
// FUNCTION About_OnCommand
//
// PURPOSE Handles WM_COMMAND messages sent to the window
//
// PARAMETERS hwnd - Window handle
// id - Identifies the menu/control/accelerator
// hwndCtl - Identifies the control sending the command
// codeNotify - Zero if from menu, one if from accelerator
//
// RETURNS Nothing
#pragma argsused
VOID
About_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
if ((id == IDOK) || (id == IDCANCEL)) {
#ifdef ABOUT_IS_MODAL
EndDialog(hwnd, TRUE);
#else
DestroyWindow(hwnd);
#endif
}
}
// FUNCTION About_OnDestroy
//
// PURPOSE Handles WM_DESTROY messages sent to the window
//
// PARAMETERS hwnd - Window handle
// id - Identifies the menu/control/accelerator
// hwndCtl - Identifies the control sending the command
// codeNotify - Zero if from menu, one if from accelerator
//
// RETURNS Nothing
#pragma argsused
VOID
About_OnDestroy(HWND hwnd)
{
hAbout = 0;
Marquee_Destroy();
}
// FUNCTION About_OnInitDialog
//
// PURPOSE Handles WM_... messages sent to the window
//
// PARAMETERS hwnd - Window handle
// hwndFocus - Handle of control to receive focus
// lParam - Initalization data
//
// RETURNS TRUE if Windows should set focus to default,
// FALSE if we issued SetFocus outselves
#pragma argsused
BOOL
About_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
static void FAR *lpData;
static HGLOBAL hg;
char szName[512], *cp;
UINT uLen;
VOID FAR *lpXlate;
VOID FAR *lpBuffer;
if (!lpData) {
//DWORD dwHandle, dwSize;
//GetModuleFileName(hInst, szName, sizeof szName);
//dwSize = GetFileVersionInfoSize(szName, &dwHandle);
//lpData = GlobalAllocPtr(0, dwSize);
//GetFileVersionInfo(szName, dwHandle, dwSize, lpData);
hg = LoadResource(hInst,
FindResource(hInst, (LPCSTR)1L, (LPCSTR)16L) );
lpData = LockResource(hg);
}
VerQueryValue(lpData, "\\VarFileInfo\\Translation", &lpXlate, &uLen);
if (uLen != 0) {
wsprintf(szName, "\\StringFileInfo\\%04x%04x\\",
*(WORD FAR *) lpXlate, *((WORD FAR *) lpXlate + 1));
cp = strchr(szName, 0);
strcpy(cp, "CompanyName");
VerQueryValue(lpData, szName, &lpBuffer, &uLen);
SetDlgItemText(hwnd