hexagon logo

Dialog Box

I am making dialog boxes with Cypress Enable. Is there any way to insert a picture into a dialog box?

I'm looking to do something similar to what Marked Sets does, where I have a picture that is a button for the operator to click on. Is this even possible to do in Cypress Enable?
  • I posted a snippet @ the other side involving a bitmap in a dialog Cypress Enable, but haven't got any feedback on whether or not it worked (didn't try it myself).
  • Vpt, where is this other side you speak of?!

    I will try it myself if you can post it or PM me. There is very little information on the capabilities of Cypress Enable on the web. I downloaded their help files, and they are actually paltry compared to the PDF PC-DMIS Basic guide that you can download from wilcox. It was a real treat to start getting dialog boxes working yesterday, after discovering they could be used.
  • Vpt, it worked! Now I have another issue I am trying to get past. Basically, I want to create something similar to the Marked Sets box. With your example, it displays all of the pictures, and if I ask for:

    results = bitmapDlg.List1
    it of course gives a number starting from 0 to signify what picture was chosen. I want to grab the filename. Using this code in the Dialog function section:
     	 Case 2 ' Click
      		fileName = ShortFilepath & DlgText("List1")
      		DlgSetPicture "Picture1", fileName
      		results = fileName


    I can get the filename, but I can't use the results variable in the actual script, in this case. How can I get the results to match the filename of the picture I have selected?
  • Are you able to use the 'fileName' variable in the script, instead of 'results'?

    Also, post the entire script with the variable dims etc.
  • No dice on using fileName instead. I was also trying to use variables for the filename, so I could adapt this to a different file location depending on user input, but that didn't work out so well, either. Here's the code. I've been changing little things one at a time, so it isn't much different than what you posted.

    '=========================================================
    ' Bitmap sample using the Dir Function
    '=========================================================
    Sub DrawBitmapSample
    
    Dim Filepath As String
    Dim ShortFilepath As String
    Dim results As String
    ShortFilepath = "C:\Windows\"
    Filepath = Shortfilepath + "*.bmp"
    
    
    Dim MyList()
      Begin Dialog BitmapDlg 60, 60, 290, 220, "Enable bitmap sample", .DlgFunc
        ListBox 10, 10, 80, 180, MyList(), .List1, 2
        Picture 100, 10, 180, 180, "Forest.bmp", 0, .Picture1
        CancelButton 42, 198, 40, 12
        OKButton 90, 198, 40, 12
      End Dialog
    
    Dim frame As BitmapDlg
    ' Show the bitmap dialog
    Dialog frame
    
    
    results = bitmapDlg.List1
    MsgBox results
    MsgBox fileName
    
    End Sub
    
    Function DlgFunc( controlID As String, action As Integer, suppValue As Integer)
      'DlgFunc = 1 ' Keep dialog active
      Select Case action
      	Case 1 ' Initialize
        	temp = Dir( "C:\Windows\*.bmp" )
        	count = 0
        	While temp <> ""
          		count = count + 1
          		temp = Dir
        	Wend
    
    		Dim x() As String
    		ReDim x(count)
    		x(0) = Dir( "C:\Windows\*.bmp" )
    
    		For i = 1 To count
      			x(i) = Dir
      		Next i
    
    		DlgListBoxArray "List1", x()
    		'results = fileName
     	 Case 2 ' Click
      		fileName = ShortFilepath & DlgText("List1")
      		DlgSetPicture "Picture1", fileName
      		results = fileName
      	
    	End Select
    End Function
  • Is it me, or is the fileName variable never dim'd?

    Try dim it in the beginning of the script - not inside another sub, by dim'ing it 'outside' the subs it will make it 'global' - valid through the entire script:

    ' Bitmap sample using the Dir Function
    '=========================================================
    Sub DrawBitmapSample
    
    [COLOR="Red"]Dim MyFilename as string[/COLOR]
    
    Dim Filepath As String
    Dim ShortFilepath As String
    Dim results As String
    ShortFilepath = "C:\Windows\"
    Filepath = Shortfilepath + "*.bmp"
    
    
    Dim MyList()
      Begin Dialog BitmapDlg 60, 60, 290, 220, "Enable bitmap sample", .DlgFunc
        ListBox 10, 10, 80, 180, MyList(), .List1, 2
        Picture 100, 10, 180, 180, "Forest.bmp", 0, .Picture1
        CancelButton 42, 198, 40, 12
        OKButton 90, 198, 40, 12
      End Dialog
    
    Dim frame As BitmapDlg
    ' Show the bitmap dialog
    Dialog frame
    
    
    results = bitmapDlg.List1
    MsgBox results
    MsgBox fileName
    
    End Sub
    
    Function DlgFunc( controlID As String, action As Integer, suppValue As Integer)
      'DlgFunc = 1 ' Keep dialog active
      Select Case action
      	Case 1 ' Initialize
        	temp = Dir( "C:\Windows\*.bmp" )
        	count = 0
        	While temp <> ""
          		count = count + 1
          		temp = Dir
        	Wend
    
    		Dim x() As String
    		ReDim x(count)
    		x(0) = Dir( "C:\Windows\*.bmp" )
    
    		For i = 1 To count
      			x(i) = Dir
      		Next i
    
    		DlgListBoxArray "List1", x()
    		'results = fileName
     	 Case 2 ' Click
      		fileName = ShortFilepath & DlgText("List1")
    
    [COLOR="red"]MyFilename = filename[/COLOR]
    [COLOR="red"]MsgBox MyFilename ' for debugging[/COLOR]
    
      		DlgSetPicture "Picture1", fileName
      		results = fileName
      	
    	End Select
    End Function 
    
  • Aha! Dimensioning the variable globally worked. Boy I'm glad this isn't my real job, I would suck at it!

    The last little bug I have is with the picture display. When the dialog box is created, the picture does not display for the first filename. If you click on a different filename and click back, it displays. How can I force it to display when the box is initialized?
  • Perhaps setting the picture after filling the picturearray?

    In the 'Case 1' section:
    DlgListBoxArray "List1", x()
    [COLOR="Red"]DlgSetPicture "Picture1", x(0)[/COLOR]
    'results = fileName


    This is untested though... (crossing fingers)

    If the above won't work, try moving it outside the case statement:

    End Select
    [COLOR="Red"]DlgSetPicture "Picture1", x(0)[/COLOR]
    End Function
  • Putting "DlgSetPicture "Picture1", x(0)" in the Case 1 section did it. If outside the case select, it makes every picture x(0). I'm off to study this extensively so I don't need to ask more questions. Thank you much! Smiley