📄 simmain.c
字号:
////////////////////////////////////////////////////////////////////////////////
// File Name : SimMain.c
// Create Date : 2001-5-10 pm 04:32:05
// Written by : CYu
// Decription : a screen simulator for basic graphic33. it may not possible to
// support other application and low level development
//------------------------------------------------------------------------------
// Copyright: EPSON Proprietary Material
// Copyright (c) 2001, All Rights Reserved
// SHANGHAI EPSON ELECTRONICS CO., LTD.
//
// DISTRIBUTION PROHIBITED without written authorization from EPSON
//------------------------------------------------------------------------------
// Modification History
//
// 2001/10/31 by longn_qi revise.
//
////////////////////////////////////////////////////////////////////////////////
/* System and Standard Header */
#include <windows.h>
#include <io.h>
#include <fcntl.h>
/* Application Header */
#include <sys\pen.h>
#include <sys\key.h>
#include <sys\keydef.h>
#include <srvstruct.h>
#include <resource.h>
/* Local Macro definition */
#define WM_REFRESH (WM_USER +1)
#define WM_POWEROFF (WM_USER +2)
#define MAX_DEBUGLOGLINE 256
#define SS_SRVSTARTED 1
#define SS_SRVOFF 0
/* Local Constant Definition */
const static char PanelClassName[] = "MyClass";
const static char ScreenClassName[] = "SimScrnCls";
const static char AppName[] = "PDA Cellular Simulator";
/* Static Variable */
static BOOL isDebugDlgClosed;
static BITMAPINFOHEADER bihPanel;
static void *pdataPanel;
static HWND hwndDebugDlg = 0;
/* External Variable Definition */
HINSTANCE hinstServer = 0;
// Shared
#pragma data_seg( "Shared" )
short serverStatus = SS_SRVOFF;
HWND hwndPanel = 0;
HWND hwndScreen = 0;
HWND hwndClient = 0;
char tcaDebugLog[82] = "Welcome";
PENDATA pen = { PENUP, 0, 0 };
KEYDATA key = { KEYUP, 0 };
#pragma data_seg( )
static HCURSOR hmove, hkey, hpen;
static HBITMAP skin, oldskin;
static BITMAP bitmap;
static HMENU hrpmenu;
/* External Variable Declaration */
extern KEYPOS kpa[256];
extern int screenWidth;
extern int screenHeight;
extern int screenPosX;
extern int screenPosY;
extern char tcaPanelFileName[256];
extern int nKeyNumber;
/* External Function Declaration */
extern BOOL GetConfigurationFromFile( void );
/* Local Function Declaration */
static BOOL InitialClass( void );
static BOOL InitialApplication( int nCmdShow );
static LRESULT CALLBACK PanelWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
static LRESULT CALLBACK ScreenWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
static BOOL CALLBACK DebugDlgProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
static BOOL CALLBACK AboutDlgProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
static void AddDebugLog( void );
static void FillKeyIntr( UINT uMsg, WPARAM wParam, LPARAM lParam );
static BOOL FillMouseSimKey( UINT uMsg, WPARAM wParam, LPARAM lParam );
static void FillPenIntr( UINT uMsg, WPARAM wParam, LPARAM lParam );
static BOOL LoadPanelBitmap( void );
static BOOL ConfigResource( HINSTANCE hInst );
/* Function Definition */
////////////////////////////////////////////////////////////////////////////////
// Function name : WinMain
// Description : Main Function
// Return type : int
// Argument : HINSTANCE hInst
// Argument : HINSTANCE hPrevInst
// Argument : LPSTR lpszCmdLine
// Argument : int nCmdShow
// Remarks :
// So also :
////////////////////////////////////////////////////////////////////////////////
int WINAPI WinMain( HINSTANCE hInst,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow )
{
MSG msg;
hinstServer = hInst;
if( !ConfigResource( hInst ) )
return FALSE;
if( !InitialClass( ) )
return FALSE;
else if( !InitialApplication( nCmdShow ) )
return FALSE;
serverStatus = SS_SRVSTARTED;
PostMessage( hwndPanel, WM_USER, 0, 0 );
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
LocalFree( pdataPanel );
DeleteObject( skin );
// DestroyWindow( hwndDebugDlg );
serverStatus = SS_SRVOFF;
return 0;
}
BOOL ConfigResource( HINSTANCE hInst )
{
hmove = LoadCursor( hInst, (LPCTSTR)IDC_MOVE );
hkey = LoadCursor( hInst, (LPCTSTR)IDC_KEY );
hpen = LoadCursor( hInst, (LPCTSTR)IDC_PEN );
hrpmenu = LoadMenu( hInst, (LPCSTR)IDR_RPMENU );
if( !GetConfigurationFromFile( ) )
return FALSE;
skin = LoadImage( hInst, tcaPanelFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT );
return TRUE;
}
////////////////////////////////////////////////////////////////////////////////
// Function name : InitialClass
// Description : Initial window class
// Return type : BOOL
// No argument
// Remarks :
// So also :
////////////////////////////////////////////////////////////////////////////////
BOOL InitialClass( void )
{
WNDCLASS wcPanel, wcScreen;
wcPanel.lpszClassName = PanelClassName;
wcPanel.hInstance = hinstServer;
wcPanel.lpfnWndProc = PanelWndProc;
wcPanel.hCursor = hmove;//LoadCursor( hinstServer, (LPCTSTR)IDC_MOVE );
wcPanel.hIcon = LoadIcon( hinstServer, (LPCTSTR)IDI_APPLICATION );
wcPanel.lpszMenuName = NULL;
wcPanel.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcPanel.style = CS_HREDRAW | CS_VREDRAW;
wcPanel.cbClsExtra = 0;
wcPanel.cbWndExtra = 0;
wcScreen.lpszClassName = ScreenClassName;
wcScreen.hInstance = hinstServer;
wcScreen.lpfnWndProc = ScreenWndProc;
wcScreen.hCursor = hpen;//LoadCursor( hinstServer, (LPCTSTR)IDC_PEN );
wcScreen.hIcon = LoadIcon( hinstServer, (LPCTSTR)IDI_APPLICATION );
wcScreen.lpszMenuName = NULL;
wcScreen.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcScreen.style = CS_HREDRAW | CS_VREDRAW;
wcScreen.cbClsExtra = 0;
wcScreen.cbWndExtra = 0;
if( !RegisterClass( &wcPanel ) || !RegisterClass( &wcScreen ) )
return FALSE;
else
return TRUE;
}
////////////////////////////////////////////////////////////////////////////////
// Function name : InitialApplication
// Description :
// Return type : BOOL
// Argument : int nCmdShow
// Remarks :
// So also :
////////////////////////////////////////////////////////////////////////////////
BOOL InitialApplication( int nCmdShow )
{
RECT rect;
// HBITMAP newBMP, oldBMP;
// BITMAP bitmap;
// GetConfigurationFromFile( );
isDebugDlgClosed = FALSE;
hwndDebugDlg = CreateDialog(
NULL, // should be dll module handle
MAKEINTRESOURCE(IDD_DbgLog),
NULL,//hwndPanel,
DebugDlgProc );
// if( !LoadPanelBitmap( ) )
// return FALSE;
// newBMP = LoadImage( hinstServer, tcaPanelFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT );
GetObject( skin, sizeof(BITMAP), &bitmap );
SetRect( &rect, 0, 0, bitmap.bmWidth, bitmap.bmHeight );
// DeleteObject( newBMP );
// SetRect( &rect, 0, 0, bihPanel.biWidth, bihPanel.biHeight );
AdjustWindowRectEx(
&rect,
WS_POPUP,
//WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
FALSE,
0 );
OffsetRect( &rect, -rect.left, -rect.top );
hwndPanel = CreateWindowEx(
0,//WS_EX_CLIENTEDGE,
PanelClassName,
AppName,
WS_POPUP,
//WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX ,
CW_USEDEFAULT,
CW_USEDEFAULT,
rect.right,
rect.bottom,
NULL,
NULL,//LoadMenu( hinstServer, MAKEINTRESOURCE( IDR_MainMenu ) ),
hinstServer,
NULL );
hwndScreen = CreateWindowEx(
WS_EX_CLIENTEDGE,
ScreenClassName,
AppName,
WS_CHILD | WS_VISIBLE,
screenPosX,
screenPosY,
screenWidth+4,
screenHeight+4,
hwndPanel,
NULL,//LoadMenu( hinstServer, MAKEINTRESOURCE( IDR_MainMenu ) ),
hinstServer,
NULL );
{
HDC hdc, memDC;
HRGN wndRGN;
COLORREF col, trcolor;
BYTE r, g, b, rt, gt, bt, rdif, gdif, bdif;
int x, y, result;
hdc = GetDC( hwndPanel );
memDC = CreateCompatibleDC( hdc );
oldskin = SelectObject( memDC, skin );
wndRGN = CreateRectRgn( 0, 0, bitmap.bmWidth, bitmap.bmHeight );
trcolor = GetPixel( memDC, 0, 0 );
rt = GetRValue(trcolor);
gt = GetGValue(trcolor);
bt = GetBValue(trcolor);
for( x = 0; x < bitmap.bmWidth; x++ )
{
for( y = 0; y < bitmap.bmHeight; y++ )
{
col = GetPixel( memDC, x, y );
r = GetRValue(col);
g = GetGValue(col);
b = GetBValue(col);
//if( col == RGB(255,255,255) )
rdif = r > rt ? r - rt: rt - r;
gdif = g > gt ? g - gt: gt - g;
bdif = b > bt ? b - bt: bt - b;
if( rdif < 10 && gdif < 10 && bdif < 10 )
{
HRGN tempRGN;
tempRGN = CreateRectRgn(x, y, x+1, y+1);
result = CombineRgn( wndRGN, wndRGN, tempRGN, RGN_XOR);
DeleteObject( tempRGN );
}
}
}
if( oldskin )
SelectObject( memDC, oldskin );
SetWindowRgn( hwndPanel, wndRGN, TRUE );
DeleteObject( wndRGN );
ReleaseDC( hwndPanel, hdc );
DeleteDC( memDC );
}
ShowWindow( hwndPanel, nCmdShow );
UpdateWindow( hwndPanel );
return TRUE;
}
////////////////////////////////////////////////////////////////////////////////
// Function name : PanelWndProc
// Description :
// Return type : LRESULT CALLBACK
// Argument : HWND hwnd
// Argument : UINT uMsg
// Argument : WPARAM wParam
// Argument : LPARAM lParam
// Remarks :
// So also :
////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK PanelWndProc( HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam )
{
// char *info = "";//"DEBUG V1.7 B4";
WPARAM newKey;
switch( uMsg )
{
case WM_MOVE:
break;
case WM_CREATE:
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc;
HDC memDC;
hdc = BeginPaint( hwnd, (LPPAINTSTRUCT)&ps );
memDC = CreateCompatibleDC( hdc );
oldskin = SelectObject( memDC, skin );
BitBlt( hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, memDC, 0, 0, SRCCOPY );
if( oldskin )
SelectObject( memDC, oldskin );
EndPaint( hwnd, (LPPAINTSTRUCT)&ps );
ReleaseDC( hwnd, hdc );
DeleteDC( memDC );
}
break;
case WM_CLOSE:
SendMessage( hwndScreen, WM_CLOSE, 0, 0 );
if( !isDebugDlgClosed )
{
//EndDialog( hwndDebugDlg, 0 );
PostMessage( hwndDebugDlg, WM_CLOSE, 0, 0 );
}
DestroyWindow( hwnd );
hwndPanel = 0;
if( hwndClient )
SendMessage( hwndClient, WM_CLOSE, 0, 0 );
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
case WM_USER:
AddDebugLog( );
break;
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MOUSEMOVE:
PostMessage( hwndScreen, WM_MOUSEMOVE, 0, 0 );
if( !FillMouseSimKey( uMsg, wParam, lParam ) )
{
SetCursor( hmove );
ShowCursor( TRUE );
if( uMsg == WM_LBUTTONDOWN )
SendMessage( hwnd, WM_NCLBUTTONDOWN, HTCAPTION, wParam );
else if( uMsg == WM_LBUTTONUP )
SendMessage( hwnd, WM_NCLBUTTONUP, HTCAPTION, wParam );
}
else
{
SetCursor( hkey );
ShowCursor( TRUE );
}
break;
case WM_RBUTTONDOWN:
{
HMENU hmenu;
POINT point;
hmenu = GetSubMenu( hrpmenu, 0 );
GetCursorPos( &point );
switch( TrackPopupMenu( hmenu, TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_RETURNCMD, point.x, point.y, 0, hwnd,NULL) )
{
case ID_RPMENU_CLOSE:
PostMessage( hwnd, WM_CLOSE, 0, 0 );
break;
case ID_RPMENU_ABOUT:
{
HWND dlg;
dlg = CreateDialog( hinstServer,
MAKEINTRESOURCE( IDD_DIALOG_ABOUT ),
hwnd,
AboutDlgProc );
ShowWindow( dlg, SW_SHOW );
}
break;
default:
break;
}
}
break;
case WM_KEYDOWN:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -