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

📄 sample.cpp

📁 这是WINCE程序进行无边框全屏显示的代码
💻 CPP
字号:
#include "sample.h"

int WINAPI WinMain(	HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR pCmdLine, int nCmdShow)
{

	HWND	hWnd;
	MSG		msg;
	

	// NOTE: Over here, the hPrevInstance is always NULL for WIN32 application
	//		 Hence, there is either usaing CreateMutex or FindWindow to find
	//		 the previous application window base on the respective registed
	//		 windows class or window name

	// Check for previous instance
	hWnd = FindWindow(TEXT("sample"), TEXT("sample"));
	if (hWnd != NULL)
	{
		// Show the previous window
		SetForegroundWindow(hWnd);
		// Unload the current instance
		return false;
	}

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

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, NULL, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return msg.wParam;
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
	__try
	{
		// Backup the current application instance
		hInst = hInstance;
		// Register main window class
		MyRegisterClass(hInstance);
		// Create main window
		hWndMain = CreateWindow(TEXT("sample"),
								TEXT("sample"),
								WS_VISIBLE,
								0,
								26,
								240,
								268,
								NULL,
								NULL,
								hInstance,
								NULL);
	
		if (!hWndMain)
			return FALSE;
		// Show current main window
		ShowWindow(hWndMain, SW_SHOW);

		UpdateWindow(hWndMain);
		if (hWndRBar)
			CommandBar_Show(hWndRBar, TRUE);

		return TRUE;
	}
	__except(EXCEPTION_EXECUTE_HANDLER)
	{
		// DO NOTHING
	}

	// Set return value
	return FALSE;
}

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			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SAMPLE));
    wc.hCursor			= 0;
    wc.hbrBackground	= (HBRUSH) GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName		= 0;
    wc.lpszClassName	= TEXT("sample");

	return RegisterClass(&wc);
}


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) 
	{
		case WM_CREATE:
			// Create Command Band
			CreateCommandBand(hWnd);
			// Initialize full screen capability
			InitFullScreen();
			break;
		case WM_COMMAND:
			switch (LOWORD(wParam))
			{
				case IDM_FILE_EXIT:
					// Destroy the XXX Application main windows
					DestroyWindow(hWnd);
					break;
				case IDM_FILE_FULLSCREEN:
					// Enable/Disable Full Screen
					ShowFullScreen();
					break;
			}
			break;
		case WM_DESTROY:
			// Reset the window 
			DoFullScreen(false);
			// Destroy the used menu
			if (hMenu != NULL)
				DestroyMenu(hMenu);
			if (hWndCBar1 != NULL)
				CommandBar_Destroy(hWndCBar1);
			if (hWndRBar != NULL)
				CommandBar_Destroy(hWndRBar);
			//
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

int CreateCommandBand (HWND hWnd)
{
	__try
	{
		INITCOMMONCONTROLSEX	iccex;
		// Ensure teh Commond Control DLL is loaded
		iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
		iccex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES;
		// Register toolbar and rebar control classes from DLL for the common control.
		InitCommonControlsEx (&iccex);

		// REBARBANDINFO structures for command bands
		REBARBANDINFO rbi;

		// Create the command bands control.
		if (!(hWndRBar = CommandBands_Create (hInst, hWnd, 0, RBS_VERTICALGRIPPER | RBS_BANDBORDERS | RBS_AUTOSIZE, NULL)))
			return 0;

		// REBARBANDINFO for the menu band.
		rbi.cbSize = sizeof (REBARBANDINFO);
		rbi.fMask = RBBIM_STYLE | RBBIM_ID | RBBIM_SIZE;
		rbi.fStyle = RBBS_CHILDEDGE | RBBS_GRIPPERALWAYS | RBBS_VARIABLEHEIGHT;
		rbi.wID = IDR_MAINMENU;
		rbi.cx = 240;
		rbi.cyMaxChild = 24;
		rbi.cxMinChild = 0;

		// Adds bands to the command bands control. 
		if (!CommandBands_AddBands (hWndRBar, hInst, 1, &rbi))
			return NULL;

		// Insert a menu bar into the menu command band. 
		if (hWndCBar1 = CommandBands_GetCommandBar (hWndRBar, 0))
		{
			// Insert menubar into CommandBar Band #1
			CommandBar_InsertMenubar (hWndCBar1, hInst, IDR_MAINMENU, 0);
			// Get the MenuBar handle inserted into the CommandBar Band#1
			hMenu = CommandBar_GetMenu(hWndCBar1, 0);
		}

		return 1;
	}
	__except(EXCEPTION_EXECUTE_HANDLER)
	{
		// PUT YOUR ERROR LOG CODING HERE
	}
	// Set return value
	return 0;
}

void ShowFullScreen(void)
{

	RECT			rt;
	MENUITEMINFO	lpmii;

	__try
	{
		// Get the respective menu state
		lpmii.cbSize = sizeof(MENUITEMINFO);
		lpmii.fMask = MIIM_STATE;
		GetMenuItemInfo(hMenu, IDM_FILE_FULLSCREEN, false, &lpmii);

		if (lpmii.fState == MFS_UNCHECKED)
		{
			// Make full screen
			DoFullScreen(true);

			// Sesize Window
			MoveWindow(hWndMain, 
						rtNewDesktop.left, 
						rtNewDesktop.top, 
						rtNewDesktop.right-rtNewDesktop.left,
						rtNewDesktop.bottom-rtNewDesktop.top, 
						false);

			// Reposition the Command bar
			MoveWindow(hWndRBar, 
						rtNewDesktop.left, 
						rtNewDesktop.top,
						24,
						240, 
						false);

			// Check the Full Screen submenu
			CheckMenuItem(hMenu, IDM_FILE_FULLSCREEN, MF_BYCOMMAND | MF_CHECKED);
		}
		else
		{
			// Restore the original window size
			DoFullScreen(false);

			// Sesize Window
			MoveWindow(hWndMain, 
						rtDesktop.left,
						rtDesktop.top,
						rtDesktop.right-rtDesktop.left,
						(rtDesktop.bottom-rtDesktop.top) - (rtTaskBar.bottom - rtTaskBar.top), 
						false);

			// Get main window working area
			GetClientRect(hWndMain, &rt);

			// Reposition the Command bar
			MoveWindow(hWndRBar, 
						rt.left, 
						rt.top, 
						0,
						0, 
						false);

			// Unchecked Full Screen submenu
			CheckMenuItem(hMenu, IDM_FILE_FULLSCREEN, MF_BYCOMMAND | MF_UNCHECKED);
		}
	}
	__except(EXCEPTION_EXECUTE_HANDLER)
	{
		// PUT YOUR ERROR LOG CODING HERE
	}
}

⌨️ 快捷键说明

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