WIP: PrintScreen saving AppleWin_ScreenShot_#.bmp

This commit is contained in:
mpohoreski 2008-07-14 16:02:44 +00:00
parent 88c866cfa8
commit b5782b7e4f
4 changed files with 171 additions and 8 deletions

View File

@ -544,6 +544,22 @@ void RegisterExtensions ()
REG_SZ,"system",7);
}
//===========================================================================
void ApppleWin_RegisterHotKeys()
{
bool bStatus = RegisterHotKey(
g_hFrameWindow , // HWND hWnd
VK_SNAPSHOT , // int id (user/custom id)
0 , // UINT fsModifiers
VK_SNAPSHOT // UINT vk
);
if (! bStatus)
{
MessageBox( g_hFrameWindow, "Unable to capture PrintScreen key", "Warning", MB_OK );
}
}
//===========================================================================
LPSTR GetCurrArg(LPSTR lpCmdLine)
@ -756,6 +772,8 @@ int APIENTRY WinMain (HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int)
MemInitialize();
VideoInitialize();
FrameCreateWindow();
ApppleWin_RegisterHotKeys(); // needs valid g_hFrameWindow
// Need to test if it's safe to call ResetMachineState(). In the meantime, just call DiskReset():
DiskReset(); // Switch from a booting A][+ to a non-autostart A][, so need to turn off floppy motor

View File

