I need draw a border color to static Frame control,
I have the code as below but it not work with my testing for static Frame and Window Dialog.
Please see the code and help me for this
void CTestDLLDlg::DrawFrameBorder(HWND hWnd,COLORREF refColor)
// Get the coordinates of the window on the screen
// Get a handle to the window's device context
HDC hDC = ::GetWindowDC(hWnd);
hPen = CreatePen(PS_INSIDEFRAME, 2* GetSystemMetrics(SM_CXBORDER), refColor);
// Draw the rectangle around the window
HPEN hOldPen = (HPEN)SelectObject(hDC, hPen);
HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(NULL_BRUSH));
Rectangle(hDC, 0, 0, (stRect.right - stRect.left), (stRect.bottom - stRect.top));
//Give the window its device context back, and destroy our pen
At initialize function I called as bellow:
CWnd* pWnd = GetDlgItem (IDC_AVATAR1);
//and for test more: DrawFrameBorder(this->m_hWnd,RGB(255,0,0))//red
But it seem to not draw the red border
Please help me
Thank in advance!
I assume that you are talking about the GroupBox...
Because the in OnInitDialog you are trying to draw the border, but do you know that the window is hidden at that time. You have to write the drawing code in OnPaint, which is called every time the window needs to be repainted.
Moreover it is not good practice to draw the control from another window. So I suggest you that you should derive a class from CStatic and write the code to draw the border inside it. Then create the member variable from this new class.
why dont use from one derived class
i write for button maybe it some helpful to you
void CButton::DrawItem(LPDRAWITEMSTRUCT lpDraw)
and you can use Framerect or Fillrect and ... in dc
if you want to this way you should derived from your class in example CButton and set OwnerDraw in property from your control
lately i am finding that I am adding functions in the public space only.. no protected no private.. may be just to access the functions easily.. how may i remove this habbit.
tell me true practical explaination that private or protected are must
You can do one thing. Create a variable in the public scope that is critical to your application and you don't want the user to modify value of the same.
If this value gets modified you are stuck.
Don't allow to do this.
You will have to think the criticallity of the variable each time you are going to declare them and at the same time you need to determine their scope
Somethings seem HARD to do, until we know how to do them.
Practices are making man perfect.
so through practice, u will be perfect.
Reading is a good option to know more and correct our assumptions and mistake and also it will fill the gaps in our knowledge.
If you read Code Complete 2, Effective C++ (or similar books), u will find that what u r doing is absolutly wrong.
Define scope for all classes u r creating.
Fix the interfaces, limit it to a minimum.
The public functions are used to communicate with other modules or object. where are as we are defining private functions for some internal calculation required by other functions in the class.
Suppose there is a function in your class which draws an object in your window. you don't need to share this function to others. because it is only required when a paint message comes in your object and draws the required object. it is limited to your class.
so scope ur object with minimum interfaces. never put internal functions to public, that is nto a good way of pragramming. if it is generic and can be used for others make it public static and meaningful.
I have a parent window, it has a Bitmap(GDI+) data member which draws a picture as background when OnPaint is called.
I create an Edit control and type a string in it. now I want to write the string to the background picture, at the exact position the Edit control be.
how to do that? help please
I ever called DrawText in OnOK, find when OnPaint is called, my string will be covered by background. so I want to make the string be part of background picture, but I don't konw how to do. help, help, help.......
-- modified at 2:39 Thursday 18th May, 2006
Last Visit: 31-Dec-99 18:00 Last Update: 29-Jul-21 22:45