I.R. developers...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Intrigued
    Indigo Rose Customer
    • Dec 2003
    • 6138

    I.R. developers...

    Brett, here is the code chunk in the Shape plugin object that I believe you suggest we check out (adjust) to get started with (as an example) with creating our own plugins. I understand this is not officially supported content, I am just hoping you have a minute to share a bit more information so I can get a grasp on how to approach learning plugin creation in C++.

    Here's the code chunk:

    Code:
    void CShapeObject::DrawShape(HDC hDC, HWND hMainWnd, RECT rcObRect,BOOL bVisible,BOOL bEnabled)
    {
    	if(!bVisible) return;
    	
    	//CBrush brushFill;
    	HBRUSH brushFill;
    	HBRUSH brushOld;
    	HPEN penStroke;
    	HPEN penOld;
    
    	if(m_nFillMode == modeSolid)
    	{
    		brushFill = CreateSolidBrush(m_crFillColor);
    		//brushFill.CreateSolidBrush(m_crFillColor);
    	} else
    	{
    		brushFill = (HBRUSH) GetStockObject(NULL_BRUSH);
    		//brushFill.CreateStockObject(NULL_BRUSH);
    	}
    
    	if(m_nStrokeMode == modeSolid)
    	{
    		penStroke = CreatePen(PS_SOLID,m_nStrokeWidth,m_crStrokeColor);
    		//penStroke.CreatePen(PS_SOLID,m_nStrokeWidth,m_crStrokeColor);
    	} else
    	{
    		penStroke = CreatePen(PS_NULL,m_nStrokeWidth,m_crStrokeColor);
    		//penStroke.CreatePen(PS_NULL,m_nStrokeWidth,m_crStrokeColor);
    	}
    
    	brushOld = (HBRUSH)SelectObject(hDC,brushFill);
    	penOld = (HPEN)SelectObject(hDC,penStroke);
    
    	switch(m_nType)
    	{
    	case typeElipse:
    		Ellipse(hDC,rcObRect.left,rcObRect.top,rcObRect.right,rcObRect.bottom);
    		break;
    	case typeRectangle:
    		Rectangle(hDC,rcObRect.left,rcObRect.top,rcObRect.right,rcObRect.bottom);
    		break;
    	case typeRoundedRect:
    		RoundRect(hDC,rcObRect.left,rcObRect.top,rcObRect.right,rcObRect.bottom,m_nCornerWidth,m_nCornerHeight);
    		break;
    	}
    
    	SelectObject(hDC,brushOld);
    	SelectObject(hDC,penOld);
    
    	DeleteObject(brushFill);
    	DeleteObject(penStroke);
    }
    I plan on working on this code chunk specifically to understand each part, to start with. But, any insight on what we are looking at to change first, to make our own plugin would be greatly appreciated. I am sure a few others here will agree when I say I appreciate your time and patience with me on this topic.
    Last edited by Intrigued; 02-03-2005, 08:24 PM.
    Intrigued
  • Intrigued
    Indigo Rose Customer
    • Dec 2003
    • 6138

    #2
    Incidently,I just finished installing Visual C++ 2005 Express (beta 1) and this Shape plugin was the first code to get to try it out.
    Intrigued

    Comment

    • Corey
      Indigo Rose Staff Alumni
      • Aug 2002
      • 9745

      #3
      Cool beans Intrigued. I'm with you all the way, anything which can help me learn how to create a plug-in would be more than welcome.

      Comment

      • Brett
        Indigo Rose Staff Member
        • Jan 2000
        • 2001

        #4
        OK, I'll try. Without knowing exactly what you are struggling with, here are some hightlights:

        This function (DrawShape) is called by AMS50 when it needs to re-draw the object.

        Code:
        if(!bVisible) return;
        bVisible is passed into this function to tell us if the object is visible or not. If not, then we just return because there is nothing to draw.

        Code:
        	HBRUSH brushFill;
        	HBRUSH brushOld;
        	HPEN penStroke;
        	HPEN penOld;
        Defining some variables. HBRUSH and HPEN are handles to the respective GDI objects. You can find out a LOT about GDI drawing and objects from the MSDN website.

        Code:
        	if(m_nFillMode == modeSolid)
        	{
        		brushFill = CreateSolidBrush(m_crFillColor);
        		//brushFill.CreateSolidBrush(m_crFillColor);
        	} else
        	{
        		brushFill = (HBRUSH) GetStockObject(NULL_BRUSH);
        		//brushFill.CreateStockObject(NULL_BRUSH);
        	}
        Depending on the value of m_nFillMode (which is a member variable of the CShapeObject class) we create a colored brush or a transparent brush.

        Code:
        	if(m_nStrokeMode == modeSolid)
        	{
        		penStroke = CreatePen(PS_SOLID,m_nStrokeWidth,m_crStrokeColor)  ;
        		//penStroke.CreatePen(PS_SOLID,m_nStrokeWidth,m_crStrokeColor)  ;
        	} else
        	{
        		penStroke = CreatePen(PS_NULL,m_nStrokeWidth,m_crStrokeColor);  
        		//penStroke.CreatePen(PS_NULL,m_nStrokeWidth,m_crStrokeColor);  
        	}
        Here we setup the pen depending on user preference from member variables.

        Code:
        	brushOld = (HBRUSH)SelectObject(hDC,brushFill);
        	penOld = (HPEN)SelectObject(hDC,penStroke);
        Select the new brush and pen into the device context and store handles to the old ones so we can restore them at the end (always a good practice).

        Code:
        	switch(m_nType)
        	{
        	case typeElipse:
        		Ellipse(hDC,rcObRect.left,rcObRect.top,rcObRect.right,rcObRect.bottom);
        		break;
        	case typeRectangle:
        		Rectangle(hDC,rcObRect.left,rcObRect.top,rcObRect.right,rcObRect.bottom);
        		break;
        	case typeRoundedRect:
        		RoundRect(hDC,rcObRect.left,rcObRect.top,rcObRect.right,rcObRect.bottom,m_nCornerWidth,m_nCornerHeight);
        		break;
        	}
        Based on what type of shape the user wants we call the appropriate GDI drawing function. This is the real guts of this function.

        Code:
        	SelectObject(hDC,brushOld);
        	SelectObject(hDC,penOld);
        Select the original brush and pen back into the device context so that we can then delete the new ones we made. This is standard windows GDI drawing practice.

        Code:
        	DeleteObject(brushFill);
        	DeleteObject(penStroke);
        Delete the GDI objects we created so we don't get memory leaks.

        Well, I hope that blow-by-blow helps a bit. Let me know if you have any specific quesitons about it. If you want a little challenge, after the switch statement, use the API function TextOut to write "Hello Plugin!" on top of the shape. You could also use SetTextColor to change the color of the text.

        Comment

        • Intrigued
          Indigo Rose Customer
          • Dec 2003
          • 6138

          #5
          Originally posted by Brett
          OK, I'll try. Without knowing exactly what you are struggling with, here are some hightlights:

          This function (DrawShape) is called by AMS50 when it needs to re-draw the object.

          Code:
          if(!bVisible) return;
          bVisible is passed into this function to tell us if the object is visible or not. If not, then we just return because there is nothing to draw.

          Code:
          	HBRUSH brushFill;
          	HBRUSH brushOld;
          	HPEN penStroke;
          	HPEN penOld;
          Defining some variables. HBRUSH and HPEN are handles to the respective GDI objects. You can find out a LOT about GDI drawing and objects from the MSDN website.

          Code:
          	if(m_nFillMode == modeSolid)
          	{
          		brushFill = CreateSolidBrush(m_crFillColor);
          		//brushFill.CreateSolidBrush(m_crFillColor);
          	} else
          	{
          		brushFill = (HBRUSH) GetStockObject(NULL_BRUSH);
          		//brushFill.CreateStockObject(NULL_BRUSH);
          	}
          Depending on the value of m_nFillMode (which is a member variable of the CShapeObject class) we create a colored brush or a transparent brush.

          Code:
          	if(m_nStrokeMode == modeSolid)
          	{
          		penStroke = CreatePen(PS_SOLID,m_nStrokeWidth,m_crStrokeColor)  ;
          		//penStroke.CreatePen(PS_SOLID,m_nStrokeWidth,m_crStrokeColor)  ;
          	} else
          	{
          		penStroke = CreatePen(PS_NULL,m_nStrokeWidth,m_crStrokeColor);  
          		//penStroke.CreatePen(PS_NULL,m_nStrokeWidth,m_crStrokeColor);  
          	}
          Here we setup the pen depending on user preference from member variables.

          Code:
          	brushOld = (HBRUSH)SelectObject(hDC,brushFill);
          	penOld = (HPEN)SelectObject(hDC,penStroke);
          Select the new brush and pen into the device context and store handles to the old ones so we can restore them at the end (always a good practice).

          Code:
          	switch(m_nType)
          	{
          	case typeElipse:
          		Ellipse(hDC,rcObRect.left,rcObRect.top,rcObRect.right,rcObRect.bottom);
          		break;
          	case typeRectangle:
          		Rectangle(hDC,rcObRect.left,rcObRect.top,rcObRect.right,rcObRect.bottom);
          		break;
          	case typeRoundedRect:
          		RoundRect(hDC,rcObRect.left,rcObRect.top,rcObRect.right,rcObRect.bottom,m_nCornerWidth,m_nCornerHeight);
          		break;
          	}
          Based on what type of shape the user wants we call the appropriate GDI drawing function. This is the real guts of this function.

          Code:
          	SelectObject(hDC,brushOld);
          	SelectObject(hDC,penOld);
          Select the original brush and pen back into the device context so that we can then delete the new ones we made. This is standard windows GDI drawing practice.

          Code:
          	DeleteObject(brushFill);
          	DeleteObject(penStroke);
          Delete the GDI objects we created so we don't get memory leaks.

          Well, I hope that blow-by-blow helps a bit. Let me know if you have any specific quesitons about it. If you want a little challenge, after the switch statement, use the API function TextOut to write "Hello Plugin!" on top of the shape. You could also use SetTextColor to change the color of the text.
          Thank for taking some time tonight to shed some light on that chunk!

          I will be reviewing it tomorrow between breaks at work.

          Thanks again for the help.

          :yes
          Last edited by Intrigued; 02-03-2005, 10:20 PM. Reason: Code - Chunks - c++ - plugin
          Intrigued

          Comment

          • Corey
            Indigo Rose Staff Alumni
            • Aug 2002
            • 9745

            #6
            AWESOME! I always love to see stuff broken down like that. That really helps me, thanks Brett! :yes

            Comment

            • Derek
              Indigo Rose Customer
              • May 2001
              • 1254

              #7
              I'm with you on this too! Fantastic help and support and is ALWAYS very much appreciated.
              :yes :yes :yes

              [you know what i'd like to see, IR get the "Global Help and Support Award 2005" for outstanding and continued support. Maybe we should start such an award program.]
              -
              = Derek
              ["All glory comes from daring to begin" - fortune cookie]

              Comment

              Working...
              X