getdeviceid.cpp
来自「WIndows mobile 5.0 pocket pc sdk sample 」· C++ 代码 · 共 502 行 · 第 1/2 页
CPP
502 行
*pszBuffer = _T('\0');
*pcbAdded = 2;
hr = S_OK;
}
return hr;
}
// Generate printable version of device ID
static HRESULT DeviceID2String (const BYTE * const bDeviceID, const DWORD cbDeviceID, const LPTSTR pszIDAsString, const DWORD cbIDAsString)
{
HRESULT hr;
LPTSTR pszOutput = pszIDAsString;
DWORD cbOutputRemaining = cbIDAsString;
DWORD i;
DWORD cbAdded;
for (i = 0; i < cbDeviceID; ++i)
{
hr = HexString (bDeviceID[i], pszOutput, cbOutputRemaining, &cbAdded);
if (FAILED (hr))
{
break;
}
cbOutputRemaining -= cbAdded;
pszOutput += cbAdded;
}
return hr;
}
static void OnPaint (HWND hWnd, HFONT hFont)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rt;
TEXTMETRIC tm;
TCHAR szDeviceID[(GETDEVICEUNIQUEID_V1_OUTPUT * 2) + 1];
TCHAR szHeader[MAX_LOADSTRING];
hdc = BeginPaint(hWnd, &ps);
if (hFont)
{
SelectObject (hdc, hFont);
}
GetClientRect(hWnd, &rt);
GetTextMetrics (hdc, &tm);
// Display the first ID
if (SUCCEEDED (DeviceID2String (g_bDeviceID1, g_cbDeviceID1, szDeviceID, ARRAYSIZE (szDeviceID))))
{
LoadString(g_hInst, IDS_DEVICEID1, szHeader, MAX_LOADSTRING);
rt.bottom = tm.tmHeight + tm.tmExternalLeading;
DrawText (hdc, szHeader, -1, &rt, DT_CENTER);
rt.top = rt.bottom;
rt.bottom += tm.tmHeight + tm.tmExternalLeading;
DrawText (hdc, szDeviceID, 10, &rt, DT_CENTER);
rt.top = rt.bottom;
rt.bottom += tm.tmHeight + tm.tmExternalLeading;
DrawText (hdc, &szDeviceID[10], 10, &rt, DT_CENTER);
}
// Display the second ID
if (SUCCEEDED (DeviceID2String (g_bDeviceID2, g_cbDeviceID2, szDeviceID, ARRAYSIZE (szDeviceID))))
{
LoadString(g_hInst, IDS_DEVICEID2, szHeader, MAX_LOADSTRING);
rt.top = rt.bottom + tm.tmHeight + tm.tmExternalLeading;
rt.bottom = rt.top + tm.tmHeight + tm.tmExternalLeading;
DrawText (hdc, szHeader, -1, &rt, DT_CENTER);
rt.top = rt.bottom;
rt.bottom += tm.tmHeight + tm.tmExternalLeading;
DrawText (hdc, szDeviceID, 10, &rt, DT_CENTER);
rt.top = rt.bottom;
rt.bottom += tm.tmHeight + tm.tmExternalLeading;
DrawText (hdc, &szDeviceID[10], 10, &rt, DT_CENTER);
}
EndPaint(hWnd, &ps);
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// 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)
{
int wmId, wmEvent;
static HFONT hFont;
#if defined(SHELL_AYGSHELL) && !defined(WIN32_PLATFORM_WFSP)
static SHACTIVATEINFO s_sai;
#endif // SHELL_AYGSHELL && !WIN32_PLATFORM_WFSP
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
#ifndef WIN32_PLATFORM_WFSP
case IDM_HELP_ABOUT:
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
break;
#endif // !WIN32_PLATFORM_WFSP
#ifdef WIN32_PLATFORM_WFSP
case IDM_OK:
DestroyWindow(hWnd);
break;
#endif // WIN32_PLATFORM_WFSP
#ifndef WIN32_PLATFORM_WFSP
case IDM_OK:
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
#endif // !WIN32_PLATFORM_WFSP
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_CREATE:
#ifdef SHELL_AYGSHELL
SHMENUBARINFO mbi;
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hWnd;
mbi.nToolBarId = IDR_MENU;
mbi.hInstRes = g_hInst;
if (!SHCreateMenuBar(&mbi))
{
g_hWndMenuBar = NULL;
}
else
{
g_hWndMenuBar = mbi.hwndMB;
}
#ifndef WIN32_PLATFORM_WFSP
// Initialize the shell activate info structure
memset(&s_sai, 0, sizeof (s_sai));
s_sai.cbSize = sizeof (s_sai);
#endif // !WIN32_PLATFORM_WFSP
#endif // SHELL_AYGSHELL
// Create a fixed pitch font to display results
LOGFONT lf;
HDC hdc;
memset (&lf, 0, sizeof (lf));
hdc = GetDC (hWnd);
lf.lfHeight = -MulDiv (10, GetDeviceCaps (hdc, LOGPIXELSY), 72);
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfWeight = FW_NORMAL;
lf.lfPitchAndFamily = FIXED_PITCH || FF_DONTCARE;
hFont = CreateFontIndirect (&lf);
ReleaseDC (hWnd, hdc);
break;
case WM_PAINT:
OnPaint (hWnd, hFont);
break;
case WM_DESTROY:
#ifdef SHELL_AYGSHELL
CommandBar_Destroy(g_hWndMenuBar);
#endif // SHELL_AYGSHELL
PostQuitMessage(0);
break;
#if defined(SHELL_AYGSHELL) && !defined(WIN32_PLATFORM_WFSP)
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;
#endif // SHELL_AYGSHELL && !WIN32_PLATFORM_WFSP
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
#ifndef WIN32_PLATFORM_WFSP
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
#ifdef SHELL_AYGSHELL
{
// Create a Done button and size it.
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
}
#endif // SHELL_AYGSHELL
return (INT_PTR)TRUE;
case WM_COMMAND:
#ifdef SHELL_AYGSHELL
if (LOWORD(wParam) == IDOK)
#endif
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
case WM_CLOSE:
EndDialog(hDlg, message);
return (INT_PTR)TRUE;
#ifdef _DEVICE_RESOLUTION_AWARE
case WM_SIZE:
{
DRA::RelayoutDialog(
g_hInst,
hDlg,
DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_ABOUTBOX_WIDE) : MAKEINTRESOURCE(IDD_ABOUTBOX));
}
break;
#endif
}
return (INT_PTR)FALSE;
}
#endif // !WIN32_PLATFORM_WFSP
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?