Example #1
0
//
//  函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  目的: 处理主窗口的消息。
//
//  WM_COMMAND	- 处理应用程序菜单
//  WM_PAINT	- 绘制主窗口
//  WM_DESTROY	- 发送退出消息并返回
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// 分析菜单选择:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: 在此添加任意绘图代码...
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
    case WM_TIMER:
        {
            switch(wParam)
            {
            case TIMER_ID::TIMER_SIMULATE_MOUSE_MOVE:
                {
                    SimulateMouseMove();   
                    break;
                }
            case TIMER_ID::TIMER_SIMULATE_KEYBOARD:
                {
                    SimulateKeyboard();
                    break;
                }
            }
            
            break;
        }
    case WM_KEYDOWN:
        {
            switch(wParam)
            {
                //屏保方法一:通过模拟鼠标事件
            case 'A':
                {                    
                    SetTimer(hWnd, TIMER_ID::TIMER_SIMULATE_MOUSE_MOVE, 2000, NULL);
                    break;
                }
            case  'B':
                {
                    KillTimer(hWnd, TIMER_ID::TIMER_SIMULATE_MOUSE_MOVE);
                    break;
                }
                //屏保方法二:模拟键盘事件
            case 'C':
                {
                    SetTimer(hWnd, TIMER_ID::TIMER_SIMULATE_KEYBOARD, 2000, NULL);
                    break;
                }
            case 'D':
                {
                    KillTimer(hWnd, TIMER_ID::TIMER_SIMULATE_KEYBOARD);
                    break;
                }
            case VK_F24:
                {
                    OutputDebugString(L"VK_F24 Key down\t");
                    break;
                }
                //屏保方法三:通过关闭系统屏保设置, 危险,会改变系统值,如程序意外退出不会改回原来值。
            case 'Z':
                {
                    SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0);
                    break;
                }  
            }
            break;
        }
    case WM_SYSCOMMAND:
        {
            switch(wParam)
            {
            case SC_SCREENSAVE:
                {
                    OutputDebugString(L"SC_SCREENSAVE\n");
                    break;
                }
            case SC_MONITORPOWER:
                {
                    OutputDebugString(L"SC_MONITORPOWER\n");
                    break;
                }
            }
            DefWindowProc(hWnd, message, wParam, lParam);
        }   
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
Example #2
0
*******************************************************************************/int main()
{
    CyGlobalIntEnable;  

#if (DEBUG_UART_ENABLED == ENABLED)
    UART_DEB_Start();
#endif /* (DEBUG_UART_ENABLED == ENABLED) */
    DBG_PRINTF("BLE HID Keyboard Example Project \r\n");

    LED_RED_Write(LED_OFF);
    LED_BLU_Write(LED_OFF);
    LED_GRN_Write(LED_OFF);

    /* Start CYBLE component and register generic event handler */
    CyBle_Start(AppCallBack);

#if (BAS_MEASURE_ENABLE != 0)
    ADC_Start();
#endif /* BAS_MEASURE_ENABLE != 0 */

    while(1) 
    {           
        /* CyBle_ProcessEvents() allows BLE stack to process pending events */
        CyBle_ProcessEvents();

        /* To achieve low power in the device */
        LowPowerImplementation();

        if((CyBle_GetState() == CYBLE_STATE_CONNECTED) && (suspend != CYBLE_HIDS_CP_SUSPEND))
        {
            if(mainTimer != 0u)
            {
                mainTimer = 0u;                
            #if (BAS_SIMULATE_ENABLE != 0)
                SimulateBattery();
                CyBle_ProcessEvents();
            #endif /* BAS_SIMULATE_ENABLE != 0 */    
            #if (BAS_MEASURE_ENABLE != 0)
                MeasureBattery();
                CyBle_ProcessEvents();
            #endif /* BAS_MEASURE_ENABLE != 0 */
                if(keyboardSimulation == ENABLED)
                {
                    SimulateKeyboard();
                }
            }
            /* Store bonding data to flash only when all debug information has been sent */
        #if(CYBLE_BONDING_REQUIREMENT == CYBLE_BONDING_YES)
        #if (DEBUG_UART_ENABLED == ENABLED)
            if((cyBle_pendingFlashWrite != 0u) &&
               ((UART_DEB_SpiUartGetTxBufferSize() + UART_DEB_GET_TX_FIFO_SR_VALID) == 0u))
            
        #else
            if(cyBle_pendingFlashWrite != 0u)
        #endif /* (DEBUG_UART_ENABLED == ENABLED) */
            {
                CYBLE_API_RESULT_T apiResult;
                
                apiResult = CyBle_StoreBondingData(0u);
                (void)apiResult;
                DBG_PRINTF("Store bonding data, status: %x \r\n", apiResult);
            }
        #endif /* CYBLE_BONDING_REQUIREMENT == CYBLE_BONDING_YES */    
        }
	}   
}