I want to know if its possible to use a variable or pointer or something as a callback in a CONTROL ADD BUTTON statement. Below is an example of what I've tried doing but didn't work.
Main reason I want to do this is for creating dynamic buttons which might point to different callback functions based on external data (for example a config file or something). I know ways around it could be creating a dialog callback and then just doing stuff in there based on which button was pressed or using a macro perhaps. Either way any help, comments are welcome. Thanks.
Code:
#COMPILE EXE #DIM ALL TYPE DialogObject dHandle AS DWORD dText AS ASCIIZ * 65 dWidth AS INTEGER dHeight AS INTEGER END TYPE TYPE ControlObject cID AS DWORD cCallback AS DWORD cType AS ASCIIZ * 33 cText AS ASCIIZ * 33 cXPos AS INTEGER cYPos AS INTEGER cWidth AS INTEGER cHeight AS INTEGER END TYPE FUNCTION addControl(BYVAL myControl AS ControlObject, BYVAL myDialogHandle AS DWORD) AS LONG SELECT CASE LCASE$(myControl.cType) CASE "button" CONTROL ADD BUTTON, myDialogHandle, myControl.cID, myControl.cText, myControl.cXPos, myControl.cYPos, myControl.cWidth, myControl.cHeight CALL DWORD myControl.cCallback CASE ELSE ' Do Nothing END SELECT END FUNCTION CALLBACK FUNCTION button_Exit() AS LONG IF CB.MSG = %WM_COMMAND THEN IF CB.CTLMSG = %BN_CLICKED THEN DIALOG END CB.HNDL FUNCTION = 1 END IF END IF END FUNCTION FUNCTION PBMAIN() ' Variable Declaration DIM dMain AS DialogObject DIM cExit AS ControlObject ' Initialization dMain.dText = "Test Program" dMain.dWidth = 250 dMain.dHeight = 300 cExit.cID = 1001 cExit.cCallback = CODEPTR(button_Exit) cExit.cType = "button" cExit.cText = "Exit" cExit.cXPos = 5 cExit.cYPos = 5 cExit.cWidth = 240 cExit.cHeight = 24 ' Dialog Creation DIALOG NEW PIXELS, 0, dMain.dText, , , dMain.dWidth, dMain.dHeight TO dMain.dHandle addControl(cExit, dMain.dHandle) DIALOG SHOW MODAL dMain.dHandle END FUNCTION
Comment