?? emwin.c
字號:
// Date : 2005-05-28
//
// Author : HOUHH
//
// File : emWin.c,the main file for the emWin Simulation...
//
// Version : ver1.0.0
#include "stdafx.h"
#include "resource.h"
#include "Branding.h"
#include "Common.h"
typedef struct tagkeystruc{
RECT keyarea;
int keystate;
SIM_HARDKEY_CB* keyrpoc;
int keymode;
}KeyStruc, lpKeyStruc;
typedef struct tagkeydata{
int VirCode; //鍵盤虛擬碼
int key; //對應在UCGUI當中的鍵值...
}KeyData, lpKey;
typedef struct tagLCD{
HWND lcd_hwnd;
int TimerID;
}LCDScreen;
#define DELAYEVERYTIME 10 //每次延時的時間(sleep())...
#define MAX_LOADSTRING 100
#define TOTAL_TASK 4 //支持多任務時的多任務數...
#define MAXKEY 80 //按鍵的個數...
#define MAXLCDNUM 16 //最大可打開LCD的個數...
#define VKEYNUM 11 //常用功能鍵數目,如VK_SHIFT等...
#define MAXLOGLEN 1024*12 //常用功能鍵數目,如VK_SHIFT等...
//以下為用到到部分全局變量...
int LCDWidth = 0, LCDHeight = 0;
int LCDWidth2 = 0, LCDHeight2 = 0;
int wndWidth = 400, wndHeight = 300;
int LOG_y0 = 0; //LOG顯示窗口縱坐標...
int xPosLCD = -1, yPosLCD = -1, Mag = 1;
int MessageBoxOnError = 1;
int LOG_xsize = 0x1F4, LOG_ysize = 0x3C;
DWORD timeStartup = 0;
char LCDCaption[200];
char LCDCaption2[200];
enum SimStausEnum {terminated=0, started, suspended, paused, notrunning, continued, notstopped};
char* SimStatusString[] = {"Application suspended",
"Application started",
"Application terminated.",
"Application paused already...",
"Application is not running...",
"Application continued",
"Application is not stopped..."};
enum SimClassNameEnum {SimulationMainframe=0, LCDInfo, LCD, LCD1, emWinDevice, emWinHardkey, Log};
char* SimClassName[] = {"emWin Simulation Mainframe",
"emWin LCD Info",
"emWin LCD",
"emWin LCD1",
"emWinDevice",
"emWinHardkey",
"Log"};
char* SimStatus[] = {"(Suspended)", "(Executing)", "(Terminated)"};
char SimErrorFile[] = {"SimError.log"};
HANDLE hLogo = 0, ahBmpDevice = 0, ahBmpDevice2 = 0;
HMENU hMenuPopup = 0; //右鍵單出控制開啟與暫停菜單...
HWND hWndMain = 0, hWndLCD1 = 0, LOG_hWnd = 0;
//motion log
HWND hWnd_MotionLog = 0;
//main task log
HWND hWnd_MainTaskLog = 0;
//Motion Data Disp
HWND HWnd_MotionDisp = 0;
DWORD rgbTransparent = 0;
//HWND LCD_aWinData
int CmdKill = 0;
HANDLE ghThread = 0;
int SuspendCount = 0;
int NumTask = 0;
HANDLE ahThread[TOTAL_TASK];
DWORD aThreadID[TOTAL_TASK];
int KeyBuffer = 0;
HANDLE SimFileMap = 0;
char LOG_acBuffer[MAXLOGLEN];
//Motion Log Buffer 緩沖
char MotionLog_Buffer[MAXLOGLEN];
char MainTaskLog_Buffer[MAXLOGLEN];
KeyStruc aHardkey[MAXKEY];
int NumHardkeys = 0;
LCDScreen LCD_aWinData[MAXLCDNUM];
KeyData aVKey2Key[] = {{VK_UP, GUI_KEY_UP}, {VK_DOWN, GUI_KEY_DOWN},{VK_LEFT, GUI_KEY_LEFT}, \
{VK_RIGHT, GUI_KEY_RIGHT}, {VK_HOME, GUI_KEY_HOME}, {VK_END, GUI_KEY_END}, {VK_SHIFT, GUI_KEY_SHIFT},\
{VK_CONTROL, GUI_KEY_CONTROL},{VK_BACK, GUI_KEY_BACKSPACE},{VK_INSERT, GUI_KEY_INSERT},{VK_DELETE, GUI_KEY_DELETE}};
//VK_SHIFT
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
ATOM RegisterClasses(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProcMain(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProcLCD(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void MainWnd_Command(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
//void MainWnd_Paint(HWND hwnd);
void MainWnd_Paint(HWND hwnd, HDC hdc);
void MainWnd_OnTimer(HWND hWnd);
void CreateWndLCD();
int FindFreeLCDIndex();
void InitMenu(HMENU hMenu);
void HandleKeyEvents(UINT message, WPARAM wParam);
//void LOG_AddPlain(const char* log);
void LOG_AddPlain(const char* log,char * LogBuffer, HWND DispHWin);
void LogTime();
void LOG_Add(const char* log);
void LOG_DelFirstLine(LOG_acBuffer);
void UpDataHALDisp(void);
// 2005-5-31 23:23:02
int SIM_GetTime();
int SIM_SetMag(int simmag);
void SIM_Delay(int delaytime);
void SIM_ExecIdle();
void THREAD_Sleep(int delaytime);
void THREAD_KillAll();
void THREAD_StartApplication();
void THREAD_ContinueApplication();
void THREAD_StopApplication();
void Thread();
void CreateTask(void * pFunc);
//初始化之前并做清除...
int APIENTRY WinMain_NoClean(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
int ret = 0, i = 0;
// char curPath[255];
//SIM初始化...
SIM_X_Init();
//初始化漢字庫2005-6-12 23:53:15
/* 2005-06-17 9:07:46
GetCurrentDirectory(255, curPath);
for(i = strlen(curPath); i > 0; i--){
if(curPath[i] == '\\'){
curPath[i+1] = 0;
break;
}
}
strcat(curPath, "GUI\\GUISource\\Chinese\\hzk16");
OpenHZ(curPath);*/
/*
i = OpenHZ("..\\..\\GUI\\GUISource\\Chinese\\hzk16");
if(i == -1){
do{
i = OpenHZ(curPath);
if(i != -1) break;
sprintf(curPath, "%s\n加載漢字庫hzk16出錯!", curPath);;
MessageBox(0, curPath, "error", 0);
}while(0);
}
*/
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_EMWIN, szWindowClass, MAX_LOADSTRING);
ret = WinMain_NoClean(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
if(hLogo != 0) DeleteObject(hLogo); //加載所有用的位圖與圖標...o
if(ahBmpDevice != 0) DeleteObject(ahBmpDevice);
if(ahBmpDevice2 != 0) DeleteObject(ahBmpDevice2);
if(SimFileMap != 0) CloseHandle(SimFileMap);
// if(i != -1) CloseHZ();
return ret;
}
///////////////////////////////////////////////////////////////////////
//
// 函數名 : FUNCTION: MyRegisterClass
// 功能描述 :
// 返回值 : ATOM
//
//
///////////////////////////////////////////////////////////////////////
ATOM RegisterClasses(HINSTANCE hInstance)
{
ATOM ret = 1;
WNDCLASSEX wcex;
//模擬器主窗口類...
//IDC_ARROW=7f00;BLACK_BRUSH
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProcMain;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_ICON1);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
wcex.lpszMenuName = (LPCSTR)IDC_EMWIN;
wcex.lpszClassName = SimClassName[SimulationMainframe];
// wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_ICON1);
wcex.hIconSm = 0;
ret = ret | RegisterClassEx(&wcex);
//模擬器硬件設備模擬窗口類...
wcex.style = 0;
wcex.lpfnWndProc = (WNDPROC)WndProcMain;
wcex.lpszMenuName = (LPCSTR)0;
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcex.lpszClassName = SimClassName[emWinDevice];
ret = ret | RegisterClassEx(&wcex);
//模擬器硬件按鍵模擬窗口類...
wcex.style = 0;
wcex.lpfnWndProc = (WNDPROC)WndProcMain;
wcex.lpszMenuName = (LPCSTR)0;
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcex.lpszClassName = SimClassName[emWinHardkey];
ret = ret | RegisterClassEx(&wcex);
//模擬器顯示屏模擬窗口類(LCD)...
wcex.style = 0;
wcex.lpfnWndProc = (WNDPROC)WndProcLCD;
wcex.lpszMenuName = (LPCSTR)0;
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
ret = LCD;
wcex.lpszClassName = SimClassName[LCD];
ret = ret | RegisterClassEx(&wcex);
//模擬器調色板信息顯示窗口類(LCD Info)...
wcex.style = 0;
wcex.lpfnWndProc = (WNDPROC)WndProcMain;
wcex.lpszMenuName = (LPCSTR)0;
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcex.lpszClassName = SimClassName[LCDInfo];
ret = ret | RegisterClassEx(&wcex);
//模擬器LOG信息顯示窗口類(LOG)...
wcex.style = 0;
wcex.lpfnWndProc = (WNDPROC)WndProcMain;
wcex.lpszMenuName = (LPCSTR)0;
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcex.lpszClassName = SimClassName[Log];
ret = ret | RegisterClassEx(&wcex);
return ret;
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(SimClassName[SimulationMainframe], szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
void InitMenu(HMENU hMenu)
{
if(ghThread != 0)
{
EnableMenuItem(hMenu, IDM_NEWLCD, MF_ENABLED);
if(SuspendCount != 0){
EnableMenuItem(hMenu, IDM_PAUSEAPP, MF_DISABLED | MF_GRAYED);
EnableMenuItem(hMenu, IDM_RESUMEAPP, MF_ENABLED);
}else{
EnableMenuItem(hMenu, IDM_PAUSEAPP, MF_ENABLED);
EnableMenuItem(hMenu, IDM_RESUMEAPP, MF_DISABLED | MF_GRAYED);
}
}else{
EnableMenuItem(hMenu, IDM_RESUMEAPP, MF_DISABLED | MF_GRAYED);
EnableMenuItem(hMenu, IDM_PAUSEAPP, MF_DISABLED | MF_GRAYED);
// EnableMenuItem(hMenu, IDM_NEWLCD, MF_DISABLED | MF_GRAYED);
}
}
LRESULT CALLBACK WndProcMain(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
RECT rt;
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message)
{
case WM_CREATE:
SetTimer(hWnd, 0, 20, 0);
break;
case WM_TIMER:
// MainWnd_OnTimer(hWnd);
break;
case WM_INITMENU:
InitMenu((HMENU)wParam);
break;
case WM_KEYDOWN:
case WM_KEYUP:
HandleKeyEvents(message, wParam);
break;
case WM_COMMAND:
MainWnd_Command(hWnd, message, wParam, lParam);
break;
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
case IDM_NEWLCD:
CreateWndLCD();
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
GetClientRect(hWnd, &rt);
rt.top+= 70;
rt.bottom+= 100;
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
MainWnd_Paint(hWnd, hdc);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
KillTimer(hWnd, 0);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
///////////////////////////////////////////////////////////////////////
//
// 函數名 : WndProcLCD
// 功能描述 : LCD模擬屏幕消息處理函數, 重要一點是處理重畫, 以及關于窗口
// : 畫面的更新,即隔多少秒要重畫一次, 另外還有MOUSE消息處理...
// 參數 : HWND hWnd
// 參數 : UINT message
// 參數 : WPARAM wParam
// 參數 : LPARAM lParam
// 返回值 : LRESULT CALLBACK
//
///////////////////////////////////////////////////////////////////////
extern void timerfunc(void);
LRESULT CALLBACK WndProcLCD(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int xPos = -1, yPos = -1;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
RECT rt;
POINT TrackMenuPoint = {0,0};
int i = 0;
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message)
{
case WM_CREATE:
SetTimer(hWnd, FindFreeLCDIndex(), 20, 0);
break;
case WM_TIMER:
timerfunc();//利用刷新LCD顯示的定時器來完成PIC GUI的計時
if(wParam <= 16){
do{
if(LCD_aWinData[wParam].TimerID == LCDSIM_GetModifyCnt()) break;
InvalidateRect(hWnd, 0, 0);
LCD_aWinData[wParam].TimerID = LCDSIM_GetModifyCnt();
break;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -