📄 obexsquirt.cpp
字号:
// Call routine to handle control message.
for (i = 0; i < dim(MainCommandItems); i++) {
if (idItem == MainCommandItems[i].Code)
return (*MainCommandItems[i].Fxn)(hWnd, idItem, hwndCtl,
wNotifyCode);
}
return 0;
}
//----------------------------------------------------------------------
// FindDevInfo - Loop through array looking for a device
//
PMYOBEXDEVICEINFO FindDevInfo (IPropertyBag* pDevBag) {
int i, j = -1;
for (i = 0; i < dim (obDevs); i++) {
// See if device data matches search
if (obDevs[i].pDevBag == pDevBag)
return &obDevs[i];
// Find first free index
if ((j == -1) && (obDevs[i].pDevBag == 0)) {
j = i;
}
}
return &obDevs[j];
}
//----------------------------------------------------------------------
// FindDevInList - Search listbox for a device.
//
int FindDevInList (HWND hWnd, PMYOBEXDEVICEINFO pDev) {
int i, nCnt;
LRESULT lr;
// Get the number of items in the listbox
nCnt = SendDlgItemMessage (hWnd, IDD_DEVICES, LB_GETCOUNT, 0, 0);
for (i = 0; i < nCnt; i++) {
lr = SendDlgItemMessage (hWnd, IDD_DEVICES, LB_GETITEMDATA,i,0);
if (lr == (int)pDev)
return i;
}
return LB_ERR;
}
//----------------------------------------------------------------------
// DoObexEventMain - Handles notifications of obex events
//
LRESULT DoObexEventMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
int i;
HRESULT hr;
TCHAR szDevStr[128];
PMYOBEXDEVICEINFO pFoundDev;
MYOBEXDEVICEINFO diDev;
memset (&diDev, 0, sizeof (diDev));
IPropertyBag *pDeviceBag = (IPropertyBag *)lParam;
if (wParam == OE_QUERY_PASSWORD) {
MessageBox (hWnd, TEXT("Query Password"), TEXT("App"), MB_OK);
return 0;
}
// Parse name
VARIANT var;
VariantInit (&var);
hr = pDeviceBag->Read (TEXT("Name"), &var, NULL);
if (SUCCEEDED(hr)) {
diDev.dwFlags |= DEV_FLAG_NAME;
lstrcpy (diDev.szName, var.bstrVal);
}
VariantClear(&var);
// Parse address
hr = pDeviceBag->Read (TEXT("Address"), &var, NULL);
if (SUCCEEDED(hr)) {
diDev.dwFlags |= DEV_FLAG_ADDRESS;
if (var.vt == VT_BSTR)
lstrcpy (diDev.szAddr, var.bstrVal);
else if (var.vt == VT_I4)
wsprintf (diDev.szAddr, TEXT("%08x"), var.ulVal);
else
diDev.dwFlags &= ~DEV_FLAG_ADDRESS;
}
VariantClear(&var);
// Parse port
hr = pDeviceBag->Read (TEXT("Port"), &var, NULL);
if (SUCCEEDED(hr)) {
diDev.dwFlags |= DEV_FLAG_PORT;
if (var.vt == VT_BSTR)
lstrcpy (diDev.szAddr, var.bstrVal);
else if (var.vt == VT_I4)
wsprintf (diDev.szAddr, TEXT("%08x"), var.ulVal);
else
diDev.dwFlags &= ~DEV_FLAG_PORT;
}
VariantClear(&var);
// Parse IrDA informtation
hr = pDeviceBag->Read (TEXT("IrDA"), &var, NULL);
VariantClear(&var);
hr = pDeviceBag->Read (TEXT("Transport"), &var, NULL);
if (SUCCEEDED(hr)) {
if (var.vt == VT_BSTR) {
WCHAR szTran[40];
memset (szTran, 0, sizeof (szTran));
wcsncpy (szTran, var.bstrVal, 38);
wcslwr (szTran);
if (wcscmp (g_szTransIrDA, szTran) == 0)
diDev.dwFlags |= DEV_TRANS_IRDA;
else if (wcscmp (g_szTransBth, szTran) == 0)
diDev.dwFlags |= DEV_TRANS_BTOOTH;
}
}
VariantClear(&var);
hr = pDeviceBag->Read (TEXT("OBEX:IrXfer"), &var, NULL);
if (SUCCEEDED(hr))
Add2List (hWnd, TEXT("OBEX:IrXfer"));
VariantClear(&var);
// Parse service UUID
hr = pDeviceBag->Read (TEXT("ServiceUUID"), &var, NULL);
if (SUCCEEDED(hr)) {
if (var.vt == VT_BSTR) {
// Compare the guid service string to ones we know about
if (wcsncmp (g_szObjPushGuid, var.bstrVal, 38) == 0)
diDev.dwFlags |= (DEV_FLAG_UUID | DEV_SERVICE_OBJPUSH);
else if (wcsncmp (g_szFtpGuid, var.bstrVal, 38) == 0)
diDev.dwFlags |= (DEV_FLAG_UUID | DEV_SERVICE_FTP);
else if (wcsncmp (g_szIrMCSyncGuid, var.bstrVal, 38) == 0)
diDev.dwFlags |= (DEV_FLAG_UUID | DEV_SERVICE_IRMCSYNC);
}
}
VariantClear(&var);
diDev.pDevBag = pDeviceBag;
// Tell the user what protocols the device supports.
lstrcpy (szDevStr, diDev.szName);
lstrcat (szDevStr, TEXT(" "));
if (diDev.dwFlags & DEV_SERVICE_OBJPUSH)
lstrcat (szDevStr, TEXT("Object Push"));
else if (diDev.dwFlags & DEV_SERVICE_FTP)
lstrcat (szDevStr, TEXT("FTP"));
else if (diDev.dwFlags & DEV_SERVICE_IRMCSYNC)
lstrcat (szDevStr, TEXT("IrMC Sync"));
else if (diDev.dwFlags & DEV_TRANS_IRDA)
lstrcat (szDevStr, TEXT("IrDA"));
// See if device already recorded
pFoundDev = FindDevInfo (pDeviceBag);
// React depending on the notice
switch ((int)wParam) {
case OE_DEVICE_ARRIVAL:
// See if device already found
if (pFoundDev->pDevBag)
break;
memcpy (pFoundDev, &diDev, sizeof (diDev));
i = SendDlgItemMessage (hWnd, IDD_DEVICES, LB_ADDSTRING, 0,
(LPARAM)szDevStr);
SendDlgItemMessage (hWnd, IDD_DEVICES, LB_SETITEMDATA, i,
(LPARAM)pFoundDev);
break;
case OE_DEVICE_UPDATE:
i = LB_ERR;
memcpy (pFoundDev, &diDev, sizeof (diDev));
// Find device entry in list box
if (pFoundDev->pDevBag) {
i = FindDevInList (hWnd, pFoundDev);
// Release because we already hold the propbag
pFoundDev->pDevBag->Release();
}
if (LB_ERR != i)
SendDlgItemMessage (hWnd, IDD_DEVICES, LB_DELETESTRING,i,0);
i = SendDlgItemMessage (hWnd, IDD_DEVICES, LB_INSERTSTRING, i,
(LPARAM)szDevStr);
SendDlgItemMessage (hWnd, IDD_DEVICES, LB_SETITEMDATA, i,
(LPARAM)pFoundDev);
break;
case OE_DISCONNECT:
case OE_DEVICE_DEPARTURE:
// See if device not in device array, ignore disconnect
if (pFoundDev->pDevBag == 0)
break;
// Find device in list box and delete
i = FindDevInList (hWnd, pFoundDev);
if (LB_ERR != i)
SendDlgItemMessage (hWnd, IDD_DEVICES, LB_DELETESTRING,i,0);
// Clear entry in device array
pFoundDev->pDevBag->Release();
pFoundDev->pDevBag = 0;
break;
case OE_QUERY_PASSWORD:
break;
}
return 0;
}
//----------------------------------------------------------------------
// DoPrintfNotifyMain - Process printf notify message
//
LRESULT DoPrintfNotifyMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
int rc;
TCHAR szBuffer[512];
DWORD dwLen = 0;
DWORD dwFlags = 0;
memset (szBuffer, 0, sizeof (szBuffer));
rc = ReadMsgQueue (hQRead, (LPBYTE)szBuffer, sizeof (szBuffer),
&dwLen, 0, &dwFlags);
if (rc) {
if (dwFlags & MSGQUEUE_MSGALERT)
SetWindowText (hWnd, szBuffer);
else {
rc = SendDlgItemMessage (hWnd, IDD_INTEXT, LB_ADDSTRING, 0,
(LPARAM)(LPCTSTR)szBuffer);
if (rc != LB_ERR)
SendDlgItemMessage (hWnd, IDD_INTEXT, LB_SETTOPINDEX, rc,
(LPARAM)(LPCTSTR)szBuffer);
}
}
return 0;
}
//----------------------------------------------------------------------
// DoPocketPCShell - Process Pocket PC required messages
//
LRESULT DoPocketPCShell (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
#if defined(WIN32_PLATFORM_PSPC) && (_WIN32_WCE >= 300)
if (wMsg == WM_SETTINGCHANGE)
return SHHandleWMSettingChange(hWnd, wParam, lParam, &sai);
if (wMsg == WM_ACTIVATE)
return SHHandleWMActivate(hWnd, wParam, lParam, &sai, 0);
#endif
return 0;
}
//----------------------------------------------------------------------
// DoDestroyMain - Process WM_DESTROY message for window.
//
LRESULT DoDestroyMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
Sleep (0); // Pass on timeslice.
PostQuitMessage (0);
return 0;
}
//======================================================================
// Command handler routines
//----------------------------------------------------------------------
// DoMainCommandExit - Process Program Exit command.
//
LPARAM DoMainCommandExit (HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
SendMessage (hWnd, WM_CLOSE, 0, 0);
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandSend - Process Program Send File command.
//
LPARAM DoMainCommandSend (HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
int i;
HRESULT hr;
PMYOBEXDEVICEINFO pDev;
TCHAR szName[MAX_PATH];
IObexDevice *pDevice = 0;
GetDlgItemText (hWnd, IDD_OUTTEXT, szName, dim(szName));
if (lstrlen (szName) == 0) {
MessageBox (hWnd, TEXT("File name needed"), TEXT("Error"),
MB_OK);
return 0;
}
// Get the selected device
i = SendDlgItemMessage (hWnd, IDD_DEVICES, LB_GETCURSEL, 0, 0);
if (i != LB_ERR) {
pDev = (PMYOBEXDEVICEINFO)SendDlgItemMessage (hWnd,
IDD_DEVICES, LB_GETITEMDATA,i,0);
// Enumeration must be stopped during transfer
if (fObex2IF)
((IObex2 *)pObex)->PauseDeviceEnum (TRUE);
else
pObex->StopDeviceEnum();
// Bind to the device
MyYield();
hr = 0;
if ((pDev->dwFlags & DEV_FLAG_DEVBOUND) == 0) {
hr = pObex->BindToDevice (pDev->pDevBag, &pDevice);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -