IonicWind Software

IWBasic => GUI Central => Topic started by: fasecero on November 22, 2008, 02:30:56 PM

Title: Ownerdraw button not work
Post by: fasecero on November 22, 2008, 02:30:56 PM
Sorry, me again.
I'm trying to make an ownerdraw button... what's wrong here?

Quote

/* OWNERDRAW BUTTON */

$include "windows.inc"

window w1
CONST BUTTON_1 = 1
uint hDC ' Device context for the button

OPENWINDOW w1,0,0,300,202,@MINBOX|@MAXBOX|@SIZE|@NOAUTODRAW,NULL,"Ownerdraw Button",&main

REM when w1 = 0 the window has been closed
WAITUNTIL w1 = 0
END

SUB main
   SELECT @MESSAGE
      CASE @IDCREATE
         ' creating the ownerdraw button
         CONTROLEX w1, "BUTTON", "", 82, 85, 136, 32, BS_OWNERDRAW, 0, BUTTON_1

      CASE WM_DRAWITEM ' message send to w1 when the button need to be painted
         ' @LPARAM contain the type DRAWITEMSTRUCT
         ' the member hdc contain the DC of the button
         ' the member rcItem the type WINRECT of the button
         hDC = _CreateCompatibleDC(*<DRAWITEMSTRUCT>@LPARAM.hdc)
            ' here i wanna draw the frame
            _DrawFrameControl(hDC,*<DRAWITEMSTRUCT>@LPARAM.rcItem,DFC_BUTTON,DFCS_BUTTONPUSH)
            ' then here other stuff...
            ' ...
            ' ...
         _DeleteDC(hDC)

      CASE @IDCLOSEWINDOW
         CLOSEWINDOW w1

      CASE @IDCONTROL
         SELECT @CONTROLID
            CASE BUTTON_1
               IF @NOTIFYCODE = 0
                  /*button clicked*/
                  MESSAGEBOX w1,"hello","ownerdraw button clicked"
               ENDIF
         ENDSELECT
   ENDSELECT
RETURN
ENDSUB


The button exist because the click work, but the frame is not painted.
Any help are welcome :)
Title: Re: Ownerdraw button not work
Post by: Ionic Wind Support Team on November 23, 2008, 11:50:43 AM
In Emergence BASIC WM_DRAWITEM is sent to the controls handler, reflected from the internal WinProc.  So you'll need to subclass the control to get the message, or subclass the window to process it before it is reflected.

This is done because Emergence uses two owner drawn button types, @BUTTON and @RGNBUTTON.

If you don't know how to subclass a control then search the forums here, or ask ;)

Paul.
Title: Re: Ownerdraw button not work
Post by: fasecero on November 23, 2008, 11:20:41 PM
Ahhh i understand now, i see why the win procedure never get the message... i will subclass the button. Ty so much for your help and time  :)
Title: Re: Ownerdraw button not work
Post by: fasecero on November 28, 2008, 03:18:00 PM
Well, i cannot get it... here i did make a try using a button subclass, but the button still don't draw anything



/* OWNERDRAW BUTTON */

$include "windows.inc"

window w1
CONST BUTTON_1 = 1
uint hDC ' Device context for the button
int hbutton 'hwnd of the button
int oldbuttonproc ' contain the button procedure without subclassing


OPENWINDOW w1,0,0,300,202,@MINBOX|@MAXBOX|@SIZE,NULL,"Ownerdraw Button",&main

REM when w1 = 0 the window has been closed
WAITUNTIL w1 = 0
END

SUB main
   SELECT @MESSAGE
      CASE @IDCREATE
         ' creating the ownerdraw button
         CONTROLEX w1, "BUTTON", "", 82, 85, 136, 32, BS_OWNERDRAW, 0, BUTTON_1
' subclassing the control...
' drawbutton is the new button procedure
hbutton = GETCONTROLHANDLE(w1,BUTTON_1)
oldbuttonproc = _SetWindowLong(hbutton,GWL_WNDPROC,&drawbutton)


      CASE @IDCLOSEWINDOW
         CLOSEWINDOW w1

      CASE @IDCONTROL
         SELECT @CONTROLID
            CASE BUTTON_1
               IF @NOTIFYCODE = 0
                  /*button clicked*/
                  MESSAGEBOX w1,"ownerdraw button clicked","Hello"
               ENDIF
         ENDSELECT
   ENDSELECT
RETURN
ENDSUB

SUB drawbutton(hWnd:INT,uMsg:INT,wParam:INT,lParam:INT),INT
SELECT uMsg
CASE WM_DRAWITEM ' message send to w1 when the button need to be painted
' @LPARAM contain the type DRAWITEMSTRUCT
' the member hdc contain the DC of the button
' the member rcItem the type WINRECT of the button
SELECT *<DRAWITEMSTRUCT>lParam.CtlID
CASE BUTTON_1
hDC = _CreateCompatibleDC(*<DRAWITEMSTRUCT>lParam.hdc)
' here i wanna draw the frame
_DrawFrameControl(hDC,*<DRAWITEMSTRUCT>lParam.rcItem,DFC_BUTTON,DFCS_BUTTONPUSH)
' then here other stuff...
' ...
' ...
_DeleteDC(hDC)
ENDSELECT
ENDSELECT
RETURN _CallWindowProc(oldbuttonproc,hWnd,uMsg,wParam,lParam)
ENDSUB

Title: Re: Ownerdraw button not work
Post by: fasecero on November 28, 2008, 03:40:44 PM
k, don't know why, but works if i not use a DC Compatible, just directly draw in the DC obtained from lParam.
I mean replacing...


hDC = _CreateCompatibleDC(*<DRAWITEMSTRUCT>lParam.hdc)
    _DrawFrameControl(hDC,*<DRAWITEMSTRUCT>lParam.rcItem,DFC_BUTTON,DFCS_BUTTONPUSH)
_DeleteDC(hDC)


with...


hDC=*<DRAWITEMSTRUCT>lParam.hdc
_DrawFrameControl(hDC,*<DRAWITEMSTRUCT>lParam.rcItem,DFC_BUTTON,DFCS_BUTTONPUSH)

Title: Re: Ownerdraw button not work
Post by: Ionic Wind Support Team on November 28, 2008, 08:53:04 PM
Yes, it is a requirement of ownerdrawn controls that you have to use the device context passed by the WM_DRAWITEM message.  At least according to Microsoft ;)
Title: Re: Ownerdraw button not work
Post by: fasecero on November 28, 2008, 08:58:55 PM
lol, understood  :). Now i will to add the things that i wanna put in the buttons (image, text and so on). ty for you help in this issue.