wnavi.cpp

来自「自己做的基于PPC2003的GPS信号接收程序」· C++ 代码 · 共 485 行

CPP
485
字号
// wnavi.cpp : Defines the entry point for the application.
//

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

// Start: Added by wangxu.
#include <voicectl.h>

// End: Added by wangxu.

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE		g_hInst;				// The current instance
HWND			g_hwndCB;				// The command bar handle

// Start: Added by wangxu.
HMENU			g_hMenuPopup;			// The popup menu handle.

// End: Added by wangxu.

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

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

	// 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_WNAVI));
    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

	g_hInst = hInstance;		// Store instance handle in our global variable
	// Initialize global strings
	LoadString(hInstance, IDC_WNAVI, szWindowClass, MAX_LOADSTRING);
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);

	// load the menu resource to use later
	g_hMenuPopup = LoadMenu(g_hInst, MAKEINTRESOURCE(IDM_MENUPOPUP)); // Added by wangxu.

	//If it is already running, then focus on the window
	hWnd = FindWindow(szWindowClass, szTitle);	
	if (hWnd) 
	{
		// set focus to foremost child window
		// The "| 0x01" is used to bring any owned windows to the foreground and
		// activate them.
		SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
		return 0;
	} 

	MyRegisterClass(hInstance, szWindowClass);
	
	hWnd = CreateWindow(szWindowClass, 
						szTitle, 
						WS_VSCROLL | WM_HSCROLL | WS_VISIBLE,  //WS_VISIBLE, Modified by Wangxu.
						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
	if (g_hwndCB)
    {
		RECT rc;
        RECT rcMenuBar;

		GetWindowRect(hWnd, &rc);
        GetWindowRect(g_hwndCB, &rcMenuBar);
		rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
		MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, 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;

	LPNMHDR pnmh;	// Added by wangxu.

	switch (message) 
	{
		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:
			switch (wmId)
			{	
				case IDM_HELP_ABOUT:
					DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
				    break;
				case IDOK:
					SendMessage (hWnd, WM_CLOSE, 0, 0);
					break;
				case ID_MENU_EXIT:	// Added by wangxu.
					SendMessage (hWnd, WM_CLOSE, 0, 0);
					break;
				case ID_MENU_HELP:	// Added by wangxu.
					MessageBox(NULL, _T("Help..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_SETTING:	// Added by wangxu.
					MessageBox(NULL, _T("Setting..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_MAPMGR:	// Added by wangxu.
					MessageBox(NULL, _T("Map Mgr..."), _T("ToDo"), MB_OK);
				    break;
				case ID_MENU_WAYPOINTMGR:	// Added by wangxu.
					MessageBox(NULL, _T("WayPointMgr..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_RM_LOADROUTE:	// Added by wangxu.
					MessageBox(NULL, _T("LoadRoute..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_RM_SAVEROUTE:	// Added by wangxu.
					MessageBox(NULL, _T("SaveRoute..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_RM_DELETEROUTE:	// Added by wangxu.
					MessageBox(NULL, _T("DeleteRoute..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_RM_SIMULATEROUTE:	// Added by wangxu.
					MessageBox(NULL, _T("SimulateRoute..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_RM_PAUSESIMULATE:	// Added by wangxu.
					MessageBox(NULL, _T("PauseSimulate..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_RM_STOPSIMULATE:	// Added by wangxu.
					MessageBox(NULL, _T("StopSimulate..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_TM_LOADTRACK:	// Added by wangxu.
					MessageBox(NULL, _T("LoadTrack..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_TM_SAVETRACK:	// Added by wangxu.
					MessageBox(NULL, _T("SaveTrack..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_TM_DELETETRACK:	// Added by wangxu.
					MessageBox(NULL, _T("DeleteTrack..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_TM_PLAYTRACK:	// Added by wangxu.
					MessageBox(NULL, _T("PlayTrack..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_TM_PAUSEPLAY:	// Added by wangxu.
					MessageBox(NULL, _T("PausePlay..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_TM_STOPPLAY:	// Added by wangxu.
					MessageBox(NULL, _T("StopPlay..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_MC_NORMAL:	// Added by wangxu.
					MessageBox(NULL, _T("Normal..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENU_MC_NIGHT:	// Added by wangxu.
					MessageBox(NULL, _T("Night..."), _T("ToDo"), MB_OK);
					break;
				case ID_TOOLBAR_ZOOMIN:	// Added by wangxu.
					MessageBox(NULL, _T("ZoomIn..."), _T("ToDo"), MB_OK);
					break;
				case ID_TOOLBAR_ZOOMOUT:	// Added by wangxu.
					MessageBox(NULL, _T("ZoomOut..."), _T("ToDo"), MB_OK);
					break;
				case ID_TOOLBAR_SEARCH:	// Added by wangxu.
					MessageBox(NULL, _T("Search..."), _T("ToDo"), MB_OK);
					break;
				case ID_TOOLBAR_PLANROUTE:	// Added by wangxu.
					MessageBox(NULL, _T("PlanRoute..."), _T("ToDo"), MB_OK);
					break;
				case ID_TOOLBAR_GPS:	// Added by wangxu.
					MessageBox(NULL, _T("GPS..."), _T("ToDo"), MB_OK);
					break;
				case ID_TOOLBAR_AUDIOREC:	// Added by wangxu.
					//MessageBox(NULL, _T("AudioRecorder..."), _T("ToDo"), MB_OK);

					// Start: Voice Recorder create.
					// Be sure that the owner window exists
					if (!IsWindow(hWnd)) 
						return FALSE;

					// initialize the control's data structure.
					CM_VOICE_RECORDER cmvr;
					memset( &cmvr, 0, sizeof(cmvr));
					cmvr.cb = sizeof(CM_VOICE_RECORDER);
					cmvr.dwStyle = VRS_NO_MOVE;
					cmvr.xPos = -1; // Use -1 to center the control relative to owner.
					cmvr.yPos = 240;
					cmvr.hwndParent = hWnd;
					cmvr.lpszRecordFileName = _T("\\My Documents\\VoiceRec.wav");

					// Returns the handle to the control.
					HWND hwndVoiceRec;
					hwndVoiceRec = VoiceRecorder_Create(&cmvr);
					if (hwndVoiceRec == NULL)
						MessageBox(NULL, _T("VoiceRecorder create failed."), NULL, MB_OK);
					// End: Voice Recorder create.

					break;
				case ID_TOOLBAR_NAVI:	// Added by wangxu.
					MessageBox(NULL, _T("Navi..."), _T("ToDo"), MB_OK);
					break;
				case ID_TOOLBAR_WANDERNAVI:	// Added by wangxu.
					MessageBox(NULL, _T("WanderNavi..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENUPOPUP_ADDWAYPOINT:	// Added by wangxu.
					MessageBox(NULL, _T("Add WayPoint..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENUPOPUP_MODIFYWAYPOINT:	// Added by wangxu.
					MessageBox(NULL, _T("Modify WayPoint..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENUPOPUP_DELETEWAYPOINT:	// Added by wangxu.
					MessageBox(NULL, _T("Delete WayPoint..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENUPOPUP_SETSTARTPOINT:	// Added by wangxu.
					MessageBox(NULL, _T("SetStartPoint..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENUPOPUP_SETPASSPOINT:	// Added by wangxu.
					MessageBox(NULL, _T("SetPassPoint..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENUPOPUP_SETENDPOINT:	// Added by wangxu.
					MessageBox(NULL, _T("SetEndPoint..."), _T("ToDo"), MB_OK);
					break;
				case ID_MEMUPOPUP_DELETEPOINT:	// Added by wangxu.
					MessageBox(NULL, _T("DeletePoint..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENUPOPUP_PLANROUTE:	// Added by wangxu.
					MessageBox(NULL, _T("PlanRoute..."), _T("ToDo"), MB_OK);
					break;
				case ID_MENUPOPUP_FULLSCREEN:	// Added by wangxu.
					//MessageBox(NULL, _T("FullScreen..."), _T("ToDo"), MB_OK);

					RECT rc;
					RECT rcMenuBar;
					GetWindowRect(hWnd, &rc);
					GetWindowRect(g_hwndCB, &rcMenuBar);
					SHFullScreen(hWnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON |  SHFS_HIDESTARTICON);
					MoveWindow( hWnd, rc.left, rc.top - (rcMenuBar.bottom - rcMenuBar.top), 
							rc.right, rc.bottom + (rcMenuBar.bottom - rcMenuBar.top), FALSE);

					break;
				default:
					return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_LBUTTONDOWN:	// Added by wangxu.
			SHRGINFO  shrg;
			HMENU    hmenu;

			shrg.cbSize = sizeof(shrg);
			shrg.hwndClient = hWnd;
			shrg.ptDown.x = LOWORD(lParam);
			shrg.ptDown.y = HIWORD(lParam);
			shrg.dwFlags = SHRG_RETURNCMD;

			if (SHRecognizeGesture(&shrg) == GN_CONTEXTMENU) {
				hmenu = GetSubMenu(g_hMenuPopup, 0);
				TrackPopupMenuEx(hmenu, TPM_LEFTALIGN, LOWORD(lParam), HIWORD(lParam), hWnd, NULL);
			}

			//MessageBox(NULL, _T("LeftButtonDown..."), _T("ToDo"), MB_OK);

			break;
		case WM_NOTIFY:		// Added by wangxu.

			// Start: Handler Voice Recorder Msg.
			pnmh = (LPNMHDR) lParam;
			switch (pnmh->code)
			{
				case VRN_ERROR:
					MessageBox(NULL, _T("VoiceRecorder error..."), _T("Error..."), MB_OK);
					break;
				case VRN_RECORD_START:
					//MessageBox(NULL, _T("Recording..."), _T("Recording..."), MB_OK);
					break;
				case VRN_RECORD_STOP:
					//MessageBox(NULL, _T("Stop recording..."), _T("Stop recording..."), MB_OK);
					break;
				case VRN_PLAY_START:
					//MessageBox(NULL, _T("Playing..."), _T("Playing..."), MB_OK);
					break;
				case VRN_PLAY_STOP:
					//MessageBox(NULL, _T("Stop playing..."), _T("Stop playing..."), MB_OK);
					break;
				case VRN_CANCEL:
					//MessageBox(NULL, _T("Cancel..."), _T("Cancel..."), MB_OK);
					break;
				case VRN_OK:
					//MessageBox(NULL, _T("OK..."), _T("OK..."), MB_OK);
					break;
				default:
					return DefWindowProc(hWnd, message, wParam, lParam);
			}
			// End: Handler Voice Recorder Msg.

			break;
		case WM_CREATE:
			g_hwndCB = CreateRpCommandBar(hWnd);
            // Initialize the shell activate info structure
            memset (&s_sai, 0, sizeof (s_sai));
            s_sai.cbSize = sizeof (s_sai);
			break;
		case WM_PAINT:
			RECT rt;
			TEXTMETRIC tm;
			INT i, cy;
			TCHAR szOut[MAX_LOADSTRING];
			//TCHAR szHello[MAX_LOADSTRING];

			hdc = BeginPaint(hWnd, &ps);
			GetClientRect(hWnd, &rt);
			//LoadString(g_hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
			//DrawText(hdc, szHello, _tcslen(szHello), &rt, DT_SINGLELINE);
			
			// Get a line height.
			GetTextMetrics (hdc, &tm);    
			cy = tm.tmHeight + tm.tmExternalLeading;

			rt.bottom = rt.top + cy;
			for (i = 0; i < 20; i++) 
			{
				wsprintf (szOut, _T("Line: %d "), i);
				DrawText(hdc, szOut, -1, &rt, DT_SINGLELINE);

				rt.top += cy;
				rt.bottom += cy;
			}

			EndPaint(hWnd, &ps);
			break; 
		case WM_DESTROY:
			CommandBar_Destroy(g_hwndCB);
			PostQuitMessage(0);
			break;
		case WM_ACTIVATE:
            // Notify shell of our activate message
			SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
     		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   = g_hInst;
	mbi.nBmpId     = IDT_TOOLBAR;	// Modified by wangxu.
	mbi.cBmpImages = 8;				// Modified by wangxu.

	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;
}

⌨️ 快捷键说明

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