⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simmain.c

📁 一个操作系统源代码 用于嵌入式设备 在Vc++环境下仿真 成功移植到多款处理器上
💻 C
📖 第 1 页 / 共 2 页
字号:
        case WM_KEYUP:
			switch( wParam )
			{
				case VK_HOME:
					newKey = KEY_Call;
					break;
				case VK_UP:
					newKey = KEY_Up;
					break;
				case VK_DOWN:
					newKey = KEY_Down;
					break;
				case VK_LEFT:
					newKey = KEY_Left;
					break;
				case VK_RIGHT:
					newKey = KEY_Right;
					break;
				case VK_BACK:
					newKey = KEY_Drop;
					break;
				case VK_DELETE:
					newKey = KEY_Done;
					break;
				case VK_ESCAPE:
					newKey = KEY_Cancel;
					break;
				case VK_RETURN:
					newKey = KEY_Menu;
					break;
				case VK_SHIFT:
					newKey = KEY_MiddleVoice;
					break;
				case VK_MULTIPLY:
					newKey = KEY_Asterisk;
					break;
				case VK_DIVIDE:
					newKey = KEY_NO;
					break;
				default:
					if( isdigit( wParam ) )
					{
						newKey = wParam - '0';
						break;
					}
					return 0;
			}
			FillKeyIntr( uMsg, newKey, lParam );
            break;
	    default:
	        return DefWindowProc( hwnd, uMsg, wParam, lParam );
    }
    return 0;
}

////////////////////////////////////////////////////////////////////////////////
// Function name  : ScreenWndProc
// Description    : 
// Return type    : LRESULT CALLBACK 
// Argument       : HWND hwnd
// Argument       : UINT uMsg
// Argument       : WPARAM wParam
// Argument       : LPARAM lParam
// Remarks        : 
// So also        : 
////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK ScreenWndProc( HWND hwnd,
								UINT uMsg,
								WPARAM wParam,
								LPARAM lParam )
{

    switch( uMsg )
    {
		case WM_MOVE:
			break;
	    case WM_CREATE:
 	        break;
	    case WM_PAINT:
			{			
				PAINTSTRUCT	ps;
				HDC		hdc = BeginPaint( hwnd, &ps );
			
				PostMessage( hwndClient, WM_REFRESH, 0, 0);

				if( hwndClient == 0 )
					TextOut( hdc, (screenWidth-108)/2, screenHeight/2-16, "已关机!", 7 );

				EndPaint( hwnd, &ps );
				ReleaseDC( hwnd, hdc );
			}
			break;
        case WM_CLOSE:
            DestroyWindow( hwnd );
            break;
        case WM_KEYDOWN:
        case WM_KEYUP:
			FillKeyIntr( uMsg, wParam, lParam );
            break;
        case WM_LBUTTONDOWN:
        case WM_LBUTTONUP:
        case WM_MOUSEMOVE:
//		case WM_MOUSELEAVE:
			FillPenIntr( uMsg, wParam, lParam );
            break;
	    default:
	        return DefWindowProc( hwnd, uMsg, wParam, lParam );
    }
    return 0;
}

////////////////////////////////////////////////////////////////////////////////
// Function name  : DebugDlgProc
// Description    : 
// Return type    : BOOLCALLBACK 
// Argument       : HWND hwndDlg
// Argument       : UINT uMsg
// Argument       : WPARAM wParam
// Argument       : LPARAM lParam
// Remarks        : 
// So also        : 
////////////////////////////////////////////////////////////////////////////////
BOOL CALLBACK DebugDlgProc( HWND hwndDlg, 
							UINT uMsg, 
							WPARAM wParam, 
							LPARAM lParam )
{
    switch( uMsg )
    {
        case WM_INITDIALOG:
            return TRUE;
		case WM_COMMAND:
            if( HIWORD( wParam ) == BN_CLICKED )
			{
				EndDialog( hwndDlg, IDOK );
//				DestroyWindow( hwndDlg );
			}
			break;
		case WM_CLOSE:
            isDebugDlgClosed = TRUE;
            EndDialog( hwndDlg, 0 );
//			DestroyWindow( hwndDlg );
            PostMessage( hwndPanel, WM_CLOSE, 0, 0 );
            break;
        default:
            break;
    }
    return FALSE;
}

