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

📄 ledtest.cpp

📁 里面有很多wince下开发的源代码
💻 CPP
字号:
// LEDTest.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "LEDTest.h"
#include <commctrl.h>
#include <windows.h>
#include "CEDDK.h"
#include "Afxwin.h"


#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE			hInst;			// The current instance
HWND				hwndCB;			// The command bar handle

// Forward declarations of functions included in this code module:
ATOM				MyRegisterClass	(HINSTANCE, LPTSTR);
BOOL				InitInstance	(HINSTANCE, int);
LRESULT CALLBACK	WndProc			(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK	About			(HWND, UINT, WPARAM, LPARAM);

volatile XLLP_GPIO_T	*v_pGPIORegs = NULL;
LARGE_INTEGER            address ;
BOOL b2,b3,b4 ;

//#define PAGE_SIZE 0x1000
#define ALIGNMENT_MASK (PAGE_SIZE-1)

/*
PVOID VirtualAllocCopy(unsigned size,char *str,PVOID pVirtualAddress)
{
PVOID ptr;
unsigned offset;

  offset = (unsigned)pVirtualAddress & ALIGNMENT_MASK;
  
	size +=offset ? PAGE_SIZE : 0;
	ptr = VirtualAlloc(0,size,MEM_RESERVE,PAGE_NOACCESS);
	if (ptr == NULL) {
	ERRORMSG(1,(TEXT("VirtualAlloc failed! %s : size=0x%x, (0x%x)\r\n"),str,size,GetLastError()));
	return(0);
	}
	
	  if (!VirtualCopy((PVOID)ptr,(PVOID)((unsigned)pVirtualAddress - offset),size,PAGE_READWRITE|PAGE_NOCACHE)) {
	  ERRORMSG(1,(TEXT("VirtualCopy failed! %s : addr=0x%x, offset=0x%x(0x%x)\r\n"),str,(unsigned)pVirtualAddress,offset,GetLastError()));
	  return(0);
	  }  
	  return((PVOID)((PBYTE)ptr+offset));
	  }
*/


int WINAPI WinMain(	HINSTANCE hInstance,
				   HINSTANCE hPrevInstance,
				   LPTSTR    lpCmdLine,
				   int       nCmdShow)
{
	MSG msg;
	HACCEL hAccelTable;
	
	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}
	
	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_LEDTEST);
	
	//v_pGPIORegs = (volatile XLLP_GPIO_T *)VirtualAllocCopy(sizeof(XLLP_GPIO_T),"DispDrvrInitialize : v_pGPIORegs",(PVOID)(GPIO_BASE_U_VIRTUAL));
	address.QuadPart = 0x40E00000 ;
    v_pGPIORegs=(volatile XLLP_GPIO_T *)MmMapIoSpace(address,sizeof(XLLP_GPIO_T),FALSE) ;
	b2=b3=b4=TRUE ;
	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	
	return msg.wParam;
}

//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    It is important to call this function so that the application 
//    will get 'well formed' small icons associated with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
	WNDCLASS	wc;
	
    wc.style			= CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc		= (WNDPROC) WndProc;
    wc.cbClsExtra		= 0;
    wc.cbWndExtra		= 0;
    wc.hInstance		= hInstance;
    wc.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_LEDTEST));
    wc.hCursor			= 0;
    wc.hbrBackground	= (HBRUSH) GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName		= 0;
    wc.lpszClassName	= szWindowClass;
	
	return RegisterClass(&wc);
}

//
//  FUNCTION: InitInstance(HANDLE, int)
//
//  PURPOSE: Saves instance handle and creates main window
//
//  COMMENTS:
//
//    In this function, we save the instance handle in a global variable and
//    create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
	HWND	hWnd;
	TCHAR	szTitle[MAX_LOADSTRING];			// The title bar text
	TCHAR	szWindowClass[MAX_LOADSTRING];		// The window class name
	
	hInst = hInstance;		// Store instance handle in our global variable
	// Initialize global strings
	LoadString(hInstance, IDC_LEDTEST, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance, szWindowClass);
	
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
	
	if (!hWnd)
	{	
		return FALSE;
	}
	
	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);
	if (hwndCB)
		CommandBar_Show(hwndCB, TRUE);
	
	return TRUE;
}

