• Wince开关蓝牙


    // WifiSwitch.cpp : 定义应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include "BTHSwitch.h"
    #include <windows.h>
    #include <commctrl.h>
    #include "bthutil.h"
    #pragma comment(lib, "bthutil.lib")
    
    #define MAX_LOADSTRING 100
    #define WM_CTLCENTER WM_USER+112
    #define WM_BTHSwitch WM_USER+7229
    #define BTH_STATUS_ON 1
    #define BTH_STATUS_OFF 0
    
    HINSTANCE            g_hInst;            // 当前实例
    HWND                hWndDes = NULL;
    int                    nRet;
    DWORD                dwMode;
    
    ATOM            MyRegisterClass(HINSTANCE, LPTSTR);
    BOOL            InitInstance(HINSTANCE, int);
    LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPTSTR    lpCmdLine,
                       int       nCmdShow)
    {
        MSG msg;
        nCmdShow = SW_HIDE;
    
        if (!InitInstance(hInstance, nCmdShow)) 
        {
            return FALSE;
        }
    
        HACCEL hAccelTable;
        hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_BTHSWITCH));
    
        while (GetMessage(&msg, NULL, 0, 0)) 
        {
            if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
    
        return (int) msg.wParam;
    }
    
    ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
    {
        WNDCLASS wc;
    
        wc.style         = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BTHSWITCH));
        wc.hCursor       = 0;
        wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
        wc.lpszMenuName  = 0;
        wc.lpszClassName = szWindowClass;
    
        return RegisterClass(&wc);
    }
    
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
        HWND hWnd;
        TCHAR szTitle[MAX_LOADSTRING] = _T("Bluetooth Switcher");        // 标题栏文本
        TCHAR szWindowClass[MAX_LOADSTRING] = _T("TBWidget");    // 主窗口类名
    
        g_hInst = hInstance; // 将实例句柄存储在全局变量中
    
        SHInitExtraControls();
    
        LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); 
        LoadString(hInstance, IDC_BTHSWITCH, szWindowClass, MAX_LOADSTRING);
    
        hWnd = FindWindow(szWindowClass, szTitle);    
        if (hWnd) 
        {
            return 0;
        } 
    
        if (!MyRegisterClass(hInstance, szWindowClass))
        {
            return FALSE;
        }
    
        hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
            CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
    
        if (!hWnd)
        {
            return FALSE;
        }
    
        ShowWindow(hWnd, nCmdShow);
        UpdateWindow(hWnd);
    
        hWndDes = FindWindow(_T("TBClass"), _T("TBMainWnd"));
        SendMessage(hWnd, WM_BTHSwitch, 0, 0);
    
        return TRUE;
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message) 
        {
        case WM_BTHSwitch:
            nRet = BthGetMode(&dwMode);
    
            if (nRet == ERROR_SUCCESS)
            {
                if (dwMode == BTH_CONNECTABLE)    // enabled
                {
                    nRet = BthSetMode(BTH_POWER_OFF);
                    if (nRet == ERROR_SUCCESS)
                    {
                        //off
                        SendMessage(hWndDes, WM_CTLCENTER, WM_BTHSwitch, BTH_STATUS_OFF);
                    }
                }
                else if (dwMode == BTH_POWER_OFF)
                {
                    nRet = BthSetMode(BTH_CONNECTABLE);
                    if (nRet == ERROR_SUCCESS)
                    {
                        //on
                        SendMessage(hWndDes, WM_CTLCENTER, WM_BTHSwitch, BTH_STATUS_ON);
                    }
                }
            }
    
            exit(0);
            break;
    
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
    
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        return 0;
    }
  • 相关阅读:
    设计模式——观察者模式
    安卓xml动画
    部署在weblogic上的springboot项目上传文件(servlet方式)
    Spring Boot 部署到weblogic 12c
    SpingBoot+Druid监控页面打不开(404)
    DAY49-前端入门-浮动布局案例、z-index、flex布局、响应式布局、过渡与动画
    DAY48-前端入门-文档流、浮动布局、清浮动、流式布局、定位布局
    DAY46-前端入门-组合选择器、标签a_img_list、盒模型、伪类、盒模型布局
    DAY45-前端入门-css的三种引用方式以及优先级、样式与长度颜色、常用样式、css选择器
    DAY44-前端入门-前端三剑客、第一个页面、常用标签、标签分类
  • 原文地址:https://www.cnblogs.com/ZzzZzz/p/2839764.html
Copyright © 2020-2023  润新知