Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. my systray clock color changer code do not work and it crashes

my systray clock color changer code do not work and it crashes

Scheduled Pinned Locked Moved C / C++ / MFC
c++linux
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ELY M
    wrote on last edited by
    #1

    This is my MFC dialog project. Im working on code to change my systray clock color to some colors. both background and text to different color. take a look at my code. void CStart_Button_ChangerDlg::OnClock() { RECT rc; HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL); if (hWnd) { if (NULL != (hWnd = ::FindWindowEx(hWnd, NULL, "TrayNotifyWnd", NULL))) { if (NULL != (hWnd = ::FindWindowEx(hWnd, NULL, "TrayClockWClass", NULL))) { //::SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)(LPTSTR) TEXT("TEST") ); HDC hdcClock; COLORREF col; HDC hdc; char s[1024]; if(hdcClock) DeleteDC(hdcClock); hdcClock = NULL; //if(bFillTray) hWnd = ::GetParent(hWnd); ::GetClientRect(hWnd, &rc); hdc = ::GetDC(NULL); hdcClock = CreateCompatibleDC(hdc); if(!hdcClock) { ::ReleaseDC(NULL, hdc); return; } //SelectObject(hdcClock, hFon); SetBkColor(hdcClock, RGB(0,0,255)); SetBkMode(hdcClock, TRANSPARENT); SetTextAlign(hdcClock, TA_CENTER|TA_TOP); SetTextColor(hdcClock, RGB(0,255,255)); //FillClock(hWnd, hdcClock, &rc, 0); HBRUSH hbr; HDC hdcTemp; int nblink; RECT *prc; if(nblink == 0 || (nblink % 2)) col = RGB(255,255,0); else col = RGB(255,0,0); //if(col & 0x80000000) col = GetSysColor(col & 0x00ffffff); //SetBkMode(hdc, OPAQUE); //SetBkColor(hdc, col); hbr = CreateSolidBrush(col); FillRect(hdc, prc, hbr); DeleteObject(hbr); ::ReleaseDC(NULL, hdc); MessageBox("TEST PASSED"); } } }

    C 1 Reply Last reply
    0
    • E ELY M

      This is my MFC dialog project. Im working on code to change my systray clock color to some colors. both background and text to different color. take a look at my code. void CStart_Button_ChangerDlg::OnClock() { RECT rc; HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL); if (hWnd) { if (NULL != (hWnd = ::FindWindowEx(hWnd, NULL, "TrayNotifyWnd", NULL))) { if (NULL != (hWnd = ::FindWindowEx(hWnd, NULL, "TrayClockWClass", NULL))) { //::SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)(LPTSTR) TEXT("TEST") ); HDC hdcClock; COLORREF col; HDC hdc; char s[1024]; if(hdcClock) DeleteDC(hdcClock); hdcClock = NULL; //if(bFillTray) hWnd = ::GetParent(hWnd); ::GetClientRect(hWnd, &rc); hdc = ::GetDC(NULL); hdcClock = CreateCompatibleDC(hdc); if(!hdcClock) { ::ReleaseDC(NULL, hdc); return; } //SelectObject(hdcClock, hFon); SetBkColor(hdcClock, RGB(0,0,255)); SetBkMode(hdcClock, TRANSPARENT); SetTextAlign(hdcClock, TA_CENTER|TA_TOP); SetTextColor(hdcClock, RGB(0,255,255)); //FillClock(hWnd, hdcClock, &rc, 0); HBRUSH hbr; HDC hdcTemp; int nblink; RECT *prc; if(nblink == 0 || (nblink % 2)) col = RGB(255,255,0); else col = RGB(255,0,0); //if(col & 0x80000000) col = GetSysColor(col & 0x00ffffff); //SetBkMode(hdc, OPAQUE); //SetBkColor(hdc, col); hbr = CreateSolidBrush(col); FillRect(hdc, prc, hbr); DeleteObject(hbr); ::ReleaseDC(NULL, hdc); MessageBox("TEST PASSED"); } } }

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I put this code in a project and compiled it. Do you ignore warnings, or are they turned off ? HDC hdcClock; COLORREF col; HDC hdc; char s[1024]; if(hdcClock) DeleteDC(hdcClock); hdcClock = NULL; You do not set hdcClock to NULL when you create it, and you never set it to anything else before trying to delete it. It's not NULL, and so it will try to delete it, but it won't point to anything valid. int nblink; RECT *prc; if(nblink == 0 || (nblink % 2)) col = RGB(255,255,0); nblink, same problem. RECT *prc; if(nblink == 0 || (nblink % 2)) col = RGB(255,255,0); else col = RGB(255,0,0); //if(col & 0x80000000) col = GetSysColor(col & 0x00ffffff); //SetBkMode(hdc, OPAQUE); //SetBkColor(hdc, col); hbr = CreateSolidBrush(col); FillRect(hdc, prc, hbr); same problem - prc. NEVER create a variable without initialising it's value. And goodness knows what half this code was trying to do, I assume you found an online sample and deleted half the code ? Also, you should step through the debugger first, before asking for help. If you do that, you may solve the problem and you'll at least be able to tell us the line that blows up, and the error you get ( actually, you should have been able to tell us the error anyhow ). Christian Graus - Microsoft MVP - C++

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups