📄 timeviewer.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/***********************************************************************
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
MODULE: TimeViewer.cpp
PURPOSE: Desktop component of sample application using ITL.
COMMENTS: N/A
***********************************************************************/
#define INITGUID
#include <windows.h>
#include <objbase.h>
#include "cemgr.h"
#include "cemgrui.h"
#include "resource.h"
#include "..\include\TvCommon.h"
#include "TimeViewer.h"
#include <cemgr_i.c>
#include <cemgrui_i.c>
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR g_szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR g_szWindowClass[MAX_LOADSTRING]; // The title bar text
IPlatformManager *g_piMgr = NULL;
IConnectionStream *g_piStream;
char g_szMessage[80];
//**********************************************************************
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
//**********************************************************************
{
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, g_szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_TIMEVIEWER, g_szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TIMEVIEWER);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
if (g_piStream)
{
DisconnectFromDevice(NULL);
}
CoUninitialize();
return msg.wParam;
}
//**********************************************************************
ATOM MyRegisterClass(HINSTANCE hInstance)
//**********************************************************************
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_TIMEVIEWER);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_TIMEVIEWER;
wcex.lpszClassName = g_szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
//**********************************************************************
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
//**********************************************************************
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(g_szWindowClass, g_szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, 450, 500, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
UpdateMenu(hWnd, FALSE);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (FAILED(hr))
{
::MessageBox(hWnd,
"CoInitializeEx Failed",
"Add Connection",
MB_OK);
}
return TRUE;
}
//**********************************************************************
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
//**********************************************************************
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case ID_CONNECTION_CONNECTTODEVICE:
ConnectToDevice(hWnd);
Refresh(hWnd);
break;
case ID_CONNECTION_DISCONNECTFROMDEVICE:
DisconnectFromDevice(hWnd);
break;
case ID_CONNECTION_REFRESH:
Refresh(hWnd);
break;
case ID_CONNECTION_CONFIGUREPLATFORMMANAGER:
ConfigurePlatMan(hWnd);
break;
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DisconnectFromDevice(NULL);
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc,
g_szMessage,
strlen(g_szMessage),
&rt,
DT_SINGLELINE | DT_VCENTER | DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
//**********************************************************************
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
//**********************************************************************
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
//**********************************************************************
BOOL ConnectToDevice(HWND hWnd)
//**********************************************************************
{
IPlatformManagerUI *piMgrUI = NULL;
IRemoteDevice *piDevice = NULL;
IConnection *piConnection = NULL;
IPlatformCE *piPlatform = NULL;
HMENU hMenu = NULL;
size_t stRet = 0;
TCHAR szText[80];
DWORD dwSize = 0;
BOOL bConnected = FALSE;
//------------------------------------------------------------------
// Instantiate the IPlatformManager COM object
//------------------------------------------------------------------
HRESULT hr = CoCreateInstance(CLSID_PlatformManager,
NULL,
CLSCTX_LOCAL_SERVER,
IID_IPlatformManager,
(void**)&g_piMgr);
if (FAILED(hr))
{
::MessageBox(hWnd,
"Unable to instantiate Platform Manager",
"Connect To Device",
MB_OK);
goto Exit;
}
//------------------------------------------------------------------
// Instantiate the IPlatformManagerUI COM object
//------------------------------------------------------------------
hr = CoCreateInstance(CLSID_PlatformManagerUI,
NULL,
CLSCTX_INPROC_SERVER,
IID_IPlatformManagerUI,
(void**)&piMgrUI) ;
if (FAILED(hr))
{
::MessageBox(hWnd,
"Unable to instantiate Platform Manager UI",
"Connect To Device",
MB_OK);
goto Exit;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -