Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #1110

Re: Highlighting Buttons on tab page freezes program

From "Craig Dawson" <craig@control.nospam.net.au>
Newsgroups comp.lang.clipper.visual-objects
References (1 earlier) <iqa97b$1eh$1@speranza.aioe.org> <4dc8ba70$0$47013$c30e37c6@pit-reader.telstra.net> <iqb5ch$dn0$1@speranza.aioe.org> <4dc95f7f$0$47016$c30e37c6@pit-reader.telstra.net> <4dca2018$0$1573$91cee783@newsreader04.highway.telekom.at>
Subject Re: Highlighting Buttons on tab page freezes program
Date 2011-05-13 06:59 +1000
Message-ID <4dcc4a3f$0$47020$c30e37c6@pit-reader.telstra.net> (permalink)

Show all headers | View raw


Thanks Bernhard,

Here is the code to the IconPushButton class I currently have.
Can anyone see anything obvious in it that would cause the GDIs to keep 
increasing? It's driving me crazy.
Regards, Craig.

METHOD Enable() CLASS IconPushbutton

// added by PDB 24/2/2003 to be able to show a "disabled" icon

IF SELF:_lDisabled==TRUE // currently disabled

SELF:_lDisabled:=FALSE

ENDIF

IF SELF:_oIconEnabled <> NULL_OBJECT

SELF:UseIcon:=SELF:_oIconEnabled:Handle()

ENDIF

InvalidateRect(SELF:handle(),NULL_PTR, TRUE) // to fix repainting problem 
caused by VO2.6 if button used on tabpage

?

SUPER:Enable()

METHOD Disable() CLASS IconPushbutton

// added by PDB 24/2/2003 to be able to show a "disabled" icon

IF SELF:_lDisabled==FALSE

SELF:_lDisabled:=TRUE

ENDIF

IF SELF:_oIconDisabled <> NULL_OBJECT

SELF:UseIcon:= SELF:_oIconDisabled:Handle()

ELSE

// don't change icon but continue to use the "Upicon"

ENDIF

InvalidateRect(SELF:handle(),NULL_PTR, TRUE) // to fix repainting problem 
caused by VO2.6 if button used on tabpage

?

?

SUPER:Disable()

CLASS IconPushbutton INHERIT PUSHBUTTON

/*

Class from Harald Kogler: kog@kns.at feb 2003

I played with the Visual Themes some time ago... this works fine for me

This is a Class, which can Display an Icon or a Bitmap next to the

Button-Text or a Button-Backgroundcolor.

Should work on any Kind of Theme you've set...

*/

?

PROTECT lIsTabWindow AS LOGIC

PROTECT lHilight AS LOGIC

PROTECT lUseImage AS LOGIC

PROTECT lUseColor AS LOGIC

PROTECT dwImgType AS DWORD

PROTECT hImage AS PTR

PROTECT _lFocus AS LOGIC

PROTECT _lPressed AS LOGIC

PROTECT _lDisabled AS LOGIC

PROTECT oBackGround AS Brush

PROTECT oBitmap AS Bitmap

PROTECT pXPTheme AS PTR

PROTECT pXPOpenThemeFunc AS PTR

PROTECT pXPCloseThemeFunc AS PTR

PROTECT pXPDrawFrameFunc AS PTR

PROTECT pXPDrawEdgeFunc AS PTR

PROTECT lXP AS LOGIC

?

PROTECT _oIconEnabled AS icon // PDB

PROTECT _oIconDisabled AS icon // pdb

DECLARE METHOD UseBitmap

DECLARE ASSIGN UseIcon

DECLARE ASSIGN UseColor

?

METHOD AxitXP() CLASS IconPushbutton

IF SELF:lXP

PCALL(SELF:pXPCloseThemeFunc, SELF:pXPTheme)

ENDIF

?

METHOD Expose(oEvent) CLASS IconPushbutton

?

LOCAL hDC, hHandle AS PTR

LOCAL sRect IS _winRECT

LOCAL sPs IS _winPAINTSTRUCT

LOCAL hPenBlack, hFont, hBrushBack, hBackGround AS PTR

LOCAL dwBtnStyle AS DWORD

LOCAL lKillFont AS LOGIC

LOCAL hDCSrc AS PTR

LOCAL oSize AS Dimension

LOCAL nOffset AS INT

LOCAL nIconheight AS DWORD // PDB, so we can resize the icon according to 
the height of the button

LOCAL nREctWidth AS DWORD

LOCAL lMultiline AS LOGIC

?

LOCAL dwXPBtnStyle AS DWORD

hHandle := SELF:handle()

hDC := BeginPaint(hHandle, @sPs)

SetBkMode(hdc, TRANSPARENT)

hPenBlack := CreatePen(PS_SOLID, 0, GetSysColor(COLOR_BTNTEXT))

hBrushBack := CreateSolidBrush(GetSysColor(COLOR_3DFACE))

IF SELF:lUseColor

hBackGround := SELF:oBackGround:handle()

SelectObject (hDC, hBackGround)

ENDIF

?

?

sRect.top := 0

sRect.left := 0

sRect.bottom := SELF:size:height - 1

sRect.right := SELF:size:width - 1

dwBtnStyle := DFCS_BUTTONPUSH

dwXPBtnStyle := 1

IF (!SELF:_lPressed .AND. SELF:_lFocus) .OR. SELF:_lPressed

IF !SELF:lXP

SelectObject(hDC, hPenBlack)

MoveToEx(hDC, sRect.left, sRect.top, NULL_PTR)

LineTo(hDC, sRect.right, sRect.top)

LineTo(hDC, sRect.right, sRect.bottom)

LineTo(hDC, sRect.left, sRect.bottom)

LineTo(hDC, sRect.left, sRect.top)

ENDIF

sRect.left += 1

sRect.top += 1

dwXPBtnStyle := 5

IF SELF:_lPressed

dwBtnStyle := DFCS_BUTTONPUSH+DFCS_PUSHED

dwXPBtnStyle := 3

ENDIF

ELSEIF !SELF:_lPressed .AND. !SELF:_lFocus

sRect.bottom += 1

sRect.right += 1

ENDIF

IF SELF:lHilight .AND. !SELF:_lPressed

dwXPBtnStyle := 2

ENDIF

IF SELF:_lDisabled

dwXPBtnStyle := 4

ENDIF

IF SELF:lXP

PCALL(SELF:pXPDrawFrameFunc, SELF:pXPTheme, hDC, 1, dwXPBtnStyle, 
@sRect,NULL_PTR)

ELSE

DrawFrameControl(hDC, @sRect, DFC_BUTTON, dwBtnStyle)

ENDIF

?

IF SELF:lUseColor

SelectObject(hDC, GetStockObject(NULL_PEN))

DO CASE

CASE SELF:_lPressed

Rectangle(hDC, sRect.left+3, sRect.top+3, sRect.right-1, sRect.Bottom-1)

CASE SELF:lXP

Rectangle(hDC, sRect.left+3, sRect.top+3, sRect.right-2, sRect.Bottom-2)

OTHERWISE

Rectangle(hDC, sRect.left+2, sRect.top+2, sRect.right-2, sRect.Bottom-2)

ENDCASE

SelectObject(hDC, hPenBlack)

ENDIF

?

?

// Draw the icon:

IF SELF:lUseImage

IF SELF:dwImgType == IMAGE_ICON

nIconHeight := SELF:size:Height-4

** nOffset := 4 // PDB

nOffset := 2 // make icon border only 2 pixels

IF SELF:_lPressed

nOffset += 1

ENDIF

** DrawIconEx(hDC, nOffset, nOffset, SELF:hImage, 16, 16, 0, NULL_PTR, 
DI_NORMAL) //PDB

DrawIconEx(hDC, nOffset, nOffset, SELF:hImage, nIconHeight, nIconHeight, 0, 
NULL_PTR, DI_NORMAL) //PDB for support 32x32 icon

ELSEIF SELF:dwImgType == IMAGE_BITMAP

nOffset := 2

IF SELF:_lPressed

nOffset += 1

ENDIF

oSize := SELF:oBitmap:size

IF (SELF:Size:width - 4) < oSize:width

oSize:width := SELF:Size:width - 4

ENDIF

IF (SELF:Size:Height - 4) < oSize:height

oSize:Height := SELF:Size:Height - 4

ENDIF

hDCSrc := CreateCompatibleDC(hDC)

SelectObject(hDCSrc, SELF:oBitmap:handle())

BitBlt(hDC, nOffset, nOffset, oSize:width, oSize:height, hDCSrc, 0, 0, 
SRCCOPY)

DeleteDC(hDCSrc)

ENDIF

ENDIF

?

// Draw the caption:

IF SLen(SELF:Caption) > 0

IF SELF:oFont == NULL_OBJECT

lKillFont := TRUE

hFont := GetStockObject(DEFAULT_GUI_FONT)

IF hFont == NULL_PTR

hFont := GetStockObject(SYSTEM_FONT)

ENDIF

ELSE

hFont := SELF:oFont:handle()

ENDIF

SelectObject(hDC, hFont)

// define rectangle for the caption

sRect.top +=2

sRect.bottom -= 3

** sRect.left += 20

//PDB: place the caption text as much aside as the icon is big:

IF nIconHeight <> 0

sRect.left := nIconheight

ELSE

sRect.left += 2 // no icon

ENDIF

sRect.right -= 4

?

// PDB: first check if the width of the button can accomadate the caption. 
If not, switch to multiline button

nREctWidth := sRect.right - sRect.left // available space

// how long is the text

IF getDisplayTextWidth(SELF:Caption,hFont) > nREctWidth

lMultiline := TRUE

ENDI

?

?

IF !SELF:_lDisabled

SetTextColor(hDC, GetSysColor(COLOR_BTNTEXT))

IF SELF:_lPressed

sRect.top += 1

sRect.left += 1

sRect.bottom += 1

sRect.right += 1

ENDIF

IF !lMultiline

DrawText(hDC, SELF:Caption, SLen(SELF:Caption), 
@sRect,DT_SINGLELINE+DT_CENTER+DT_VCENTER)

ELSE

DrawText(hDC, SELF:Caption, SLen(SELF:Caption), 
@sRect,DT_CENTER+DT_WORDBREAK)

ENDIF

ELSE

sRect.top += 1

sRect.left += 1

sRect.bottom += 1

sRect.right += 1

SetTextColor(hDC, GetSysColor(COLOR_3DHILIGHT))

IF !lMultiline

DrawText(hDC, SELF:Caption, SLen(SELF:Caption), 
@sRect,DT_SINGLELINE+DT_CENTER+DT_VCENTER)

ELSE

DrawText(hDC, SELF:Caption, SLen(SELF:Caption), 
@sRect,DT_CENTER+DT_WORDBREAK)

ENDIF

// draw shadow

sRect.top -= 1

sRect.left -= 1

sRect.bottom -= 1

sRect.right -= 1

SetTextColor(hDC, GetSysColor(COLOR_3DSHADOW))

IF !lMultiline

DrawText(hDC, SELF:Caption, SLen(SELF:Caption), 
@sRect,DT_SINGLELINE+DT_CENTER+DT_VCENTER)

ELSE

DrawText(hDC, SELF:Caption, SLen(SELF:Caption), 
@sRect,DT_CENTER+DT_WORDBREAK)

ENDIF

ENDIF

IF SELF:_lFocus

SetTextColor(hDC, GetSysColor(COLOR_BTNTEXT))

DrawFocusRect(hDC, @sRect)

ENDIF

ENDIF

EndPaint(hHandle, @sPs)

IF lKillFont

DeleteObject(hFont)

ENDIF

DeleteObject(hPenBlack)

DeleteObject(hBrushBack)

ReleaseDC(hHandle, hDC)

DeleteDC(hDC)

?

?

?

METHOD MouseButtonUp(oEvent) CLASS IconPushbutton

IF SELF:lUseImage

IF oEvent:IsLeftButton

_lPressed := FALSE

SELF:owner:RepaintBoundingBox(BoundingBox{SELF:origin, SELF:size})

ENDIF

ENDIF

SUPER:MouseButtonUp(oEvent)

ASSIGN IconDisabled(oIco) CLASS IconPushbutton

// Set the icon for disabled state

// you can set this assign in the INIT() of an inherited icon class (bv 
CopyPushbutton)

SELF:_oIconDisabled:=oIco

RETURN _oIconDisabled

METHOD InitXP() CLASS IconPushbutton

** A few fixes made by Paul De Bie 25/2/2003 because of 5333 crash

LOCAL pszControl AS PTR

LOCAL pszUCString AS PTR

LOCAL iRet AS INT

LOCAL iUCStrLen AS INT

IF !SELF:lXP

SELF:pXPOpenThemeFunc := 
GetProcAddress(GetModuleHandle(String2Psz("UXTHEME")),String2Psz("OpenThemeData"))

SELF:pXPCloseThemeFunc := 
GetProcAddress(GetModuleHandle(String2Psz("UXTHEME")), 
String2Psz("CloseThemeData"))

SELF:pXPDrawFrameFunc := 
GetProcAddress(GetModuleHandle(String2Psz("UXTHEME")), 
String2Psz("DrawThemeBackground"))

SELF:pXPDrawEdgeFunc := 
GetProcAddress(GetModuleHandle(String2Psz("UXTHEME")),String2Psz("DrawThemeEdge"))

IF SELF:pXPOpenThemeFunc != NULL_PTR .AND. SELF:pXPCloseThemeFunc != 
NULL_PTR .AND. SELF:pXPDrawFrameFunc != NULL_PTR .AND. SELF:pXPDrawEdgeFunc 
!= NULL_PTR

SELF:lXP := TRUE

ENDIF

ENDIF

// IF SELF:lXP

// pszControl := String2Psz("BUTTON")

// nStrLen := MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pszControl, -1, 
NULL_PTR, 0)

//

// IF nStrLen != 0

// pszUCString := MemAlloc(nStrLen)

// *** EXE CRASHES ON NEXT STATEMENT!!!

// iRet := MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, 
pszControl, -1,pszUCString, nStrLen)

// //

// SELF:pXPTheme := PCALL(pXPOpenThemeFunc, NULL, PSZUCString)

// IF SELF:pXPTheme == NULL_PTR

// SELF:lXP := FALSE

// ENDIF

// MemFree(pszUCString)

// ENDIF

// ENDIF

// PDB:

IF SELF:lXP

// allocate a buffer large enough for equivalent Unicode string

// at most twice as big; +1 for trailing terminator

iUCStrLen := 2 * (SLen("BUTTON") +1)

pszUCString := MemAlloc(iUCStrLen)

pszControl := String2Psz("BUTTON")

IF pszUCString != NULL_PTR

// write the number of "wide" characters to pszUCString

iRet := MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, 
pszControl, -1,pszUCString, iUCStrLen)

IF iRet !=0 // succes? open XP Theme

SELF:pXPTheme := PCALL(pXPOpenThemeFunc, NULL, pszUCString)

IF SELF:pXPTheme == NULL_PTR

SELF:lXP := FALSE

ENDIF

ELSE

SELF:lXP := FALSE

ENDIF

MemFree(pszUCString)

ENDIF

ENDIF

?

METHOD UseBitmap(oBmp AS Bitmap, hBitmap AS PTR) AS LOGIC PASCAL CLASS 
IconPushbutton

IF hBitmap == NULL_PTR

SELF:lUseImage := FALSE

SELF:hImage := NULL_PTR

SELF:AxitXP()

ELSE

SELF:lUseImage := TRUE

SELF:dwImgType := IMAGE_BITMAP

* SELF:oBitmap := BitMap{ResourceID{NULL_STRING, _GetInst()}}

SELF:oBitmap := oBmp

* SELF:oBitmap:hBitMapPtr := hBitmap

SELF:hImage := hBitmap

SELF:InitXP()

ENDIF

RETURN SELF:lUseImage

ASSIGN UseColor(oBrush AS Brush) AS LOGIC PASCAL CLASS IconPushbutton

// attention: has NO EFFECT when there is an icon assigned to the button!

IF oBrush == NULL_OBJECT

SELF:lUseColor := FALSE

IF SELF:oBackGround != NULL_OBJECT

DeleteObject(SELF:oBackground:handle())

SELF:oBackGround:destroy()

SELF:oBackGround := NULL_OBJECT

ENDIF

SELF:AxitXP()

ELSE

SELF:lUseColor := TRUE

IF SELF:oBackground != oBrush .AND. SELF:oBackground != NULL_OBJECT

DeleteObject(SELF:oBackground:handle())

SELF:oBackground:destroy()

ENDIF

SELF:oBackGround := oBrush

SELF:InitXP()

ENDIF

InvalidateRect(SELF:handle(), NULL_PTR, TRUE)

RETURN SELF:lUseColor

ASSIGN UseIcon(hIcon AS PTR) AS LOGIC PASCAL CLASS IconPushbutton

IF hIcon == NULL_PTR

SELF:lUseImage := FALSE

SELF:hImage := NULL_PTR

SELF:AxitXP()

ELSE

SELF:lUseImage := TRUE

SELF:lXP := FALSE // to force the InitXp to check if XP Themes are active

SELF:dwImgType := IMAGE_ICON

SELF:hImage := hIcon

SELF:InitXP()

ENDIF

RETURN SELF:lUseImage

?

?

ASSIGN IconEnabled(oIco) CLASS IconPushbutton

// Set the icon for enabled state

// you can set this assign in the INIT() of an inherited icon class (bv 
CopyPushbutton)

SELF:_oIconEnabled:=oIco

RETURN _oIconEnabled

METHOD FocusChange(oEvent) CLASS IconPushbutton

// Callback, called if object recieves or loose focus

// PDB: this makes that the button, when you tab to them (with tab key), 
have a "focused" look (blue border)

SUPER:focusChange (oEvent)

IF oEvent:gotFocus

// give the button a look such as the "default" one

PostMessage (SELF:handle(), BM_SETSTYLE, BS_DEFPUSHBUTTON, 1)

SELF:_lFocus := TRUE

ELSE

PostMessage (SELF:handle(), BM_SETSTYLE, BS_PUSHBUTTON, 1)

SELF:_lFocus := FALSE

ENDIF

IF SELF:lUseImage // if image, redraw the button

InvalidateRect(SELF:handle(), NULL_PTR, TRUE)

ENDIF

RETURN

METHOD Destroy() CLASS IconPushbutton

IF SELF:oBitmap != NULL_OBJECT

DeleteObject(SELF:oBitmap:handle())

SELF:oBitmap:destroy()

SELF:oBitmap := NULL_OBJECT

SELF:hImage := NULL_PTR

ENDIF

IF SELF:oBackGround != NULL_OBJECT

DeleteObject(SELF:oBackGround:handle())

SELF:oBackGround:Destroy()

SELF:oBackGround := NULL_OBJECT

ENDIF

SELF:AxitXP()

SUPER:Destroy()

?

METHOD SetStyle(kStil, lAktivieren) CLASS IconPushbutton

IF IsNil(lAktivieren)

lAktivieren := TRUE

ENDIF

IF kStil == WS_DISABLED

SELF:_lDisabled := lAktivieren

ENDIF

IF kStil == BS_DEFPUSHBUTTON .AND. lAktivieren == FALSE

PostMessage (SELF:handle(), BM_SETSTYLE, BS_PUSHBUTTON, 1)

ELSE

SUPER:SetStyle(kStil, lAktivieren)

ENDIF

?

METHOD Init(oOwner, nID, oPoint, oDim, cText, kStyle) CLASS IconPushbutton

SUPER:init(oOwner, nID, oPoint, oDim, cText, kStyle)

// Stelle fest, ob es sich beim Owner um ein Tabfenster

// der Klasse Dialogwindow handelt

IF IsInstanceOf(oOwner, #DIALOGWINDOW)

* SELF:lIsTabWindow := !(_And (GetWindowLong (oOwner:handle (), GWL_Style), 
WS_POPUP) != 0 )

ENDIF

METHOD MouseButtonDown(oEvent) CLASS IconPushbutton

IF SELF:lUseImage

IF oEvent:IsLeftButton

_lPressed := TRUE

SELF:owner:RepaintBoundingBox(BoundingBox{SELF:origin, SELF:size})

ENDIF

ENDIF

SUPER:MouseButtonDown(oEvent)

FUNCTION getDisplayTextWidth( cText, xFont )

// returns the width of a text string in PIXELS

// needs to get a pointer to a font!

LOCAL dwSize AS DWORD

LOCAL winSize IS _winSize

LOCAL nWidth AS DWORD

LOCAL hOldFont AS PTR

LOCAL hFont AS PTR

LOCAL hDC AS PTR

hDC := CreateIC( String2Psz( "DISPLAY" ), NULL_PSZ, NULL_PSZ, NULL_PTR )

IF !(hDC == NULL_PTR)

IF IsPtr(xFont)

hFont := xFont

ELSEIF IsInstanceOfUsual(xFont,#font)

hFont := xFont:handle()

ELSE

(errorBox{,"Error: invalid font parameter in function getDisplayTextWidth( 
cText, xFont )"}):show()

ENDIF

IF !(hFont == NULL_PTR)

hOldFont := SelectObject( hDC, hFont )

ENDIF

GetTextExtentPoint32( hDC, Cast2Psz( cText ), SLen( cText ), @winSize )

dwSize := DWORD(_CAST, MakeLong(WORD(_CAST, winSize.cx), 
WORD(_CAST,winSize.cy)))

nWidth := LoWord( dwSize )

IF !(hOldFont == NULL_PTR)

SelectObject( hDC, hOldFont )

ENDIF

?

ENDIF

RETURN nWidth

?

TEXTBLOCK readme

/*

Class from Harald Kogler: kog@kns.at feb 2003

I played with the Visual Themes some time ago... this works fine for me

This is a Class, which can Display an Icon or a Bitmap next to the

Button-Text or a Button-Backgroundcolor.

Should work on any Kind of Theme you've set...

REMARKS FROM PAUL DE BIE:

- To set a background color:

Assign UseColor --> Brush e.g. SELF:occPbtest:Usecolor := 
Brush{Color{COLORYELLOW},HATCHSOLID}

- To set an icon:

Assign IconEnabled --> icon object e.g. SELF:oCCpbTest:IconEnabled := 
{PrinterUp}

or e.g. SELF:oCCpbTest:IconEnabled := { ResourceId{"PrinterUp", 
_GetInst()} }

Assign IconDisabled --> icon object (if not set, then uses the same Icon as 
IconEnabled)

?

Changed by PDB 02/2003:

======================

- icons are now always 32*32 instead of 16*16 (but if your button is smaller 
than 32 pixels, the icons will be automatically reduced in size)

- added possibility to enable/disable the button.

- can now be used just as the former Iconpushbutton class; by making icon 
resources first for enabled/disabled states

- Use now the assign IconEnabled or IconDisabled (ICO object type) to set 
the Up/Enabled icons (normally they must be set

in the INIT of the subclassed pushbutton, but you can change them afterwards 
too.)

-> a SELF:Enable() must be done once to set the icon for the first time; you 
can also do this from within the Init() of

your subclassed buttons

- Fixed a 5333 crash in INITXP() method

- Tested to see if XP Theme can be changed while Appli is running: OK this 
gives no problems, it works!

Changed PDB 23/6/2003:

=====================

- In ExposeEX and ExposeCol; I now check to see if the caption (text) fits 
on the pushbutton; if not the pushbutton style is

changed to multiline instead of single line

Changed PDB 31/10/2005:

======================

- Merged the two Expose methods (ExposeEX and ExposeCol) which makes it now 
possible to use both an Icon AND a background color

?

REMARK: don't use the Bitmap anymore - didn't test it to see it supports my 
changes!

?

HOW TO USE THIS CLASS

=====================

?

- In order to compile, you will have to put all of the icons in a folder 
called:

C:\Cavo_Bitmaps_and_Icons\General_use

If you want them in another folder, then search/replace the foldername in 
all resource entities. Attention: do NOT use

foldernames that contain spaces or it won't compile.

?

?

- If you don't need icons, but just a colored background:

inherit your pushbutton from Iconpushbutton class

Assign the color SELF:occPbtest:Usecolor := 
Brush{Color{COLORYELLOW},HATCHSOLID}

?

- If you want to show Icons with two states (enabled/disabled):

?

You need two icons for each pushbutton, one normal and one "greyed out". You 
can easily do this

with an Icon editor. Or with a graphics program: open the colored icon, 
convert it to greyscale, then save with another name.

I have for each type of pushbutton a different class; I have them all in a 
library that I link into my application when needed.

So all I have to do when I need, say, a pushbutton with a printer, is to put 
a standard PB (via the WED) on my form

and have it inherit from the appropriate class, e.g. printerPushButton.

Below an example for one such pushbutton class.

In this example I use two icons: PrinterDisabled.ico and PrinterUp.ico in a 
folder c:\temp\

?

?

CLASS PrinterPushButton INHERIT IconPushbutton

METHOD INIT(oOwner,nId,oPoint,oDimension,cText) CLASS PrinterPushButton

SUPER:INIT(oOwner,nId,oPoint,oDimension,cText)

SELF:IconEnabled := PrinterUP{}

SELF:iconDisabled := PrinterDisabled{}

SELF:Enable()

CLASS PRINTERDISABLED INHERIT Icon

RESOURCE PRINTERDISABLED Icon c:\temp\PrinterDisabled.ico

METHOD Init() CLASS PRINTERDISABLED

SUPER:init(ResourceID{"PRINTERDISABLED", _GetInst()})

CLASS PRINTERUP INHERIT Icon

RESOURCE PRINTERUP Icon c:\temp\PrinterUp.ico

METHOD Init() CLASS PRINTERUP

SUPER:init(ResourceID{"PRINTERUP", _GetInst()})

?

?

NB: you'll have some more work setting up all the classes for each 
pushbutton;

but afterwards in your application it's a piece of cake and no code needed 
at all, just "inherit from" and voilà.

?

?

?

?

?

*/

METHOD Dispatch(oEvent) CLASS IconPushbutton

IF oEvent:Message == BM_SETSTATE

// Button Status geändert ?

IF ! SELF:_lPressed .AND. oEvent:wParam == 1

SELF:_lPressed := TRUE

SELF:Owner:RepaintBoundingBox(BoundingBox{SELF:Origin,SELF:Size})

ELSEIF SELF:_lPressed .AND. oEvent:wParam == 0

SELF:_lPressed := FALSE

SELF:Owner:RepaintBoundingBox(BoundingBox{SELF:Origin,SELF:Size})

ENDIF

ENDIF

** IF oEvent:uMsg == WM_PAINT

** SELF:Expose(oEvent)

** SELF:EventReturnValue := 0L

** RETURN 0L

** ENDIF

IF oEvent:message == WM_MOUSEMOVE .AND. !SELF:lHilight

SELF:lHilight := TRUE

ENDIF

IF oEvent:message == 0x2A3 .AND. SELF:lHilight//WM_MOUSELEAVE

SELF:lHilight := FALSE

ENDIF

IF oEvent:message == 0x128 //WM_UPDATEUISTATE

SELF:Expose(oEvent)

SELF:EventReturnValue := 1L

RETURN 1L

ENDIF

IF oEvent:message == 0x031A //WM_THEMECHANGED

SELF:AxitXP()

SELF:lXP := FALSE

SELF:InitXP()

ENDIF

IF oEvent:message == WM_GETDLGCODE

IF oEvent:wParam = VK_RETURN

// Drückt zwar den Button, ruft aber nicht die Methode auf

*PostMessage (SELF:handle(), WM_KEYDOWN, VK_SPACE, 0)

// Rufe die Methode zum Button auf (Falls diese existiert)

IF SELF:lIsTabWindow // Nur bei Tabwindows

IF IsMethod (SELF:owner, SELF:NameSym)

Send (SELF:owner, SELF:NameSym)

ENDIF

** SELF:EventReturnValue := 1L

** RETURN 1L

ENDIF

ENDIF

ENDIF

RETURN SUPER:Dispatch(oEvent)

CLASS cdPosItemButton INHERIT ICONPUSHBUTTONEXPORT aItemInfo AS ARRAY

EXPORT cItemNo AS STRING

METHOD Dispatch(oEvent) CLASS cdPosItemButton

// CASE InList(oE:Message, WM_MOUSEMOVE, WM_LBUTTONDOWN, WM_LBUTTONUP)

IF oEvent:message == WM_RBUTTONDOWN //MOVE .AND. !SELF:lHilight


IF SELF:NameSym != #pbPosButton .AND. SELF:NameSym != #pbPosButtonNew // 
Just so we don't process again if button is clicked in the setup button 
window

IF IsMethod (SELF:owner:owner, #cdSetupButton)

SELF:owner:owner:cdSetupButton(SELF)

ENDIF

ENDIF

ENDIF

RETURN SUPER:Dispatch(oEvent)

?

?

Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-10 07:39 +1000
  Re: Highlighting Buttons on tab page freezes program "Willie Moore" <williem@wmconsulting.com> - 2011-05-09 21:51 -0500
    Re: Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-10 14:09 +1000
      Re: Highlighting Buttons on tab page freezes program "Willie Moore" <williem@wmconsulting.com> - 2011-05-10 05:52 -0500
        Re: Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-11 01:53 +1000
          Re: Highlighting Buttons on tab page freezes program "Willie Moore" <williem@wmconsulting.com> - 2011-05-10 11:57 -0500
          Re: Highlighting Buttons on tab page freezes program "Willie Moore" <williem@wmconsulting.com> - 2011-05-10 11:57 -0500
          Re: Highlighting Buttons on tab page freezes program "Bernhard Mayer" <Idonotexisthere@nowhere.com> - 2011-05-11 07:35 +0200
            Re: Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-13 06:59 +1000
              Re: Highlighting Buttons on tab page freezes program "Stephen Quinn" <stevejqNO@bigpondSPAM.net.au> - 2011-05-13 08:57 +1000
                Re: Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-14 08:47 +1000
              Re: Highlighting Buttons on tab page freezes program "Bernhard Mayer" <Idonotexisthere@nowhere.com> - 2011-05-13 07:55 +0200
                Re: Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-14 08:52 +1000
                Re: Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-14 17:16 +1000
                Re: Highlighting Buttons on tab page freezes program - Solved! "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-15 02:30 +1000
                Re: Highlighting Buttons on tab page freezes program - Solved! "Gerhard Bunzel" <g.bunzel@domonet.de> - 2011-05-16 00:08 +0200
                Re: Highlighting Buttons on tab page freezes program - Solved! "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-17 21:55 +1000
                Re: Highlighting Buttons on tab page freezes program - Solved! "Willie Moore" <williem@wmconsulting.com> - 2011-05-17 07:19 -0500
                Re: Highlighting Buttons on tab page freezes program - Solved! "Paul D B" <polleke@NOMORESPAMhnt.be> - 2011-05-18 17:00 +0200
  Re: Highlighting Buttons on tab page freezes program Sherlock <sherlock@sherlock.com.au> - 2011-05-10 05:01 -0700
    Re: Highlighting Buttons on tab page freezes program "Craig Dawson" <craig@control.nospam.net.au> - 2011-05-11 01:58 +1000
  Re: Highlighting Buttons on tab page freezes program "Paul D B" <polleke@NOMORESPAMhnt.be> - 2011-05-18 16:39 +0200
    Re: Highlighting Buttons on tab page freezes program "Paul D B" <polleke@NOMORESPAMhnt.be> - 2011-05-18 16:42 +0200

csiph-web