The code below is my attempt to create (via cut and paste from some of the examples hereabouts) some moveable and resizeable windows. It is an early step towards creating a GUI forms designer. The code below sort of works but the windows (dialogs) which are created each time you press the GO button are not anchored to the underlying dialog, which can be slid out from under them. How can I correct this?
Code:
' One day this will be a GUI forms designer ' compiled by Chris Holbrook 30 Nov 2007 #COMPILE EXE #DIM ALL #INCLUDE "commctrl.inc" #INCLUDE "win32api.inc" %IDD_CTLMARKER_dialog = 123 %IDC_CTLMARKER_tb = 1241 %IDC_CTLMARKER_lb = 1242 %IDC_exit_bn = 1243 %IDC_GO_BN = 1244 DECLARE FUNCTION Showarc_dd(BYVAL hParent AS DWORD) AS LONG DECLARE FUNCTION ShowCTLMARKER_dialog(BYVAL hParent AS DWORD) AS LONG FUNCTION PBMAIN () AS LONG GLOBAL garcpath, gevent, gCTLMARKERtext AS STRING GLOBAL gCTLMARKERx, gCTLMARKERy, gCTLMARKERdialog AS LONG gCTLMARKERdialog = -1 showarc_dd(0) END FUNCTION '------------------------------------------------------------------------------ CALLBACK FUNCTION Showarc_ddProc() LOCAL hparent AS LONG ' asciiz buffer for populating listview LOCAL szString AS ASCIIZ * 256 SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG ' Initialization handler InitCommoncontrols CASE %WM_NCACTIVATE STATIC hWndSaveFocus AS DWORD IF ISFALSE CBWPARAM THEN ' Save control focus hWndSaveFocus = GetFocus() ELSEIF hWndSaveFocus THEN ' Restore control focus SetFocus(hWndSaveFocus) hWndSaveFocus = 0 END IF CASE %WM_NOTIFY CASE %WM_COMMAND ' Process control notifications SELECT CASE AS LONG CBCTL CASE %IDC_GO_BN IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN showCTLMARKER_dialog(CBHNDL) FUNCTION = 1 EXIT FUNCTION END IF END SELECT END SELECT END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ FUNCTION Showarc_dd(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG LOCAL hfont1 AS DWORD LOCAL hDlg AS DWORD DIALOG NEW hParent, "Not Yet a Forms Designer", 70, 70, 538, 286, _ %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR _ %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _ %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _ OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR TO hDlg CONTROL ADD BUTTON, hDlg, %IDC_go_bn, "GO", 50, 100, 35, 20 DIALOG SHOW MODAL hDlg, CALL Showarc_ddProc TO lRslt FUNCTION = lRslt END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ CALLBACK FUNCTION ShowCTLMARKER_dialogProc() STATIC hparent AS DWORD STATIC htext AS STRING LOCAL l AS LONG DIM r AS RECT DIM szText AS ASCIIZ * 2048 LOCAL hfont AS LONG, hfont2 AS LONG, x AS LONG, y AS LONG LOCAL hDC AS DWORD LOCAL ps AS paintstruct SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG ' Initialization handler gCTLMARKERx = gCTLMARKERx + 10 gCTLMARKERy = gCTLMARKERy + 10 DIALOG SET LOC CBHNDL, gCTLMARKERx, gCTLMARKERy hParent = GetParent(CBHNDL) gCTLMARKERdialog = CBHNDL htext = gevent getclientrect CBHNDL, r szText = htext hDC = GetDC( CBHNDL) hfont = SendMessage(CBHNDL, %WM_GETFONT, 0, 0) hfont2 = SelectObject(hDC, hfont) '-----------------fix text width r.nright = 250 '---------------- calculate pixel depth of wrapped text DrawText hDC, szText, LEN(szText), r, %DT_WORDBREAK OR %DT_CALCRECT OR %DT_LEFT '---------------- convert to dialog units DIALOG PIXELS CBHNDL, r.nright, r.nbottom TO UNITS x, y '---------------- allow for border width, exit button, and scale depth DIALOG SET SIZE CBHNDL, x+3,22 + y' (y*.66) '---------------- set dialog dimensions.... CONTROL SET SIZE CBHNDL, %idc_CTLMARKER_lb, x,5 + y'*.66 '---------------- ...and insert text which should wrap to predicted dimensions CONTROL SET TEXT CBHNDL, %idc_CTLMARKER_lb, htext SelectObject ps.hdc, hfont2 releaseDC CBHNDL, hDC CASE %WM_NCACTIVATE STATIC hWndSaveFocus AS DWORD IF ISFALSE CBWPARAM THEN ' Save control focus hWndSaveFocus = GetFocus() ELSEIF hWndSaveFocus THEN ' Restore control focus SetFocus(hWndSaveFocus) hWndSaveFocus = 0 END IF CASE %WM_LBUTTONDOWN SendMessage CBHNDL, %WM_NCLBUTTONDOWN, %HTCAPTION, BYVAL %NULL ' force drag DIALOG GET LOC CBHNDL TO gCTLMARKERx, gCTLMARKERy ' CASE %WM_COMMAND ' ' Process control notifications ' SELECT CASE AS LONG CBCTL ' CASE %idc_exit_bn ' 'CONTROL SEND hparent, %IDC_stm_graphic1, %WM_user+1, 0, 0 ' DIALOG END CBHNDL,0 ' END SELECT END SELECT END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ FUNCTION ShowCTLMARKER_dialog(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG LOCAL hDlg AS DWORD DIALOG NEW hParent, "", 176, 133, 190, 29, %WS_POPUP OR %WS_THICKFRAME OR _ %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _ %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_TOOLWINDOW OR _ %WS_EX_TOPMOST OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _ %WS_EX_RIGHTSCROLLBAR, TO hDlg DIALOG SET COLOR hDlg, -1, RGB(255, 255, 155) CONTROL ADD LABEL, hDlg, %IDC_CTLMARKER_lb, "", 0, 5, 120, 13, %WS_CHILD OR _ %WS_VISIBLE OR %SS_LEFT, %WS_EX_TRANSPARENT OR %WS_EX_LEFT OR _ %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_CTLMARKER_lb, -1, -2 'CONTROL ADD BUTTON, hDlg, %IDC_exit_bn, "X close", 0, 0, 35, 10 CONTROL SEND hDlg, %IDC_CTLMARKER_lb, %EM_SETLIMITTEXT,2048,0 DIALOG SHOW MODELESS hDlg, CALL ShowCTLMARKER_dialogProc TO lRslt FUNCTION = lRslt END FUNCTION '------------------
Comment