bezier.cpp

来自「CIRRUS 93XX系列windows mobile 6.0 BSP」· C++ 代码 · 共 240 行

CPP
240
字号
/**********************************************************************
#                                                                      
# Filename: bezier.cpp
#                                                                      
# Description:
#
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
# ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
# PARTICULAR PURPOSE.
#
# Use of this source code is subject to the terms of the Cirrus end-user
# license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
# If you did not accept the terms of the EULA, you are not authorized to 
# use this source code. For a copy of the EULA, please see the 
# EULA.RTF on your install media.
#
# Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved                       
#                                                                      
#**********************************************************************/

//
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "font.h"
#include "resource.h"

extern "C" int g_bActive;
static HANDLE hThread	=NULL;
extern "C" HICON hBrzierIco	=NULL;
static HWND  HMainWnd	=NULL;

long FAR PASCAL WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

    switch (message)
    {
#ifdef UNDER_CE
        case WM_ACTIVATE:
#else
        case WM_ACTIVATEAPP:
#endif
            return 0L;

        case WM_CLOSE:
			g_bActive=FALSE;
			if(hThread)
			{
				if(WaitForSingleObject(hThread,5000)==WAIT_TIMEOUT)
				{
					{
						DWORD dwexitcode;
						GetExitCodeThread(hThread,&dwexitcode);
						TerminateThread(hThread,dwexitcode);
					}
				}
				CloseHandle(hThread);
			}
			DestroyWindow(hWnd);
            return 0L;
        case WM_DESTROY:
            // Clean up and close the app
            PostQuitMessage(0);
            return 0L;

        case WM_KEYDOWN:
            // Handle any non-accelerated key commands
            switch (wParam)
            {
                case VK_ESCAPE:
                case 'q':
                case 'Q':
                    PostMessage(hWnd, WM_CLOSE, 0, 0);
                    return 0L;
            }
            break;

        case WM_SETCURSOR:
            // Turn off the cursor since this is a full-screen app
            SetCursor(NULL);
            return TRUE;

     }
    return DefWindowProc(hWnd, message, wParam, lParam);

}

static int              g_crunch    =0;
static unsigned long    g_ulDepth   =64;
static unsigned long    g_ulPoints  =8;

extern "C" int meter_main(int crunch , unsigned long ulDepth, unsigned long ulPoints);


DWORD WINAPI ThreadProc(  LPVOID lpParameter)
{	
	meter_main(g_crunch,g_ulDepth,g_ulPoints);
	ExitThread(0);
	return 0;
}

void printUsage()
{
	fprintf(stderr, 
		"USAGE: bezier.exe <flags>\n"
		"\t-p<num>    The number of control points, an even number between 4 and\n"
		"\t           16(inclusive), default 8\n"
		"\t-d<num>    The number of previous beziers to leave on the screen as a\n"
		"\t           trail, a number between 1 and 256 (inclusive), default 64\n"
		"\t-c         Use MaverickCrunch to do the floating point arithmetic\n"
		"\t           By default, The program will use Windows CE internal soft \n"
		"\t           floating point library to do the arithmetic.\n"
    );
}


int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPTSTR    wlpCmdLine,
					int       nCmdShow)
{
    WNDCLASS                    wc;
    MSG                         msg;
	BOOL                        bUsage = FALSE;
	char*                       pNext;
	char                        lpCmdLine[200];

	WideCharToMultiByte(  CP_ACP, 
							  WC_COMPOSITECHECK, 
							  (LPCWSTR)wlpCmdLine, 
							  wcslen( wlpCmdLine ), 
							  (LPSTR) lpCmdLine, 
							  200, 
							  NULL, 
							  NULL);

    pNext = strtok(lpCmdLine,"-/");
 	while (pNext) 
	{
		switch(*pNext)
		{
		case 'c':
		    g_crunch =1;
			break;
		case 'd':
			pNext++;
			while(*pNext == ' ') 
				pNext++;
			g_ulDepth=atoi(pNext);
            if(g_ulDepth > MAXDEPTH)
            {
                printf("Depth must be less than %d!\n", MAXDEPTH);
                bUsage = TRUE;
            }
            if(g_ulDepth <=1)
            {
                printf("Depth must be greater than 1!\n");
                bUsage = TRUE;
            }
			break;
		case 'p':
			pNext++;
			while(*pNext == ' ') 
				pNext++;
			g_ulPoints=atoi(pNext);
            if(g_ulPoints < 4)
            {
                printf("Points must be greater than 4!\n");
                bUsage = TRUE;
            }
            if(g_ulPoints > MAXPOINTS)
            {
                printf("Points must be less than %d!\n", MAXPOINTS);
                bUsage = TRUE;
            }
            if(g_ulPoints & 1)
            {
                printf("Points must be even!\n");
                bUsage = TRUE;
            }
			break;

		case 'h':
		case '?':
			bUsage = TRUE;
		}

		pNext = strtok(NULL,"-");
	}

	if (bUsage)
	{
		printUsage();
		exit(1);
	}
	fprintf(stderr, "Press the <Esc> to quit the program.\n");

    // Set up and register window class
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = hBrzierIco = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = TEXT("Bezier");
    RegisterClass(&wc);

    // Create a window
    HMainWnd = CreateWindowEx(WS_EX_TOPMOST,
                          TEXT("Bezier"),
                          TEXT("Bezier"),
                          WS_POPUP,
                          0,
                          0,
                          GetSystemMetrics(SM_CXSCREEN),
                          GetSystemMetrics(SM_CYSCREEN),
                          NULL,
                          NULL,
                          hInstance,
                          NULL);
    if (!HMainWnd)
        return -1;
    ShowWindow(HMainWnd, nCmdShow);
    UpdateWindow(HMainWnd);
    SetFocus(HMainWnd);

	hThread = CreateThread(NULL, 0, ThreadProc, NULL, 0, NULL);

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
	return 0;
}    

⌨️ 快捷键说明

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