//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	TCHAR szHello[MAX_LOADSTRING];
	
	switch (message) 
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam); 
		wmEvent = HIWORD(wParam); 
		// Parse the menu selections:
		switch (wmId)
		{
		case IDM_HELP_ABOUT:
			DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
			break;
		case IDM_FILE_EXIT:
			DestroyWindow(hWnd);
			break;
			//case IDM_LED_D1:
			//	v_pGPIORegs->GPSR2 |= 0x02000000 ;
			break ;
		case IDM_LED_D2:
			if ( b2 )
			{
				b2 = FALSE ;
				v_pGPIORegs->GPSR3 |= 0x00000800 ;
			}
			else
			{
				b2 =TRUE ;
				v_pGPIORegs->GPCR3 |= 0x00000800;
			}
			break;
		case IDM_LED_D3:
			if ( b3 )
			{
				b3= FALSE ;
				v_pGPIORegs->GPSR3 |= 0x00001000 ;
			}
			else
			{
				b3= TRUE ;
				v_pGPIORegs->GPCR3 |= 0x00001000 ;
			}
			break ;
		case IDM_LED_D4:
			if ( b4 )
			{
				b4 = FALSE ;
				v_pGPIORegs->GPSR3 |= 0x00000001 ;
			}
			else
			{
				b4 = TRUE ;
				v_pGPIORegs->GPCR3 |= 0x00000001 ;
			}
			break ;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
		case WM_CREATE:
			hwndCB = CommandBar_Create(hInst, hWnd, 1);			
			CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);
			CommandBar_AddAdornments(hwndCB, 0, 0);
			break;
		case WM_PAINT:
			RECT rt;
			HDC hdcSrc ;
			BOOL bRet ;
			HBITMAP hOldBitmap,hBitmap ;
			hdc = BeginPaint(hWnd, &ps);	
			hdcSrc = CreateCompatibleDC(hdc) ;
			hBitmap = LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP1));
			hOldBitmap = (struct HBITMAP__ *)SelectObject(hdcSrc,hBitmap) ;

			bRet = BitBlt(hdc,0,0,320,240,hdcSrc,0,0,SRCCOPY) ;

			SelectObject(hdcSrc,hOldBitmap) ;
			DeleteObject(hBitmap) ;
			DeleteDC(hdcSrc) ;
			

			//GetClientRect(hWnd, &rt);
			//RETAILMSG(1,(TEXT("width=%d,height=%d"),rt.right-rt.left,rt.bottom-rt.top));
			//LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
			//DrawText(hdc, szHello, _tcslen(szHello), &rt, 
			//	DT_SINGLELINE | DT_VCENTER | DT_CENTER);
			EndPaint(hWnd, &ps);
			break;
		case WM_DESTROY:
			CommandBar_Destroy(hwndCB);
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

// Mesage handler for the About box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	RECT rt, rt1;
	int DlgWidth, DlgHeight;	// dialog width and height in pixel units
	int NewPosX, NewPosY;
	
	switch (message)
	{
	case WM_INITDIALOG:
		// trying to center the About dialog
		if (GetWindowRect(hDlg, &rt1)) {
			GetClientRect(GetParent(hDlg), &rt);
			DlgWidth	= rt1.right - rt1.left;
			DlgHeight	= rt1.bottom - rt1.top ;
			NewPosX		= (rt.right - rt.left - DlgWidth)/2;
			NewPosY		= (rt.bottom - rt.top - DlgHeight)/2;
			
			// if the About box is larger than the physical screen 
			if (NewPosX < 0) NewPosX = 0;
			if (NewPosY < 0) NewPosY = 0;
			SetWindowPos(hDlg, 0, NewPosX, NewPosY,
				0, 0, SWP_NOZORDER | SWP_NOSIZE);
		}
		return TRUE;
		
	case WM_COMMAND:
		if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
		{
			EndDialog(hDlg, LOWORD(wParam));
			return TRUE;
		}
		break;
	}
    return FALSE;
}

⌨️ 快捷键说明

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