April 24, 2024, 04:46:45 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Custom control question

Started by Haim, November 07, 2008, 08:44:33 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Haim

Hello,
I created a simple custom control.
It gets painted in the wndproc, in response to WM_ERASEBKGND and WM_PAINT messages.
This quite restricts the usability of the class. I would like to virtualize the the painting of the control, with VIRTUAL metthods.
Can anyone tell me how to replace the functionality from the WM_PAINT response in the WNDPROC with a virtual DoPaint method?

Haim

Ionic Wind Support Team

Depends on how its written.

If your basing it off of the built in window class then simply override OnPaint to do your drawing.

If you're building it from scratch using your own class then store the THIS pointer in the windows data area when creating the control:

SetWindowLongA(m_hwnd,0,this);

Then in your API handler for the control you can retrieve the "this" pointer, and call your own virtual functions within the class.

MyControl *pWnd = GetWindowLongA(hwnd,0)

   SELECT uMsg
   {
      CASE WM_PAINT:
         if(pWnd <> NULL)
            result = *pWnd.OnPaint(wParam, lParam);
      CASE WM_ERASEBKGND:
         if(pWnd <> NULL)
            result = *pWnd.OnErase(wParam, lParam);

Paul.
Ionic Wind Support Team

Haim

Thank you Paul for your explanation.
I am using the "from scratch" method and i'll try your suggestion very soon.
Thanks again.

Haim

Haim

Hello,
I am having trouble implementing a virtual method of a custom control.
Everything works OK when I remove the 'VIRTUAL' from the code. When I use VIRTUAL, the method does not get called.
What am I doing wrong?

The control is defined as:

CLASS CShapeCtrl
{
   DECLARE WndProc(UINT uMsg,WPARAM wParam,LPARAM lParam),UINT;
   DECLARE CShapeCtrl();
   DECLARE _CShapeCtrl();
   DECLARE Init(),int;
   DECLARE VIRTUAL OnPaint(WPARAM wparam,LPARAM lparam),int;
   
   HWND m_hwnd;
   HWND m_hparent;
   int m_type;
}


The OnPaint method is defined as:

CShapeCtrl::OnPaint(WPARAM wparam, LPARAM lparam),int
{
   
   PAINTSTRUCT ps;
   rect rc;
   ::getclientrect(m_hwnd,&rc);
   beginpaint(m_hwnd,&ps);
   point p;
   textouta(ps.hdc,10,10,"PAINT",5);
   movetoex(ps.hdc,rc.left,rc.top,&p);
   lineto(ps.hdc,rc.right,rc.bottom);
   endpaint(m_hwnd,&ps);
   RETURN TRUE;
}

and it is called from the WndProc like this:


CShapeCtrl::WndProc(UINT uMsg,WPARAM wParam,LPARAM lParam),UINT
{
select (uMsg)
{
case WM_PAINT:
         RETURN OnPaint(wparam, lparam);
....
}
....

}

Any help would be appreciated.

Haim