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

📄 basicdisplay.c

📁 symbol scanner sample
💻 C
字号:
//--------------------------------------------------------------------
// FILENAME:		BasicDisplay.c
//
// Copyright(c) 2005 Symbol Technologies Inc. All rights reserved.
//
// DESCRIPTION:		This simple application demonstrates how to use 
//					the Symbol Windows CE Display API's.
//
//					The API's used are as follows:
//
//						DISPLAY_GetBacklightIntensity
//						DISPLAY_GetBacklightIntensityLevels
//						DISPLAY_GetBacklightState
//						DISPLAY_GetContrast
//						DISPLAY_GetContrastLevels
//						DISPLAY_GetKeyLiteInfo
//						DISPLAY_SetBacklightIntensity
//						DISPLAY_SetBacklightState
//						DISPLAY_SetContrast
//						DISPLAY_SetKeyLiteInfo
//
//
// 
//
//--------------------------------------------------------------------

#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>

#include "resource.h"
#include "dispcapi.h"

#define		countof(x)		sizeof(x)/sizeof(x[0])	

// Global variables
HINSTANCE				g_hInst;
DWORD					g_dwContrastLevels, g_dwContrast;
DWORD					g_dwBacklightLevels, g_dwBacklight, g_dwBacklightState;
DWORD					g_dwKeyliteState, g_dwKeyliteTimeout;

// Forward declarations
LRESULT CALLBACK BasicDisplayProc(HWND,UINT,WPARAM,LPARAM);
void	ErrorExit(HWMD, UINT, LPTSTR, DWORD);
LPTSTR	LoadMsg(UINT, LPTSTR, int);


//----------------------------------------------------------------------------
//
//  FUNCTION:   WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
//
//  PURPOSE:    Entry point function, initializes the application, instance,
//              and then launches the message loop.
//
//  PARAMETERS:
//      hInstance     - handle that uniquely identifies this instance of the
//                      application
//      hPrevInstance - always zero in Win32
//      lpszCmdLine   - any command line arguements pass to the program
//      nCmdShow      - the state which the application shows itself on
//                      startup
//
//  RETURN VALUE:
//      (int) Returns the value from PostQuitMessage().
//
//----------------------------------------------------------------------------

int WINAPI WinMain(HINSTANCE hInstance,
				   HINSTANCE hPrevInstance,
				   LPWSTR lpszCmdLine,
				   int nCmdShow)
{
	int nResult;
	DWORD dwError;

	g_hInst = hInstance;		// save the instance handle to a global variable
	nResult = DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_SDISPLAY), NULL, 
						BasicDisplayProc);
	if (nResult == -1)
		dwError = GetLastError();

	return nResult;
}


//----------------------------------------------------------------------------
//
//  FUNCTION:   BasicDisplayProc(HINSTANCE, HINSTANCE, LPSTR, int)
//
//  PURPOSE:    Application-defined callback function that processes messages 
//				sent to BasicDisplay dialog. 
//
//  PARAMETERS:
//      hwnd     - handle to the dialog box. 
//      uMsg	 - specifies the message. 
//      wParam   - specifies additional message-specific information. 
//      lParam   - specifies additional message-specific information. 
//
//  RETURN VALUE:
//      (BOOL) return TRUE if it processed the message, and FALSE if it did not. 
//
//----------------------------------------------------------------------------

LRESULT CALLBACK BasicDisplayProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	static HWND		hContrastLevels, hBacklightLevels, hBacklightState, hKeyliteStates;
	DWORD			dwError, dwValue;
	TCHAR			szBuf[256];

	switch(uMsg)
    {
		case WM_INITDIALOG:

			// Initialize the combo box for Contrast
			hContrastLevels = GetDlgItem(hwnd, IDC_COMBO_CONTRAST);
			dwError = DISPLAY_GetContrastLevels(&g_dwContrastLevels);
			if (dwError == E_DSP_SUCCESS && g_dwContrastLevels > 0)
			{
				dwError = DISPLAY_GetContrast(&g_dwContrast);
				if (dwError != E_DSP_SUCCESS)
					ErrorExit(hwnd, IDS_FAILURE, TEXT("DISPLAY_GetContrast"), dwError);
				for (dwValue = 0; dwValue < g_dwContrastLevels; dwValue++)
					ComboBox_InsertString(hContrastLevels, 0, _ltot(dwValue, szBuf, 10));
				ComboBox_SetCurSel(hContrastLevels, g_dwContrastLevels - 1 - g_dwContrast);
			}
			else
				ComboBox_Enable(hContrastLevels, FALSE);

			// Initialize the combo box and check box for Backlight
			hBacklightLevels = GetDlgItem(hwnd, IDC_COMBO_BACKLIGHT);
			dwError = DISPLAY_GetBacklightIntensityLevels(&g_dwBacklightLevels);
			if (dwError == E_DSP_SUCCESS && g_dwBacklightLevels > 0)
			{
				dwError = DISPLAY_GetBacklightIntensity(&g_dwBacklight);
				if (dwError != E_DSP_SUCCESS)
					ErrorExit(hwnd, IDS_FAILURE, TEXT("DISPLAY_GetBacklightIntensity"), dwError);
				for (dwValue = 0; dwValue < g_dwBacklightLevels; dwValue++)
					ComboBox_InsertString(hBacklightLevels, 0, _ltot(dwValue, szBuf, 10));
				ComboBox_SetCurSel(hBacklightLevels, g_dwBacklightLevels - 1 - g_dwBacklight);
			}
			else
				ComboBox_Enable(hBacklightLevels, FALSE);

			hBacklightState = GetDlgItem(hwnd, IDC_CHECK_BACKLIGHT);
			dwError = DISPLAY_GetBacklightState(&g_dwBacklightState);
			if (dwError == E_DSP_SUCCESS)
			{
				Button_SetCheck(hBacklightState, (g_dwBacklightState == BACKLIGHT_ON));
			}
			else
				Button_Enable(hBacklightState, FALSE);

			// Initialize the combo box for Keylite
			hKeyliteStates = GetDlgItem(hwnd, IDC_COMBO_KEYLITE);
			ComboBox_AddString(hKeyliteStates, TEXT("OFF")); 
			ComboBox_AddString(hKeyliteStates, TEXT("ON"));
			ComboBox_AddString(hKeyliteStates, TEXT("TRACKBACKLIGHT"));
			ComboBox_AddString(hKeyliteStates, TEXT("TIMEOUT"));

			dwError = DISPLAY_GetKeyLiteInfo(&g_dwKeyliteState, &g_dwKeyliteTimeout);
			if (dwError == E_DSP_SUCCESS)
				ComboBox_SetCurSel(hKeyliteStates, g_dwKeyliteState);
			else
				ComboBox_Enable(hKeyliteStates, FALSE);
			
			break;

		case WM_COMMAND:
			
			switch (LOWORD(wParam))
            {
				case IDC_COMBO_CONTRAST:
					// Set dispaly contrast
					if (CBN_SELCHANGE == HIWORD(wParam))
					{
						DWORD dwLevel = g_dwContrastLevels - 1 - ComboBox_GetCurSel(hContrastLevels);
						dwError = DISPLAY_SetContrast(dwLevel);
						if (dwError != E_DSP_SUCCESS)
						{
							MessageBox(hwnd, LoadMsg(IDS_CONTRAST_NOTSUPPORT, szBuf, countof(szBuf)), NULL, MB_OK);
							ComboBox_SetCurSel(hContrastLevels, g_dwContrastLevels - 1 - g_dwContrast);
						}
						else
							g_dwContrast = dwLevel;
					}
					break;

				case IDC_CHECK_BACKLIGHT:
					// Set backlight state
					if (BN_CLICKED == HIWORD(wParam))
					{
						DWORD dwState = (Button_GetCheck(hBacklightState) == BST_CHECKED) ? BACKLIGHT_ON : BACKLIGHT_OFF;
						dwError = DISPLAY_SetBacklightState(dwState);
						if (dwError != E_DSP_SUCCESS)
						{
							MessageBox(hwnd, LoadMsg(IDS_BKLIGHTSTATE_NOTSUPPORT, szBuf, countof(szBuf)), NULL, MB_OK);
							Button_SetCheck(hBacklightState, (g_dwBacklightState == BACKLIGHT_ON));
						}
						else
							g_dwBacklightState = dwState;
					}
					break;

				case IDC_COMBO_BACKLIGHT:
					// Set backlight intensity
					if (CBN_SELCHANGE == HIWORD(wParam))
					{
						DWORD dwLevel = g_dwBacklightLevels - 1 - ComboBox_GetCurSel(hBacklightLevels);
						dwError = DISPLAY_SetBacklightIntensity(dwLevel);
						if (dwError != E_DSP_SUCCESS)
						{
							MessageBox(hwnd, LoadMsg(IDS_BKLIGHTLEV_NOTSUPPORT, szBuf, countof(szBuf)), NULL, MB_OK);
							ComboBox_SetCurSel(hBacklightLevels, g_dwBacklightLevels - 1 - g_dwBacklight);
						}
						else
							g_dwBacklight = dwLevel;
					}
					break;

				case IDC_COMBO_KEYLITE:
					// Set keylite state
					if (CBN_SELCHANGE == HIWORD(wParam))
					{
						DWORD dwState = ComboBox_GetCurSel(hKeyliteStates);
						dwError = DISPLAY_SetKeyLiteInfo(dwState, g_dwKeyliteTimeout);
						if (dwError != E_DSP_SUCCESS)
						{
							MessageBox(hwnd, LoadMsg(IDS_KEYLITE_NOTSUPPORT, szBuf, countof(szBuf)), NULL, MB_OK);
							ComboBox_SetCurSel(hKeyliteStates, g_dwKeyliteState);
						}
						else
							g_dwKeyliteState = dwState;
		
					}
					break;

				case IDCANCEL:

					EndDialog(hwnd, 0);
					
					break;
			}

			break;

	}

	return FALSE;
}

//----------------------------------------------------------------------------
//
//  FUNCTION:   ErrorExit(HWND, UINT, LPTSTR)
//
//  PURPOSE:    Handle critical errors and exit dialog. 
//
//  PARAMETERS:
//      hwnd     - handle to the dialog box. 
//      uID		 - ID of the message string to be displayed 
//      szFunc   - function name if it's an API function failure 
//
//  RETURN VALUE:
//      None.
//
//----------------------------------------------------------------------------

void ErrorExit(HWND hwnd, UINT uID, LPTSTR szFunc, DWORD dwError)
{
	TCHAR szMsg[256];
	TCHAR szMsgBuf[256];

	if (szFunc == NULL)
		_tcscpy(szMsg, LoadMsg(uID, szMsgBuf, countof(szMsgBuf)));
	else
		_stprintf(szMsg, TEXT("%s %s (%x)"), szFunc, 
					LoadMsg(uID, szMsgBuf, countof(szMsgBuf)), dwError);
	MessageBox(hwnd, szMsg, NULL, MB_OK);

	EndDialog(hwnd, 0);
}

//----------------------------------------------------------------------------
//
//  FUNCTION:   LoadMsg(UINT, LPTSTR, int)
//
//  PURPOSE:    Load a message string for the string table
//
//  PARAMETERS:
//      uID		 - ID of the message string to be loaded
//      lpBuffer - buffer to hold the message string
//		nBufSize - size of lpBuffer
//
//  RETURN VALUE:
//      (LPTSTR) pointer to lpBuffer
//
//----------------------------------------------------------------------------

LPTSTR LoadMsg(UINT uID, LPTSTR lpBuffer, int nBufSize)
{
	if (!LoadString(g_hInst, uID, lpBuffer, nBufSize))
		_tcscpy(lpBuffer, TEXT(""));

	return lpBuffer;
}



⌨️ 快捷键说明

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