Announcement

Collapse
No announcement yet.

ComboBox Problem...

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

  • Scott Turchin
    replied
    My experience has been to subclass the thing, I learned the hard way I guess hehe...

    All this thing does is store URL's, it has nto checked for dupe's yet and has some bugs but works good on NT where no address bar is available hehe..

    Catches the typing in the combobox, processes on $CRLF..


    Scott

    Code:
    ' ** Eliminate unnecessary macros
    %NOANIMATE    = 1
    %NODRAGLIST   = 1
    %NOHEADER     = 1
    %NOIMAGELIST  = 1
    %NOLISTVIEW   = 1
    %NOTABCONTROL = 1
    %NOTRACKBAR   = 1
    %NOTREEVIEW   = 1
    %NOUPDOWN     = 1
    
    '------------------------------------------------------------------------------
    #Dim All
    #Compile Exe
    #Option Version4
    #Register None
    #Include "CCS.INC"
    #Include "commctrl.inc"
    #Resource "ADDRBAR.PBR"
    
    %PROGRAM = 1024
    %HAND    = 2005
    %WM_TRAYICON    = %WM_USER + 400
    
    '* FILE
    %IDM_EXIT            = %WM_USER       + 2048
    '* HELP
    %IDM_HELP             = %IDM_EXIT     + 1       ' Help
    %IDM_ABOUT            = %IDM_HELP     + 1       ' About Program.Exe
    %IDM_CLEAR            = %IDM_ABOUT    + 1
    
    %ID_URLTEXT           = %WM_USER + 101
    %IDCOMBOBOX           = %WM_USER + 102
    
    Global g_hInst      As Long
    Global hDlg         As Long
    Global aDlg         As Long
    Global hEdit        As Long
    Global hMenu        As Long
    Global pMenu        As Long
    Global hIcon        As Long
    Global hStatus      As Long
    Global g_hFile      As Long
    Global hCombo       As Long
    Global hMutex       As Long
    Global g_Result     As Long
    Global g_Left       As Long
    Global g_Top        As Long
    
    Global g_szURL      As String 'My URL
    Global g_szDestURL  As String
    Global g_HistFile   As String
    Global HistArray()  As String
    Global HistIndex    As Long  'index we are currently on at any given point in time
    Global lCount       As Long  'How many are in array
    Global lLoop        As Long  'for counting
    Global OldCBProc    As Long  'For subclassing the combobox
    
    Global WndRect      As RECT
    Global lpwndpl      As WINDOWPLACEMENT
    
    '------------------------------------------------------------------------------
    Declare CallBack Function DialogProc() As Long
    Declare Function SaveLocation() As Long
    
    '------------------------------------------------------------------------------
    
    '========================================================================================================================
    Function WinMain (ByVal hInstance     As Long, _
                      ByVal hPrevInstance As Long, _
                      lpCmdLine           As Asciiz Ptr, _
                      ByVal iCmdShow      As Long) As Long
    
    Local szClassName As Asciiz * 80
    Local wndclass          As WndClassEx
    Dim HistArray(1 To 1000) As String
    
    InitCommonControls
    Call InitUrlCtrl
    
    
      g_szCCS                = "Computer Creations Software"
      g_szMine               = "Internet Address Bar"
      g_hInst                = hInstance
      szClassName            = "ADDRBAR"
      g_szVer                = "v1.10"
      g_szCopyrite           = "Copyright © 2000"
      g_szURL                = "http://www.tngbbs.com"
      %HK                    = %HKEY_LOCAL_MACHINE
      g_HistFile             = "HISTORY.TXT"
      hIcon = LoadIcon(g_hInst, ByVal %PROGRAM)
    
      wndclass.cbSize        = SizeOf(WndClass)
      wndclass.style         = %CS_HREDRAW Or %CS_VREDRAW
      wndclass.lpfnWndProc   = CodePtr( DialogProc )
      wndclass.cbClsExtra    = 0
      wndclass.cbWndExtra    = 0
      wndclass.hInstance     = hInstance
      wndclass.hIcon         = hIcon
      wndclass.hCursor       = LoadCursor( %NULL, ByVal %IDC_ARROW )
      wndclass.hbrBackground = GetStockObject( %HOLLOW_BRUSH )
      wndclass.lpszMenuName  = %NULL
      wndclass.lpszClassName = VarPtr( szClassName )
      wndclass.hIconSm       = LoadIcon( hInstance, ByVal %IDI_APPLICATION )
      RegisterClassEx wndclass
    
    
    If IsTrue App_PrevInstance(szClassName) Then
        MsgBox "Another instance of " + g_szMine + " is already running!",%MB_ICONSTOP,g_szMine
        Exit Function
    Else
        hMutex = CreateMutex(ByVal %Null, 0, szClassName)
    End If
    
    
    'Binary registry routine here
    g_Result = SetWindowPlacement(ByVal hDlg, lpwndpl)
    
    hMenu = LoadMenu(g_hInst, "MAINMENU")
    pMenu = GetSubMenu(LoadMenu(g_hInst, "POPUPMENU"), 0)
    g_hFile = FreeFile
    If IsTrue Exist(g_HistFile) Then
       Open g_HistFile For Input As #g_hFile
       Do Until Eof(g_hFile)
          Incr lCount
          Line Input #g_hFile, HistArray(lCount)
       Loop
       Close g_hFile
    End If
    
    'Array is now loaded
    g_Top = Val(GetSetting(%HKEY_LOCAL_MACHINE,"Software\Computer Creations Software\" + g_szMine,"Top","0"))
    g_Left = Val(GetSetting(%HKEY_LOCAL_MACHINE,"Software\Computer Creations Software\" + g_szMine,"Left","0"))
    
    Dialog New 0, g_szMine,g_Top, g_Left,300,30, %WS_MINIMIZEBOX Or %WS_CAPTION Or %WS_SYSMENU Or %WS_EX_LEFT  To hDlg
    Control Add ComboBox, hDlg, %IDCOMBOBOX, HistArray(), 5, 1, 290,120, %CBS_DROPDOWN Or %WS_TABSTOP
    Dialog Send hDlg, %WM_SETICON, %ICON_BIG, hIcon
    Menu Attach hMenu, hDlg
    Dialog Show Modal hDlg Call DialogProc To g_Result
    
    Array Scan HistArray(1), = "", To lCount
    If OldCBProc Then SetWindowLong hCombo, %GWL_WNDPROC, OLDCBProc
    
    g_hFile = FreeFile
    Open g_HistFile For Output As #g_hFile
    For lLoop = 1 To lCount
        If Len(HistArray(lLoop)) Then Print #g_hFile, HistArray(lLoop)
    Next
    Close g_hFile
    End Function  ' WinMain
    
    '========================================================================================================================
    
    CallBack Function DialogProc() As Long
    Local wMsg              As Long
    Local wParam            As Long
    Local lParam            As Long
    Static zText            As Asciiz * 255
    Static ti               As NOTIFYICONDATA
    Static p                As POINTAPI
    
    
    wMsg = CbMsg
    lParam = CbLparam
    wparam = CbWparam
    
      Select Case wMsg
    
        Case %WM_CREATE
        Case %WM_INITDIALOG
    '        SetWindowPos hDlg, %HWND_NOTOPMOST, 0, 0, 0, 0, %SWP_NOMOVE Or %SWP_NOSIZE
            SetWindowPos hDlg, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOMOVE Or %SWP_NOSIZE
            ' ** Add tray icon
            ti.cbSize           = SizeOf(ti)
            ti.hWnd             = hDlg
            ti.uID              = g_hInst
            ti.uFlags           = %NIF_ICON Or %NIF_MESSAGE Or %NIF_TIP
            ti.uCallbackMessage = %WM_TRAYICON
            ti.hIcon            = hIcon
            ti.szTip            = g_szMine + " " + g_szVer
            Shell_NotifyIcon %NIM_ADD, ti
            DestroyIcon ti.hIcon
    
            Control Handle hDlg, %IDCOMBOBOX To hCombo   'Sub-class, to trap keyboard events
            OldCBProc = SetWindowLong(hCombo, %GWL_WNDPROC, CodePtr(CBProc))
            ComboBox Select hDlg, %IDCOMBOBOX, 1
    '        Dialog Show State hDlg, %SW_HIDE
    
        Case %WM_DESTROY
    '        SaveSetting %HKEY_LOCAL_MACHINE,"Software\Computer Creations Software\" + g_szMine,"Top", Format$(WndRect.nTop)
    '        SaveSetting %HKEY_LOCAL_MACHINE,"Software\Computer Creations Software\" + g_szMine,"Left", Format$(WndRect.nLeft)
    
            g_Result = GetWindowRect(hDlg, WndRect)
            g_Result = GetWindowPlacement(ByVal hDlg, lpwndpl)
            SaveSetting %HKEY_LOCAL_MACHINE,"Software\Computer Creations Software\" + g_szMine,"Window", lpwndpl
          Function = 0
          Exit Function
    
        Case %WM_SETFOCUS
    
        Case %WM_MENUSELECT
    
        Case %WM_SIZE
    
        Case %WM_COMMAND
          Select Case LoWrd(wParam)
            Case %IDM_CLEAR
                 g_Result = MsgBox("Are you sure you wish to clear the history?", %MB_ICONINFORMATION Or %MB_YESNO, g_szMine)
                 If g_Result = %IDYES Then
                     Control Disable hDlg, %IDM_CLEAR
                     If IsTrue Exist(g_HistFile) Then
                        Kill g_HistFile
                        Erase HistArray()
                        ReDim HistArray(1 To 1000) As String
                     End If
                 End If
    
            Case %IDCOMBOBOX
                  If LoWrd(CbCtlMsg) = %CBN_SELENDOK Then
                       ComboBox Get Text hDlg ,%IDCOMBOBOX To g_szDestURL
                       Array Scan HistArray(1), = g_szDestURL, To HistIndex
                       ComboBox Select hDlg, %IDCOMBOBOX, HistIndex
                       g_Result = ShellExecute(ByVal %NULL, "open", g_szDestURL + Chr$(0), ByVal %NULL, ByVal %NULL,%SW_SHOWMAXIMIZED)
    
                   End If
                   Function = 1
                   Exit Function
    
    
            Case %IDM_EXIT
                     Select Case CbCtlMsg
                         Case %BN_CLICKED
                              Shell_NotifyIcon %NIM_DELETE, ti
                              Dialog End hDlg,1
                     End Select
    
            Case %IDM_HELP
    
                 Function = 0
                 Exit Function
            Case %IDM_ABOUT
                 g_Result = CCSShellAbout(hDlg, _
                                 %FALSE,_
                                 g_szMine,_
                                 g_szVer,_
                                 g_szCCS,_
                                 g_szCopyrite,_
                                 g_szURL,_
                                 hIcon)
              Function = 0
              Exit Function
    
          End Select
    
        Case %WM_TRAYICON
    
          Select Case LoWrd(lParam)
    
            ' ** Left button press
            Case %WM_LBUTTONDOWN
            Case %WM_LBUTTONUP, %WM_LBUTTONDBLCLK
              If IsWindowVisible(hDlg) = %FALSE Then
                ShowWindow hDlg, %SW_SHOW Or %SW_SHOWNORMAL
                SetForegroundWindow hDlg
              End If
    
            ' ** Right button press
            Case %WM_RBUTTONDOWN
              If IsWindowVisible(hDlg) = %FALSE Then
                SetForegroundWindow hDlg
                GetCursorPos p
                TrackPopupMenu pMenu, 0, p.x, p.y, 0, hDlg, ByVal %NULL
                Postmessage hDlg, %WM_NULL, 0, 0
              End If
            Function = 1
    
          End Select
    
        Case %WM_SYSCOMMAND
    
          ' ** If either the minimize or close buttons are pressed, hide the
          '    window so it doesn't appear in the task bar.
    
          Select Case LoWrd(wParam)
    
            Case %SC_MINIMIZE
              ShowWindow hDlg, %SW_HIDE
              Function = 1
              Exit Function
    
            Case %SC_CLOSE
              Shell_NotifyIcon %NIM_DELETE, ti
              Dialog End CbHndl, 1
              Exit Function
    
          End Select
    
      End Select
    End Function
    
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Combobox subclass
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    Function CBProc(ByVal hWnd As Long, ByVal wMsg As Long, _
                    ByVal wParam As Long, ByVal lParam As Long) As Long
    Local KeyNum As Long
    
    Select Case wMsg
        Case %WM_KEYDOWN
        Case %WM_CHAR
        Case %WM_KEYUP
        Case %CB_GETDROPPEDSTATE 'get enter key from a %CBS_DROPDOWN combo
             Control Get Text hDlg ,%IDCOMBOBOX To g_szDestURL
             Incr lCount
             HistArray(lCount) = g_szDestURL 'Add to array to write to disk.
    '         ComboBox Add hDlg, %IDCOMBOBOX, g_szDestURL
             g_Result = ShellExecute(ByVal %NULL, "open", g_szDestURL + Chr$(0), ByVal %NULL, ByVal %NULL,%SW_SHOWMAXIMIZED)
    End Select
    Function = CallWindowProc(OldCBProc, hWnd, wMsg, wParam, lParam)
    End Function
    
    '========================================================================================================================
    ------------------
    Scott

    Leave a comment:


  • Lance Edmonds
    replied
    Set the following styles for the CONTROL ADD COMBOBOX statement:
    Code:
    %CBS_DROPDOWNLIST OR %WS_VSCROLL OR %CBS_DISABLENOSCROLL
    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Lloyd Snyder
    started a topic ComboBox Problem...

    ComboBox Problem...

    I am experimenting with ComboBoxes at the moment, and seem
    to be over-looking something... I can't seem to get a scroll bar
    to allow me to choose the last 2 names in the example below:

    TYPE UserInfoStruct
    UserName AS ASCIIZ * 256
    Password AS ASCIIZ * 256
    END TYPE
    GLOBAL UserInfo AS UserInfoStruct
    CALLBACK FUNCTION OkButton
    COMBOBOX GET TEXT CBHNDL, 1 TO UserInfo.UserName
    CONTROL GET TEXT CBHNDL, 2 TO UserInfo.Password
    DIALOG END CBHNDL
    END FUNCTION

    FUNCTION PBMAIN AS LONG
    REGISTER DlgHandle AS LONG
    LOCAL LogonInfo AS ASCIIZ * 256
    DIM CBChoice(1 TO DATACOUNT) AS STRING
    DATA User1, User2, User3, User4, User5, User6
    FOR a& = 1 TO DATACOUNT
    CBChoice(a&) = READ$(a&)
    NEXT a&
    DIALOG NEW %HWND_DESKTOP, "Logon",,, 200, 100 TO DlgHandle
    CONTROL ADD COMBOBOX, DlgHandle, 1, CBChoice(), 2, 5, 196, 53, %CBS_DROPDOWNLIST
    CONTROL ADD TEXTBOX, DlgHandle, 2, "", 2, 55, 196, 12, %ES_PASSWORD
    CONTROL ADD BUTTON, DlgHandle, 3, "Logon", 75, 76, 30, 15, %BS_DEFAULT CALL OkButton
    COMBOBOX SELECT DlgHandle, 1, 1
    DIALOG SHOW MODAL DlgHandle
    LogonInfo = "UserName: " + UserInfo.UserName + CHR$(13) + "Password: " + UserInfo.Password
    MSGBOX LogonInfo, %MB_OK, "Logon Complete"
    END FUNCTION

    The ComboBox lists User1, 2, 3, and 4... I can't get it to
    add a scrollbar to the other 2...

    ------------------
Working...
X