📄 main.c
字号:
//----------------------------------------------------------------------------
//
// MAIN.C
//
// Copyright (c) Seiko Epson Corp. 1998, 2001 All rights reserved.
//
//
//----------------------------------------------------------------------------
#include <windows.h>
#include <mmsystem.h>
#include "resource.h"
#include "hal.h"
#include "appcfg.h"
//---------------------------------------------------------------------------
//
// Function declarations
//
//---------------------------------------------------------------------------
static int MsgBox(HWND hwndParent,UINT fuType,LPSTR pszFormat,...);
static BOOL ToggleFF(void);
static BOOL ToggleChrominance(void);
static BOOL ToggleLuminance(void);
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
static BOOL InitApplication(HINSTANCE hInstance);
static BOOL InitInstance(HINSTANCE hInstance,int nCmdShow);
extern AboutDlg(HWND hwnd);
//---------------------------------------------------------------------------
//
// Globals
//
//---------------------------------------------------------------------------
HWND ghwndMain;
HINSTANCE ghInstance;
//---------------------------------------------------------------------------
//
//
//---------------------------------------------------------------------------
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int cmdShow)
{
MSG msg;
ghInstance = hInstance;
if (!InitApplication (hInstance)) // Initialize shared things
return FALSE; // Exits if unable to initialize
// Perform initializations that apply to a specific instance
if (!InitInstance (hInstance, cmdShow))
return FALSE;
while (GetMessage(&msg, NULL, 0, 0))
{
if (!IsWindow(ghwndMain) || !IsDialogMessage(ghwndMain, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
//----------------------------------------------------------------------------
//
// FUNCTION: InitApplication(HINSTANCE)
//
// PURPOSE: Initializes window data and registers window class
//
//----------------------------------------------------------------------------
static BOOL InitApplication(HINSTANCE hInstance)
{
WNDCLASS wc;
// Fill in window class structure with parameters that describe the
// main window.
wc.style = CS_HREDRAW | CS_VREDRAW; // Class style(s).
wc.lpfnWndProc = (WNDPROC)WndProc; // Window Procedure
wc.cbClsExtra = 0; // No per-class extra data.
wc.cbWndExtra = DLGWINDOWEXTRA;
wc.hInstance = hInstance; // Owner of this class
wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Cursor
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); // Default color
wc.lpszMenuName = NULL;
wc.lpszClassName = "FILT"; // Name to register as
// Register the window class and return success/failure code.
return (RegisterClass(&wc));
}
//----------------------------------------------------------------------------
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
//
//----------------------------------------------------------------------------
static BOOL InitInstance(HINSTANCE hInstance,int nCmdShow)
{
switch (seRegisterDevice(&HalInfo))
{
case ERR_OK:
break;
case ERR_UNKNOWN_DEVICE:
MsgBox(HWND_DESKTOP,MB_OK | MB_ICONSTOP,
"ERROR: Did not find a 13506 device.");
return FALSE;
default:
MsgBox(HWND_DESKTOP,MB_OK | MB_ICONSTOP,
"ERROR: Could not register S1D13506 device.");
return FALSE;
}
// Create the main window for this application instance.
ghwndMain = CreateDialog (hInstance, MAKEINTRESOURCE(IDD_DIALOG1),
HWND_DESKTOP, (WNDPROC)WndProc) ;
// If window could not be created, fail the call
if (!ghwndMain)
return FALSE;
// Make the window visible; update its client area
ShowWindow(ghwndMain, nCmdShow); // Show the window
return TRUE;
}
//----------------------------------------------------------------------------
//
// main window message handler
//
//----------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM uParam, LPARAM lParam)
{
unsigned wmId,wmEvent;
unsigned byte,check;
switch (msg)
{
case WM_INITDIALOG: // message: initialize dialog box
case WM_CREATE:
// see what's active.
byte = seReadRegByte(0x1fc);
switch (byte & 0x7)
{
case 0: //no display
case 1: //LCD
case 2: //CRT
case 3: //LCD+CRT
case 4: //TV
case 5: //LCD + TV
CheckDlgButton(hwnd,IDC_FF,BST_UNCHECKED);
break;
case 6: //TV + FF
case 7: //LCD + TV + FF
CheckDlgButton(hwnd,IDC_FF,BST_CHECKED);
break;
}
byte = seReadRegByte(0x5b);
if (byte & 0x10)
CheckDlgButton(hwnd,IDC_LUMINANCE,BST_CHECKED);
if (byte & 0x20)
CheckDlgButton(hwnd,IDC_CHROMINANCE,BST_CHECKED);
return TRUE;
case WM_COMMAND:
wmId = LOWORD(uParam);
wmEvent = HIWORD(uParam);
switch (wmId)
{
case IDC_FF:
if (ToggleFF())
check = BST_CHECKED;
else
check = BST_UNCHECKED;
CheckDlgButton(hwnd,IDC_FF,check);
break;
break;
case IDC_CHROMINANCE:
if (ToggleChrominance())
check = BST_CHECKED;
else
check = BST_UNCHECKED;
CheckDlgButton(hwnd,IDC_CHROMINANCE,check);
break;
case IDC_LUMINANCE:
if (ToggleLuminance())
check = BST_CHECKED;
else
check = BST_UNCHECKED;
CheckDlgButton(hwnd,IDC_LUMINANCE,check);
break;
case IDC_ABOUT:
AboutDlg(hwnd);
break;
default:
return (DefWindowProc(hwnd, msg, uParam, lParam));
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, uParam, lParam);
}
return 0;
}
//----------------------------------------------------------------------------
//
//
//----------------------------------------------------------------------------
static BOOL ToggleChrominance()
{
BYTE reg5b;
reg5b = seReadRegByte(0x5b);
reg5b ^= 0x20;
seWriteRegByte(0x5b,reg5b);
return ((reg5b & 0x20) != 0);
}
//----------------------------------------------------------------------------
//
//
//----------------------------------------------------------------------------
static BOOL ToggleLuminance()
{
BYTE reg5b;
reg5b = seReadRegByte(0x5b);
reg5b ^= 0x10;
seWriteRegByte(0x5b,reg5b);
return ((reg5b & 0x10) != 0);
}
//----------------------------------------------------------------------------
//
//
//----------------------------------------------------------------------------
static BOOL ToggleFF()
{
BOOL retval;
BYTE reg1fc,reg18;
// reg60 = seReadRegByte(0x60);
// seWriteRegByte(0x60,(reg60 | 0x80)); // kill the display
reg1fc = seReadRegByte(0x1fc);
switch (reg1fc & 0x7)
{
case 0x4: //TV FF OFF
case 0x5: //TV + LCD FF OFF
case 0x6: //TV FF ON
case 0x7: //TV + LCD FF ON
reg1fc ^= 2;
seWriteRegByte(0x1fc,reg1fc);
reg18 = seReadRegByte(0x18);
if (reg1fc & 0x2)
{
reg18 |= 0x80; // set PCLK*2 bit
retval = TRUE;
}
else
{
reg18 &= ~0x80; // clear PCLK*2 bit
retval = FALSE;
}
seWriteRegByte(0x18,reg18);
break;
default:
retval = FALSE;
}
// seWriteRegByte(0x60,reg60);
return retval;
}
//----------------------------------------------------------------------------
//
// FUNCTION: MsgBox
//
// PURPOSE: A printf-like interface to MessageBox.
//
// ENTRY: hwndParent - The "owning" parent window.
// fuType - A set of MB_* flags.
// pszFormat - A printf-like format string.
// ... - Other printf-like arguments as needed.
//
// RETURNS: INT - The result of the MessageBox API.
//
//----------------------------------------------------------------------------
#define MAX_PRINTF_OUTPUT 1024
static int MsgBox(HWND hwndParent,UINT fuType,LPSTR pszFormat,...)
{
char szOutput[MAX_PRINTF_OUTPUT];
va_list ArgList;
va_start (ArgList, pszFormat);
wvsprintf (szOutput, pszFormat, ArgList);
va_end (ArgList);
return MessageBox (hwndParent, szOutput, "13506GRAB", fuType);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -