📄 winmain.c
字号:
if (strcmp(acTitle, acTitleNew)) {
strcpy(acTitle, acTitleNew);
SetWindowText(hWnd, acTitle);
}
}
/*********************************************************************
*
* _MainWnd_Paint
*/
static void _MainWnd_Paint(HWND hWnd) {
PAINTSTRUCT ps;
HDC hdc, hdcImage;
hdc = BeginPaint(hWnd, &ps); {
RECT r;
GetClientRect(hWnd, &r);
hdcImage = CreateCompatibleDC(hdc); {
int x0, y0;
HBITMAP hBitmap = LoadBitmap(_hInst, (LPCTSTR) IDB_LOGO);
BITMAP Bitmap;
GetObject(hBitmap, sizeof(Bitmap), &Bitmap);
DeleteObject(hBitmap);
x0 = (r.right - r.left-Bitmap.bmWidth) / 2;
y0 = (r.bottom - r.top-Bitmap.bmHeight) / 2;
SelectObject(hdcImage, _hLogo);
BitBlt(hdc, x0, y0, Bitmap.bmWidth, Bitmap.bmHeight, hdcImage, 0, 0, SRCCOPY);
} DeleteDC(hdcImage);
} EndPaint(hWnd, &ps);
}
/*********************************************************************
*
* _WndProcMain
*/
static LRESULT CALLBACK _WndProcMain(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
int r =0;
_HandleKeyEvents(message, wParam);
switch (message) {
case WM_COMMAND:
r = _MainWnd_Command(hWnd, message, wParam, lParam);
break;
case WM_PAINT: _MainWnd_Paint(hWnd); break;
case WM_TIMER: _MainWnd_OnTimer(hWnd); break;
case WM_CREATE:
SetTimer (hWnd, 0, 20, NULL);
break;
case WM_DESTROY:
KillTimer (hWnd, 0);
PostQuitMessage(0);
break;
case WM_INITMENU: _InitMenu((HMENU)wParam); break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return r;
}
/*********************************************************************
*
* _TranslateAccelerator
This function does basically the same thing as the WIN32 function
of the same name (without underscore)
*/
static int _TranslateAccelerator(HWND hWnd, HACCEL hAcc, MSG* pMsg) {
if (pMsg->message == WM_KEYDOWN) {
int i, NumAccels;
ACCEL aAccel[20];
NumAccels = CopyAcceleratorTable(hAcc, aAccel, 20);
for (i = 0; i < NumAccels; i++) {
int falt0 = (aAccel[i].fVirt & FALT) ? 1 : 0;
int falt1 = pMsg->lParam & (1<<29) ? 1 : 0;
if ((falt0 == falt1) && (pMsg->wParam == (WPARAM)aAccel[i].key)) {
SendMessage(hWnd, WM_COMMAND, aAccel[i].cmd, 0);
return 1; // Message handled
}
}
}
return 0; // Message no handled
};
/*********************************************************************
*
* _WinMain_NoClean
*/
static int _WinMain_NoClean(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
char *sErr;
MSG msg;
HACCEL hAccelTable;
_pCmdLine = lpCmdLine;
if (strlen(lpCmdLine)) {
_MessageBoxOnError = 0;
}
_timeStartup = timeGetTime();
_hInst = hInstance;
_RegisterClasses();
//
// Load Resources
//
_hLogo = LoadImage(_hInst, (LPCTSTR) IDB_LOGO, IMAGE_BITMAP, 0, 0, 0);
_ahBmpDevice[0] = (HBITMAP)LoadImage(_hInst, "Device.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
_ahBmpDevice[1] = (HBITMAP)LoadImage(_hInst, "Device1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if (_ahBmpDevice[0] ==0)
_ahBmpDevice[0] = (HBITMAP)LoadImage(_hInst, (LPCTSTR) IDB_DEVICE, IMAGE_BITMAP, 0, 0, 0);
if (_ahBmpDevice[1] ==0)
_ahBmpDevice[1] = (HBITMAP)LoadImage(_hInst, (LPCTSTR) IDB_DEVICE+1, IMAGE_BITMAP, 0, 0, 0);
_hMenuPopup = LoadMenu(_hInst, (LPCSTR)IDC_SIMULATION_POPUP);
_hMenuPopup = GetSubMenu(_hMenuPopup,0);
//
// Init LCD simulation
//
sErr = LCDSIM_Init();
if (sErr) {
_MessageBox1(sErr);
return 1;
}
_LOG_y0 = _GetYSizePhys()+30;
/* Use device simulation or standard window */
if (_ahBmpDevice[0] && (_xPosLCD >= 0)) {
BITMAP bmpDevice;
GetObject(_ahBmpDevice[0], sizeof(bmpDevice), &bmpDevice);
_hWndMain = CreateWindowEx(0, // Extended style -> Use WS_EX_TOPMOST if you want window to stay on top
acClassNameDevice, "Target device",
WS_CLIPCHILDREN | WS_POPUP| WS_VISIBLE,
10, 20, bmpDevice.bmWidth, bmpDevice.bmHeight, 0, NULL, _hInst, NULL);
} else {
_hWndMain = CreateWindow(acClassNameMain, BRANDING_GetAppNameLong(),
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_VISIBLE, CW_USEDEFAULT, 0,
_GetXSizePhys() + 250,
_GetYSizePhys() + 150,
NULL, NULL, hInstance, NULL);
if (!_hWndMain)
return FALSE;
_CreateWndLCD();
_LOG_Create(_hInst, _hWndMain);
}
ShowWindow(_hWndMain, 1);
_THREAD_StartApplication();
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMULATION);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0)) {
if (!_TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
_THREAD_KillAll(); // Kill background thread
return msg.wParam;
}
/*********************************************************************
*
* SIM_HARDKEY_ ... functions
*
**********************************************************************
The following routines are available for the simulated application.
The routines are "C" linked.
*/
/*********************************************************************
*
* SIM_HARDKEY_GetState
*/
int SIM_HARDKEY_GetState(unsigned int i) {
if (i > countof (_aHardkey))
return 0;
return _aHardkey[i].IsPressed;
}
/*********************************************************************
*
* SIM_HARDKEY_SetState
*/
int SIM_HARDKEY_SetState(unsigned int i, int State) {
int r;
if (i > countof (_aHardkey)) {
return 0;
}
r = _aHardkey[i].IsPressed;
_aHardkey[i].IsPressed = State;
return r;
}
/*********************************************************************
*
* SIM_HARDKEY_GetNum
*/
int SIM_HARDKEY_GetNum(void) {
return _NumHardkeys;
}
/*********************************************************************
*
* SIM_HARDKEY_SetCallback
*/
SIM_HARDKEY_CB* SIM_HARDKEY_SetCallback(unsigned int KeyIndex, SIM_HARDKEY_CB* pfCallback) {
SIM_HARDKEY_CB* r;
if (KeyIndex > countof (_aHardkey)) {
return 0;
}
r = _aHardkey[KeyIndex].pfCallback;
_aHardkey[KeyIndex].pfCallback = pfCallback;
return r;
}
/*********************************************************************
*
* SIM_HARDKEY_SetMode
*/
int SIM_HARDKEY_SetMode (unsigned int KeyIndex, int Mode) {
int r;
if (KeyIndex > countof (_aHardkey)) {
return 0;
}
r = _aHardkey[KeyIndex].Mode;
_aHardkey[KeyIndex].Mode = Mode;
return r;
}
/*********************************************************************
*
* SIM_ ... functions
*
**********************************************************************
The following routines are available for the simulated application.
The routines are "C" linked.
*/
/*********************************************************************
*
* SIM_SetTransColor
*/
int SIM_SetTransColor(int Color) {
int r = _rgbTransparent;
_rgbTransparent = Color;
return r;
}
/*********************************************************************
*
* SIM_SetLCDColorWhite
*/
int SIM_SetLCDColorWhite(unsigned int Index, int Color) {
int r =0;
if (Index < countof(LCDSIM_aLCDColorWhite)) {
r = LCDSIM_aLCDColorWhite[Index];
LCDSIM_aLCDColorWhite[Index] = Color;
}
return r;
}
/*********************************************************************
*
* SIM_SetLCDColorBlack
*/
int SIM_SetLCDColorBlack(unsigned int Index, int Color) {
int r =0;
if (Index < countof(LCDSIM_aLCDColorBlack)) {
r = LCDSIM_aLCDColorBlack[Index];
LCDSIM_aLCDColorBlack[Index] = Color;
}
return r;
}
/*********************************************************************
*
* SIM_SetMag
*/
void SIM_SetMag(int MagX, int MagY) {
if (_MagX != 0) {
_MagX = MagX;
}
if (_MagY != 0) {
_MagY = MagY;
}
}
/*********************************************************************
*
* SIM_GetMagX, SIM_GetMagY
*/
int SIM_GetMagX(void) { return _MagX; }
int SIM_GetMagY(void) { return _MagY; }
/*********************************************************************
*
* SIM_SetLCDPos
*/
void SIM_SetLCDPos(int x, int y) {
_xPosLCD = x;
_yPosLCD = y;
}
/*********************************************************************
*
* SIM_GetTime
*/
int SIM_GetTime(void) { return timeGetTime() - _timeStartup; }
/*********************************************************************
*
* SIM_Delay
*/
void SIM_Delay(int ms) {
_THREAD_Sleep(ms);
SIM_GetTime();
}
/*********************************************************************
*
* SIM_ExecIdle
*/
void SIM_ExecIdle(void) {
_THREAD_Sleep(1);
}
/*********************************************************************
*
* SIM_WaitKey
*/
int SIM_WaitKey(void) {
int r;
SIM_Log("\nSIM_WaitKey()");
while (_KeyBuffer == 0) {
GUI_Delay(10);
}
r = _KeyBuffer;
_KeyBuffer =0;
SIM_Log(" Done.");
return r;
}
/*********************************************************************
*
* SIM_GetKey
*/
int SIM_GetKey(void) {
int r;
r = _KeyBuffer;
if (r)
_KeyBuffer=0;
return r;
}
/*********************************************************************
*
* SIM_StoreKey
*/
void SIM_StoreKey(int Key) {
if (!_KeyBuffer)
_KeyBuffer = Key;
}
/*********************************************************************
*
* SIM_Log
*/
void SIM_Log(const char *s) {
OutputDebugString(s);
_LogTime();
_LOG_Add(s);
}
/*********************************************************************
*
* SIM_Warn
*/
void SIM_Warn(const char *s) {
_LogTime();
_LOG_AddRed();
_LOG_Add(s);
}
/*********************************************************************
*
* SIM_ErrorOut
*/
void SIM_ErrorOut(const char *s) {
static int Cnt;
_LogTime();
_LOG_AddRed();
_LOG_Add(s);
if (_MessageBoxOnError) {
Cnt++;
_MessageBox1(s);
}
_SendToErrorFile(s);
}
/*********************************************************************
*
* SIM_EnableMessageBoxOnError
*/
void SIM_EnableMessageBoxOnError(int Status) {
_MessageBoxOnError = Status;
}
/*********************************************************************
*
* SIM_GetCmdLine
*/
const char * SIM_GetCmdLine(void) {
return _pCmdLine;
}
/*********************************************************************
*
* SIM_CreateTask
*/
void SIM_CreateTask(char * pName, void * pFunc) {
if (_NumTask < countof(_ahThread)) {
_ahThread[_NumTask] = CreateThread(NULL, 0, _CreateTask, pFunc, CREATE_SUSPENDED, &_aThreadID[_NumTask]);
SetThreadPriority(_ahThread[_NumTask], THREAD_PRIORITY_LOWEST);
ResumeThread(_ahThread[_NumTask]);
_NumTask++;
}
}
/*********************************************************************
*
* SIM_Start
*/
void SIM_Start(void) {
while(1)
Sleep(10);
}
/*********************************************************************
*
* WinMain
*
**********************************************************************
*/
#if (SIM_WINMAIN)
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
int r;
SIM_X_Init();
r = _WinMain_NoClean(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
if (_hWndLCD1)
DestroyWindow(_hWndLCD1);
if (_ahBmpDevice[0])
DeleteObject(_ahBmpDevice[0]);
if (_ahBmpDevice[1])
DeleteObject(_ahBmpDevice[1]);
if (_hLogo)
DeleteObject(_hLogo);
if (_hFileError)
CloseHandle(_hFileError);
return r;
}
#endif
/*************************** End of file ****************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -