[Herecast-commit] herecast/src/TodayItem whereami.cpp,1.10,1.11
Status: Beta
Brought to you by:
mdpaciga
|
From: Mark P. <mdp...@us...> - 2005-07-25 18:41:54
|
Update of /cvsroot/herecast/herecast/src/TodayItem In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32257/src/TodayItem Modified Files: whereami.cpp Log Message: moved HerecastCleanup call to fix device lockup. Index: whereami.cpp =================================================================== RCS file: /cvsroot/herecast/herecast/src/TodayItem/whereami.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** whereami.cpp 24 Jul 2005 20:28:49 -0000 1.10 --- whereami.cpp 25 Jul 2005 18:41:38 -0000 1.11 *************** *** 38,50 **** #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; --- 38,50 ---- #define UPDATE_INTERVAL_MS 10000 //how often to do location scan ! //global variables ! HICON g_hIcon; ! HWND g_hWnd; ! HWND g_hWndDummy = NULL; ! HINSTANCE g_hInst2; ! TCHAR g_acMessage[MESSAGE_BUF] = {0}; ! Location *g_Location; ! BOOL g_refreshNeeded = FALSE; ! WORD g_iconId = IDI_SMALLICON; *************** *** 57,152 **** /*************************************************************************/ ! /* Entry point for the dll */ /*************************************************************************/ BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { ! switch (ul_reason_for_call) ! { ! case DLL_PROCESS_ATTACH: ! ! // The DLL is being loaded for the first time by a given process. ! // Perform per-process initialization here. If the initialization ! // is successful, return TRUE; if unsuccessful, return FALSE. ! g_hInst2 = (HINSTANCE)hModule; ! ! //load the icon ! g_hIcon = (HICON)LoadImage(g_hInst2,MAKEINTRESOURCE(IDI_DISPLAYICON),IMAGE_ICON,16,16,LR_DEFAULTCOLOR ); ! WindowsUtils_SetNotificationIcon(g_hIcon); ! ! //initilize the application class, and set the global window handle ! UnregisterClass((LPCTSTR)LoadString(g_hInst2, IDS_TODAY_APPNAME,0,0), g_hInst2); ! UnregisterClass(TEXT("Herecast"), g_hInst2); ! InitilizeClasses(); ! g_hWnd = 0; g_Location = NULL; ! ! break; ! ! case DLL_PROCESS_DETACH: ! // The DLL is being unloaded by a given process. Do any ! // per-process clean up here, such as undoing what was done in ! // DLL_PROCESS_ATTACH. The return value is ignored. ! DestroyIcon(g_hIcon); ! //HerecastCleanup(); ! DestroyWindow(g_hWndDummy); ! UnregisterClass((LPCTSTR)LoadString(g_hInst2, IDS_TODAY_APPNAME,0,0), g_hInst2); ! UnregisterClass(TEXT("Herecast"), g_hInst2); ! g_hInst2 = NULL; ! break; ! } ! ! return TRUE; } /*************************************************************************/ ! /* Handle any messages that may be needed for the plugin */ ! /* Handled messages: */ ! /* WM_TODAYCUSTOM_QUERYREFRESHCACHE */ ! /* WM_CREATE */ ! /* WM_LBUTTONUP */ ! /* WM_PAINT */ ! /* WM_DESTROY */ /*************************************************************************/ LRESULT CALLBACK WndProc (HWND hwnd, UINT uimessage, WPARAM wParam, LPARAM lParam) { ! switch (uimessage) ! { ! //check to see if a refresh is required ! case WM_TODAYCUSTOM_QUERYREFRESHCACHE: ! { ! INT iItemHeight; ! BOOL bReturn = FALSE; ! TODAYLISTITEM *ptli = (TODAYLISTITEM *)wParam; ! if (WaitForSingleObject(SHELL_API_READY_EVENT, 0) == WAIT_TIMEOUT) ! { ! return FALSE; ! } ! ! // adjust the height of the today item ! 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; ! } ! ! return bReturn; ! ! } ! ! case WM_LBUTTONUP: if (LOWORD(lParam) > 16) { //clicked on today item text if (g_Location) --- 57,150 ---- /*************************************************************************/ ! /* Entry point for the dll */ /*************************************************************************/ BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { ! switch (ul_reason_for_call) ! { ! case DLL_PROCESS_ATTACH: ! ! // The DLL is being loaded for the first time by a given process. ! // Perform per-process initialization here. If the initialization ! // is successful, return TRUE; if unsuccessful, return FALSE. ! g_hInst2 = (HINSTANCE)hModule; ! ! //load the icon ! g_hIcon = (HICON)LoadImage(g_hInst2,MAKEINTRESOURCE(IDI_DISPLAYICON),IMAGE_ICON,16,16,LR_DEFAULTCOLOR ); ! WindowsUtils_SetNotificationIcon(g_hIcon); ! ! //initilize the application class, and set the global window handle ! UnregisterClass((LPCTSTR)LoadString(g_hInst2, IDS_TODAY_APPNAME,0,0), g_hInst2); ! UnregisterClass(TEXT("Herecast"), g_hInst2); ! InitilizeClasses(); ! g_hWnd = 0; g_Location = NULL; ! ! break; ! ! case DLL_PROCESS_DETACH: ! // The DLL is being unloaded by a given process. Do any ! // per-process clean up here, such as undoing what was done in ! // DLL_PROCESS_ATTACH. The return value is ignored. ! DestroyIcon(g_hIcon); ! UnregisterClass((LPCTSTR)LoadString(g_hInst2, IDS_TODAY_APPNAME,0,0), g_hInst2); ! UnregisterClass(TEXT("Herecast"), g_hInst2); ! g_hInst2 = NULL; ! break; ! } ! ! return TRUE; } /*************************************************************************/ ! /* Handle any messages that may be needed for the plugin */ ! /* Handled messages: */ ! /* WM_TODAYCUSTOM_QUERYREFRESHCACHE */ ! /* WM_CREATE */ ! /* WM_LBUTTONUP */ ! /* WM_PAINT */ ! /* WM_DESTROY */ /*************************************************************************/ LRESULT CALLBACK WndProc (HWND hwnd, UINT uimessage, WPARAM wParam, LPARAM lParam) { ! switch (uimessage) ! { ! //check to see if a refresh is required ! case WM_TODAYCUSTOM_QUERYREFRESHCACHE: ! { ! INT iItemHeight; ! BOOL bReturn = FALSE; ! TODAYLISTITEM *ptli = (TODAYLISTITEM *)wParam; ! if (WaitForSingleObject(SHELL_API_READY_EVENT, 0) == WAIT_TIMEOUT) ! { ! return FALSE; ! } ! ! // adjust the height of the today item ! 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; ! } ! ! return bReturn; ! ! } ! ! case WM_LBUTTONUP: if (LOWORD(lParam) > 16) { //clicked on today item text if (g_Location) *************** *** 156,254 **** dlgScanner2_create(g_hInst2, SW_SHOW); } ! break; ! ! case WM_PAINT: ! PAINTSTRUCT ps; ! RECT rcWindBounds; ! RECT rcMyBounds; ! HDC hDC; ! HFONT hFontOld; ! COLORREF crText; ! GetWindowRect( hwnd, &rcWindBounds); ! ! hDC = BeginPaint(hwnd, &ps); ! ! // create a custom rectangle relative to the client area ! rcMyBounds.left = 0; ! rcMyBounds.top = 0; ! rcMyBounds.right = rcWindBounds.right - rcWindBounds.left; ! rcMyBounds.bottom = rcWindBounds.bottom - rcWindBounds.top; ! ! // draw the icon on the screen ! SetBkMode(hDC, TRANSPARENT); ! DrawIcon(hDC, 2, 0, g_hIcon); ! ! BOOL bIsFarEast; ! LOGFONT lf; ! HFONT hSysFont; ! HFONT hFont; ! //determine if this is a Far East platform ! switch (PRIMARYLANGID(LANGIDFROMLCID(GetSystemDefaultLCID()))) ! { ! case LANG_CHINESE: ! case LANG_KOREAN: ! case LANG_JAPANESE: ! bIsFarEast = TRUE; ! break; ! ! default: ! bIsFarEast = FALSE; ! break; ! } ! hSysFont = (HFONT) GetStockObject(SYSTEM_FONT); ! GetObject(hSysFont, sizeof(LOGFONT), &lf); ! // If it is far east, use a normal font at 9 points, ! // otherwise use a bold font as 8 points ! if (bIsFarEast) ! { ! lf.lfWeight = FW_NORMAL; ! // Calculate the font size, making sure to round the result to the nearest integer ! lf.lfHeight = (long) -((9.0 * (double)GetDeviceCaps(hDC, LOGPIXELSY) / 72.0)+.5); ! } ! else ! { ! lf.lfWeight = FW_NORMAL; //FW_BOLD; ! // Calculate the font size, making sure to round the result to the nearest integer ! lf.lfHeight = (long) -((8.0 * (double)GetDeviceCaps(hDC, LOGPIXELSY) / 72.0)+.5); ! } ! // create the font ! hFont = CreateFontIndirect(&lf); ! ! // Select the system font into the device context ! hFontOld = (HFONT) SelectObject(hDC, hFont); ! // determine the theme's current text color ! // this color will change when the user picks a new theme, ! // so get it each time the display needs to be painted ! crText = SendMessage(GetParent(hwnd), TODAYM_GETCOLOR, (WPARAM) TODAYCOLOR_TEXT, NULL); ! // set that color ! SetTextColor(hDC, crText); ! // 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 ! SelectObject(hDC, hFontOld); ! DeleteObject(hFont); ! EndPaint(hwnd, &ps); ! break; ! ! // this fills in the background with the today screen image ! case WM_ERASEBKGND: ! TODAYDRAWWATERMARKINFO dwi; ! dwi.hdc = (HDC)wParam; ! GetClientRect(hwnd, &dwi.rc); ! ! dwi.hwnd = hwnd; ! SendMessage(GetParent(hwnd), TODAYM_DRAWWATERMARK, 0,(LPARAM)&dwi); ! return TRUE; case WM_COMMAND: --- 154,252 ---- dlgScanner2_create(g_hInst2, SW_SHOW); } ! break; ! ! case WM_PAINT: ! PAINTSTRUCT ps; ! RECT rcWindBounds; ! RECT rcMyBounds; ! HDC hDC; ! HFONT hFontOld; ! COLORREF crText; ! GetWindowRect( hwnd, &rcWindBounds); ! ! hDC = BeginPaint(hwnd, &ps); ! ! // create a custom rectangle relative to the client area ! rcMyBounds.left = 0; ! rcMyBounds.top = 0; ! rcMyBounds.right = rcWindBounds.right - rcWindBounds.left; ! rcMyBounds.bottom = rcWindBounds.bottom - rcWindBounds.top; ! ! // draw the icon on the screen ! SetBkMode(hDC, TRANSPARENT); ! DrawIcon(hDC, 2, 0, g_hIcon); ! ! BOOL bIsFarEast; ! LOGFONT lf; ! HFONT hSysFont; ! HFONT hFont; ! //determine if this is a Far East platform ! switch (PRIMARYLANGID(LANGIDFROMLCID(GetSystemDefaultLCID()))) ! { ! case LANG_CHINESE: ! case LANG_KOREAN: ! case LANG_JAPANESE: ! bIsFarEast = TRUE; ! break; ! ! default: ! bIsFarEast = FALSE; ! break; ! } ! hSysFont = (HFONT) GetStockObject(SYSTEM_FONT); ! GetObject(hSysFont, sizeof(LOGFONT), &lf); ! // If it is far east, use a normal font at 9 points, ! // otherwise use a bold font as 8 points ! if (bIsFarEast) ! { ! lf.lfWeight = FW_NORMAL; ! // Calculate the font size, making sure to round the result to the nearest integer ! lf.lfHeight = (long) -((9.0 * (double)GetDeviceCaps(hDC, LOGPIXELSY) / 72.0)+.5); ! } ! else ! { ! lf.lfWeight = FW_NORMAL; //FW_BOLD; ! // Calculate the font size, making sure to round the result to the nearest integer ! lf.lfHeight = (long) -((8.0 * (double)GetDeviceCaps(hDC, LOGPIXELSY) / 72.0)+.5); ! } ! // create the font ! hFont = CreateFontIndirect(&lf); ! ! // Select the system font into the device context ! hFontOld = (HFONT) SelectObject(hDC, hFont); ! // determine the theme's current text color ! // this color will change when the user picks a new theme, ! // so get it each time the display needs to be painted ! crText = SendMessage(GetParent(hwnd), TODAYM_GETCOLOR, (WPARAM) TODAYCOLOR_TEXT, NULL); ! // set that color ! SetTextColor(hDC, crText); ! // 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 ! SelectObject(hDC, hFontOld); ! DeleteObject(hFont); ! EndPaint(hwnd, &ps); ! break; ! ! // this fills in the background with the today screen image ! case WM_ERASEBKGND: ! TODAYDRAWWATERMARKINFO dwi; ! dwi.hdc = (HDC)wParam; ! GetClientRect(hwnd, &dwi.rc); ! ! dwi.hwnd = hwnd; ! SendMessage(GetParent(hwnd), TODAYM_DRAWWATERMARK, 0,(LPARAM)&dwi); ! return TRUE; case WM_COMMAND: *************** *** 256,259 **** --- 254,262 ---- break; + case WM_DESTROY: + // destroy the main dummy window too + HerecastCleanup(); + return 0; + case WM_NOTIFY: NMHDR *nmhptr = (LPNMHDR)lParam; *************** *** 273,279 **** } break; ! } ! return DefWindowProc (hwnd, uimessage, wParam, lParam) ; } --- 276,282 ---- } break; ! } ! return DefWindowProc (hwnd, uimessage, wParam, lParam) ; } *************** *** 301,312 **** break; ! case WM_DESTROY: KillTimer(hWnd, ID_TIMER_UPDATE); WebAgent::shutdown(); ! break; case WM_COMMAND: ! wmId = LOWORD(wParam); ! wmEvent = HIWORD(wParam); switch (wmId) { case IDMSG_ADD_SUBSCRIPTION: { --- 304,315 ---- break; ! case WM_DESTROY: KillTimer(hWnd, ID_TIMER_UPDATE); WebAgent::shutdown(); ! break; case WM_COMMAND: ! wmId = LOWORD(wParam); ! wmEvent = HIWORD(wParam); switch (wmId) { case IDMSG_ADD_SUBSCRIPTION: { *************** *** 391,423 **** /*************************************************************************/ ! /* Create and register our window class for the today item */ /*************************************************************************/ INT InitilizeClasses() { ! WNDCLASS wc; ! memset(&wc, 0, sizeof(wc)); ! ! wc.style = 0; ! wc.lpfnWndProc = (WNDPROC) WndProc; ! wc.hInstance = g_hInst2; ! wc.hIcon = 0; ! wc.hCursor = 0; ! wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); ! //wc.lpszClassName = (LPCTSTR)LoadString(g_hInst2, IDS_TODAY_WINDOWCLASS,0,0); wc.lpszClassName = TEXT("dlgHerecastTodayItemClass"); ! ! //register our today item window ! if(!RegisterClass(&wc)) { ! return 0 ; ! } // create another class for the "public" window, similar to the above ! wc.lpfnWndProc = (WNDPROC) WndProc_dummy; wc.lpszClassName = TEXT("Herecast"); ! ! //register our window ! if(!RegisterClass(&wc)) { ! return 0 ; ! } return 1; } --- 394,426 ---- /*************************************************************************/ ! /* Create and register our window class for the today item */ /*************************************************************************/ INT InitilizeClasses() { ! WNDCLASS wc; ! memset(&wc, 0, sizeof(wc)); ! ! wc.style = 0; ! wc.lpfnWndProc = (WNDPROC) WndProc; ! wc.hInstance = g_hInst2; ! wc.hIcon = 0; ! wc.hCursor = 0; ! wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); ! //wc.lpszClassName = (LPCTSTR)LoadString(g_hInst2, IDS_TODAY_WINDOWCLASS,0,0); wc.lpszClassName = TEXT("dlgHerecastTodayItemClass"); ! ! //register our today item window ! if(!RegisterClass(&wc)) { ! return 0 ; ! } // create another class for the "public" window, similar to the above ! wc.lpfnWndProc = (WNDPROC) WndProc_dummy; wc.lpszClassName = TEXT("Herecast"); ! ! //register our window ! if(!RegisterClass(&wc)) { ! return 0 ; ! } return 1; } *************** *** 457,461 **** /*************************************************************************/ ! /* Initilize the DLL by creating a new window */ /*************************************************************************/ HWND InitializeCustomItem(TODAYLISTITEM *ptli, HWND hwndParent) --- 460,464 ---- /*************************************************************************/ ! /* Initilize the DLL by creating a new window */ /*************************************************************************/ HWND InitializeCustomItem(TODAYLISTITEM *ptli, HWND hwndParent) *************** *** 473,482 **** LPCTSTR className = TEXT("dlgHerecastTodayItemClass"); //LPCTSTR className=(LPCTSTR)LoadString(g_hInst2,IDS_TODAY_WINDOWCLASS,0,0); ! LPCTSTR appName = (LPCTSTR)LoadString(g_hInst2,IDS_TODAY_APPNAME,0,0); ! ! //create a new window ! g_hWnd = CreateWindow(className,appName,WS_VISIBLE | WS_CHILD, ! 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) { --- 476,485 ---- LPCTSTR className = TEXT("dlgHerecastTodayItemClass"); //LPCTSTR className=(LPCTSTR)LoadString(g_hInst2,IDS_TODAY_WINDOWCLASS,0,0); ! LPCTSTR appName = (LPCTSTR)LoadString(g_hInst2,IDS_TODAY_APPNAME,0,0); ! ! //create a new window ! g_hWnd = CreateWindow(className,appName,WS_VISIBLE | WS_CHILD, ! 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) { *************** *** 485,500 **** } ! // attach our winproc to the newly created window ! SetWindowLong(g_hWnd, GWL_WNDPROC, (LONG) WndProc); ! ! //display the window ! ShowWindow (g_hWnd, SW_SHOWNORMAL); ! UpdateWindow (g_hWnd) ; ! return g_hWnd; } /*************************************************************************/ ! /* Message Handler for the options dialog */ /*************************************************************************/ LRESULT WINAPI CustomItemOptionsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) --- 488,503 ---- } ! // attach our winproc to the newly created window ! SetWindowLong(g_hWnd, GWL_WNDPROC, (LONG) WndProc); ! ! //display the window ! ShowWindow (g_hWnd, SW_SHOWNORMAL); ! UpdateWindow (g_hWnd) ; ! return g_hWnd; } /*************************************************************************/ ! /* Message Handler for the options dialog */ /*************************************************************************/ LRESULT WINAPI CustomItemOptionsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) |