Make Option for Today Plugin ? - Windows Mobile Development and Hacking General

I made a Today Plugin with option to change the heigh. It run OK when I make option in Today seting. But I want to show option dialog by tap in to my Today Item and change Option from that.
There is the code in WndPro
//Our main WndProc. Does everything after initialization.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch (message)
{
case WM_TIMER:
//Recalculate and paint the time for the count down.
TimeUpdate(hWnd);
return TRUE;
case WM_ERASEBKGND:
//We return true here since we handle our own background painting.
return TRUE;
case WM_TODAYCUSTOM_CLEARCACHE :
//We have no cache to clear so we ignore this message.
break;
case WM_TODAYCUSTOM_QUERYREFRESHCACHE:
//If the cyp member is set to 0 then you must set it to your windows height.
//This makes sure the shell gives you a certain amout of room for your painting.
if (g_bDayView)
{
g_ItemHeight = 26;
}
if (g_bMonthView)
{
g_ItemHeight = 105;
}
if (g_bClockView)
{
g_ItemHeight = 100;
}
//g_curTime = 0;
if (((TODAYLISTITEM*)wParam)->cyp == 0)
{
((TODAYLISTITEM*)wParam)->cyp = g_ItemHeight; //the shell draws a line at the bottom of our window.
return 1;
}
break;
case WM_PAINT:
//Paint like you would in any other application.
hdc = BeginPaint(hWnd, &ps);
PaintAll(hWnd, hdc);
EndPaint(hWnd, &ps);
break;
case WM_LBUTTONUP:
g_stylusPt.x = LOWORD(lParam); g_stylusPt.y = HIWORD(lParam);
if((g_stylusPt.x < 32)&&(g_stylusPt.y < 32))
DialogBox(g_hInstance, (LPCTSTR)IDD_TODAY_CUSTOM, hWnd, (DLGPROC)CustomItemOptionsDlgProc);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
Click to expand...
Click to collapse
And there is the code in Custom Dialog
BOOL WINAPI CustomItemOptionsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
SHINITDLGINFO shidi;
HWND hCurrentRadioButton;
switch (message)
{
case WM_INITDIALOG:
// Create a Done button and size it.
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
// select both as the radio button default
if(!g_bUserSet)
{
CheckRadioButton(hDlg, IDC_CLOCK_VIEW, IDC_MONTH_VIEW, IDC_DAY_VIEW);
}
// determine what the current config is and preserve it
else
{
if(g_bDayView)
{
CheckRadioButton(hDlg, IDC_CLOCK_VIEW, IDC_MONTH_VIEW, IDC_DAY_VIEW);
}
if(g_bMonthView)
{
CheckRadioButton(hDlg, IDC_CLOCK_VIEW, IDC_DAY_VIEW, IDC_MONTH_VIEW);
}
if(g_bClockView)
{
CheckRadioButton(hDlg, IDC_DAY_VIEW, IDC_MONTH_VIEW, IDC_CLOCK_VIEW);
}
}
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
// check to see if both is checked
hCurrentRadioButton = GetDlgItem(hDlg, IDC_DAY_VIEW);
if(BST_CHECKED == SendMessage(hCurrentRadioButton, BM_GETCHECK, NULL, NULL))
{
g_bDayView = TRUE;
g_bMonthView = FALSE;
g_bClockView = FALSE;
}
// check to see if only program is checked
hCurrentRadioButton = GetDlgItem(hDlg, IDC_MONTH_VIEW);
if(BST_CHECKED == SendMessage(hCurrentRadioButton, BM_GETCHECK, NULL, NULL))
{
g_bDayView = FALSE;
g_bMonthView = TRUE;
g_bClockView = FALSE;
}
// check to see if only storage is checked
hCurrentRadioButton = GetDlgItem(hDlg, IDC_CLOCK_VIEW);
if(BST_CHECKED == SendMessage(hCurrentRadioButton, BM_GETCHECK, NULL, NULL))
{
g_bDayView = FALSE;
g_bMonthView = FALSE;
g_bClockView = TRUE;
}
g_bUserSet = TRUE;
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
Click to expand...
Click to collapse
It shows Dialog, change all value of variable. But the Today Item's is not change.
Could anyone tell me how to do.
Thanks

Try this...
Instead of your line:
Code:
if (((TODAYLISTITEM*)wParam)->cyp == 0)
check for cyp not being set to desired height (g_ItemHeight), i.e.:
Code:
if (((TODAYLISTITEM*)wParam)->cyp != g_ItemHeight)
That should work for you.

It works OK
Thank you very, very much

nncuong said:
It works OK
Thank you very, very much
Click to expand...
Click to collapse
My pleasure

Related

How to create a GPRS connection in eVC?

As IE, MSN, when it launches, it creates a GPRS connection to Internet automaticly.
How can I do such thing in my own program in eVC 4.0 ?
Thanks.
All right.
No one answers my question, so I do it by myself. :evil:
Code:
#include <windows.h>
#include <winsock.h>
#if (WIN32_PLATFORM_PSPC>300 || WIN32_PLATFORM_WFSP )
#include <objbase.h>
#include <initguid.h>
#include <connmgr.h>
typedef HRESULT(*CONNMGRCONNECTIONSTATUS) (HANDLE hConnection,
DWORD * pdwStatus);
typedef HRESULT(*CONNMGRRELEASECONNECTION) (HANDLE hConnection,
LONG lCache);
typedef HRESULT(*CONNMGRESTABLISHCONNECTION) (CONNMGR_CONNECTIONINFO *
pConnInfo,
HANDLE * phConnection,
DWORD dwTimeout,
DWORD * pdwStatus);
#endif
HANDLE phWebConnection;
BOOL EstablishDatacall(TCHAR * IPout);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
// TODO: Place code here.
TCHAR MyIP[20];
if (EstablishDatacall(MyIP) == TRUE) {
TCHAR Message[255];
wsprintf(Message, L"IP: %s", MyIP);
MessageBox(NULL, Message, L"Success", MB_OK);
} else {
MessageBox(NULL,
L"Data call could not be established or has been established",
L"Information", MB_OK);
}
return 0;
}
BOOL EstablishDatacall(TCHAR * IPout)
{
CHAR szHostname[255];
TCHAR IP[17];
HOSTENT *pHostEnt = NULL;
int nAdapter = 0;
IN_ADDR *tsim = NULL;
BOOL tried2Connect = FALSE;
IP[0] = 0; // Clear the IP Address
if (IPout != NULL) {
IPout[0] = 0;
}
tryagain:
nAdapter = 0;
gethostname(szHostname, sizeof(szHostname));
pHostEnt = gethostbyname(szHostname);
while (pHostEnt != NULL && pHostEnt->h_addr_list[nAdapter]) {
// in case a device has multiple ethernet cards
// i.e. 802.11, Bluetooth, USB-Cradle
// we need to go though all pHostEnt->h_addr_list[nAdapter]
tsim = (IN_ADDR *) pHostEnt->h_addr_list[nAdapter];
if (IPout != NULL) {
wsprintf(IPout, TEXT("%d.%d.%d.%d"),
tsim->S_un.S_un_b.s_b1,
tsim->S_un.S_un_b.s_b2,
tsim->S_un.S_un_b.s_b3, tsim->S_un.S_un_b.s_b4);
}
if (tsim->S_un.S_un_b.s_b1 == 192 ||
tsim->S_un.S_un_b.s_b1 == 169 ||
tsim->S_un.S_un_b.s_b1 == 127 || tsim->S_un.S_un_b.s_b1 == 255) {
// If you want to make sure you have a real Internet
// connection you cannot bet on IpAddresses starting with
// 127 and 255. 192 and 169 are local IP addresses and
// might be routed or proxied
nAdapter++;
} else {
wsprintf(IP, TEXT("%d.%d.%d.%d"),
tsim->S_un.S_un_b.s_b1,
tsim->S_un.S_un_b.s_b2,
tsim->S_un.S_un_b.s_b3, tsim->S_un.S_un_b.s_b4);
break;
}
}
// the next lines only work with Pocket PC Phone
// and Smartphone
#if (WIN32_PLATFORM_PSPC>300 || WIN32_PLATFORM_WFSP )
// Pocket PC Phone Edition has set WIN32_PLATFORM_PSPC to 310
if (IP[0] == 0 && tried2Connect == FALSE) {
CONNMGRCONNECTIONSTATUS g_hConnMgrConnectionStatus = NULL;
CONNMGRESTABLISHCONNECTION g_hConnMgrEstablishConnectionSync =
NULL;
// It is good practice to load the cellcore.dll
// dynamically to be able to compile the code even for
// older platforms
HINSTANCE hcellDll = LoadLibrary(TEXT("cellcore.dll"));
if (hcellDll) {
// We need the Status and a call to establish the
// connection
g_hConnMgrConnectionStatus =
(CONNMGRCONNECTIONSTATUS) GetProcAddress(hcellDll,
TEXT
("ConnMgrConnectionStatus"));
// The next line is just for debugging. You will have
// to decide what you want to do if this call fails
DWORD a = GetLastError();
g_hConnMgrEstablishConnectionSync =
(CONNMGRESTABLISHCONNECTION) GetProcAddress(hcellDll,
TEXT
("ConnMgrEstablishConnectionSync"));
//a = GetLastError();
// Here comes the main code:
// First we check if we might have a connection
DWORD pdwStatus;
(*g_hConnMgrConnectionStatus) (&phWebConnection, &pdwStatus);
if (pdwStatus == CONNMGR_STATUS_CONNECTED) {
//We are already connected!
//This code should never run since we should
//have a valid IP already.
//If you still get here, you probably have
//stale connection.
return TRUE;
} else {
//We are not connected, so lets try:
//The CONNECTIONINFO is the structure that
//tells Connection Manager how we want
//to connect
CONNMGR_CONNECTIONINFO sConInfo;
memset(&sConInfo, 0, sizeof(CONNMGR_CONNECTIONINFO));
sConInfo.cbSize = sizeof(CONNMGR_CONNECTIONINFO);
// We want to use the guidDestNet parameter
sConInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
// This is the highest data priority.
sConInfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
sConInfo.dwFlags = 0;
// Lets be nice and share the connection with
// other applications
sConInfo.bExclusive = FALSE;
sConInfo.bDisabled = FALSE;
sConInfo.guidDestNet = IID_DestNetInternet;
// We want to wait until the connection was
// established successful but not longer then
// 60 seconds. You can use
// ConnMgrEstablishConnection to establish
// an asynchronous connection.
if ((*g_hConnMgrEstablishConnectionSync)
(&sConInfo, &phWebConnection, 60000,
&pdwStatus) == S_OK) {
//We are successfully connected!
//Now lets try to get the new IP address
tried2Connect = TRUE;
goto tryagain;
} else {
tried2Connect = FALSE;
//Doh! Connection failed!
}
}
}
}
#endif
return tried2Connect;
}

Create file error when open LCD

I'm try write a application to addjust LCD backlight.But it failed at the
first step Create file.GetLastError return 161.
Somesone can tell me what's wrong with it?
Sorry for my poor english.
thx
Below is my code
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
TCHAR *pszDevice=_T("\\\\.\\LCD");
HANDLE hLCD=NULL;
hLCD=CreateFileW(pszDevice,
GENERIC_READ,
FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
0,
NULL);
DWORD dwError=GetLastError();
if(INVALID_HANDLE_VALUE!=hLCD)
{
MessageBox(NULL,_T("Got Lcd"),_T("MyMessage"),MB_OK);
}
CloseHandle(hLCD);
return 0;
}
Hi ft1860!
I don't think you can do it that way, although I never tried it. You should check out power management API:
http://msdn.microsoft.com/library/d...pplicationsToTurnSmartphoneBacklightOffOn.asp
This example is for smartphones but should work on a PPC just as well.
P.S.:
Error 161 is "The specified path is invalid" so you should check the device name (no idea what that might be).
levenum said:
Hi ft1860!
I don't think you can do it that way, although I never tried it. You should check out power management API:
http://msdn.microsoft.com/library/d...pplicationsToTurnSmartphoneBacklightOffOn.asp
This example is for smartphones but should work on a PPC just as well.
P.S.:
Error 161 is "The specified path is invalid" so you should check the device name (no idea what that might be).
Click to expand...
Click to collapse
hi levenum
Thanks your comment,but according to this document
http://windowssdk.msdn.microsoft.co...r/base/ioctl_video_set_display_brightness.asp
It say we can set the current AC and DC backlight levels by invoke DeviceIoControl with IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS parameter.
So first I must create a handle of LCD,but I cann't open it successfully,
why?
oh,I make a mistake
IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS is Win32 function.
On smart device,I should use SetPowerRequirement to set the backlight.
But when I invoke SetPowerRequirement on my Universal with D0 or D4,it say success ,but nothing happened.
maybe you have to access backlight by BKL1: device.
CreateFile(L"BKL1:", ....
or write the brightness value into registry.. that works for sure.
buzz
buzz_lightyear said:
maybe you have to access backlight by BKL1: device.
CreateFile(L"BKL1:", ....
or write the brightness value into registry.. that works for sure.
buzz
Click to expand...
Click to collapse
Thanks
I'll try it.
It seem that SetPowerRequirement D0-D4 just Open or close backlight,
but what I want is adjust the backlight's brightness.
ft1860 said:
It seem that SetPowerRequirement D0-D4 just Open or close backlight,
but what I want is adjust the backlight's brightness.
Click to expand...
Click to collapse
then just do it through registry.
buzz
buzz_lightyear said:
ft1860 said:
It seem that SetPowerRequirement D0-D4 just Open or close backlight,
but what I want is adjust the backlight's brightness.
Click to expand...
Click to collapse
then just do it through registry.
buzz
Click to expand...
Click to collapse
oh,thanks
It almost work.
It works fine on my Universal,but it doesn't work on my x50v with WM5.
I should not debug it on my x50v,there is so many bugs in Dell's WM5 update.
Another question is how to get the max brightness value.On my Universal it is 10,but on my x50v it is 8;
below is my new code
#include <WinReg.h>
#include <pm.h>
TCHAR tszAppName[] = TEXT("PMSAMPLE");
TCHAR tszTitle[] = TEXT("Power Manager Sample");
HINSTANCE g_hInst = NULL; // Local copy of hInstance
HANDLE g_hEventShutDown = NULL;
HANDLE g_hPowerNotificationThread = NULL;
HWND g_hSystemState = NULL;
//***************************************************************************
// Function Name: SetBacklightRequirement
//
// Purpose: Sets or releases the device power requirement to keep the
// backlight at D0
//
// Arguments:
// IN BOOL fBacklightOn - TRUE to leave the backlight on
//
void SetBacklightRequirement(BOOL fBacklightOn)
{
// the name of the backlight device
TCHAR tszBacklightName[] = TEXT("BKL1:");
static HANDLE s_hBacklightReq = NULL;
if (fBacklightOn)
{
if (NULL == s_hBacklightReq)
{
// Set the requirement that the backlight device must remain
// in device state D0 (full power)
s_hBacklightReq = SetPowerRequirement(tszBacklightName, D4,
POWER_NAME, NULL, 0);
if (!s_hBacklightReq)
{
RETAILMSG(1, (L"SetPowerRequirement failed: %X\n",
GetLastError()));
}
}
}
else
{
if (s_hBacklightReq)
{
if (ERROR_SUCCESS != ReleasePowerRequirement(s_hBacklightReq))
{
RETAILMSG(1, (L"ReleasePowerRequirement failed: %X\n",
GetLastError()));
}
s_hBacklightReq = NULL;
}
}
}
#define REG_BACKLIGHT L"ControlPanel\\Backlight"
//#define REG_VAL_BATT_TO L"BatteryTimeout"
//#define REG_VAL_AC_TO L"ACTimeout"
#define REG_VAL_BN L"BrightNess"
#define REG_VAL_ACBN L"ACBrightness"
unsigned int OldBattBN=0;
unsigned int OldACBN=0;
void RegOptionBL( DWORD dw1,DWORD dw2)
{
HKEY hKey = 0;
DWORD dwSize;
HANDLE hBL;
static bool bOpened=false;
if ( ERROR_SUCCESS == RegOpenKeyEx( HKEY_CURRENT_USER,REG_BACKLIGHT, 0, 0, &hKey ) )
{
if( !bOpened )
{
bOpened=true;
dwSize = 4;
RegQueryValueEx( hKey, REG_VAL_BN,NULL,NULL,(unsigned char*)&OldBattBN,&dwSize );
dwSize = 4;
RegQueryValueEx( hKey, REG_VAL_ACBN,NULL,NULL,(unsigned char*) &OldACBN,&dwSize );
// dwSize = 4;
// dwValue = 0xefff ;
// RegSetValueEx( hKey,REG_VAL_BATT_TO,NULL,REG_DWORD,(unsigned char *)&dwValue,dwSize );
// dwSize = 4;
// dwValue = 0xefff ;
// RegSetValueEx( hKey,REG_VAL_AC_TO,NULL,REG_DWORD,(unsigned char *)&dwValue,dwSize );
dwSize = 4;
RegSetValueEx( hKey,REG_VAL_BN,NULL,REG_DWORD,(unsigned char *)&dw1,dwSize );
dwSize = 4;
RegSetValueEx( hKey,REG_VAL_ACBN,NULL,REG_DWORD,(unsigned char *)&dw2,dwSize );
}
else
{
if (OldBattBN)
{
dwSize = 4;
RegSetValueEx( hKey,REG_VAL_BN,NULL,REG_DWORD,(unsigned char *)&OldBattBN,dwSize );
}
if (OldACBN)
{
OldACBN = 4;
RegSetValueEx( hKey,REG_VAL_ACBN,NULL,REG_DWORD,(unsigned char *)&OldACBN,dwSize );
}
}
RegCloseKey( hKey );
hBL = CreateEvent( NULL, FALSE, FALSE,L"BackLightChangeEvent" );
if( hBL )
{
SetEvent(hBL);
CloseHandle( hBL );
}
}
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
int nResult = 0;
// Create mutex to track whether or not an application is already running
HANDLE hMutex = CreateMutex(0, 0, _T("_PMSAMPLE_EXE_MUTEX_"));
// check the result code
if (NULL != hMutex)
{
if (ERROR_ALREADY_EXISTS != GetLastError())
{
SetBacklightRequirement(TRUE);
RegOptionBL(8,8);
Sleep(5000);
RegOptionBL(-1,-1);
SetBacklightRequirement(FALSE);
}
else
{
}
CloseHandle(hMutex);
}
return ( nResult >= 0 );
}

WM6 - how to Query WLAN "connection" status

I am desperately trying to work around some unknown problem caused by our NDIS IM driver on WM6 and HTC TyTn ( TyTn at least, but most likely other devices as well ). I started some other threads regarding different facets of this problem, and no help is coming. Now I am just trying to work around it.
in short the problem is when power events happen the WLAN will never connect.
The work around is programmatically open the control panel with STControlPanel class and press the down button 1 time then the f1 key ( right dash ). This "presses connect" on the last configured access point. This works around my problem, however, I need to detect when the access point has connected. There is a "connecting" and "connected" message for the access point in this control panel dialog ( control panel # 17 ).
My Question: Is there some way to get this text "connecting" or "connected" from the control panel #17?
I have tried wzc, ndisuio, winsock, and other "non control panel" ways to detect connected state, but the IM problem fools all these methods. The only thing I have ever seen that successfully shows when the problem has occurred is the "connecting"/"connected" status in the control panel 17.
Please Help Someone.
p.s. If I can get this worked around, we sell a commercial grade ndis intermediate driver toolkit letting you easily write plugins without any of the hard driver details. We have redirectors, transparent proxy, tunnelers, virtual adapters, lots of good stuff. Also the same plugin will work on all windows desktop platforms vista - 98, WM5/6 and CE and also linux and solaris...
Hello skk
What about notification API?
Here is the solution (simple concept) for Your problem. Interesting parts are in bold.
SNapiTest.cpp
Code:
#include "stdafx.h"
#include "SNapiTest.h"
#include <windows.h>
#include <commctrl.h>
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE g_hInst; // current instance
HWND g_hWndMenuBar; // menu bar handle
[b]
const DWORD WM_WIFISTATUS = WM_USER + 1;
bool g_connecting;
bool g_connected;
HREGNOTIFY g_hNotify;
HREGNOTIFY g_hNotify2;
[/b]
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE, LPTSTR);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
// Perform application initialization:
if (!InitInstance(hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable;
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SNAPITEST));
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
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_SNAPITEST));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}
//
// FUNCTION: InitInstance(HINSTANCE, 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;
TCHAR szTitle[MAX_LOADSTRING]; // title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // main window class name
g_hInst = hInstance; // Store instance handle in our global variable
// SHInitExtraControls should be called once during your application's initialization to initialize any
// of the device specific controls such as CAPEDIT and SIPPREF.
SHInitExtraControls();
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_SNAPITEST, szWindowClass, MAX_LOADSTRING);
//If it is already running, then focus on the window, and exit
hWnd = FindWindow(szWindowClass, szTitle);
if (hWnd)
{
// set focus to foremost child window
// The "| 0x00000001" is used to bring any owned windows to the foreground and
// activate them.
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
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;
}
// When the main window is created using CW_USEDEFAULT the height of the menubar (if one
// is created is not taken into account). So we resize the window after creating it
// if a menubar is present
if (g_hWndMenuBar)
{
RECT rc;
RECT rcMenuBar;
GetWindowRect(hWnd, &rc);
GetWindowRect(g_hWndMenuBar, &rcMenuBar);
rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// 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;
PAINTSTRUCT ps;
HDC hdc;
static SHACTIVATEINFO s_sai;
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, About);
break;
case IDM_OK:
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_CREATE:
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;
}
// Initialize the shell activate info structure
memset(&s_sai, 0, sizeof (s_sai));
s_sai.cbSize = sizeof (s_sai);
[b]
g_connecting = false;
g_connected = false;
{HRESULT hr = RegistryNotifyWindow(SN_WIFISTATECONNECTING_ROOT,
SN_WIFISTATECONNECTING_PATH, SN_WIFISTATECONNECTING_VALUE,
hWnd, WM_WIFISTATUS, 0, NULL, &g_hNotify);}
{HRESULT hr2 = RegistryNotifyWindow(SN_WIFISTATECONNECTING_ROOT,
SN_WIFISTATECONNECTED_PATH, SN_WIFISTATECONNECTED_VALUE,
hWnd, WM_WIFISTATUS, 0, NULL, &g_hNotify2);}
[/b]
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
[b]
case WM_WIFISTATUS:
{
DWORD newValue = (DWORD) wParam;
WCHAR caption[] = L"Wifi Status";
if ((newValue & SN_WIFISTATECONNECTED_BITMASK) == SN_WIFISTATECONNECTED_BITMASK)
{
if (!g_connected)
{
g_connected = true;
g_connecting = false;
MessageBox(hWnd, L"Connected!!", caption, MB_OK);
}
break;
}
if ((newValue & SN_WIFISTATECONNECTING_BITMASK) == SN_WIFISTATECONNECTING_BITMASK)
{
if (!g_connecting)
{
g_connecting = true;
g_connected =false;
MessageBox(hWnd, L"Connecting...", caption, MB_OK);
}
}
break;
}
[/b]
case WM_DESTROY:
CommandBar_Destroy(g_hWndMenuBar);
[B]
RegistryCloseNotification(g_hNotify);
RegistryCloseNotification(g_hNotify2);
[/B]
PostQuitMessage(0);
break;
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;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
// 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);
}
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
case WM_CLOSE:
EndDialog(hDlg, message);
return TRUE;
}
return (INT_PTR)FALSE;
}
Needed includes:
// TODO: reference additional headers your program requires here
#include <snapi.h>
#include <regext.h>
snapi.h
Thank you so much for your post. I just found snapi.h, I assume this is snapitest.h?
IT WORKS!
It works! You are my hero RStein. You are a god among men.
Great. ) Thanks for sharing the results.

Radiogroup and radiobutton selection in ExpandableListView

i've an ExpandableListView, where i can select different radiobutton choice in a radiobuttongroup. My problem: not all radiobuttons are selected...the behaviour is random.
this is my code
Code:
void prepareMainList(String data)
{
Document doc;
NodeList nl;
newsNotificationData = new ArrayList<Map<String, String>>(); //set this struct in other case
groupData = new ArrayList<Map<String, String>>();
childData = new ArrayList<List<Map<String, String>>>();
if ((data.compareTo("") != 0) && (data != null) )
{
doc = parser.getDomElement(data); // getting DOM element
nl = doc.getElementsByTagName(KEY_GROUP);
categoryList = new HashSet<CategoryClass>();
// looping through all song nodes <song>
for (int i = 0; i < nl.getLength(); i++)
{
// creating new HashMap
Map<String, String> curGroupMap = new HashMap<String, String>();
Map<String, String> curNewsMap = new HashMap<String, String>();
Element el = (Element) nl.item(i);
CategoryClass myCat = new CategoryClass();
myCat.id = parser.getValue(el, "id");
myCat.name = parser.getValue(el, KEY_NAME);
myCat.subCategory = new HashSet<TournamentClass>();
// adding each child node to HashMap key => value
curGroupMap.put(CATEGORY, parser.getValue(el, KEY_NAME));
Log.d("test", "category id added: " + myCat.id);
// adding HashList to ArrayList
groupData.add(curGroupMap);
//notification
curNewsMap.put("CID_" + myCat.id, getValueFromCategory(myCat.id));
newsNotificationData.add(curNewsMap);
NodeList ls = el.getElementsByTagName("girone");
//Log.d("test", "getDataFromWebService get children count : " + ls.getLength());
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (int j = 0; j < ls.getLength(); j++)
{
Element elc = (Element) ls.item(j);
Map<String, String> curChildMap = new HashMap<String, String>();
TournamentClass myTournament = new TournamentClass();
myTournament.id = elc.getAttribute("id");
myTournament.name = parser.getValue(elc, KEY_CHILD_NAME);
curChildMap.put(TOURNAMENT, parser.getValue(elc, KEY_CHILD_NAME));
children.add(curChildMap);
myCat.subCategory.add(myTournament);
//notification
curNewsMap.put("TID_" + myTournament.id, "-1");
newsNotificationData.get(i).put("TID_" + myTournament.id, getValueFromTournament(myTournament.id));
}
childData.add(children);
categoryList.add(myCat);
//newsNotificationData.add(curNewsMap);
}
}
catList = (ExpandableListView) findViewById(R.id.expandableSettings);
catList.setClickable(true);
catList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
Log.d("test", "GROUP PRESSED");
return false;
}
});
// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(
this,
groupData,
R.layout.settings_header,
new String[] { CATEGORY, TOURNAMENT },
new int[] { R.id.settingsCatTitle, android.R.id.text2 },
childData,
R.layout.settings_child,
new String[] { CATEGORY, TOURNAMENT },
new int[] { android.R.id.text1, R.id.settingsSubTitle }
){
@Override
public View getGroupView (final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
{
//final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
final View v = super.getGroupView(groupPosition, isExpanded, convertView, parent);
//Log.d("test", "get tournament selected");
TextView tv = (TextView)v.findViewById( R.id.settingsCatTitle );
String catSel = tv.getText().toString();
//get objects
String groupName = groupData.get(groupPosition).get("CATEGORY");
final CategoryClass myCat = getCategoryFromName(groupName);
RadioGroup groupNN;
// *** Gestisce l'header della categoria ***
groupNN = (RadioGroup) v.findViewById(R.id.radioGroupNN);
groupNN.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
//Log.d("Header chk", "id" + checkedId);
if(!isDataLoaded) return;
for (int i = 0, l = group.getChildCount(); i < l; i++)
{
RadioButton xRadio = (RadioButton) group.getChildAt(i);
xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
xRadio.setTextColor(R.drawable.settings_gradient_on);
}
//-----change data to send
String notifValue = "0";
//get checked value
switch (checkedId)
{
case R.id.button_News:
notifValue = "0";
break;
case R.id.button_Notif:
notifValue = "1";
break;
case R.id.button_All:
notifValue = "2";
break;
case R.id.button_no:
notifValue = "-1";
break;
default:
break;
}
//set graphics on selected radio button
RadioButton radio = (RadioButton) v.findViewById(checkedId);
if (radio != null)
{
//radio.setTextSize(30);
// Marco Moscatelli 28/11/2013 - imposto il check a true
//radio.setChecked(true);
radio.setBackgroundResource(R.drawable.settings_gradient_on);
radio.setTextColor(Color.LTGRAY);
}
updateNewsNotificationCenter(groupPosition, myCat.id, null, notifValue);
isDataLoaded = false;
//Log.d("test", "------END SET CATEGORY------- ");
}
});
//-----data to send changed
isDataLoaded = false;
//set default schema
//String defaultbtnValue = null;
String defaultbtnValue = newsNotificationData.get(groupPosition).get("CID_" + myCat.id);
//Log.d("test", "check current cat id : "+ myCat.id);
RadioButton defNNRadio = null;
//Log.d("test", "defaultbtnValue : "+ defaultbtnValue);
if (defaultbtnValue == null)defaultbtnValue = "-1";
switch(Integer.parseInt(defaultbtnValue))
{
case 0:
defNNRadio = (RadioButton) v.findViewById(R.id.button_News);
break;
case 1:
defNNRadio = (RadioButton) v.findViewById(R.id.button_Notif);
break;
case 2:
defNNRadio = (RadioButton) v.findViewById(R.id.button_All);
break;
case -1:
defNNRadio = (RadioButton) v.findViewById(R.id.button_no);
break;
default:
break;
}
//set default button
for (int i = 0, l = groupNN.getChildCount(); i < l; i++)
{
RadioButton xRadio = (RadioButton) groupNN.getChildAt(i);
xRadio.setChecked(false);
xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
xRadio.setTextColor(R.drawable.settings_gradient_on);
}
if (defNNRadio != null)
{
defNNRadio.setChecked(true);
defNNRadio.setBackgroundResource(R.drawable.settings_gradient_on);
defNNRadio.setTextColor(Color.LTGRAY);
}
return v;
}
@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
Log.d("test", "getChildView");
RadioGroup groupNN;
// *** gestisco i gironi della categoria ***
groupNN = (RadioGroup) v.findViewById(R.id.radioGroupNN_child);
//get objects
String groupName = groupData.get(groupPosition).get("CATEGORY");
final CategoryClass myCat = getCategoryFromName(groupName);
Map<String, String> childName = childData.get(groupPosition).get(childPosition);
final TournamentClass myTournament = getTournamentFromName(groupName, childName.get("TOURNAMENT"));
groupNN.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
//Log.d("Item chk", "id" + checkedId);
if(!isDataLoaded) return;
Log.d("test", "------INIT SET TOURNAMENT------- : " + myTournament.id);
for (int i = 0, l = group.getChildCount(); i < l; i++)
{
RadioButton xRadio = (RadioButton) group.getChildAt(i);
xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
xRadio.setTextColor(color.SettingsTextOffColor);
}
//-----change data to send
String notifValue = "0";
//get checked value
switch (checkedId)
{
case R.id.button_News:
notifValue = "0";
break;
case R.id.button_Notif:
notifValue = "1";
break;
case R.id.button_All:
notifValue = "2";
break;
case R.id.button_no:
notifValue = "-1";
break;
default:
break;
}
//Get Tournament and keep id of it...after save notification mode in a struct and send all on POSTS
RadioButton radio = (RadioButton) v.findViewById(checkedId);
if (radio != null)
{
// Marco Moscatelli 28/11/2013 - Imposto il check a true
//radio.setChecked(true);
//group.check(radio.getId());
// end
radio.setBackgroundResource(R.drawable.settings_gradient_on);
radio.setTextColor(Color.LTGRAY);
}
//prepare data
updateNewsNotificationCenter(groupPosition, myCat.id, myTournament.id, notifValue);
Log.d("test", "------END SET TOURNAMENT------- ");
}
//}
});
//set default schema
String defaultbtnValue = newsNotificationData.get(groupPosition).get("TID_" + myTournament.id);
RadioButton defNNRadio = null;
//Log.d("test", "defaultbtnValue : "+ defaultbtnValue);
if (defaultbtnValue == null)defaultbtnValue = "-1";
switch(Integer.parseInt(defaultbtnValue))
{
case 0:
defNNRadio = (RadioButton) v.findViewById(R.id.button_News);
break;
case 1:
defNNRadio = (RadioButton) v.findViewById(R.id.button_Notif);
break;
case 2:
defNNRadio = (RadioButton) v.findViewById(R.id.button_All);
break;
case -1:
defNNRadio = (RadioButton) v.findViewById(R.id.button_no);
break;
}
for (int i = 0, l = groupNN.getChildCount(); i < l; i++)
{
RadioButton xRadio = (RadioButton) groupNN.getChildAt(i);
xRadio.setChecked(false);
xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
xRadio.setTextColor(color.SettingsTextOffColor);
}
//set default schema
if (defNNRadio != null)
{
defNNRadio.setChecked(true);
defNNRadio.setBackgroundResource(R.drawable.settings_gradient_on);
defNNRadio.setTextColor(Color.LTGRAY);
}
//isDataLoaded = true;
return v;
}
thanks in advance

Starting chronometer with if condition comparing strings

I have an android application that is receiving a string from an arduino via Bluetooth, names the string "data" and displays it by setting a TextView to the string "data". I want a chronometer to start when the incoming string matches a predefined string.
For example:
Code:
if data.equals(startChrono)){
chronometerLeft.setBase(SystemClock.elapsedRealtime());
chronometerLeft.start();
I actually have the arduino sending a "g" and am setting my string goL to be "g" but cannot get the chronometer to start when the g is received. My TextView shows the g. Code is below. I've tried several things and at a loss. Using same code for chronometer.start() with onClickListener with a button works great. I just need it to start the chronometer when i receive a specific string from the arduino.
Code:
beginListenForData();
// text.setText("Bluetooth Opened");
}
void beginListenForData() {
final Handler handler = new Handler();
final byte delimiter = 10; // This is the ASCII code for a newline
// character
stopWorker = false;
readBufferPosition = 0;
readBuffer = new byte[1024];
workerThread = new Thread(new Runnable() {
public void run() {
while (!Thread.currentThread().isInterrupted() && !stopWorker) {
try {
int bytesAvailable = mmInputStream.available();
if (bytesAvailable > 0) {
byte[] packetBytes = new byte[bytesAvailable];
mmInputStream.read(packetBytes);
for (int i = 0; i < bytesAvailable; i++) {
byte b = packetBytes[i];
if (b == delimiter) {
byte[] encodedBytes = new byte[readBufferPosition];
System.arraycopy(readBuffer, 0,
encodedBytes, 0,
encodedBytes.length);
final String data = new String(
encodedBytes, "US-ASCII");
readBufferPosition = 0;
handler.post(new Runnable() {
public void run() {
text.setText(data);
String goL = "g";
String goR = "f";
chronometerLeft = (Chronometer)findViewById(R.id.chronometerLeft);
chronometerRight = (Chronometer)findViewById(R.id.chronometerRight);
if(data.equals(goL)){
chronometerLeft.setBase(SystemClock.elapsedRealtime());
chronometerLeft.start();
if(data.equals(goR))
chronometerRight.setBase(SystemClock.elapsedRealtime());
chronometerRight.start();
}
}
});
} else {
readBuffer[readBufferPosition++] = b;
}
}
}
} catch (IOException ex) {
stopWorker = true;
}
}
}
});
workerThread.start();
}
Sorry to bother, but in your while loop condition, what does the '!' before Thread do?

Categories

Resources