[Herecast-commit] herecast/src/TodayItem whereami.cpp,1.8,1.9
Status: Beta
Brought to you by:
mdpaciga
|
From: Mark P. <mdp...@us...> - 2005-07-24 19:34:29
|
Update of /cvsroot/herecast/herecast/src/TodayItem In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29530/src/TodayItem Modified Files: whereami.cpp Log Message: moved important parts to a new doScan function and the dummy window (more like the XP version); re-arranged some stuff and deleted unused variables Index: whereami.cpp =================================================================== RCS file: /cvsroot/herecast/herecast/src/TodayItem/whereami.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** whereami.cpp 24 Jul 2005 18:21:54 -0000 1.8 --- whereami.cpp 24 Jul 2005 19:34:20 -0000 1.9 *************** *** 35,57 **** #include "../HerecastLib/LibMain/herecast.h" ! #define INVALID_HEIGHT 0xFFFFFFFF ! #define UPDATE_INTERVAL 5 // * 2 seconds? ! #define UPDATE_INTERVAL_MS 10000 //applies to the new fake window //global variables HICON g_hIcon; - UINT g_plugInHeight; HWND g_hWnd; HWND g_hWndDummy; HINSTANCE g_hInst2; ! BOOL g_bFirstDisplay = TRUE; ! HWND g_hMessage; ! TCHAR g_acMessage[MESSAGE_BUF]; ! BOOL g_bUserSet; Location *g_Location; // forward function declarations static INT InitilizeClasses(); /*************************************************************************/ --- 35,56 ---- #include "../HerecastLib/LibMain/herecast.h" ! #define INVALID_HEIGHT 0xFFFFFFFF ! #define UPDATE_INTERVAL_MS 10000 //how often to do location scan //global variables HICON g_hIcon; HWND g_hWnd; HWND g_hWndDummy; HINSTANCE g_hInst2; ! TCHAR g_acMessage[MESSAGE_BUF] = {0}; Location *g_Location; + BOOL g_refreshNeeded = FALSE; + WORD g_iconId = IDI_SMALLICON; // forward function declarations static INT InitilizeClasses(); + VOID doScan(HWND hWnd); + /*************************************************************************/ *************** *** 116,124 **** { INT iItemHeight; ! TCHAR *acMessage; ! ! BOOL bReturn = FALSE; ! ! TODAYLISTITEM *ptli = (TODAYLISTITEM *)wParam; --- 115,119 ---- { INT iItemHeight; ! BOOL bReturn = FALSE; TODAYLISTITEM *ptli = (TODAYLISTITEM *)wParam; *************** *** 132,179 **** iItemHeight = 20; ! // determine location and see if it has changed ! //static time_t nextUpdate = UPDATE_INTERVAL; ! static time_t nextUpdate = 0; ! static bFirstTime = true; ! if (nextUpdate-- <= 0){ ! ! // if the device was just rebooted, we can't do new Location too fast. ! if (bFirstTime && (GetTickCount() < 20000)) { ! acMessage = L"Searching for a wireless signal..."; ! bFirstTime = false; ! nextUpdate = 2; ! } ! else { ! nextUpdate = UPDATE_INTERVAL; ! ! if (!g_Location) { ! g_Location = new Location(g_hInst2); ! WindowsUtils_SetNotificationWindow(hwnd); ! ! // when the program is started, check if any new subscriptions ! // have been added while the program was closed. ! // TODO: don't do this until after a location fix has been established ! SubscriptionAgent *pSA = SubscriptionAgent::instance(); ! pSA->checkNew(g_hInst2, hwnd); ! } ! ! g_Location->scan(); ! g_Location->checkUploadNeeded(); ! ! acMessage = g_Location->toString(); ! } ! ! if(wcscmp(acMessage, g_acMessage) != 0) { ! wcscpy(g_acMessage, acMessage); ! bReturn = TRUE; ! } ! } ! ! if (NULL == ptli) bReturn = TRUE; ! ! if (0 == ptli->cyp) ! { ptli->cyp = iItemHeight; bReturn = TRUE; --- 127,140 ---- iItemHeight = 20; ! // determine if the item text should be changed ! if (g_refreshNeeded) { ! g_refreshNeeded = FALSE; ! bReturn = TRUE; ! } ! if (NULL == ptli) { bReturn = TRUE; ! } ! else if (0 == ptli->cyp) { ptli->cyp = iItemHeight; bReturn = TRUE; *************** *** 182,191 **** return bReturn; - } - case WM_CREATE: - break; - case WM_LBUTTONUP: if (LOWORD(lParam) > 16) { //clicked on today item text --- 143,148 ---- *************** *** 204,208 **** HDC hDC; HFONT hFontOld; - TCHAR szTextBuffer[MESSAGE_BUF]; COLORREF crText; --- 161,164 ---- *************** *** 273,278 **** // draw the item text rcMyBounds.left = rcMyBounds.left + 30; ! wsprintf(szTextBuffer, g_acMessage); ! DrawText(hDC, szTextBuffer, -1, &rcMyBounds, DT_LEFT); // Select the previous font back into the device context --- 229,233 ---- // draw the item text rcMyBounds.left = rcMyBounds.left + 30; ! DrawText(hDC, g_acMessage, -1, &rcMyBounds, DT_LEFT); // Select the previous font back into the device context *************** *** 284,291 **** break; - case WM_DESTROY : - WebAgent::shutdown(); - return 0 ; - // this fills in the background with the today screen image case WM_ERASEBKGND: --- 239,242 ---- *************** *** 328,344 **** { INT wmId, wmEvent; - //COPYDATASTRUCT *pCD; switch (uimessage) { case WM_CREATE: SetTimer(hWnd, ID_TIMER_UPDATE, UPDATE_INTERVAL_MS, NULL); break; case WM_TIMER: ! //TODO doScan(hWnd); break; case WM_DESTROY: KillTimer(hWnd, ID_TIMER_UPDATE); break; --- 279,304 ---- { INT wmId, wmEvent; switch (uimessage) { case WM_CREATE: + doScan(hWnd); SetTimer(hWnd, ID_TIMER_UPDATE, UPDATE_INTERVAL_MS, NULL); + + // when the program is started, check if any new subscriptions + // have been added while the program was closed. + { + SubscriptionAgent *pSA = SubscriptionAgent::instance(); + pSA->checkNew(g_hInst2, hWnd); + } + break; case WM_TIMER: ! doScan(hWnd); break; case WM_DESTROY: KillTimer(hWnd, ID_TIMER_UPDATE); + WebAgent::shutdown(); break; *************** *** 384,387 **** --- 344,391 ---- /*************************************************************************/ + /* Performs a location scan */ + /*************************************************************************/ + VOID doScan(HWND hWnd) + { + PTCHAR acMessage; + DWORD status = 0; + + + // if the device has just rebooted, don't scan yet + + if (GetTickCount() < 20000) { + wcscpy(g_acMessage, L"Searching for a wireless signal..."); + g_refreshNeeded = TRUE; + return; + } + + + // if the Location object hasn't been created yet, do so + + if (!g_Location) { + g_Location = new Location(g_hInst2); + WindowsUtils_SetNotificationWindow(hWnd); + } + + + g_Location->scan(); + g_Location->checkUploadNeeded(); + acMessage = g_Location->toString(&status); + + if (wcscmp(acMessage, g_acMessage)) { + wcscpy(g_acMessage, acMessage); + + g_iconId = IDI_SMALLICON; + if (status & APDB_LOOKUP_NOTFOUND) g_iconId = IDI_STATUS_UNKNOWN; + else if (status & APDB_LOOKUP_BUSY) g_iconId = IDI_STATUS_BUSY; + else if (status & APDB_LOOKUP_ERROR) g_iconId = IDI_STATUS_ERROR; + + g_refreshNeeded = TRUE; + + } + } + + + /*************************************************************************/ /* Create and register our window class for the today item */ /*************************************************************************/ *************** *** 426,429 **** --- 430,448 ---- } + + // create "dummy" window at the top level to receive messages from + // other applications + g_hWndDummy = CreateWindow(TEXT("Herecast"), TEXT("Herecast"), 0, + CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, g_hInst2, NULL); + + if (!g_hWndDummy) { + return NULL; + } + + ShowWindow(g_hWndDummy, SW_HIDE); //this window is never actually shown + UpdateWindow(g_hWndDummy); + + + // create the main today item window LPCTSTR className = TEXT("dlgHerecastTodayItemClass"); //LPCTSTR className=(LPCTSTR)LoadString(g_hInst2,IDS_TODAY_WINDOWCLASS,0,0); *************** *** 434,437 **** --- 453,463 ---- CW_USEDEFAULT,CW_USEDEFAULT,240,0,hwndParent, NULL, g_hInst2, NULL) ; + // if the second window didn't work, destroy both and return + if (!g_hWnd) { + DestroyWindow(g_hWndDummy); + g_hWndDummy = NULL; + return NULL; + } + // attach our winproc to the newly created window SetWindowLong(g_hWnd, GWL_WNDPROC, (LONG) WndProc); *************** *** 441,460 **** UpdateWindow (g_hWnd) ; - - // create a second "dummy" window at the top level to receive messages - // from other applications - g_hWndDummy = CreateWindow(TEXT("Herecast"), TEXT("Herecast"), 0, - CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, g_hInst2, NULL); - - if (!g_hWndDummy) { - DestroyWindow(g_hWnd); - g_hWnd = NULL; - return NULL; - } - - ShowWindow(g_hWndDummy, SW_HIDE); //this window is never actually shown - UpdateWindow(g_hWndDummy); - - return g_hWnd; } --- 467,470 ---- |