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

📄 fullscreendlg.cpp

📁 Understanding the Shell Behavior for the CE Platforms
💻 CPP
字号:
// FullScreenDlg.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "FullScreenDlg.h"
#include <commctrl.h>
#include <aygshell.h>
#include <sipapi.h>

#define MAX_LOADSTRING 100

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

static SHACTIVATEINFO s_sai;

// 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);
HWND				CreateRpCommandBar(HWND);
BOOL CALLBACK       FullScreenDlgProc(HWND, UINT, WPARAM, LPARAM);


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_FULLSCREENDLG);

	// 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_FULLSCREENDLG));
    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 = NULL;
	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_FULLSCREENDLG, szWindowClass, MAX_LOADSTRING);
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);

	//If it is already running, then focus on the window
	hWnd = FindWindow(szWindowClass, szTitle);	
	if (hWnd) 
	{
		SetForegroundWindow ((HWND) (((DWORD)hWnd) | 0x01));    
		return 0;
	} 

	MyRegisterClass(hInstance, szWindowClass);
	
	RECT	rect;
	GetClientRect(hWnd, &rect);
	
	hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
	if (!hWnd)
	{	
		return FALSE;
	}
	//When the main window is created using CW_USEDEFAULT the height of the menubar (if one
	// is created is not taken into account). So we resize the window after creating it
	// if a menubar is present
	{
		RECT rc;
		GetWindowRect(hWnd, &rc);
		rc.bottom -= MENU_HEIGHT;
		if (hwndCB)
			MoveWindow(hWnd, rc.left, rc.top, rc.right, rc.bottom, 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)
{
	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_TACO:
				case IDM_BURRITOS:
				case IDM_TAMALES:
                    DialogBox(hInst, TEXT("FullScreenDlg"), 
                                hWnd, FullScreenDlgProc );
                    break;
				case IDM_HELP_ABOUT:
					DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
				    break;
				case IDOK:
					SendMessage(hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd);
					SendMessage (hWnd, WM_CLOSE, 0, 0);
					break;
				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_CREATE:
			hwndCB = CreateRpCommandBar(hWnd);
			break;
		case WM_PAINT:
			RECT rt;
			hdc = BeginPaint(hWnd, &ps);
			GetClientRect(hWnd, &rt);
			DrawText(hdc, TEXT("Las Comidas"), _tcslen(TEXT("Las Comidas")), &rt, 
				DT_SINGLELINE | DT_VCENTER | DT_CENTER);
			EndPaint(hWnd, &ps);
			break; 
		case WM_DESTROY:
			CommandBar_Destroy(hwndCB);
			PostQuitMessage(0);
			break;
		case WM_SETTINGCHANGE:
			SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
     		break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

HWND CreateRpCommandBar(HWND hwnd)
{
	SHMENUBARINFO mbi;

	memset(&mbi, 0, sizeof(SHMENUBARINFO));
	mbi.cbSize     = sizeof(SHMENUBARINFO);
	mbi.hwndParent = hwnd;
	mbi.nToolBarId = IDM_MENU;
	mbi.hInstRes   = hInst;
	mbi.nBmpId     = 0;
	mbi.cBmpImages = 0;

	if (!SHCreateMenuBar(&mbi)) 
		return NULL;

	return mbi.hwndMB;
}

// Mesage handler for the About box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	SHINITDLGINFO shidi;

	switch (message)
	{
		case WM_INITDIALOG:
			// Create a Done button and size it.  
			shidi.dwMask = SHIDIM_FLAGS;
			shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
			shidi.hDlg = hDlg;
			SHInitDialog(&shidi);
			return TRUE; 

		case WM_COMMAND:
			if (LOWORD(wParam) == IDOK) {
				EndDialog(hDlg, LOWORD(wParam));
				return TRUE;
			}
			break;
	}
    return FALSE;
}

//----------------------------------------------------------------------
// FullScreenDlgProc
//----------------------------------------------------------------------
BOOL CALLBACK FullScreenDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
    SHINITDLGINFO shidi;
    MENUITEMINFO mii;
    HWND hWndParent, hWndBmp;
    HMENU hSHMenu;
    RECT rc;
    HDC hdc, hdcMemory;
    BITMAP bmp;
    HBITMAP hBmp;
    int cx, cy;
    BOOL bOk;

  // Valid states
  //#define SHFS_SHOWTASKBAR            0x0001
  //#define SHFS_HIDETASKBAR            0x0002
  //#define SHFS_SHOWSIPBUTTON          0x0004
  //#define SHFS_HIDESIPBUTTON          0x0008
  //#define SHFS_SHOWSTARTICON          0x0010
  //#define SHFS_HIDESTARTICON          0x0020
	
    switch (wMsg) 
	{
      case WM_INITDIALOG:
          hWndParent = GetParent(hWnd);
          //
          // Valid mask values
          //#define SHIDIM_FLAGS                0x0001
  
          shidi.hDlg = hWnd;
          shidi.dwMask = SHIDIM_FLAGS;
          shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIZEDLGFULLSCREEN;
  
          SHInitDialog(&shidi);
  
          SHFullScreen(hWnd, SHFS_HIDETASKBAR );
          SHFullScreen(hWndParent, SHFS_HIDESIPBUTTON );
          ShowWindow(hwndCB, SW_HIDE);
          hdc = GetDC(hWnd);
          cx = GetDeviceCaps(hdc, HORZRES);
          cy = GetDeviceCaps(hdc, VERTRES);
          ReleaseDC(hWnd, hdc);

          rc.left = 0; 
          rc.top = 0;
          rc.right = cx;
          rc.bottom = cy;
          MoveWindow(hWnd, rc.left, rc.top, rc.right, rc.bottom, TRUE); 

  
          hSHMenu = (HMENU)SendMessage((hwndCB), 
                        SHCMBM_GETMENU, (WPARAM)0, 
                        (LPARAM)IDM_MENU);

          InsertMenu(hSHMenu, 0, MF_BYPOSITION | MF_STRING, 
              IDM_TACO +3, TEXT("Enchiladas"));
                     
          memset((char *)&mii, 0, sizeof(mii));
          mii.cbSize = sizeof(mii); 
          mii.fMask  = MIIM_TYPE;
          mii.dwTypeData = TEXT("Enchiladas");
          mii.cch = MAX_LOADSTRING;
          mii.fType =  MFT_STRING; 
          GetMenuItemInfo(hSHMenu, IDM_MENU, FALSE, &mii);
  
          SHSetNavBarText(hWndParent, TEXT("Ole!"));
          SHDoneButton(hWndParent, SHDB_SHOW);

          break;

        case WM_COMMAND:
          
         switch (LOWORD (wParam)) 
          {
           case IDOK:
           case IDCANCEL:
            EndDialog (hWnd, 1);
            ShowWindow(hwndCB, SW_SHOW);
            return TRUE;

	        default:
			        break;
          }

        break;

		default:
			break;
	}//end switch (wMsg) 
 return FALSE;	
}

⌨️ 快捷键说明

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