CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2005
    Location
    Brasil
    Posts
    57

    Arrow InputBox Icon ???

    Hi there...

    Is it possible to put an icon in a InputBox (just like an MsgBox) ???

    I wouldn't like to use a normal form to simulate the inputbox, but I'm not sure if it's possible !

    I was thinking about a PictureBox (or Image) in a form, and call its image:

    InputBox = PictureBox.Picture & " My message..................", "Title"

    but the result is always something like: 12548756 My message.................

    I've already tried the LoadPicture method too, but got an error.

    Could anyone help me ??

    Thanks in advance...

    Marcos.

  2. #2
    Join Date
    Aug 2006
    Posts
    145

    Re: InputBox Icon ???

    by far the simplest way is to just make your own inputbox form (i've attached an example, but here's the code):
    Code:
    ' In your Input Box form (frmInput in this case)
    ' It's got various controls - check the example:
    
    Option Explicit
    
    Private bOK As Boolean
    
    Public Function ShowInput(ByVal sPrompt As String, Optional ByVal sTitle As String, _
                              Optional ByVal sDefault As String, Optional ByVal lXPos As Long = -1, _
                              Optional ByVal lYPos As Long = -1, Optional ByVal IPic As IPictureDisp) As String
                              
        lblPrompt.Caption = sPrompt
        
        If Len(sTitle) Then Me.Caption = sTitle Else Me.Caption = App.Title
        
        With txtInput
            .Text = sDefault
            .SelStart = 0
            .SelLength = Len(.Text)
        End With
        
        If lXPos > -1 Then Me.Left = lXPos
        If lYPos > -1 Then Me.Top = lYPos
        
        If Not IPic Is Nothing Then
            Set picIcon.Picture = IPic
            picIcon.Visible = True
        End If
        
        Me.Show vbModal
        
        If bOK Then ShowInput = txtInput.Text Else ShowInput = vbNullString
        
        Unload Me
    End Function
    
    Private Sub cmdCancel_Click()
        Me.Hide
    End Sub
    
    Private Sub cmdOK_Click()
        bOK = True
        Me.Hide
    End Sub
    and then when you call it you do:
    Code:
    ' In form1, for example:
    
    Private Sub Command1_Click()
        Dim sInput As String
        
        sInput = frmInput.ShowInput("This is a test", "MyApp", "test", _
                                    , , LoadPicture(App.Path & "\CLIP07.ICO"))
        Debug.Print sInput
    End Sub
    the best thing about doing it this way is that it's fully customisable and reuseable

    Attached Files Attached Files

  3. #3
    Join Date
    Aug 2005
    Location
    Brasil
    Posts
    57

    Thumbs up Re: InputBox Icon ???

    All right, my friend...

    In true, I wouldn't like to use a normal form simulating the InputBox, but I don't think it's possible...

    I'll use your solution. It looks to me that's the best way for my purpose.

    Tanks for the help and time...

    Marcos.

  4. #4
    Join Date
    Aug 2006
    Posts
    145

    Re: InputBox Icon ???

    Quote Originally Posted by marcosav
    In true, I wouldn't like to use a normal form simulating the InputBox, but I don't think it's possible...
    there's very little that isn't possible. Here's an example I've knocked up:

    In a Module:
    Code:
    Option Explicit
    
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    
    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    
    ' Timer API
    Private Declare Function SetTimer Lib "user32" _
        (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, _
        ByVal lpTimerFunc As Long) As Long
    
    Private Declare Function KillTimer Lib "user32" ( _
        ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
    
    ' Window Manip API
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
        (ByVal hwndParent As Long, ByVal hwndChildAfter As Long, _
        ByVal lpszClass As String, ByVal lpszWindow As String) As Long
    
    Private Declare Function MoveWindow Lib "user32" ( _
        ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, _
        ByVal nHeight As Long, ByVal bRepaint As Long) As Long
        
    Private Declare Function GetWindowRect Lib "user32" ( _
        ByVal hwnd As Long, lpRect As RECT) As Long
    
    Private Declare Function ClientToScreen Lib "user32" ( _
        ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    
    Private Declare Function IsWindowVisible Lib "user32" ( _
        ByVal hwnd As Long) As Long
        
    ' Drawing API
    Private Declare Function GetDC Lib "user32" ( _
        ByVal hwnd As Long) As Long
        
    Private Declare Function CreateCompatibleDC Lib "gdi32" ( _
        ByVal hDC As Long) As Long
    
    Private Declare Function SelectObject Lib "gdi32" ( _
        ByVal hDC As Long, ByVal hObject As Long) As Long
    
    Private Declare Function BitBlt Lib "gdi32" ( _
        ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, _
        ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, _
        ByVal dwRop As Long) As Long
    
    Private Declare Function DeleteDC Lib "gdi32" ( _
        ByVal hDC As Long) As Long
    
    ' Constants & Variables
    Private Const NV_INPUTBOX As Long = &H5000&
    Private sFindTitle As String, oPicDisp As IPictureDisp
    
    Public Function PictureInputBox(ByVal ofrm As Form, ByVal sPrompt As String, ByVal sTitle As String, _
                                    ByVal IPic As IPictureDisp) As String
        sFindTitle = sTitle
        Set oPicDisp = IPic
        SetTimer ofrm.hwnd, NV_INPUTBOX, 10, AddressOf Customise
        PictureInputBox = InputBox(sPrompt, sTitle)
    End Function
    
    Private Sub Customise(ByVal plngHandle As Long, ByVal uMsg As Long, _
                          ByVal plngEventId As Long, ByVal dwTime As Long)
        Const lDiff As Long = 30
        Dim lhWnd As Long, lhWndChild As Long
        Dim hDC As Long, hPicDC As Long, lOldBMP As Long
        Dim r As RECT, pt As POINTAPI
        
        lhWnd = FindWindowEx(0&, 0&, "#32770", sFindTitle)
        If IsWindowVisible(lhWnd) Then
            lhWndChild = FindWindowEx(lhWnd, 0&, "Static", vbNullString)
            If lhWndChild Then
                ClientToScreen lhWnd, pt
                GetWindowRect lhWndChild, r
                MoveWindow lhWndChild, r.Left - pt.x + lDiff, _
                                       r.Top - pt.y, _
                                       r.Right - r.Left - lDiff, _
                                       r.Bottom - r.Top, True
                hDC = GetDC(lhWnd)
                hPicDC = CreateCompatibleDC(hDC)
                lOldBMP = SelectObject(hPicDC, oPicDisp.Handle)
                BitBlt hDC, r.Left - pt.x, r.Top - pt.y, 20, 20, hPicDC, 0, 0, vbSrcCopy
                SelectObject hPicDC, lOldBMP
                DeleteDC hPicDC
            End If
            KillTimer plngHandle, plngEventId
        End If
    End Sub
    and to call it:
    Code:
    Private Sub Command1_Click()
        Dim sInput As String
        
        sInput = PictureInputBox(Me, "Say Something", "Can you see the pic?", _
                                 LoadPicture(App.Path & "\test.bmp"))
        Debug.Print sInput
    End Sub
    the picture has to be a bmp file - you can do some CreateCompatibleBitmap stuff that would ensure you could use other file types but i don't know anything about graphics so I haven't bothered. You could also make use of TransparenBlt or StretchBlt etc.

    if you decide to play with this then bewarned that any errors in the Customise Sub will cause the IDE to crash (cos of the API timer)


    You can see why I suggested the other way now, so much easier...

    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured