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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Any thing wrong in this peace of code?

Any thing wrong in this peace of code?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 Posts 4 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.
  • G Offline
    G Offline
    G Haranadh
    wrote on last edited by
    #1

    CDC *pDC; pDC = GetDC(); DrawLed(pDC,m_nLedColor,m_nLedMode,m_nLedShape); ReleaseDC(pDC); I am getting run time error:(:confused:


    Nice talking to you. :-O
    If you judge people, you have no time to love them. -- Mother Teresa

    PJ ArendsP P J G 4 Replies Last reply
    0
    • G G Haranadh

      CDC *pDC; pDC = GetDC(); DrawLed(pDC,m_nLedColor,m_nLedMode,m_nLedShape); ReleaseDC(pDC); I am getting run time error:(:confused:


      Nice talking to you. :-O
      If you judge people, you have no time to love them. -- Mother Teresa

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      G Haranadh wrote:

      I am getting run time error

      And the error is?


      You may be right
      I may be crazy
      -- Billy Joel --

      Within you lies the power for good, use it!!!

      Within you lies the power for good; Use it!

      1 Reply Last reply
      0
      • G G Haranadh

        CDC *pDC; pDC = GetDC(); DrawLed(pDC,m_nLedColor,m_nLedMode,m_nLedShape); ReleaseDC(pDC); I am getting run time error:(:confused:


        Nice talking to you. :-O
        If you judge people, you have no time to love them. -- Mother Teresa

        P Offline
        P Offline
        prasad_som
        wrote on last edited by
        #3

        Have you tried running it through debugger, and what call stack says ?

        G Haranadh wrote:

        DrawLed(pDC,m_nLedColor,m_nLedMode,m_nLedShape);

        This is very insufficient information, to guess the problem.

        Prasad Notifier using ATL | Operator new[],delete[][^]

        G 1 Reply Last reply
        0
        • G G Haranadh

          CDC *pDC; pDC = GetDC(); DrawLed(pDC,m_nLedColor,m_nLedMode,m_nLedShape); ReleaseDC(pDC); I am getting run time error:(:confused:


          Nice talking to you. :-O
          If you judge people, you have no time to love them. -- Mother Teresa

          J Offline
          J Offline
          John R Shaw
          wrote on last edited by
          #4

          Absolutely not, but like prasad_som said we do not have enough information. What is the prototype of ‘DrawLed”? You did not give the header, and more importantly you did not state the library. Without those it is a total mystery.

          INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

          1 Reply Last reply
          0
          • G G Haranadh

            CDC *pDC; pDC = GetDC(); DrawLed(pDC,m_nLedColor,m_nLedMode,m_nLedShape); ReleaseDC(pDC); I am getting run time error:(:confused:


            Nice talking to you. :-O
            If you judge people, you have no time to love them. -- Mother Teresa

            G Offline
            G Offline
            G Haranadh
            wrote on last edited by
            #5
            ///////////////////////////////////////////////////////////////////////////////
            // Name:		SetLed
            // Description:	This method will draw the LED to the specified DC.
            //
            // Entry:
            //				CDC *pDC - DC to draw to
            //
            //				int iLedColor - Where color is defined by:
            //			 		LED_COLOR_RED
            //					LED_COLOR_GREEN
            //					LED_COLOR_YELLOW
            //					LED_COLOR_BLUE
            //
            //				int iMode - where mode is defined by:
            //					LED_ON
            //					LED_OFF
            //					LED_DISABLED
            //
            //				int iShape - where shape is defined by:
            //					LED_ROUND
            //					LED_SQUARE
            ///////////////////////////////////////////////////////////////////////////////
            void CLed::DrawLed(CDC *pDC,int nLEDColor, int nMode, int nShape)
            {
            	CRect rect;
            	GetClientRect(&rect);
            
            	// Center led within an oversized window
            	if(rect.Width() >= LED_SIZE && rect.Height() >= LED_SIZE)
            	{
            		int nWidth = rect.Width();
            		int nHeight = rect.Height();
            		rect.left += (nWidth - LED_SIZE)/2;
            		rect.right -= (nWidth - LED_SIZE)/2;
            		rect.top += (nHeight - LED_SIZE)/2;
            		rect.bottom -= (nHeight - LED_SIZE)/2;
            	}
            
            	// Prepare temporary DCs and bitmaps
            	CBitmap TransBitmap;
            	TransBitmap.CreateBitmap(LED_SIZE,LED_SIZE,1,1,NULL);
            	CBitmap bitmapTemp;
            	CBitmap* pBitmap = &m_LedBitmap;
            	CDC srcDC;
            	CDC dcMask;
            	CDC TempDC;
            	TempDC.CreateCompatibleDC(pDC);
            	srcDC.CreateCompatibleDC(pDC);
            	dcMask.CreateCompatibleDC(pDC);
            
            	CBitmap* pOldBitmap = srcDC.SelectObject(pBitmap);
            	CBitmap* pOldMaskbitmap = dcMask.SelectObject(&TransBitmap);
            	bitmapTemp.CreateCompatibleBitmap(pDC,LED_SIZE,LED_SIZE);
            
            	// Work with tempDC and bitmapTemp to reduce flickering
            	CBitmap *pOldBitmapTemp = TempDC.SelectObject(&bitmapTemp);
            	TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE, pDC, rect.left, rect.top, SRCCOPY); 
            
            	// Create mask
            	COLORREF OldBkColor = srcDC.SetBkColor(RGB(255,0,255));
            	dcMask.BitBlt(0, 0, LED_SIZE, LED_SIZE,&srcDC, nMode*LED_SIZE, nLEDColor+nShape, SRCCOPY); 
            	TempDC.SetBkColor(OldBkColor);
            
            	// Using the IDB_LEDS bitmap, index into the bitmap for the appropriate
            	// LED. By using the mask color (RGB(255,0,255)) a mask has been created
            	// so the bitmap will appear transparent.
            	TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE, &srcDC, nMode*LED_SIZE, nLEDColor+nShape, SRCINVERT); 
            	TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE,&dcMask, 0, 0, SRCAND); 
            	TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE, &srcDC, nMode*LED_SIZE, nLEDColor+nShape, SRCINVERT); 
            
            	// Since the actual minipulation is done to tempDC so there is minimal
            	// flicker, it is now time to draw the r
            
            1 Reply Last reply
            0
            • P prasad_som

              Have you tried running it through debugger, and what call stack says ?

              G Haranadh wrote:

              DrawLed(pDC,m_nLedColor,m_nLedMode,m_nLedShape);

              This is very insufficient information, to guess the problem.

              Prasad Notifier using ATL | Operator new[],delete[][^]

              G Offline
              G Offline
              G Haranadh
              wrote on last edited by
              #6

              Please see this code.... Sorry for late.:)[^]


              Nice talking to you. :-O
              If you judge people, you have no time to love them. -- Mother Teresa

              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