BOOL CALLBACK AboutDlgProc( HWND hwndDlg, 
							UINT uMsg, 
							WPARAM wParam, 
							LPARAM lParam )
{
    switch( uMsg )
    {
        case WM_INITDIALOG:
            return TRUE;
 		case WM_COMMAND:
			EndDialog( hwndDlg, IDOK );
			DestroyWindow( hwndDlg );
			break;
       case WM_CLOSE:
            EndDialog( hwndDlg, 0 );
			DestroyWindow( hwndDlg );
            break;
        default:
            break;
    }
    return FALSE;
}

//------------------------------------------------------------------------------
// Function name  : AddDebugLog
// Description    : 
// No return value
// No argument
// Remarks        : 
// So also        : 
//------------------------------------------------------------------------------
void AddDebugLog(  )
{
    HWND hwndList;
	int nLine;

	hwndList = GetDlgItem( hwndDebugDlg, IDC_LstDebugLog );
    //  get the number of lines in the list
    nLine = SendMessage( hwndList, LB_GETCOUNT, 0, 0 );
    // check if the log buffer is full. if so, delete the first one.
    if( nLine >= MAX_DEBUGLOGLINE )
    	SendMessage( hwndList, LB_DELETESTRING, 0, 0 );
    // append the text
    SendMessage( hwndList, LB_ADDSTRING, 0, (LPARAM)tcaDebugLog );
    SendMessage( hwndList, LB_SETTOPINDEX, nLine-30, 0 );    		

	return;
}

////////////////////////////////////////////////////////////////////////////////
// Function name  : FillKeyIntr
// Description    : 
// No return value
// Argument       : UINT uMsg
// Argument       : WPARAM wParam
// Argument       : LPARAM lParam
// Remarks        : 
// So also        : 
////////////////////////////////////////////////////////////////////////////////
void FillKeyIntr(	UINT uMsg, 
					WPARAM wParam, 
					LPARAM lParam )
{
	static DWORD		count = 0;

	switch( uMsg )
    {
        case WM_KEYDOWN:
			key.keyvalue = wParam;
            if( key.flag == KEYUP )
            	key.flag = KEYDOWN;
            else
			{
            	key.flag = KEYREPEAT;
				count++;
				if( wParam == KEY_Cancel && count == 5 )
				{
					HDC	hdc;
					
					hdc = GetDC( hwndScreen );
					if( hwndClient != 0 )
					{
						TextOut( hdc, (screenWidth-108)/2, screenHeight/2-16, "正在关机!", 9 );
						TextOut( hdc, (screenWidth-108)/2, screenHeight/2, "请等候!", 7 );
						ReleaseDC( hwndScreen, hdc );

						PostMessage( hwndClient, WM_POWEROFF, 0, 0);
						
					}
					else
					{
						STARTUPINFO si;
						PROCESS_INFORMATION pi;
					    memset( &si, 0, sizeof( STARTUPINFO ) );

						TextOut( hdc, (screenWidth-108)/2, screenHeight/2-16, "正在开机!", 9 );
						TextOut( hdc, (screenWidth-108)/2, screenHeight/2, "请等候!", 7 );
						ReleaseDC( hwndScreen, hdc );

						if( !CreateProcess(
										"simapp.exe",          // name of executable module
										NULL,                   // command line string
										NULL,                   // SD
										NULL,                   // SD
										FALSE,                  // handle inheritance option
										NORMAL_PRIORITY_CLASS,  // creation flags
										NULL,                   // new environment block
										NULL,                   // current directory name
										&si,                    // startup information
										&pi                     // process information
										) )
							{
								MessageBox( NULL, "Unable to run OS!", "Error", MB_OK | MB_ICONERROR );
								break;
							}
					}
				}
			}
            break;
        case WM_KEYUP:
            //key.keyvalue = 0;
            key.flag = KEYUP;
			count = 0;
            break;
    }
}

////////////////////////////////////////////////////////////////////////////////
// Function name  : FillMouseSimKey
// Description    : 
// No return value
// Argument       : UINT uMsg
// Argument       : WPARAM wParam
// Argument       : LPARAM lParam
// Remarks        : 
// So also        : 
////////////////////////////////////////////////////////////////////////////////
BOOL FillMouseSimKey(	UINT uMsg, 
						WPARAM wParam, 
						LPARAM lParam )
{
    int x, y, i;
	static BOOL pressKey = FALSE;
	static int preKey = -1;

    switch( uMsg )
    {
        case WM_LBUTTONDOWN:
            x = LOWORD( lParam );
            y = HIWORD( lParam );
            for(i=0;i<nKeyNumber;i++)
            {
                if( x>kpa[i].pt.x - 8 && x<kpa[i].pt.x + 8 && y>kpa[i].pt.y - 8 && y<kpa[i].pt.y + 8 )
                {
                    FillKeyIntr( WM_KEYDOWN, kpa[i].uKeyCode, 0 );
                    pressKey = TRUE;
					preKey = i;
					return TRUE;
                }
            }
            break;
        case WM_LBUTTONUP:
            /*
			x = LOWORD( lParam );
            y = HIWORD( lParam );
            for(i=0;i<nKeyNumber;i++)
            {
                if( x>kpa[i].pt.x - 8 && x<kpa[i].pt.x + 8 && y>kpa[i].pt.y - 8 && y<kpa[i].pt.y + 8 )
                {
                    FillKeyIntr( WM_KEYUP, kpa[i].uKeyCode, 0 );
					break;
                }
            }
			*/
            if( pressKey == TRUE )
			{
				pressKey = FALSE;
				preKey = -1;
				FillKeyIntr( WM_KEYUP, 0, 0 );
				return TRUE;
			}
            break;
		case WM_MOUSEMOVE:
			x = LOWORD( lParam );
			y = HIWORD( lParam );
			for(i=0;i<nKeyNumber;i++)
			{
				if( x>kpa[i].pt.x - 8 && x<kpa[i].pt.x + 8 && y>kpa[i].pt.y - 8 && y<kpa[i].pt.y + 8 )
				{
					if( pressKey == TRUE )
						FillKeyIntr( WM_KEYDOWN, kpa[i].uKeyCode, 0 );	
					return TRUE;
				}
			}
			break;
    }

	return FALSE;
}

////////////////////////////////////////////////////////////////////////////////
// Function name  : FillPenIntr
// Description    : 
// No return value
// Argument       : UINT uMsg
// Argument       : WPARAM wParam
// Argument       : LPARAM lParam
// Remarks        : 
// So also        : 
////////////////////////////////////////////////////////////////////////////////
void FillPenIntr(	UINT uMsg, 
					WPARAM wParam, 
					LPARAM lParam )
{
    switch( uMsg )
    {
        case WM_LBUTTONDOWN:
            pen.x = LOWORD( lParam );
            pen.y = HIWORD( lParam );
            pen.flag = PENDOWN;
            break;
        case WM_LBUTTONUP:
            pen.flag = PENUP;
            break;
        case WM_MOUSEMOVE:
            if( wParam == MK_LBUTTON )
            {
                pen.x = LOWORD( lParam );
                pen.y = HIWORD( lParam );
                pen.flag = PENMOVE;
            }
			else
				pen.flag = PENUP;
			break;
//		case WM_MOUSELEAVE:
//			pen.flag = PENUP;
            break;
    }
}

////////////////////////////////////////////////////////////////////////////////
// Function name  : LoadPanelBitmap
// Description    : 
// Return type    : BOOL
// No argument
// Remarks        : 
// So also        : 
////////////////////////////////////////////////////////////////////////////////
BOOL LoadPanelBitmap( void )
{
    int handle;
    int nFileLength;

    handle = _open( tcaPanelFileName, _O_RDONLY | _O_BINARY );
    if( handle == -1 )
    {
        MessageBox( NULL, "Can not load panel bitmap file!", "Error", MB_ICONERROR|MB_OK );
        return FALSE;
    }

    _lseek( handle, sizeof( BITMAPFILEHEADER ), SEEK_SET );
    _read( handle, &bihPanel, sizeof( BITMAPINFOHEADER ) );
    if( bihPanel.biBitCount!=24 )
    {
        MessageBox( NULL, "24 bit panel bitmap is required!", "Error", MB_ICONERROR|MB_OK );
        _close( handle );
        return FALSE;
    }
    nFileLength = _filelength( handle ) - sizeof( BITMAPINFOHEADER ) - sizeof( BITMAPFILEHEADER );
    pdataPanel = LocalAlloc( LPTR, nFileLength );
    if( !pdataPanel )
    {
        _close( handle );
        return FALSE;
    }
    _read( handle, pdataPanel, nFileLength );
    _close( handle );

    return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -