How Do I Programmatically Turn the PPT8866 Bluetooth Radio On/Off?

Article ID: 11057322

Question

How Do I Programmatically Turn the PPT8866 Bluetooth Radio On/Off?

Facts

PPT8866 WM 2003 running images from DCP1.3

Answer

The Bluetooth radio on a PPT8866 (running WM2003 DCP 1.3 image) can be programmatically turned on or off.

This can be done usingMicrosoft Bluetooth APIs.  The APIs areBthGetMode() and BthSetMode().  The Microsoft help file within eVC ++ 4.0 explains their usage.  Below is sample source code for BthGetMode().  BthSetMode is similar.

[BthGetModeSample.cpp]
 
// BthGetModeSample.cpp : Defines the entry point for the application.

//

#include "stdafx.h"
#include "BthGetModeSample.h"
#include <commctrl.h>
#include <aygshell.h>
#include <sipapi.h>
#include <bthutil.h>
#include <winsock.h>
#include <ws2bth.h>

#define MAX_LOADSTRING 100

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

static SHACTIVATEINFO s_sai;
static HWND                             nWndDebugData;
CRITICAL_SECTION      m_CritSectBT;
DWORD            ThreadID;
HANDLE           hThread;
// 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);
void                                           LogData(WCHAR *szStr);
static                                        DWORD WINAPI BT_State(LPVOID pvarg);

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

            // 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_BTHGETMODESAMPLE));
    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_BTHGETMODESAMPLE, szWindowClass, MAX_LOADSTRING);
            LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
                 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);
            }

            hThread = CreateThread (NULL, 0, BT_State, 0, 0, &ThreadID);
            CloseHandle (hThread);

            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];
            static int cxClient;
            static int cyClient;

            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;
                                                default:
                                                  return DefWindowProc(hWnd, message, wParam, lParam);
                                    }
                                    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);
                                    // Create the debug output list box
                                    nWndDebugData = CreateWindow(
                                                TEXT("listbox"),
                                                NULL,
                                                WS_CHILD
                                                 | WS_VISIBLE
                                                 | LBS_STANDARD,
                                                0, 0, 0, 0,
                                                hWnd, (HMENU)1,
                                                ((LPCREATESTRUCT)lParam)->hInstance, NULL);
                                    break;
                        case WM_PAINT:
                                    RECT rt;
                                    hdc = BeginPaint(hWnd, &ps);
                                    GetClientRect(hWnd, &rt);
                                    LoadString(g_hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
                                    DrawText(hdc, szHello, _tcslen(szHello), &rt,
                                                DT_SINGLELINE | DT_VCENTER | DT_CENTER);
                                    EndPaint(hWnd, &ps);
                                            
}