タップ&ホールドでメニューだしたりごそごそと改造。
いちおうX01TとZERO3以外のその他端末向けです。ZERO3用は本家kazuaki氏のところへ。
Download: WifiInfoSetup_Universal.1.30.1.CAB
Download: WifiInfoSetup_X01T.1.30.1.CAB
いつものように以下パッチ
なんか1カ所化け化けだし今回サイズでかすぎるし、そろそろ差分パッチやめるべきなのか。
diff -c WifiInfo.ORG/Bt.cpp WifiInfo/Bt.cpp *** WifiInfo.ORG/Bt.cpp 2008-09-07 06:43:56.000000000 +0900 --- WifiInfo/Bt.cpp 2008-10-01 15:29:58.000000000 +0900 *************** *** 43,49 **** { g_hWnd = hWnd; ! g_dwBtStatusPrev = GetWifiStatus(); RegisterNotification(); } --- 43,49 ---- { g_hWnd = hWnd; ! g_dwBtStatusPrev = GetBtStatus(); RegisterNotification(); } *************** *** 195,198 **** dwBthMode = BTH_CONNECTABLE; } return BthSetMode(dwBthMode); ! } \ ・ユ・。・、・・ヒイケヤ、ャ、「、熙゙、サ、・--- 195,220 ---- dwBthMode = BTH_CONNECTABLE; } return BthSetMode(dwBthMode); ! } ! ! BOOL GetBtDiscoverable() ! { ! if (!BtIsPresent()) ! return FALSE; ! ! return SN_BLUETOOTHSTATEDISCOVERABLE_BITMASK & GetBtStatus(); ! } ! ! VOID SetBtDiscoverable(BOOL bDiscoverable) ! { ! if (!BtIsPresent()) ! return; ! ! DWORD dwBthMode; ! if (bDiscoverable) { ! dwBthMode = BTH_DISCOVERABLE; ! } else { ! dwBthMode = BTH_CONNECTABLE; ! } ! BthSetMode(dwBthMode); ! } diff -c WifiInfo.ORG/Bt.h WifiInfo/Bt.h *** WifiInfo.ORG/Bt.h 2008-09-07 06:43:56.000000000 +0900 --- WifiInfo/Bt.h 2008-10-01 15:26:48.000000000 +0900 *************** *** 22,26 **** --- 22,28 ---- INT TurnBtPowerOff(); // Bluetoothオフ BOOL BtIsPresent(); // Bluetoothが存在するか DWORD GetBtStatus(); // Bluetoothが接続しているか + BOOL GetBtDiscoverable(); // Bluetoothが発見可能か + VOID SetBtDiscoverable(BOOL bDiscoverable); #endif /* _MY_BT_H_ */ diff -c WifiInfo.ORG/Wifi.cpp WifiInfo/Wifi.cpp *** WifiInfo.ORG/Wifi.cpp 2008-09-21 21:48:16.000000000 +0900 --- WifiInfo/Wifi.cpp 2008-10-02 00:41:45.000000000 +0900 *************** *** 22,27 **** --- 22,28 ---- #pragma comment(lib, "Ws2.lib") #include <iphlpapi.h> #pragma comment(lib, "Iphlpapi.lib") + #include <Pm.h> #include "wifi.h" #include "bt.h" *************** *** 36,41 **** --- 37,43 ---- #define STOP_LED_BLINK_EVENT_NAME _T("WifiInfoStopLedBlink") #define WIFI_TIMER_REMOVE_EVENT_NAME _T("WifiIncoDisconnectTimerRemoveEvent") #define WIFI_GET_RSSI_MUTEX_NAME _T("WifiInfoGetRssi") + #define WIFI_DEVICE_GUID _T("{98C5250D-C29A-4985-AE5F-AFE5367E5006}\\") #define WIFI_DEVICE_NAME_LENGTH MAX_PATH #define QUERY_BUFFER_SIZE 1024 *************** *** 58,64 **** static WIFI_POWER_MODE g_wifiPowerMode = WIFI_POWER_MODE_MAX_PSP; static LONG g_lRssi = 0L; static TCHAR g_szIPAddress[32] = _T(""), ! g_szWifiDeviceName[WIFI_DEVICE_NAME_LENGTH] = _T(""); BOOL g_bTurnWifiLedOn = TRUE, g_bTurnBtOff = TRUE, --- 60,67 ---- static WIFI_POWER_MODE g_wifiPowerMode = WIFI_POWER_MODE_MAX_PSP; static LONG g_lRssi = 0L; static TCHAR g_szIPAddress[32] = _T(""), ! g_szWifiDeviceName[WIFI_DEVICE_NAME_LENGTH] = _T(""), ! g_szWifiDeviceFullName[WIFI_DEVICE_NAME_LENGTH] = _T(""); BOOL g_bTurnWifiLedOn = TRUE, g_bTurnBtOff = TRUE, *************** *** 92,98 **** static VOID StopBlinkLedThread(); static BOOL GetIPAddress(PTCHAR); - // ********************************************************************** // 外部公開用 // --- 95,100 ---- *************** *** 104,109 **** --- 106,134 ---- RegisterNotification(); UpdateStatus(GetWifiStatus()); + + #ifdef UNIVERSAL + // アダプタ名が取得できるので。 + HKEY hkey; + RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Comm\\", 0, KEY_ALL_ACCESS, &hkey); + + wchar_t name[32]; + DWORD n = 0, length = 31; + while (RegEnumKeyEx(hkey, n++, name, &length, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) + { + length = 31; + HKEY hsubkey; + DWORD data, sz = sizeof(DWORD); + RegOpenKeyEx(hkey, name, 0, KEY_ALL_ACCESS, &hsubkey); + if (RegQueryValueEx(hsubkey, L"Wireless", NULL, NULL, (LPBYTE)&data, &sz) == ERROR_SUCCESS) { + wcscat_s(g_szWifiDeviceFullName, WIFI_DEVICE_NAME_LENGTH, WIFI_DEVICE_GUID); + wcscat_s(g_szWifiDeviceFullName, WIFI_DEVICE_NAME_LENGTH, name); + break; + } + } + + RegCloseKey(hkey); + #endif } // 終了 *************** *** 121,142 **** // 無線LAN ON VOID TurnWifiPowerOn() { HANDLE hEvent = NULL; hEvent = CreateEvent(NULL, FALSE, FALSE, WIFI_POWON_EVENT_NAME); if (hEvent != NULL) { ! ! // 無線LAN ONイベント発行 // TODO: DevicePowerNotifyの方式に変える? SetEvent(hEvent); CloseHandle(hEvent); hEvent = NULL; } } // 無線LAN OFF VOID TurnWifiPowerOff() { HANDLE hEvent = NULL; hEvent = CreateEvent(NULL, FALSE, FALSE, WIFI_POWOFF_EVENT_NAME); --- 146,187 ---- // 無線LAN ON VOID TurnWifiPowerOn() { + #ifdef X01T + SHELLEXECUTEINFO si = {sizeof(SHELLEXECUTEINFO), 0, NULL, NULL, + L"\\Windows\\tfwifi.exe", NULL, L"\\Windows", SW_SHOW, + 0, NULL, NULL, NULL, 0, NULL, NULL}; + ShellExecuteEx(&si); + #elif UNIVERSAL + // DevicePower D0 でON + DevicePowerNotify((PVOID)g_szWifiDeviceFullName, D0, POWER_NAME); + SetDevicePower((PVOID)g_szWifiDeviceFullName, POWER_NAME, D0); + #else HANDLE hEvent = NULL; hEvent = CreateEvent(NULL, FALSE, FALSE, WIFI_POWON_EVENT_NAME); if (hEvent != NULL) { ! // 無線LAN ONイベント発行 // TODO: DevicePowerNotifyの方式に変える? SetEvent(hEvent); CloseHandle(hEvent); hEvent = NULL; } + #endif } // 無線LAN OFF VOID TurnWifiPowerOff() { + #ifdef X01T + SHELLEXECUTEINFO si = {sizeof(SHELLEXECUTEINFO), 0, NULL, NULL, + L"\\Windows\\tfwifi.exe", NULL, L"\\Windows", SW_SHOW, + 0, NULL, NULL, NULL, 0, NULL, NULL}; + ShellExecuteEx(&si); + #elif UNIVERSAL + // DevicePower D4 でOFF + DevicePowerNotify((PVOID)g_szWifiDeviceFullName, D4, POWER_NAME); + SetDevicePower((PVOID)g_szWifiDeviceFullName, POWER_NAME, D4); + #else HANDLE hEvent = NULL; hEvent = CreateEvent(NULL, FALSE, FALSE, WIFI_POWOFF_EVENT_NAME); *************** *** 145,150 **** --- 190,196 ---- CloseHandle(hEvent); hEvent = NULL; } + #endif } // 無線LAN LED ON/OFF *************** *** 641,648 **** SendMessage(g_hWnd, WM_WIFI_CONNECTING, 0L, 0L); } else ! //if (!(dwWifiStatus & SN_WIFISTATEPOWERON_BITMASK)) { ! if (0 == dwWifiStatus) { OnWifiPowerOff(); SendMessage(g_hWnd, WM_WIFI_POWER_OFF, 0L, 0L); } --- 687,694 ---- SendMessage(g_hWnd, WM_WIFI_CONNECTING, 0L, 0L); } else ! if (!(dwWifiStatus & SN_WIFISTATEPOWERON_BITMASK)) { ! //if (0 == dwWifiStatus) { OnWifiPowerOff(); SendMessage(g_hWnd, WM_WIFI_POWER_OFF, 0L, 0L); } *************** *** 902,904 **** --- 948,1003 ---- return TRUE; } + + // CAMモード状態を取得する + BOOL GetWifiPowerMode() + { + NDIS_802_11_POWER_MODE ndisPowerMode = Ndis802_11PowerModeMax; + + // PowerModeの設定 + if (!(GetWifiStatus() & SN_WIFISTATEPOWERON_BITMASK)) { + return FALSE; + } + if (NULL == g_hNdis) { + if (OpenNdisUio()) { + GetPowerMode(&ndisPowerMode); + if (Ndis802_11PowerModeCAM == ndisPowerMode) { + return TRUE; + } + CloseNdisUio(); + } + } else { + GetPowerMode(&ndisPowerMode); + if (Ndis802_11PowerModeCAM == ndisPowerMode) { + return TRUE; + } + } + return FALSE; + } + + // CAMモード状態を設定する + VOID SetWifiPowerMode(BOOL bCam) + { + NDIS_802_11_POWER_MODE ndisPowerMode = Ndis802_11PowerModeMax; + + // PowerModeの設定 + if (!(GetWifiStatus() & SN_WIFISTATEPOWERON_BITMASK)) { + return; + } + if (NULL == g_hNdis) { + if (OpenNdisUio()) { + if (bCam) { + SetPowerMode(Ndis802_11PowerModeCAM); + } else { + SetPowerMode(Ndis802_11PowerModeMAX_PSP); + } + CloseNdisUio(); + } + } else { + if (bCam) { + SetPowerMode(Ndis802_11PowerModeCAM); + } else { + SetPowerMode(Ndis802_11PowerModeMAX_PSP); + } + } + } \ ・ユ・。・、・・ヒイケヤ、ャ、「、熙゙、サ、・diff -c WifiInfo.ORG/Wifi.h WifiInfo/Wifi.h *** WifiInfo.ORG/Wifi.h 2008-09-08 00:22:04.000000000 +0900 --- WifiInfo/Wifi.h 2008-10-01 15:27:29.000000000 +0900 *************** *** 36,39 **** --- 36,41 ---- PTCHAR GetWifiSSID(); // 接続中のSSID取得 PTCHAR GetWifiIPAddress(); // 接続中のIPアドレス取得 BOOL GetWifiRssi(PLONG); // 無線LANのRSSIを取得 + BOOL GetWifiPowerMode(); + VOID SetWifiPowerMode(BOOL bCam); #endif /* _MY_WIFI_H_ */ diff -c WifiInfo.ORG/WifiInfo.cpp WifiInfo/WifiInfo.cpp *** WifiInfo.ORG/WifiInfo.cpp 2008-09-08 00:22:02.000000000 +0900 --- WifiInfo/WifiInfo.cpp 2008-10-02 00:20:04.000000000 +0900 *************** *** 140,146 **** g_hBtOffIcon = NULL, g_hBtOnIcon = NULL, g_hBtDiscoverableIcon = NULL; ! static RECT g_rcWnd, // Todayプラグイン領域 g_rcWifi, // 無線LAN用領域 --- 140,147 ---- g_hBtOffIcon = NULL, g_hBtOnIcon = NULL, g_hBtDiscoverableIcon = NULL; ! static HMENU g_hWifiMenu = NULL, ! g_hBtMenu = NULL; static RECT g_rcWnd, // Todayプラグイン領域 g_rcWifi, // 無線LAN用領域 *************** *** 184,189 **** --- 185,191 ---- static VOID SaveConfig_Bt(); static VOID GetRects(); static VOID UpdateMessage(); + static VOID UpdateMenuState(); static VOID SetWifiConnectingMessage(); static VOID SetWifiConnectedMessage(); static VOID SetWifiPowerOffMessage(); *************** *** 213,218 **** --- 215,222 ---- g_hBtOnIcon = (HICON)LoadImage(g_hInst, MAKEINTRESOURCE(IDI_BT_ON), IMAGE_ICON, DRA::SCALEX(16), DRA::SCALEY(16), LR_DEFAULTCOLOR); g_hBtDiscoverableIcon = (HICON)LoadImage(g_hInst, MAKEINTRESOURCE(IDI_BT_DISCOVERABLE), IMAGE_ICON, DRA::SCALEX(16), DRA::SCALEY(16), LR_DEFAULTCOLOR); + g_hWifiMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_WIFIMENU)); + g_hBtMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_BTMENU)); UnregisterClass(APP_NAME, g_hInst); InitializeClasses(); *************** *** 231,236 **** --- 235,243 ---- DestroyIcon(g_hBtOnIcon); DestroyIcon(g_hBtDiscoverableIcon); + DestroyMenu(g_hWifiMenu); + DestroyMenu(g_hBtMenu); + UnregisterClass(APP_NAME, g_hInst); g_hInst = NULL; break; *************** *** 283,288 **** --- 290,296 ---- s_bWifiIsStarted = (SN_WIFISTATEPOWERON_BITMASK & GetWifiStatus()); s_bBtIsStarted = (SN_BLUETOOTHSTATEPOWERON_BITMASK & GetBtStatus()); UpdateMessage(); + UpdateMenuState(); break; case WM_DESTROY: *************** *** 503,508 **** --- 511,534 ---- s_nFocus = WIFI; } + // ポップアップメニュー + SHRGINFO shrg; + 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) { + ClientToScreen(hWnd, &shrg.ptDown); + UpdateMenuState(); + if (s_nFocus == WIFI) { + ::TrackPopupMenuEx(GetSubMenu(g_hWifiMenu, 0), 0, shrg.ptDown.x, shrg.ptDown.y, hWnd, NULL); + } else { + ::TrackPopupMenuEx(GetSubMenu(g_hBtMenu, 0), 0, shrg.ptDown.x, shrg.ptDown.y, hWnd, NULL); + } + return 0; + } + // タップ(フォーカス取得) PostMessage(GetParent(hWnd), TODAYM_TOOKSELECTION, (WPARAM)hWnd, 0); s_bTodayItemIsSelected = TRUE; *************** *** 570,575 **** --- 596,643 ---- InvalidateRect(g_hWnd, NULL, TRUE); break; + case WM_COMMAND: + switch (LOWORD(wParam)) { + case ID_WIFI_ON: + s_bWifiIsStarted = TRUE; + SetWifiConnectingMessage(); + InvalidateRect(g_hWnd, NULL, TRUE); + TurnWifiPowerOn(); + return 0; + + case ID_WIFI_OFF: + s_bWifiIsStarted = FALSE; + SetWifiPowerOffMessage(); + InvalidateRect(g_hWnd, NULL, TRUE); + TurnWifiPowerOff(); + return 0; + + case ID_WIFI_CAM: + SetWifiPowerMode(!GetWifiPowerMode()); + InvalidateRect(g_hWnd, NULL, TRUE); + return 0; + + case ID_BT_ON: + s_bBtIsStarted = TRUE; + SetBtPowerOnMessage(); + InvalidateRect(g_hWnd, NULL, TRUE); + TurnBtPowerOn(); + return 0; + + case ID_BT_OFF: + s_bBtIsStarted = FALSE; + SetBtPowerOffMessage(); + InvalidateRect(g_hWnd, NULL, TRUE); + TurnBtPowerOff(); + return 0; + + case ID_BT_DISCOVER: + SetBtDiscoverable(!GetBtDiscoverable()); + InvalidateRect(g_hWnd, NULL, TRUE); + return 0; + } + break; + } return DefWindowProc (hWnd, uiMessage, wParam, lParam); } *************** *** 1128,1133 **** --- 1196,1244 ---- } } + // メニュー状態を更新 + static VOID UpdateMenuState() + { + // Wifi + HMENU wifiMenu = GetSubMenu(g_hWifiMenu, 0); + DWORD dwWifiStatus = GetWifiStatus(); + if (SN_WIFISTATEPOWERON_BITMASK & dwWifiStatus) { + EnableMenuItem(wifiMenu, ID_WIFI_ON, MF_GRAYED); + EnableMenuItem(wifiMenu, ID_WIFI_OFF, MF_ENABLED); + EnableMenuItem(wifiMenu, ID_WIFI_CAM, MF_ENABLED); + if (GetWifiPowerMode()) { + CheckMenuItem(wifiMenu, ID_WIFI_CAM, MF_CHECKED); + } else { + CheckMenuItem(wifiMenu, ID_WIFI_CAM, MF_UNCHECKED); + } + } else { + EnableMenuItem(wifiMenu, ID_WIFI_ON, MF_ENABLED); + EnableMenuItem(wifiMenu, ID_WIFI_OFF, MF_GRAYED); + EnableMenuItem(wifiMenu, ID_WIFI_CAM, MF_GRAYED); + CheckMenuItem(wifiMenu, ID_WIFI_CAM, MF_UNCHECKED); + } + + // Bt + HMENU btMenu = GetSubMenu(g_hBtMenu, 0); + if (BtIsPresent()) { + if (SN_BLUETOOTHSTATEPOWERON_BITMASK & GetBtStatus()) { + EnableMenuItem(btMenu, ID_BT_ON, MF_GRAYED); + EnableMenuItem(btMenu, ID_BT_OFF, MF_ENABLED); + EnableMenuItem(btMenu, ID_BT_DISCOVER, MF_ENABLED); + if (SN_BLUETOOTHSTATEDISCOVERABLE_BITMASK & GetBtStatus()) { + CheckMenuItem(btMenu, ID_BT_DISCOVER, MF_CHECKED); + } else { + CheckMenuItem(btMenu, ID_BT_DISCOVER, MF_UNCHECKED); + } + } else { + EnableMenuItem(btMenu, ID_BT_ON, MF_ENABLED); + EnableMenuItem(btMenu, ID_BT_OFF, MF_GRAYED); + EnableMenuItem(btMenu, ID_BT_DISCOVER, MF_GRAYED); + CheckMenuItem(btMenu, ID_BT_DISCOVER, MF_UNCHECKED); + } + } + } + // 無線LAN接続中のメッセージ設定 static VOID SetWifiConnectingMessage() { diff -c WifiInfo.ORG/WifiInfo.rc WifiInfo/WifiInfo.rc *** WifiInfo.ORG/WifiInfo.rc 2008-09-08 00:15:58.000000000 +0900 --- WifiInfo/WifiInfo.rc 2008-10-01 14:50:47.000000000 +0900 *************** *** 155,160 **** --- 155,188 ---- IDI_BT_ON ICON "bt_on.ico" IDI_BT_DISCOVERABLE ICON "bt_discoverable.ico" IDI_WIFI_OFF ICON "Wifi_off.ico" + + ///////////////////////////////////////////////////////////////////////////// + // + // Menu + // + + IDR_BTMENU MENU + BEGIN + POPUP "(popup)" + BEGIN + MENUITEM "オン", ID_BT_ON + MENUITEM "オフ", ID_BT_OFF + MENUITEM SEPARATOR + MENUITEM "探索を有効にする", ID_BT_DISCOVER + END + END + + IDR_WIFIMENU MENU + BEGIN + POPUP "(popup)" + BEGIN + MENUITEM "オン", ID_WIFI_ON + MENUITEM "オフ", ID_WIFI_OFF + MENUITEM SEPARATOR + MENUITEM "CAMモード", ID_WIFI_CAM + END + END + #endif // 日本語 resources ///////////////////////////////////////////////////////////////////////////// diff -c WifiInfo.ORG/resource.h WifiInfo/resource.h *** WifiInfo.ORG/resource.h 2008-09-08 00:16:22.000000000 +0900 --- WifiInfo/resource.h 2008-10-01 15:18:32.000000000 +0900 *************** *** 14,19 **** --- 14,22 ---- #define IDI_BT_OFF 114 #define IDI_BT_ON 115 #define IDI_BT_DISCOVERABLE 116 + #define IDR_BTMENU 117 + #define IDR_MENU2 118 + #define IDR_WIFIMENU 118 #define IDD_TODAY_CUSTOM 500 #define IDC_SHOW_SSID 1001 #define IDC_SHOW_CONNECTED_MESSAGE 1002 *************** *** 33,45 **** #define IDC_USE_CAM_MODE 1014 #define IDC_BT_OFF_MESSAGE 1016 #define IDC_SHOW_1_LINE 1017 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS ! #define _APS_NEXT_RESOURCE_VALUE 117 ! #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1018 #define _APS_NEXT_SYMED_VALUE 101 #endif --- 36,54 ---- #define IDC_USE_CAM_MODE 1014 #define IDC_BT_OFF_MESSAGE 1016 #define IDC_SHOW_1_LINE 1017 + #define ID_WIFI_ON 40007 + #define ID_WIFI_OFF 40008 + #define ID_WIFI_CAM 40009 + #define ID_BT_ON 40010 + #define ID_BT_OFF 40011 + #define ID_BT_DISCOVER 40012 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS ! #define _APS_NEXT_RESOURCE_VALUE 119 ! #define _APS_NEXT_COMMAND_VALUE 40013 #define _APS_NEXT_CONTROL_VALUE 1018 #define _APS_NEXT_SYMED_VALUE 101 #endif