Results 1 to 7 of 7

Thread: difference between cancel and "" in input box

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Location
    u.s.a
    Posts
    127

    Post

    How can one differentiate between a user pressing cancel in an inputbox, and not entering a string in the input box and then pressing OK.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    You can't, but if you'd like a form that looks like an InputBox and does allow you to tell the difference, email me.

    ------------------
    Marty
    What did the fish say when it hit the concrete wall?
    > > > > > "Dam!"

  3. #3
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Post

    There is no way...if th user clicks cancel, a zero length string is returned. If you want to capture the fact which button the user pressed, you should write your own input box form, then you can capture both the text and the button pressed.

    Hope that helps,

    ~seaweed

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    If you want a more customizable InputBox function without having to write your own, here's some code I've been working on.

    It allows you to customize the Color, Positioning, Font/FontSize, Password Char and can Raise an Error if the dialog is cancelled, (Works the same way the Common Dialog does).

    I'm giving this code up as Freeware but, if you use it, I'd like some credit for all the hours I've put into it.

    [code]'*******************************************************
    '* InputBoxEx() - Written by Aaron Young, Jan/Feb 2000
    '*
    '* MailTo:[email protected]
    '*
    '* © Copyright 2000, Aaron Young - All rights reserved.
    '*
    '* Allows the inbuilt InputBox to be Customized in
    '* the following ways:
    '*
    '* Back/ForeColor
    '* Font/Fontsize
    '* Dialog Centering
    '* Password Character Masking
    '* Can Raise a Trappable Error when the Dialog is Cancelled
    '*
    '* Usage:
    '*
    '* Result = InputboxEx( _
    '* Message,[Title],[Default],[Default],[XPos],[YPos], _
    '* [HelpFile],[Context],[ForeColor],[BackColor], _
    '* [FontName],[FontSize],[PasswordChar],[CancelError])
    '*
    '* This code is Freeware, but if you use it in whole
    '* or part, I would appreciate some credit for my work.
    '*
    '* Place this Code in a Module..
    '*
    '*******************************************************

    Option Explicit

    Private Type LOGBRUSH
    lbStyle As Long
    lbColor As Long
    lbHatch As Long
    End Type

    Private Type CWPSTRUCT
    lParam As Long
    wParam As Long
    message As Long
    hwnd As Long
    End Type

    Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
    End Type

    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
    Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Private Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
    Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
    Private Declare Function CreateBrushIndirect Lib "gdi32" (lpLogBrush As LOGBRUSH) As Long
    Private Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal H As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, ByVal W As Long, ByVal I As Long, ByVal u As Long, ByVal S As Long, ByVal C As Long, ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, ByVal PAF As Long, ByVal F As String) As Long
    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

    ' System Color Constants
    Private Const COLOR_BTNFACE = 15
    Private Const COLOR_BTNTEXT = 18

    ' SetWindowPos Constants
    Private Const SWP_FRAMECHANGED = &H20
    Private Const SWP_NOSIZE = &H1
    Private Const SWP_NOZORDER = &H4

    Private Const WH_CALLWNDPROC = 4

    Private Const GWL_WNDPROC = (-4)

    ' Windows Messages
    Private Const WM_GETFONT = &H31
    Private Const WM_CREATE = &H1
    Private Const WM_CTLCOLORBTN = &H135
    Private Const WM_CTLCOLORDLG = &H136
    Private Const WM_CTLCOLORSTATIC = &H138
    Private Const WM_CTLCOLOREDIT = &H133
    Private Const WM_DESTROY = &H2
    Private Const WM_SHOWWINDOW = &H18
    Private Const WM_COMMAND = &H111

    Private Const BN_CLICKED = 0
    Private Const IDOK = 1

    Private Const EM_SETPASSWORDCHAR = &HCC

    ' InputboxEx Variables
    Private INPUTBOX_HOOK As Long
    Private INPUTBOX_HWND As Long
    Private INPUTBOX_PASSCHAR As String
    Private INPUTBOX_BACKCOLOR As Long
    Private INPUTBOX_FORECOLOR As Long
    Private INPUTBOX_FONT As String
    Private INPUTBOX_FONTSIZE As Integer
    Private INPUTBOX_SHOWING As Boolean
    Private INPUTBOX_CENTERV As Boolean
    Private INPUTBOX_CENTERH As Boolean
    Private INPUTBOX_OK As Boolean

    Private Function InputBoxProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim tLB As LOGBRUSH
    Dim lFont As Long
    Dim tRECT As RECT
    Dim lNotify As Long
    Dim lID As Long

    Select Case Msg
    Case WM_COMMAND
    'Check to see if the OK Button was Pressed..
    lNotify = Val("&H" & Left$(Right$("00000000" & Hex$(wParam), 8), 4))
    lID = Val("&H" & Right$(Right$("00000000" & Hex$(wParam), 8), 4))
    If lNotify = BN_CLICKED Then
    INPUTBOX_OK = (lID = IDOK)
    End If

    Case WM_SHOWWINDOW
    'Reposition Inputbox if Neccessary
    Call GetWindowRect(hwnd, tRECT)
    If INPUTBOX_CENTERH Then tRECT.Left = ((Screen.Width / Screen.TwipsPerPixelX) - (tRECT.Right - tRECT.Left)) / 2
    If INPUTBOX_CENTERV Then tRECT.Top = ((Screen.Height / Screen.TwipsPerPixelY) - (tRECT.Bottom - tRECT.Top)) / 2
    Call SetWindowPos(hwnd, 0, tRECT.Left, tRECT.Top, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_FRAMECHANGED)

    Case WM_CTLCOLORDLG, WM_CTLCOLORSTATIC, WM_CTLCOLORBTN, WM_CTLCOLOREDIT
    'Set the Colors
    If Msg = WM_CTLCOLOREDIT Then
    If Len(INPUTBOX_PASSCHAR) Then
    Call SendMessage(lParam, EM_SETPASSWORDCHAR, Asc(INPUTBOX_PASSCHAR), ByVal 0&)
    End If
    Else
    Call SetTextColor(wParam, INPUTBOX_FORECOLOR)
    Call SetBkColor(wParam, INPUTBOX_BACKCOLOR)
    If Msg = WM_CTLCOLORSTATIC Then
    'Set the Font
    lFont = CreateFont(-((INPUTBOX_FONTSIZE / 72) * 96), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, INPUTBOX_FONT)
    Call SelectObject(wParam, lFont)
    End If
    'Create a Solid Brush using that Color
    tLB.lbColor = INPUTBOX_BACKCOLOR
    'Return the Handle to the Brush to Paint the Inputbox
    InputBoxProc = CreateBrushIndirect(tLB)
    Exit Function
    End If

    Case WM_DESTROY
    'Remove the Inputbox Subclassing
    Call SetWindowLong(hwnd, GWL_WNDPROC, INPUTBOX_HWND)

    End Select
    InputBoxProc = CallWindowProc(INPUTBOX_HWND, hwnd, Msg, wParam, ByVal lParam)
    End Function

    Private Function HookWindow(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim tCWP As CWPSTRUCT
    Dim sClass As String
    'This is where you need to Hook the Inputbox
    CopyMemory tCWP, ByVal lParam, Len(tCWP)
    If tCWP.message = WM_CREATE Then
    sClass = Space(255)
    sClass = Left(sCl

  5. #5
    Junior Member
    Join Date
    Jan 1999
    Posts
    26

    Post


  6. #6
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    HOLY F****** S*** Aaron.... that's A LOT of code!!!
    Good work too!

    ------------------
    DiGiTaIErRoR
    VB, QBasic, Iptscrae, HTML
    Quote: There are no stupid questions, just stupid people.

  7. #7
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Post

    I will give you the credit right here and now.
    Really good work, I wish my unborn son will have you as a rolemodel

    Many Credits to Aaron Young for giving us this code.

    It people like you that make life worth living.


    ------------------
    On Error Goto Bed =:0)
    [email protected]

    [This message has been edited by onerrorgoto (edited 02-18-2000).]

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