home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
COMBOBOX.PRG
< prev
next >
Wrap
Text File
|
1993-06-23
|
12KB
|
523 lines
////////////////////////////
//
// Clip-4-Win combobox demo
//
// Copyright (C) 1992,1993 Skelton Software, Kendal Cottage, Hillam, Leeds, UK.
// All Rights Reserved.
//
// Compile: combobox /n /w
// Link: /se:600 combobox,,,clip4win,clip4win.def
//
////////////////////////////
#define WIN_WANT_CB
#define WIN_WANT_CLIPBOARD
#define WIN_WANT_ALL
#include "windows.ch"
#define MAKELPARAM(nLow, nHigh) ((nLow) + (nHigh) * 65536)
#define CR chr(13)
#ifndef LIB_ONLY
#define ID_CBOX 1 // unique id (used for the combobox)
static hWnd, hInst, cText, hCBox, cAppName := "Clip-4-Win"
static bEvent := {|nEvent| nil} // current event handler
function main()
local hMenu, nEvent
hWnd = WinSetup(cAppName, "Clip-4-Win Combo Box Demo")
hInst = _GetInstance()
hMenu = MenuSetup()
HideCaret(hWnd)
do while .t.
do while (nEvent := ChkEvent()) == EVENT_NONE
// some "background" processing could go here
enddo
eval(bEvent, nEvent) // give the event to the right handler
enddo
return 0
procedure DoAbout()
MessageBox( , "Written by John Skelton.", "Info", MB_OK)
return
procedure DoExit()
quit
return
// This is non-modal, but you have to send/receive messages
procedure DoCBox()
local aList := {"Some strings", "for ComboBox", "as an example", "for you"}
if hCBox != nil
DestroyWindow(hCBox)
endif
hCBox = CreateWindow("combobox", ; // window class
, ; // caption for title bar (none)
WS_CHILD + WS_VISIBLE ; // window style
+ CBS_SIMPLE, ; // ... just a simple one
100, ; // x co-ordinate
50, ; // y co-ordinate
200, ; // width
137, ; // height
hWnd, ; // hWnd of parent
ID_CBOX, ; // id for child control to use
hInst) // our own app instance
aeval(aList, {|cStr| SendMessage(hCBox, CB_ADDSTRING, 0, cStr)} )
bEvent = {|nEvent| CBoxEvent(nEvent)}
SetFocus(hCBox)
return
// This is non-modal, but you have to send/receive messages
procedure DoDropDown()
local aList := {"Item 1", "for ComboBox", "Item 3", "Item 4"}
if hCBox != nil
DestroyWindow(hCBox)
endif
hCBox = CreateWindow("combobox", ; // window class
, ; // caption for title bar (none)
WS_CHILD + WS_VISIBLE ; // window style
+ CBS_DROPDOWNLIST, ; // ... drops down when selected
100, ; // x co-ordinate
50, ; // y co-ordinate
200, ; // width
100, ; // height
hWnd, ; // hWnd of parent
ID_CBOX, ; // id for child control to use
hInst) // our own app instance
aeval(aList, {|cStr| SendMessage(hCBox, CB_ADDSTRING, 0, cStr)} )
bEvent = {|nEvent| CBoxEvent(nEvent)}
SetFocus(hCBox)
return
procedure CBoxEvent(nEvent)
local i, lRedraw := .f.
do case
case nEvent == EVENT_CONTROL
if _lastwParam() == ID_CBOX // child id
if _lastHilParam() == CBN_SELCHANGE
i = SendMessage(hCBox, CB_GETCURSEL, 0, 0)
cText = space(SendMessage(hCBox, CB_GETLBTEXTLEN, i, 0))
SendMessage(hCBox, CB_GETLBTEXT, i, @cText)
// MessageBox( , nstr(i) + cText, "GETLBTEXT", MB_OK)
lRedraw = .t.
endif
endif
case nEvent == EVENT_REDRAW
lRedraw = .t.
case nEvent == EVENT_SETFOCUS
SetFocus(hCBox)
endcase
if lRedraw
SetPos(15, 15)
? "Text chosen:" ; ? ; ? padr(cText, 40)
endif
return
function nstr(n)
return alltrim(str(n)) + " "
#endif // !LIB_ONLY
/////////
//
// CBAddString( <hCBox>, <cNewStr> ) --> nLine
//
// Add a new string to the list box part of a combo box
//
// Returns the position of the string added, or CB_ERR if an
// error occurs (but CB_ERRSPACE if not enough room)
//
/////////
function CBAddString(hCBox, cNewStr)
return SendMessage(hCBox, CB_ADDSTRING, 0, cNewStr)
/////////
//
// CBCopy( <hCBox> ) --> nil
//
// Copy the edit control part of a combo box to the Windows clipboard
//
/////////
procedure CBCopy(hCBox)
SendMessage(hCBox, WM_COPY, 0, 0)
return
/////////
//
// CBCut( <hCBox> ) --> nil
//
// Cut the contents of the edit control part of a combo box to
// the Windows clipboard
//
/////////
procedure CBCut(hCBox)
SendMessage(hCBox, WM_CUT, 0, 0)
return
/////////
//
// CBDeleteString( <hCBox>, <nLine> ) --> nCount
//
// Deletes a string from the list box part of a combo box.
// <nLine> is the position of the string to delete
//
// Returns the the number of strings left, or CB_ERR if an
// error occurs
//
/////////
function CBDeleteString(hCBox, nLine)
return SendMessage(hCBox, CB_DELETESTRING, nLine, 0)
/////////
//
// CBDir( <hCBox>, <nAttr>, <cFileSpec> ) --> nLine
//
// Add a list of filenames to the list box part of a combo box
//
// Returns the position of the last filename added, or CB_ERR if an
// error occurs (but CB_ERRSPACE if not enough room)
//
/////////
function CBDir(hCBox, nAttr, cFileSpec)
return SendMessage(hCBox, CB_DIR, nAttr, cFileSpec)
/////////
//
// CBFindString( <hCBox>, <cStr>, [ <nStart> ] ) --> nLine
//
// Find a string in the list box part of a combo box.
// <nStart> optionally specifies the start of the search
//
// Returns the position of the string found, or CB_ERR if not found
//
// See Also: CBFindStrExact()
//
/////////
function CBFindString(hCBox, cStr, nStart)
if nStart == nil
nStart = -1 // search from the start
endif
return SendMessage(hCBox, CB_FINDSTRING, nStart, cStr)
/////////
//
// CBFindStrExact( <hCBox>, <cStr>, [ <nStart> ] ) --> nLine
//
// Find a string in the list box part of a combo box.
// <nStart> optionally specifies the start of the search
//
// Returns the position of the string found, or CB_ERR if not found
//
// See Also: CBFindString()
//
/////////
function CBFindStrExact(hCBox, cStr, nStart)
if nStart == nil
nStart = -1 // search from the start
endif
return SendMessage(hCBox, CB_FINDSTRINGEXACT, nStart, cStr)
/////////
//
// CBGetCount( <hCBox> ) --> nCount
//
// Returns the number of items in the list box of a combo box
//
/////////
function CBGetCount(hCBox)
return SendMessage(hCBox, CB_GETCOUNT, 0, 0)
/////////
//
// CBGetCurSel( <hCBox> ) --> nLine
//
// Returns the position of the currently selected item in the list box
// of a combo box (or CB_ERR if nothing is selected)
//
/////////
function CBGetCurSel(hCBox)
return SendMessage(hCBox, CB_GETCURSEL, 0, 0)
/////////
//
// CBGetDropRect( <hCBox> ) --> aRect
//
// Returns the screen (not window) co-ordinates of the drop-down
// rectangle for the list box part of a combo box, in
// the form {left, top, right, bottom}
//
/////////
function CBGetDropRect(hCBox)
local cRect := space(8) // room for int[4]
SendMessage(hCBox, CB_GETDROPPEDCONTROLRECT, 0, @cRect)
return bin2a(cRect, "int[4]")
/////////
//
// CBGetDropState( <hCBox> ) --> lDroppedDown
//
// Returns .t. if the list box part of a combo box is dropped down
//
/////////
function CBGetDropState(hCBox)
return SendMessage(hCBox, CB_GETDROPPEDSTATE, 0, 0) != 0
/////////
//
// CBGetEditSel( <hCBox> ) --> aSel
//
// Returns the start and end of the selected part of a the edit
// control part of a combo box
//
// aSel is in the form { start, end }
//
/////////
function CBGetEditSel(hCBox)
return bin2a(c4w_l2bin(SendMessage(hCBox, CB_GETEDITSEL, 0, 0)), "int[2]")
/////////
//
// CBGetLBText( <hCBox>, <nLine> ) --> cLine
//
// Returns the specified line from within the list box of a combo box
// (<nLine> starts at 0)
//
/////////
function CBGetLBText(hCBox, nLine)
local nLen, cBuf := space(SendMessage(hCBox, CB_GETLBTEXTLEN, nLine, 0) + 1)
nLen = SendMessage(hCBox, CB_GETLBTEXT, nLine, @cBuf)
return iif(nLen == CB_ERR, nil, left(cBuf, nLen))
/////////
//
// CBGetLBTLen( <hCBox>, <nLine> ) --> nLen
//
// Returns the length of a line in the list box of a combo box
//
// <nLine> counts from zero.
//
/////////
function CBGetLBTLen(hCBox, nLine)
return SendMessage(hCBox, CB_GETLBTEXTLEN, nLine, 0)
/////////
//
// CBGetText( <hCBox> ) --> cText
//
// Get all the text in the edit control part of a combo box
//
/////////
function CBGetText(hCBox)
local nLen, cBuf
// get the length, and include room for the trailing null that Windows
// wants to add (even though we don't want it!)
nLen = SendMessage(hCBox, WM_GETTEXTLENGTH, 0, 0) + 1
cBuf = space(nLen)
nLen = SendMessage(hCBox, WM_GETTEXT, nLen, @cBuf) // note: not an EM_ msg
return left(cBuf, nLen)
/////////
//
// CBInsertString( <hCBox>, <cNewStr>, <nLine> ) --> nLen
//
// Insert a new string in the list box part of a combo box
//
// Returns the length of the string added, or CB_ERR if an
// error occurs (but CB_ERRSPACE if not enough room)
//
/////////
function CBInsertString(hCBox, cNewStr, nLine)
return SendMessage(hCBox, CB_INSERTSTRING, nLine, cNewStr)
/////////
//
// CBLimitText( <hCBox>, <nMax> ) --> nil
//
// Sets the maximum number of characters allowed in the edit control
// of a combo box
// (in the range 0-nnnn, where nnnn is limited by the heapsize
// specified in the .def file for the linker)
//
/////////
procedure CBLimitText(hCBox, nMax)
SendMessage(hCBox, CB_LIMITTEXT, nMax, 0)
return
/////////
//
// CBPaste( <hCBox> ) --> nil
//
// Paste the contents of the Windows clipboard into the edit
// control part of a combo box
//
/////////
procedure CBPaste(hCBox)
SendMessage(hCBox, WM_PASTE, 0, 0)
return
/////////
//
// CBResetContent( <hCBox> ) --> nil
//
// Empty the list box and edit control of a combo box
//
/////////
procedure CBResetContent(hCBox)
SendMessage(hCBox, CB_RESETCONTENT, 0, 0)
return
/////////
//
// CBSelectString( <hCBox>, <cStr>, [ <nStart> ] ) --> nLine
//
// Find a string in the list box part of a combo box, and (if found)
// select it and copy it into the edit control.
// <nStart> optionally specifies the start of the search
//
// Returns the position of the string found, or CB_ERR if not found
//
/////////
function CBSelectString(hCBox, cStr, nStart)
if nStart == nil
nStart = -1 // search from the start
endif
return SendMessage(hCBox, CB_SELECTSTRING, nStart, cStr)
/////////
//
// CBSetCurSel( <hCBox>, <nLine> ) --> nRet
//
// Sets the position of the currently selected item in the list box
// of a combo box
//
// <nLine> can be -1 to remove any selection, and clear the edit control
//
// Returns <nLine> (or CB_ERR if <nLine> is too big or -1)
//
/////////
function CBSetCurSel(hCBox, nLine)
return SendMessage(hCBox, CB_SETCURSEL, nLine, 0)
/////////
//
// CBSetEditSel( <hCBox>, <nStart>, <nEnd> ) --> nil
//
// Sets the start and end of the selected part of the edit control
// part of a combo box.
//
// Special values:
//
// nStart = 0, and nEnd = -1 all the text is selected
// nStart = -1 nothing selected
//
/////////
procedure CBSetEditSel(hCBox, nStart, nEnd)
SendMessage(hCBox, CB_SETEDITSEL, 0, MAKELPARAM(nStart, nEnd))
return
/////////
//
// CBShowDropDown( <hCBox>, <lShow> ) --> nil
//
// Shows/hides the drop-down list box part of a combo box
//
/////////
procedure CBShowDropDown(hCBox, lShow)
SendMessage(hCBox, CB_SHOWDROPDOWN, iif(lShow, 1, 0), 0)
return
#ifndef LIB_ONLY
function MenuSetup()
local hWnd := SelectWindow(), hMenu, hPopupMenu
if (hMenu := GetMenu(hWnd)) != nil
DestroyMenu(hMenu)
endif
// do new one (forget old value)
hMenu = CreateMenu()
hPopupMenu = CreatePopupMenu()
AppendMenu(hMenu, "file", MF_ENABLED + MF_POPUP, "&File", hPopupMenu)
AppendMenu(hPopupMenu, "exit", MF_ENABLED + MF_STRING, "E&xit", {|| Alert("Thanks for running this demo"), DoExit()})
hPopupMenu = CreatePopupMenu()
AppendMenu(hMenu, "demo", MF_ENABLED + MF_POPUP, "&Demo", hPopupMenu)
AppendMenu(hPopupMenu, "combo1", MF_ENABLED + MF_STRING, "&Combo box", {|c| DoCBox()})
AppendMenu(hPopupMenu, "combo2", MF_ENABLED + MF_STRING, "&DropDown", {|c| DoDropDown()})
hPopupMenu = CreatePopupMenu()
AppendMenu(hMenu, "help", MF_ENABLED + MF_POPUP, "&Help", hPopupMenu)
AppendMenu(hPopupMenu, "about", MF_ENABLED + MF_STRING, "&About", {|| DoAbout()})
SetMenu(hWnd, hMenu)
return hMenu
#endif // !LIB_ONLY