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

📄 bb.cpp

📁 一套完整的wince内核定制实验源代码
💻 CPP
字号:
// bb.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"
/*
#include <celog.h>



        // Definitions for our debug zones                               
        #define ZONEID_INIT      0
        #define ZONEID_TRACE     1
        #define ZONEID_MEMORY    2
        #define ZONEID_RSVD3     3
        #define ZONEID_RSVD4     4
        #define ZONEID_RSVD5     5
        #define ZONEID_RSVD6     6
        #define ZONEID_RSVD7     7
        #define ZONEID_RSVD8     8
        #define ZONEID_RSVD9     9
        #define ZONEID_RSVD10   10
        #define ZONEID_RSVD11   11
        #define ZONEID_RSVD12   12
        #define ZONEID_RSVD13   13        
        #define ZONEID_WARN     14
        #define ZONEID_ERROR    15

        // These masks are useful for initialization of dpCurSettings
        #define ZONEMASK_INIT      (1<<ZONEID_INIT) 
        #define ZONEMASK_TRACE     (1<<ZONEID_TRACE) 
        #define ZONEMASK_MEMORY    (1<<ZONEID_MEMORY) 
        #define ZONEMASK_RSVD3     (1<<ZONEID_RSVD3) 
        #define ZONEMASK_RSVD4     (1<<ZONEID_RSVD4) 
        #define ZONEMASK_RSVD5     (1<<ZONEID_RSVD5) 
        #define ZONEMASK_RSVD6     (1<<ZONEID_RSVD6) 
        #define ZONEMASK_RSVD7     (1<<ZONEID_RSVD7) 
        #define ZONEMASK_RSVD8     (1<<ZONEID_RSVD8) 
        #define ZONEMASK_RSVD9     (1<<ZONEID_RSVD9) 
        #define ZONEMASK_RSVD10    (1<<ZONEID_RSVD10)
        #define ZONEMASK_RSVD11    (1<<ZONEID_RSVD11)
        #define ZONEMASK_RSVD12    (1<<ZONEID_RSVD12)
        #define ZONEMASK_RSVD13    (1<<ZONEID_RSVD13)        
        #define ZONEMASK_WARN      (1<<ZONEID_WARN )  
        #define ZONEMASK_ERROR     (1<<ZONEID_ERROR) 
 
#ifdef DEBUG
        // These macros are used as the first arg to DEBUGMSG
        #define ZONE_INIT       DEBUGZONE(ZONEID_INIT)
        #define ZONE_TRACE      DEBUGZONE(ZONEID_TRACE)
        #define ZONE_MEMORY     DEBUGZONE(ZONEID_MEMORY)
        #define ZONE_RSVD3      DEBUGZONE(ZONEID_RSVD3)
        #define ZONE_RSVD4      DEBUGZONE(ZONEID_RSVD4)
        #define ZONE_RSVD5      DEBUGZONE(ZONEID_RSVD5)
        #define ZONE_RSVD6      DEBUGZONE(ZONEID_RSVD6)
        #define ZONE_RSVD7      DEBUGZONE(ZONEID_RSVD7)
        #define ZONE_RSVD8      DEBUGZONE(ZONEID_RSVD8)
        #define ZONE_RSVD9      DEBUGZONE(ZONEID_RSVD9)
        #define ZONE_RSVD10     DEBUGZONE(ZONEID_RSVD10)
        #define ZONE_RSVD11     DEBUGZONE(ZONEID_RSVD11)
        #define ZONE_RSVD12     DEBUGZONE(ZONEID_RSVD12)
        #define ZONE_RSVD13     DEBUGZONE(ZONEID_RSVD13)
        #define ZONE_WARN       DEBUGZONE(ZONEID_WARN )
        #define ZONE_ERROR      DEBUGZONE(ZONEID_ERROR)
#endif

DBGPARAM dpCurSettings = {
    TEXT("MemLeak"), {
        TEXT("Init"),TEXT("Trace Fn( );"),TEXT("Memory"),TEXT(""),
        TEXT(""),TEXT(""),TEXT(""),TEXT(""),
        TEXT(""),TEXT(""),TEXT(""),TEXT(""),
        TEXT(""),TEXT(""),TEXT(""),TEXT("")},
    // By default, turn on the zones for init and errors.
    ZONEMASK_INIT    
}; 

*/


#define MAX_LOADSTRING 100


// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];								// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];								// The title bar text

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

int WINAPI WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR     lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

//	DEBUGREGISTER(NULL);      // Register the debug zones


	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_BB, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_BB);

	// 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:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASS wc;

    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = (WNDPROC) WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = 0;
    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;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
      0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   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)
{
	PAINTSTRUCT ps;
	HDC hdc;
	TCHAR szHello[MAX_LOADSTRING];
	LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

	switch (message) 
	{
		case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			// TODO: Add any drawing code here...
			RECT rt;
			GetClientRect(hWnd, &rt);
			DrawText(hdc, szHello, _tcslen(szHello), &rt, DT_CENTER);
			EndPaint(hWnd, &ps);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		case WM_LBUTTONDOWN:
			{
				static int flag = 0;
				static HANDLE hMem = NULL;
				static HANDLE hMem2 = NULL;
								
				switch(flag)
				{

				case 0:

					// Resevering Memory , 2 pages, 8K
					
					hMem = VirtualAlloc(NULL, 1024 * 4 * 2, MEM_RESERVE, PAGE_READWRITE);
					NKDbgPrintfW(TEXT("hMem is %p. \r\n"), hMem);
					flag ++;
					break;
				case 1:
					hMem2 = VirtualAlloc(NULL, 1024 * 4, MEM_RESERVE, PAGE_READONLY);
					NKDbgPrintfW( L"hMem2 is %p. \r\n", hMem2);
					flag ++;
					break;
				case 2:
					// Commit Memory, 1K
					VirtualAlloc(hMem, 1024, MEM_COMMIT, PAGE_READWRITE);
					flag ++;
					break;
				case 3:
					// Release Memory
					VirtualFree(hMem, 1024 * 4 * 2, MEM_RELEASE);
					flag  = 1;
					break;
				default:
					;
					// error here
				}
			}

			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

⌨️ 快捷键说明

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