Announcement

Collapse
No announcement yet.

Calling anyone with MLG experience!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling anyone with MLG experience!

    I've hit a wall with MLG, and hope someone can point me in the right direction.

    You know how in MS Excel, you press the left/right/up/down keys, and the "current cell" changes? The user can tell the "current cell" because it's outlined, and it's easy to see the outline shift from one cell to the next.

    I'm trying to emulate that behavior programmatically with MLG, but I'm not having any success. I can programmatically set the selected cell, put a string and read it back, but cannot get that cell's border to display.

    I've also noticed that the program can detect which cells are selected if the user selects a range, but it's difficult if the user selects only one cell.

    I'm having trouble with borders vs selections. Not clear which functions to use to simply "set the focus" on what I want as the "current cell".


    Contrary to what I see most MLG programmers are concerned with, my use of MLG is not for displaying database query results, but for obtaining complex user inputs. (I will be taking inputs and doing immediate calculations and displaying results, as a kind of "mini-spreadsheet".)

    Below is my test program. It has 3 grids because ultimately I'll need to transfer data from one to another. It also has a pile of buttons, each attempting to do something that I need to learn the proper calls for, and a lot of commented-out trial-and-error code and ideas to try next.

    It ain't pretty, but it's helping me learn...

    I invite you to take a look and help by pointing me toward what functions I am obviously overlooking.

    Thanks!
    -John
    Code:
    'test1.bas   by jhm
    'I'm learning how to build an app to use MLG...
    'rather than just copy the demos, I'm building this step by step...
    '==================================================================
    'Oooo, gotta try this!
    '  %MLG_SORT
    '  Purpose: Sort grid based on a column's value.  Will honor character,number or date data types of the selected column.
    '  Parameters:
    '  wParam : %MLG_ASCEND or %MLG_DESCEND
    '          lParam : Column 1 to 255
    '  Return: Return 1 if operation failed
    '  Comments or Restrictions: Assumes no formatting at the row level (.ie row headers will not be included in the sort)
    '==================================================================
    'ToDo:
    '- modify all test code: include a param to specify  lWhichGrid
    '==================================================================
    
    #Compile Exe
    #Dim All
    
    
    #Include Once "windows.inc"
    #Include Once "mlg.inc"
    #Include Once "ClipboardContainsText.inc"
    
    Global hMainDlg As Dword
    Global hGrid1, hGrid2, hGrid3 As Dword 'Long
    Global ghWhichGridHasFocus As Dword 'Long
    
    %IDC_MLGGRID1  = 1001
    %IDC_MLGGRID2  = 1002
    %IDC_MLGGRID3  = 1003
    %IdTest1       = 1101
    %IdTest2       = 1102
    %IdTest3       = 1103
    %IdTest4       = 1104
    %IdTest5       = 1105
    %IdTest6       = 1106
    %IdTest7       = 1107
    %IdTest8       = 1108
    %IdTest9       = 1109
    %IdTest10      = 1110
    %IdTest11      = 1111
    %IdTest12      = 1112
    %IdTest13      = 1113
    %IdTest14      = 1114
    %IdTest15      = 1115
    %IdTest16      = 1116
    %IdTest17      = 1117
    
    
    'declare FUNCTION IsDllThere Lib "MLG.DLL" alias "IsDllThere" (MyDll AS STRING) AS LONG
    Declare Function IsDllThere Lib "MLG.DLL" Alias "ISDLLTHERE" (MyDll As String) As Long
    
    
    Function PBMain () As Long
       Local MainPanelHeight, lGridHeight, lMainDlgFlags, lResult, lRet, lArySlot As Long
       Local y, yy As Long
       Local sSwitches, sNewSheet As String
    
       MainPanelHeight =  400   ' should really get the max screen height from my ScreenMetrics.inc... later  *****
    
       MLG_Init
    
       lMainDlgFlags = %DS_ModalFrame Or %WS_Border Or %WS_ClipSiblings Or %WS_DlgFrame Or %WS_Popup ' defaults
                      'PB adds these: %DS_3DLook Or %DS_SetFont Or %DS_NoFailCreate
       lMainDlgFlags = lMainDlgFlags Or %WS_Caption Or %WS_SysMenu Or %WS_MaximizeBox Or %WS_MinimizeBox
    
       Dialog New %HWND_Desktop, "jhm test1",80,20,600,MainPanelHeight, lMainDlgFlags To hMainDlg
    
       '--------------------------------------------------------------------------------------------
       sSwitches = "r8/c7"                   ' set rows and columns
       lGridHeight = 122
       '
       'hide scrollbars
       sSwitches = sSwitches & "/d0"          ' leave them visible
       'sSwitches = sSwitches & "/d3"          ' d3 hides both scrollbars
       '
       'column titles: Name (invisible), Lot#, RecipeAmt, UOM, ActualAmt, ProgressiveWeight, Notes
       sSwitches = sSwitches & "/j1Name,Lot#,Recipe Amt,UOM,Actual Amt,Progrssve Wt,Notes"
       '
       'Column widths:        rowhdr, c1  c2
       sSwitches = sSwitches & "/x25,120,120,90,50,90,90,207"
       '
       '/y2 extra pixel height, vertical positioning, fontsize
       sSwitches = sSwitches & "/y4/v2/s10"                                ' *****  truncated descenders w fontsize < 16
       sSwitches = sSwitches & "/z1"          ' create the shadow array for cell formats...  BUT this precludes multi-col sorting!!
       '  ... might help make stuff invisible??
       '  ... or, %SETROWFORMAT and %SETCOLFORMAT messages which use the  RowColDataType structure
       '  ... Note that a row format for a particular attribute will supercede the column format for that attribute.
       '
       'context Menu:
       'sSwitches = sSwitches & "/m1Insert Row Before,Insert Row After,-,Delete Row"
       'sSwitches = sSwitches & "/m2"                                         ' need info on this - dig out from source code
       sSwitches = sSwitches & "/m3AAA,BBB,CCC"   ' just guessing here...     ' need info on this - dig out from source code
       '
       'change row header to arrow
       'sSwitches = sSwitches & "/a1"          ' not sure why I'd want that...
       '
       'display of headers
       'sSwitches = sSwitches & "/h1"          ' no row header     ' leaves blank space!
       'sSwitches = sSwitches & "/h2"          ' no col header     ' leaves blank space!
       'sSwitches = sSwitches & "/h3"          ' neither header    yea, maybe under certain circumstances?
       '
       '--------------------------------------------------------------------------------------------
       'Actions we let the user take:
       sSwitches = sSwitches & "/b3"          ' b3 lets user select entire grid w click of upper left header
       '--------------------------------------------------------------------------------------------
       Control Add "MYLITTLEGRID", hMainDlg, %IDC_MLGGRID1, sSwitches, 6, 6, 530, lGridHeight, %MLG_STYLE
       Control Handle hMainDlg, %IDC_MLGGRID1 To hGrid1
       SendMessage hGrid1,%MLG_SETCELL,0,0     ' remove the big X (anti-theft feature) from the grid...
       '--------------------------------------------------------------------------------------------
       '--------------------------------------------------------------------------------------------
       Control Add "MYLITTLEGRID", hMainDlg, %IDC_MLGGRID2, sSwitches, 6, lGridHeight + 12, 530, lGridHeight, %MLG_STYLE
       Control Handle hMainDlg, %IDC_MLGGRID2 To hGrid2
       SendMessage hGrid2,%MLG_SETCELL,0,0     ' remove the big X (anti-theft feature) from the grid...
       '--------------------------------------------------------------------------------------------
       '--------------------------------------------------------------------------------------------
       Control Add "MYLITTLEGRID", hMainDlg, %IDC_MLGGRID3, sSwitches, 6, (lGridHeight * 2) + 18, 530, lGridHeight, %MLG_STYLE
       Control Handle hMainDlg, %IDC_MLGGRID3 To hGrid3
       SendMessage hGrid3,%MLG_SETCELL,0,0     ' remove the big X (anti-theft feature) from the grid...
       '--------------------------------------------------------------------------------------------
       '--------------------------------------------------------------------------------------------
       'somehow we're losing our scrollbars??? NO! A grid only shows scrollbars WHEN IT HAS FOCUS!
       '--------------------------------------------------------------------------------------------
       '--------------------------------------------------------------------------------------------
       'may want to try these out:
       lArySlot = SendMessage (hGrid1, %MLG_ADDSHEET, 15, 3)          ' how to tell if a funcflag returns a value, and how?
       sNewSheet = "Added Sheet"
       SendMessage hGrid1, %MLG_NAMESHEET, lArySlot, StrPtr(sNewSheet)
       ? "lArySlot = " & Str$(lArySlot)
       'SendMessage hGrid1, %MLG_SETWORKBOOKPROP, %MLG_SETUSERTABEDIT,%TRUE        ' %MLG_SETUSERTABEDIT equate not defined!
       'SendMessage hGrid1, %MLG_SETWORKBOOKPROP, %MLG_SETUSERTABMOVE,%TRUE        ' %MLG_SETUSERTABMOVE equate not defined!
       '
       SendMessage hGrid1, %MLG_SHOWSHEETTABS,70,0        ' horizontal scrollbar must be visible
       '--------------------------------------------------------------------------------------------
       'using one of the 4 user slots:
       SendMessage hGrid1, %MLG_SETSHEETUSER,2,948 'store 948 in sheet slot number 2
       lRet = SendMessage (hGrid1, %MLG_GETSHEETUSER,2,0) 'returns 948
       ? "lRet of GetSheetUser = " & Str$(lRet)
       '--------------------------------------------------------------------------------------------
       'See the CALLBACK's WM_Initialize section for more setup, like column formats.
       '--------------------------------------------------------------------------------------------
    
       y = MainPanelHeight
       yy = 15  ' button spacing
    
       Control Add Button, hMainDlg, %IdOk,    "OK",            550, y - (yy *  1), 40, 14, %BS_Default Or %WS_TabStop 'CALL OkButton
       Control Add Button, hMainDlg, %IdCancel,"Cancel",        550, y - (yy *  2), 40, 14 'CALL CancelButton
    
       Control Add Button, hMainDlg, %IdTest1, "set 1 cell",    550, y - (yy *  4), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest2, "get curr cell", 550, y - (yy *  5), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest3, "get sel range", 550, y - (yy *  6), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest4, "SaveAll Data",  550, y - (yy *  7), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest5, "Un/Hide col",   550, y - (yy *  8), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest6, "Print preview", 550, y - (yy *  9), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest7, "Clear usr sel", 550, y - (yy * 10), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest8, "Print no prev", 550, y - (yy * 11), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest9, "FOCUS?",        550, y - (yy * 12), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest10,"Load 2 grids",  550, y - (yy * 13), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest11,"Load from CB",  550, y - (yy * 14), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest12,"Clear 3 4",     550, y - (yy * 15), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest13,"CIRCLE",        550, y - (yy * 16), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest14,"test14",        550, y - (yy * 17), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest15,"test15",        550, y - (yy * 18), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest16,"test16",        550, y - (yy * 19), 40, 14 'CALL
       Control Add Button, hMainDlg, %IdTest17,"test17",        550, y - (yy * 20), 40, 14 'CALL
    
    
       'test of PB Help finding My Little Grid keywords in my new MLG.PBKeys
       'MLG_SetColMaxLen()     'ok!
    
       Dialog Show Modal hMainDlg, Call MainDlgProc To lResult
    
    End Function
    
    Function PreLoadAGrid(lWhichGrid As Long) As Long
       Local i, j As Long
       Local mm As String
       'load the grid with temp test data items    OK!
       For i = 1 To 7
          For j = 1 To 7
             mm = Trim$(i) & $Spc & Trim$(j)
             'MLG_Put hGrid1,i,j,VARPTR(mm),1     ' string operand expected  NOPE!
             MLG_Put (lWhichGrid, i, j, mm, 1)       ' refresh is 1, no refreseh is 0   ' OK!
          Next j
       Next i
    
       'make one column just for dates"
       MLG_FormatColDate(lWhichGrid, 5, %YYYYMMDDL, %MLG_JUST_CENTER)   ' I like it!
       '(Now, what numbers are OK to enter?)
    
    End Function
    
    
    CallBack Function MainDlgProc( ) As Long
    '_
    '   ByVal hDlg As Dword,  _
    '   ByVal hMsg As Long,   _
    '   ByVal wParam As Long, _
    '   ByVal lParam As Long) As Long
    
       Dim lRow    As Long           'row number
       Dim lCol    As Long           'column number
       Dim sTemp   As String         'retrieved cell content string
       Dim zRet    As AsciiZ * 256   'retrieved cell content string
       Dim mylen   As Long
    
       Local i, j As Long
       Local lSR, lER, lSC, lEC As Long    ' corners of Range
       'lSR = 2 : lER = 4 : lSC = 3 : lEC = 5
       'DIM sRange(lSR TO lER, lSC TO lEC) AS STRING                'retrieved cell content string using an array
       Local lStartRow, lStartCol, lEndRow, lEndCol As Long
       '
       Local lRet  As Long
       Local mm    As String
       Local lLoHi As Long
       '-------------------------------------------------
       Local rct As rect     '  PrintAreaRect as rect
       '-------------------------------------------------
    
       'always find out which grid has focus!
       ' HOW?
       '
    
       Select Case Cb.Msg
       Case %WM_InitDialog
    
       Case %WM_Command
          Select Case Cb.CtlMsg          '
          Case %BN_Clicked
             Select Case Cb.Ctl
             Case %IdOk
                ? FuncName$
                Function = 1
    
             Case %IdTest1    ' set 1 cell
    
                SendMessage hGrid1,%MLG_SETSELECTED,3,4   ' MAYBE THIS is NOT the right call?
                'need to make it visible
                SendMessage hGrid1, %MLG_REFRESH, 0,0                 ' thought that would help... but no
                Call MLG_FormatCellBorder (hGrid1, 3, 4, %MLG_OUTLINE, 3, 4)     ' didn't work till I loaded the grid!
                rct.nTop      =  3  ' Start Row
                rct.nLeft     =  4  ' Start Col        2
                rct.nBottom   =  3  ' End Row
                rct.nRight    =  4  ' End Column       6
    
    
                'SendMessage hGrid1, %MLG_SETMULTICELLSELECTION, varptr(rct), 0   '  selection is not the function we want, but border may be...
                SendMessage hGrid1, %MLG_SETMULTICELLBORDER , VarPtr(rct), 0      '  maybe we could use that last param for "turn it off"
    
                'use FormatOverRide  ?
                'for.CellFormatExtra = 1
                ' %MLG_SETFORMATOVERRIDE
    
                ' %MLG_SETTOPROW and %MLG_SETLEFTCOL
    
               #If 0  ' jhm...*****
                Local lCurCell, lCurCellHiCol, lCurCellLoRow As Long
                lCurCell = SendMessage(hGrid1,%MLG_GETSELECTED,0,0)
                lCurCellHiCol =
                lCurCellLoRow =
                ? "Grid dimensions: " & Str$(totrows) & " x " & Str$(totcols)
                'but here, it returns the proper sizes: 14 x 7
    
                   '%MLG_GETSELECTED
                   'Purpose: To retrieve the currently selected cell.  For use With Row counts less than 65000.
                   'Parameters:
                   'wParam : Not used
                   'lParam : Not used
                   'Return: LowWord=selected Row, HighWord=selected Column
                   'Comments Or Restrictions: None
               #EndIf
    
               #If 0
                'test of a call in the INC, where copy to clipboard isn't working, and this returned 0,0
                Local totrows, totcols As Long
                SendMessage hGrid1,%MLG_GETROWCOLTOTEX,VarPtr(totrows),VarPtr(totcols)
                ? "Grid dimensions: " & Str$(totrows) & " x " & Str$(totcols)
                'but here, it returns the proper sizes: 14 x 7
               #EndIf
    
                Function = 1
    
             Case %IdTest2    ' get the contents of the CURRENT cell...
                'determine current cell indices
                SendMessage hGrid1,%MLG_GETSELECTEDEX,VarPtr(lRow),VarPtr(lCol)  'needs the EX version, else vars are 0
                '-----------------------------------
    
                'nope, not with string
                'SendMessage hGrid1,%MLG_GETCELL,MakLng(lRow,lCol),VarPtr(sTemp)
                '? sTemp,,"From cell row " & str$(lRow) & ", col " & str$(lCol)
    
                   'Is this useful?  %MLG_MAKELONG  (probably for non-PB languages)
    
                'AsciiZ works!
                'SendMessage hGrid1,%MLG_GETCELL,MakLng(lRow,lCol),VarPtr(zRet)   'OK This works! AsciiZ
                '? zRet,,"From cell row " & Str$(lRow) & ", col " & Str$(lCol)    '
    
    
                'PREFERRED: the following does work OK:
                sTemp = MLG_Get(hGrid1,lRow,lCol)                                'OK!
                ? Space$(70) & $CrLf & sTemp,,"From cell row " & Str$(lRow) & ", col " & Str$(lCol)
    
                'and this non-PB method works too!
                'mylen = 256
                'SendMessage hGrid1,%MLG_GETCELLEX,lRow,lCol
                'SendMessage hGrid1,%MLG_GETBUFFER,VARPTR(zRet),mylen
                '? zRet,,"From cell row " & Str$(lRow) & ", col " & Str$(lCol)    '
    
                Function = 1
    
             Case %IdTest3    ' get values from user-selected range
    
                mm = ""
                'lSR = 3 : lSC = 2 : lER = 5 : lEC = 6      ' rectangle from:  3,2  to:  5,6  (R,C)
    
                'OK, now figure out how to get the points of the user-selected rectangle!     ****************************
                '  %MLG_GETROWBLOCKSEL     %MLG_GETCOLBLOCKSEL
                '  %MLG_GETROWBLOCKSELEX   %MLG_GETCOLBLOCKSELEX          same, but for over 65000 rows...
                SendMessage hGrid1,%MLG_GETMULTICELLSELECTION,VarPtr(rct),0
                lSR   = rct.nTop
                lSC   = rct.nLeft
                lER   = rct.nBottom
                lEC   = rct.nRight
    
                ReDim sRange(lER, lEC) As String
                'MLG_GetEx hGrid1,s()    'gets the contents from the grid into an array, based on the DIM of the array...
                MLG_GetEx hGrid1,sRange()                 'retrieve cell content string using an array
                'array is loaded, now let's see it...
                For i = lSR To lER          ' rows
                   For j = lSC To lEC       ' columns
                      mm = mm & $Tab & sRange(i,j)
                   Next j
                   mm = mm & $CrLf
                Next i
                ? mm,,"Range"
    
    
                'first, I think we need to select some rows>>>>> pretty sure...
                'MLG_CopyRowBlockToClipBoard(hGrid AS DWORD,CopyColHeader AS LONG,OPT BYVAL AllowAlECowsCols AS LONG)
                'call MLG_CopyRowBlockToClipBoard(hGrid1,0,0)   'the only "copy to clipboard" routine provided, presumed all columns ugh
                'call MLG_CopyUserSelToClipBoard(hGrid1,0,0)    ' my clone! no headers
                Call MLG_CopyUserSelToClipBoard(hGrid1,1,0)     ' my clone! with headers
                ? "Copied to clipboard!"
                Function = 1
    
             Case %IdTest4    ' save data
                Local title, folder, filter, start, defaulttext, filevar As String
                Local flags As Long
    
                'save data...
                title$ = "Save File As"
                folder$ = Exe.Path$
                filter$ = Chr$("MLG Sheet (*.mlg)", 0)
                start$ = ""
                defaulttext$ = "mlg"
                flags = %OFN_PathMustExist Or %OFN_Explorer Or %OFN_OverWritePrompt
                Display Savefile ,,,"Save File", folder, filter, start, defaulttext, flags To filevar
                If Len(filevar) Then
                   'zstr = TRIM$(filevar)
                   zRet = Trim$(filevar)
                   'SendMessage hGrid1,%MLG_SAVESHEET,0,VARPTR(zstr)
                   SendMessage hGrid1,%MLG_SAVESHEET,0,VarPtr(zRet)
                Else
                   'no action  'ESC or Cancel
                End If
                Function = 1
    
             Case %IdTest5    ' Hide columns (also, on a timer?)
             'seems that there must be a "visible" cell cursor, and an "invisible" current cell tracker...
             '   'cause the user selection was NOT cleared, and the Get1Cell button DID retrieve from cell 3,4 (SetCell button)
             '
             ' SendMessage hGrid1,%MLG_LOADSHEET,0,zSpec
             '------------------------------------------
    
                'MLG_HideColBlock(hGrid AS DWORD)
                'The columns can be unhid with the %MLG_HIDECOLUMN message
                ? "Hide/unhide"                                               ' needs to be implemented!   **************
    
                'OR, just change the font color to same as cell background...
                '   MLG_FormatCellFont(BYVAL hGrid1 AS DWORD,BYVAL row1 AS LONG,BYVAL col1 AS LONG, MyFontSlot AS LONG, OPT row2 AS LONG, col2 AS LONG)
             'OR?
                'MLG_FormatCellTextColor(BYVAL hGrid1 AS DWORD,BYVAL row1 AS LONG,BYVAL col1 AS LONG, MyColorSlot AS LONG, OPT row2 AS LONG, col2 AS LONG)
    
    
    '         %MLG_HIDECOLUMN
    '         Purpose: To temporarily hide a column and allow for it to be restored to previous width.
    '         Parameters:
    '         wParam : %MLG_HIDECOL, %MLG_UNHIDECOL, %MLG_UNHIDEALLCOLS
    '                lParam : Column 1 to 255 (ignored with %MLG_UNHIDEALLCOLS)
    '         Return: None
    '         Comments or Restrictions: None
    
                Function = 1
    
    
             #If 10
             Case %IdTest6    ' print preview
                'If the MLG_Print.DLL isn't loaded, load it now...
         '''       lRet = IsDllThere("MLG_Print.DLL")   ' this STILL gets error message:  Can't find the MLG printing DLL  -  Abort
                If lRet Then
                   ? "lRet = " & Str$(lRet)
                End If
    
                SendMessage hGrid1,%MLG_GETMULTICELLSELECTION,VarPtr(rct),0    ' get the user-selected range (swiped from above)
                SendMessage hGrid1,%MLG_SETPRINTAREA,VarPtr(rct),0             '
                'SendMessage hGrid1,%MLG_PRINT,0,0                       'Show no Print Dialog and regenerate the print file
                '
                SendMessage hGrid1,%MLG_SETPAGEOPTIONS,0,%MLG_PRINT_LANDSCAPE     ' ok! (we need to check rectangle and decide Lndscp or Portrt)
                'the following numbers DO work!
                rct.nTop    = 250
                rct.nRight  = 150
                rct.nBottom = 200
                rct.nLeft   = 150
                SendMessage hGrid1,%MLG_SETPRINTMARGINS,VarPtr(rct),0             ' fine!
                '                                              ***************************
                SendMessage hGrid1, %MLG_PRINTPREVIEW, 0,0   ' getting the gbPreview Panel!
                'SendMessage hGrid1, %MLG_PRINTPREVIEW, 1,0   ' getting the Printer Selection Panel
                '                                              ***************************
                '
                'SendMessage hGrid1,%MLG_SETPRINTOPTIONS,%MLG_PRINTPREVIEWAUTOCLOSE,1  ' 0= don't close,  other = close
                SendMessage hGrid1,%MLG_ALTERATTRIBUTE,%MLG_PRINTPREVIEWAUTOCLOSE,1  ' 0= don't close,  other = close
    
                Function = 1
             #EndIf
    
             Case %IdTest7    ' CLEAR the user selection             ' NOT WORKING..... WHY NOT?
                '------------------------------------------
                'To be sure SAVE was good, CLEAR THE GRID, then LOAD from file!
                'SendMessage hGrid1,%MLG_CLEARBLOCKSEL,0,0 ' 3=Clear Row and Column Highlighting, 0=refresh   NOT THE RIGHT CALL!  ****????
                'SendMessage hGrid1,%MLG_CLEARBLOCKSEL,1,0 ' 3=Clear Row and Column Highlighting, 0=refresh   NOT THE RIGHT CALL!  ****????
                'SendMessage hGrid1,%MLG_CLEARBLOCKSEL,2,0 ' 3=Clear Row and Column Highlighting, 0=refresh   NOT THE RIGHT CALL!  ****????
             '''SendMessage hGrid1,%MLG_CLEARBLOCKSEL,3,0 ' 3=Clear Row and Column Highlighting, 0=refresh   NOT THE RIGHT CALL!  ****????
                '
                'SendMessage hGrid1,%MLG_CLEARBLOCKSEL,0,1 ' 3=Clear Row and Column Highlighting, 0=refresh   NOT THE RIGHT CALL!  ****????
                'SendMessage hGrid1,%MLG_CLEARBLOCKSEL,1,1 ' 3=Clear Row and Column Highlighting, 0=refresh   NOT THE RIGHT CALL!  ****????
                'SendMessage hGrid1,%MLG_CLEARBLOCKSEL,2,1 ' 3=Clear Row and Column Highlighting, 0=refresh   NOT THE RIGHT CALL!  ****????
                'SendMessage hGrid1,%MLG_CLEARBLOCKSEL,3,1 ' 3=Clear Row and Column Highlighting, 0=refresh   NOT THE RIGHT CALL!  ****????
                '
                '------------------------------------------
                'or:
                'SendMessage hGrid1,%MLG_CLEARGRID,2,0 ' 2=use next param, 0=do nothing    ' nope!
                '
    
                'what about:            InvalidateRect hWnd, ByVal %NULL, 0 : MLG_UpdateWindow hwnd
         '''                           InvalidateRect hGrid1, ByVal %NULL, 0 '':  MLG_UpdateWindow hGrid1      'NOPE!!!
                ''''''''''''''''''
    
                '-----------------------------------
                'determine current cell indices
                SendMessage hGrid1,%MLG_GETSELECTEDEX,VarPtr(lRow),VarPtr(lCol)  'needs the EX version, else vars are 0
                '------   copied from above   ------
             '   sTemp = MLG_Get(hGrid1,lRow,lCol)                                'OK!
             '   ? Space$(70) & $CrLf & sTemp,,"From cell row " & Str$(lRow) & ", col " & Str$(lCol)
                '-----------------------------------
                'now set the current cell to that same
                SendMessage hGrid1,%MLG_SETSELECTED,lRow,lCol            'NOPE!
                '-----------------------------------
    
                Function = 1
    
             Case %IdTest8    ' Do the printing!    (Actually been doing this via PrintPreview, but here, want to do it w NO Preview)
                SendMessage hGrid1,%MLG_PRINT,1,0
    
             Case %IdTest9    ' which grid has focus?
                ? "ghWhichGridHasFocus = " & Str$(ghWhichGridHasFocus)
    
             Case %IdTest10   ' load grids
                PreLoadAGrid(hGrid1)
                PreLoadAGrid(hGrid2)
                'PreLoadAGrid(hGrid3)
    
             Case %IdTest11   ' Load G3 from CB
                'Having gotten stuff onto the CB from previous button,
                'put that data into grid 3, at the cursor location
                '-------------------------------------------------
                'We need to check if there's anything on the CB. HOW?
                'if ClipboardContainsText() then exit function
                If Not ClipboardContainsText() Then Exit Function
                '  If no, exit.
                '  If yes, then get the "current" cell on grid 3
                'end if
                'See if there are enough rows and columns to accomodate the paste
                '  If no, exit
                '  If yes, set loops to the upper left corner
                'Go ahead and replace cell contents from CB
                ? "In process"
    
    
    
    
             Case %IdTest12   ' trying to clear the cell we selected in test1
                Call MLG_FormatCellBorder (hGrid1, 3, 4, %MLG_CLEAR)
                'Call MLG_FormatCellBorder (hGrid1, 3, 4, %MLG_CLEAR, 3, 4)     ' didn't work till I loaded the grid!
    
             Case %IdTest13    ' "CIRCLE"
                ' loop the "current cell" around in a rectangle
                '------------------------------------------------
                'SendMessage hGrid1,%MLG_ALTERATTRIBUTE, %SHOWCROSSCURSOR
                'SendMessage hGrid1,%MLG_SETFORMATOVERRIDEEX, %MLG_TYPE_BORDER
                '------------------------------------------------
                'We use whatever rectangle the user selected...
                'For example: let's start at 2,2 and go right to 2,6,
                '  then down to 6,6 and left to 6,2,
                '  then up to 2, 2 and pause/beep
                'as we move from cell to cell, enter the value of: lNumMoves
                '
                'Ooooh, so we need a marquee algo!
                '  r2c2 r2c3 r2c4 r2c5 r2c6, r3c6 r4c6 r5c6 r6c6, r6c5 r6c4 r6c3 r6c2, r5c2 r4c2 r3c2 r2c2
                '  hold the row and increase the columns
                '  hold the column and increase the rows
                '  hold the row and DEcrease the columns
                '  hold the column and DEcrease the rows
                '
                'would it help to determine a column count and a row count?
                '  lColCount = (lEC - lSC) + 1
                '  lRowCount = (lER - lSR) + 1
                '
                'get the range selected by the user
                SendMessage hGrid1,%MLG_GETMULTICELLSELECTION,VarPtr(rct),0
                lSR   = rct.nTop        ' Start Row
                lSC   = rct.nLeft       ' Start Col        2
                lER   = rct.nBottom     ' End Row
                lEC   = rct.nRight      ' End Column       6
    
                mm = ""
                Local lNumMoves As Long
                For j = lSC To lEC       ' columns
                   MLG_FormatCellBgndColor(hGrid1,lSR, j, lNumMoves Mod 16)
                   MLG_FormatCellBorder (hGrid1, lSR, j, %MLG_OUTLINE)
                   'SendMessage hGrid1,%MLG_SETSELECTED,lSR, j                   ' THIS ALLOWS GRID TO SCROLL, no thanks
                   SendMessage hGrid1, %MLG_REFRESH, 0,0
                   Sleep 500
                   Incr lNumMoves
                   mm = Trim$(lNumMoves)
                   MLG_Put (hGrid1, lSR, j, mm, 1)  ' 1 = refresh
                   MLG_FormatCellBorder (hGrid1, i, lSC, %MLG_CLEAR)
                   SendMessage hGrid1, %MLG_REFRESH, 0,0
                Next j
                For i = lSR+1 To lER          ' rows
                   MLG_FormatCellBgndColor(hGrid1,i, lEC, lNumMoves Mod 16)
                   MLG_FormatCellBorder (hGrid1, i, lEC, %MLG_OUTLINE)
                   'SendMessage hGrid1,%MLG_SETSELECTED,i, lEC
                   SendMessage hGrid1, %MLG_REFRESH, 0,0
                   Sleep 500
                   Incr lNumMoves
                   mm = Trim$(lNumMoves)
                   MLG_Put (hGrid1, i, lEC, mm, 1)  ' 1 = refresh
                   MLG_FormatCellBorder (hGrid1, i, lSC, %MLG_CLEAR)
                   SendMessage hGrid1, %MLG_REFRESH, 0,0
                Next i
    
                For j = lEC-1 To lSC Step -1       ' columns
                   MLG_FormatCellBgndColor(hGrid1,lER, j, lNumMoves Mod 16)
                   MLG_FormatCellBorder (hGrid1, lER, j, %MLG_OUTLINE)
                   'SendMessage hGrid1,%MLG_SETSELECTED,lER, j
                   SendMessage hGrid1, %MLG_REFRESH, 0,0
                   Sleep 500
                   Incr lNumMoves
                   mm = Trim$(lNumMoves)
                   MLG_Put (hGrid1, lER, j, mm, 1)  ' 1 = refresh
                   MLG_FormatCellBorder (hGrid1, i, lSC, %MLG_CLEAR)
                   SendMessage hGrid1, %MLG_REFRESH, 0,0
                Next j
                For i = lER-1 To lSR+1 Step -1          ' rows
                   MLG_FormatCellBgndColor(hGrid1,i, lSC, lNumMoves Mod 16)
                   MLG_FormatCellBorder (hGrid1, i, lSC, %MLG_OUTLINE)
                   'SendMessage hGrid1,%MLG_SETSELECTED,i, lSC
                   SendMessage hGrid1, %MLG_REFRESH, 0,0
                   Sleep 500
                   Incr lNumMoves
                   mm = Trim$(lNumMoves)
                   MLG_Put (hGrid1, i, lSC, mm, 1)  ' 1 = refresh
                   MLG_FormatCellBorder (hGrid1, i, lSC, %MLG_CLEAR)
                   SendMessage hGrid1, %MLG_REFRESH, 0,0
                Next i
    
    
    
    
             Case %IdTest14   '
             Case %IdTest15   '
             Case %IdTest16   '
             Case %IdTest17   '
    
    
             Case %IdCancel
                ? "Bye!"
                Dialog End Cb.Hndl, 0
                Function = 1
    
             End Select
          End Select
    
    
       Case %WM_Notify
    
          Local myrow, mycol, oldrow As Long
          Local MLGN As MyGridData Ptr        ' Ha! found it!
    
          MLGN = Cb.LParam
          'If @MLGN.NMHeader.idFrom = %IDC_MLGGRID1 Then ' Notification messages      ********   NEED TO HANDLE MULTIPLE grid IDs   ********
    
          Select Case @MLGN.NMHeader.idFrom
          Case %IDC_MLGGRID1
             ghWhichGridHasFocus = 1
          Case %IDC_MLGGRID2
             ghWhichGridHasFocus = 2
          Case %IDC_MLGGRID3
             ghWhichGridHasFocus = 3
          End Select
    
             Select Case @MLGN.NMHeader.code  '
             Case %MLGN_RETURN
                [email protected] 'current row
                [email protected] 'current col
                'The enter key has been pressed.  The grid will dismiss the edit box if it had focus and will move the cell selection box according to the "e" switch.
    
             Case %MLGN_ROWCHANGE
                [email protected] 'current row
                [email protected]'previous row
                'The row selection has changed.  May need to load a record into the application
    
             Case %MLGN_KILLFOCUS
                '[email protected]   ' handle of the control receiving focus   ghWhichGridHasFocus
                [email protected]
    
             End Select
          'End If
       End Select
    End Function


  • #2
    Code:
    'ClipboardContainsText.inc   by jhm
    'from: https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/51093-determining-the-state-of-the-clipboard msg#10
    
    #if not %DEF(%ClipboardContainsText_INC)
       %ClipboardContainsText_INC = 1
    
    Function ClipboardContainsText() As Long
    'If x is something other than a nul string, CB has something there.
       Local x As String
       Clipboard Get Text To x
       If x <> "" Then Function = %TRUE
    End Function
    
    #endif   ' end of:   #if not %DEF(%ClipboardContainsText_INC)
    
    
    
    
    
    #if 0  ' an alternative from Lloyd Gallant in msg#2 of the above thread...
    FUNCTION ClipboardContainsText() AS LONG
       'IF IsClipboardFormatAvailable(%CF_TEXT) THEN
       '   Function = %TRUE ' "There is text on the clipboard"
       ''ELSE
       ''   Function = %FALSE ' "There is no text on the clipboard"
       'END IF
       Function = IsClipboardFormatAvailable(%CF_TEXT)
    END FUNCTION
    
    #endif

    Comment


    • #3
      John,
      That is what I use to enable or disable an edit button "Paste"

      Code:
            IF IsClipboardFormatAvailable(%CF_TEXT) THEN
                EnableWindow GetDlgItem(hWndMain, %IDM_HB_PASX), %TRUE
            ELSE
                EnableWindow GetDlgItem(hWndMain, %IDM_HB_PASX), %FALSE
            END IF
      Just replace %IDM_HB_PASX with %IdTest11

      Comment


      • #4
        I appreciate that suggestion Jim, but I don't see how it turns on the "current cell" border.

        What am I missing?

        Thanks,
        -John

        Comment


        • #5
          Thanks to Gary for help!

          Turns out that instead of following the %MLG_SetSelected message with the %MLG_REFRESH message,
          Code:
                   Case %IdTest1    ' set 1 cell
          
                      SendMessage hGrid1,%MLG_SETSELECTED,3,4   ' MAYBE THIS is NOT the right call?
                      'need to make it visible
                      SendMessage hGrid1, %MLG_REFRESH, 0,0
          I just need to use an API call:
          Code:
                         SendMessage hGrid1, %MLG_SetSelected,3,4
                         SetFocus hGrid1
          As this is my "sandbox code" for learning MLG, I'm currently making lots of other changes each evening. Code, test, learn, repeat...

          In a few days, I'll repost cleaner code that shows some of the functions I'm working on. Should be fun for others learning MLG...

          Ciao for now!
          -John

          Comment

          Working...
          X