@ -81,7 +81,7 @@ static RECT framerect = {0,0,0,0};
HWND g_hFrameWindow = (HWND)0;
BOOL fullscreen = 0;
static BOOL helpquit = 0;
static BOOL painting = 0;
static BOOL g_bPaintingWindow = 0;
static HFONT smallfont = (HFONT)0;
static HWND tooltipwindow = (HWND)0;
static BOOL g_bUsingCursor = 0; // 1=AppleWin is using (hiding) the mouse-cursor
@ -374,7 +374,7 @@ static void DrawCrosshairs (int x, int y) {
static void DrawFrameWindow () {
FrameReleaseDC();
PAINTSTRUCT ps;
HDC dc = (painting ? BeginPaint(g_hFrameWindow,&ps)
HDC dc = (g_bPaintingWindow ? BeginPaint(g_hFrameWindow,&ps)
: GetDC(g_hFrameWindow));
VideoRealizePalette(dc);
@ -405,7 +405,7 @@ static void DrawFrameWindow () {
// DRAW THE STATUS AREA
DrawStatusArea(dc,DRAW_BACKGROUND | DRAW_LEDS);
if (painting)
if (g_bPaintingWindow)
EndPaint(g_hFrameWindow,&ps);
else
ReleaseDC(g_hFrameWindow,dc);
@ -689,6 +689,22 @@ LRESULT CALLBACK FrameWndProc (
break;
}
// @see: http://answers.google.com/answers/threadview?id=133059
// Win32 doesn't pass the PrintScreen key via WM_CHAR
// else if (wparam == VK_SNAPSHOT)
// Solution: 2 choices:
// 1) register hotkey, or
// 2) Use low level Keyboard hooks
// We use the 1st one since it is compatible with Win95
case WM_HOTKEY:
// wparam = user id
// lparam = modifiers: shift, ctrl, alt, win
if (wparam == VK_SNAPSHOT)
{
Video_TakeScreenShot();
}
break;
case WM_KEYDOWN:
KeybUpdateCtrlShiftStatus();
if ((wparam >= VK_F1) && (wparam <= VK_F8) && (buttondown == -1))
@ -1015,9 +1031,9 @@ LRESULT CALLBACK FrameWndProc (
case WM_PAINT:
if (GetUpdateRect(window,NULL,0)) {
painting = 1;
g_bPaintingWindow = 1;
DrawFrameWindow();
painting = 0;
g_bPaintingWindow = 0;
}
break;
@ -1552,7 +1568,7 @@ HDC FrameGetDC () {
//===========================================================================
HDC FrameGetVideoDC (LPBYTE *addr, LONG *pitch)
{
if (fullscreen && g_bAppActive && !painting)
if (fullscreen && g_bAppActive && !g_bPaintingWindow)
{
RECT rect = { FSVIEWPORTX,
FSVIEWPORTY,
@ -1612,7 +1628,7 @@ void FrameReleaseDC () {
//===========================================================================
void FrameReleaseVideoDC () {
if (fullscreen && g_bAppActive && !painting) {
if (fullscreen && g_bAppActive && !g_bPaintingWindow) {
// THIS IS CORRECT ACCORDING TO THE DIRECTDRAW DOCS
RECT rect = {FSVIEWPORTX,

View File

@ -245,7 +245,7 @@ static bool bVideoScannerNTSC = true; // NTSC video scanning (or PAL)
const UINT nVBlStop_NTSC = 21;
const UINT nVBlStop_PAL = 29;
//-------------------------------------
// Prototypes (Private) _____________________________________________
void DrawDHiResSource ();
void DrawHiResSource ();
@ -258,6 +258,12 @@ void DrawMonoLoResSource ();
void DrawMonoTextSource (HDC dc);
void DrawTextSource (HDC dc);
void Util_MakeScreenShotFileName( char *pFinalFileName_ );
bool Util_TestScreenShotFileName( const char *pFileName );
void Video_TakeScreenShot();
void Video_SaveScreenShot( const char *pScreenShotFileName );
void Video_MakeScreenShot();
//===========================================================================
void __stdcall CopySource (int destx, int desty,
int xsize, int ysize,
@ -2315,4 +2321,125 @@ bool VideoGetVbl(const DWORD uExecutedCycles)
}
}
// alias for nSuffixScreenShotFileName
static int nLastScreenShot = 0;
const int nMaxScreenShot = 999999999;
//const int nMaxScreenShot = 2;
//===========================================================================
void Util_MakeScreenShotFileName( char *pFinalFileName_ )
{
const char sPrefixScreenShotFileName[] = "AppleWin_ScreenShot_";
sprintf( pFinalFileName_, "%s%09d.bmp", sPrefixScreenShotFileName, nLastScreenShot );
}
//===========================================================================
bool Util_TestScreenShotFileName( const char *pFileName )
{
bool bFileExists = false;
FILE *pFile = fopen( pFileName, "rt" );
if (pFile)
{
fclose( pFile );
bFileExists = true;
}
return bFileExists;
}
//===========================================================================
void Video_TakeScreenShot()
{
char sScreenShotFileName[ MAX_PATH ];
// find last screenshot filename so we don't overwrite the existing user ones
bool bExists = true;
while( bExists )
{
if (nLastScreenShot > nMaxScreenShot) // Holy Crap! User has maxed the number of screenshots!?
{
sprintf( sScreenShotFileName, "You have more then %d screenshot filenames! They will no longer be saved.\n\nEither move some of your screenshots or increase the maximum in video.cpp\n", nMaxScreenShot );
MessageBox( NULL, sScreenShotFileName, "Warning", MB_OK );
nLastScreenShot = 0;
return;
}
Util_MakeScreenShotFileName( sScreenShotFileName );
bExists = Util_TestScreenShotFileName( sScreenShotFileName );
if( !bExists )
{
break;
}
nLastScreenShot++;
}
Video_SaveScreenShot( sScreenShotFileName );
nLastScreenShot++;
}
typedef short int16;
typedef int int32;
struct WinBmpHeader_t
{
char nCookie[2] ; // BM
int32 nSizeFile ; // 0 = ignre
int16 nReserved1 ;
int16 nReserved2 ;
int32 nOffsetData ;
int32 nStructSize ;
int32 nWidthPixels ;
int32 nHeightPixels ;
int16 nPlanes ;
int16 nBitsPerPixel ;
int32 nCompression ; // 0 = BI_RGB
int32 nSizeImage ; // 0 = ignore
int32 nXPelsPerMeter ;
int32 nYPelsPerMeter ;
int32 nPaletteColors ;
int32 nImportantColors;
};
WinBmpHeader_t g_tBmpHeader;
//===========================================================================
void Video_MakeScreenShot()
{
// get BMP
g_tBmpHeader.nCookie[ 0 ] = 'B';
g_tBmpHeader.nCookie[ 0 ] = 'M';
g_tBmpHeader.nReserved1 = 0;
g_tBmpHeader.nReserved2 = 0;
g_tBmpHeader.nOffsetData = sizeof( WinBmpHeader_t );
g_tBmpHeader.nStructSize = sizeof( WinBmpHeader_t );
g_tBmpHeader.nWidthPixels = 560;
g_tBmpHeader.nHeightPixels = 192;
g_tBmpHeader.nPlanes = 1;
g_tBmpHeader.nBitsPerPixel = 24;
g_tBmpHeader.nCompression = BI_RGB;
g_tBmpHeader.nSizeImage = 0;
g_tBmpHeader.nXPelsPerMeter = 0;
g_tBmpHeader.nYPelsPerMeter = 0;
g_tBmpHeader.nPaletteColors = 0;
g_tBmpHeader.nImportantColors = 0;
}
//===========================================================================
void Video_SaveScreenShot( const char *pScreenShotFileName )
{
Video_MakeScreenShot();
FILE *pFile = fopen( pScreenShotFileName, "wb" );
if( pFile )
{
// Write Header
// Write Data
fwrite( &g_tBmpHeader, sizeof( g_tBmpHeader ), 1, pFile );
fclose( pFile );
}
MessageBox( NULL, pScreenShotFileName, "Screen Captured", MB_OK );
}

View File

@ -71,6 +71,8 @@ bool VideoGetSW80COL();
DWORD VideoGetSnapshot(SS_IO_Video* pSS);
DWORD VideoSetSnapshot(SS_IO_Video* pSS);
void Video_TakeScreenShot();
BYTE __stdcall VideoCheckMode (WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft);
BYTE __stdcall VideoCheckVbl (WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft);
BYTE __stdcall VideoSetMode (WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft);