Documente online.
Zona de administrare documente. Fisierele tale
Am uitat parola x Creaza cont nou
 HomeExploreaza
upload
Upload




Controale clasice

economie


Controale clasice


W pune la dispozitie 6 (sase) controale clasice. Un control nu este altceva decit o fereastra cu stiluri speciale. Trebuie retinut faptul ca a lucra cu un asemea control este ca si cum am lucra cu o fereastra. Tipurile controalelor, structurile WNDCLASS si clasele corespondente MFC sunt date in tabela urmatoare:




Controale clasice


Control Type

WNDCLASS

MFC Class

Buttons

"BUTTON"

CButton

List boxes

"LISTBOX"

CListBox

Edit controls

"EDIT"

CEdit

Combo boxes

"COMBOBOX"

CComboBox

Scroll bars

"SCROLLBAR"

CScrollBar

Static controls

"STATIC"

CStatic


Un control este creat prin instantierea clasei respective din MFC urmat apoi de apelul functiei Create din acea clasa. MFC creaza un obiect in doi pasi. De descris avantajele si dezavantajele acestei metode.

Daca m_wndPushButton este un obiect CButton, instructiunea


m_wndPushButton.Create (_T ("Start"), WS_CHILD ¦ WS_VISIBLE ¦

BS_PUSHBUTTON, rect, this, IDC_BUTTON);


creaza un control push button ce contine textul "Start".

Descriere parametrii pt. fct. Create:

primul parametru specifica textul controlului;

al doilea param. reprezinta stilul ferestrei, ce reprezinta o combinatie intre stilurile ferestrei si stiluri specifice controlului.; Controlul creat este o fereastra descendent (copil) al ferestrei identificata de al patrulea parametru (in SDK se furnizeaza un HWND la fereastra parinte);

al treilea parametru specifica marimea si pozitia (in pixeli) controlului, data printr-un obiect CRect; pozitia este relativa la coltul din stg sus al ferestrei parinte;

ultimul parametru este ID-ul butonului (controlului - un intreg), folosit in diverse functii pentru a avea access la el; acest ID trebuie sa aiba o valoare unica in interiorul ferestrei date pentru a putea identifica corect controlul si functiile care trateaza mesajele de notificare.


Unele controale (ListBox, Edit) pentru a se alinia la noile stiluri, au o noua functie membru CreateEx. Stilurile extinse se scriu numai in cadrul acestei functii (vezi CreateWindow si CreateWindowEx).


Daca m_wndListBox este un obiect CListBox, urmatoarea instructiune creaza un control list box cu stilulu extins WS_EX_CLIENTEDGE:


m_wndListBox.CreateEx (WS_EX_CLIENTEDGE, _T ("LISTBOX"), NULL,

WS_CHILD | WS_VISIBLE | LBS_STANDARD, rect, this, IDC_LISTBOX);


Ca o alternativa, putem deriva clasa noastra din CListBox, si apoi rescriem functia PreCreateWindow in clasa derivata, si aplicam stilul de fereastra WS_EX_CLIENTEDGE:


BOOL CMyListBox::PreCreateWindow (CREATESTRUCT& cs)



Un control trimite notificari parintelui sub forma de mesaje WM_COMMAND. Tipurile de notificari depind de tipul controlului, dar in fiecare caz, informatia din parametrii mesajului, wParam si lParam, identifica controlul care trimite mesajul si actiunea ceruta de mesaj.

De exemplu, cind un push button este apasat (clic), codul de notificare este BN_CLICKED in HIWORD(wParam) si ID-ul controlului in LOWORD(wParam), iar handler-ul ferestrei controlului in lParam.

Cadrul de lucru MFC, insereaza in harta de mesaje acest mesaj de notificare, ascunzind detaliile de implementare pentru tratarea mesajului WM_COMMAND (se face legatura intre ID-ul controlului si functia care trateaza mesajul de notificare):


ON_BN_CLICKED (IDC_BUTTON, OnButtonClicked)


ON_BN_CLICKED este un macrou, si asemenea macro-uri exista pentru fiecare mesaj de notificare de la fiecare control.

Exista un macro generic ON_CONTROL, care manipuleaza toate notificarile si toate tipurile de controale, si ON_CONTROL_RANGE, care mapeaza notificari in mod identic de la doua sau mai multe controale la o functie comuna. Comunicarea intre controale si parinti (proprietarii controlului) este in ambele directii. De ex. parintele poate trimite mesajul BM_SETCHECK unui control check box cu parametrul wParam BST_CHECKED.


MFC simplifica interfata controlului bazata pe mesaje prin construirea de functii membru in clasa controlului care wrap BM_SETCHECK si alte mesaje ale controlului. De exemplu:


m_wndCheckBox.SetCheck (BST_CHECKED);


plaseaza un check mark in interiorul check box-ului reprezentat de un obiect CButton, numit m_wndCheckBox

Din cauza ca un control este o fereastra, anumite functii membru pe care controlul le mosteneste din CWnd sunt folositoare pentru controlul programarii.

De exemplu aceeasi functie care modifica titlul unei ferestre, SetWindowText, modifica textul (eticheta) unui push button, sau schimba continutul unui control de editare (box edit). Alte functii: GetWindowText, EnableWindow, SetFont. Daca vrem sa facem ceva in control si nu gasim o functie corespunzatoare in clasa controlului va trebui sa cautam o asemenea functie in clasa CWnd din care sunt derivate toate contraolele.

Clasa CButton


CButton reprezinta controale de tip button bazate pe clasa WNDCLASS "BUTTON". Controalele button exista in patru variante: push buttons, check boxes, radio buttons, si group boxes. Se vor desena cele patru tipuri.


Cand cream un control buton, vom specifica tipul acestuia prin includerea unuia din urmatoarele flag-uri in stilul ferestrei butonului:


Style

Description

BS_PUSHBUTTON

Creates a standard push button control

BS_DEFPUSHBUTTON

Creates a default push button; used in dialog boxes to identify the push button that's clicked if Enter is pressed

BS_CHECKBOX

Creates a check box control

BS_AUTOCHECKBOX

Creates a check box control that checks and unchecks itself when clicked

BS_3STATE

Creates a three-state check box control

BS_AUTO3STATE

Creates a three-state check box control that cycles through three states-checked, unchecked, and indeterminate-when clicked

BS_RADIOBUTTON

Creates a radio button control

BS_AUTORADIOBUTTON

Creates a radio button control that, when clicked, checks itself and unchecks other radio buttons in the group

BS_GROUPBOX

Creates a group box control


In plus, putem adauga urmatoarele valori (OR pe biti) la stilul ferestrei controlului privitoare la linierea textului ce insoteste controlul:




Style

Description

BS_LEFTTEXT

Moves the text accompanying a radio button or check box control from the button's right (the default) to its left

BS_RIGHTBUTTON

Same as BS_LEFTTEXT

BS_LEFT

Left justifies the button text in the control rectangle

BS_CENTER

Centers the button text in the control rectangle

BS_RIGHT

Right justifies the button text in the control rectangle

BS_TOP

Positions the button text at the top of the control rectangle

BS_VCENTER

Positions the button text in the center of the control rectangle vertically

BS_BOTTOM

Positions the button text at the bottom of the control rectangle

BS_MULTILINE

Allows text too long to fit on one line to be broken into two or more lines


Exista si alte tipuri de stiluri de butoane, dar care sunt folosite mai putin. De ex., BS_NOTIFY, programeaza un buton sa trimita notificarile BN_DOUBLECLICKED, BN_KILLFOCUS, si BN_SETFOCUS.

BS_OWNERDRAW creaza un buton owner-draw (desenat de proprietar - programatorul va scrie cod pentru acest lucru) - infatisarea (aparenta) butonului este gestionata de parintele butonului.

Butoane Push

Un push button este un control buton creat cu stilul BS_PUSHBUTTON. Cind este apasat, controlul trimite parintelui notificarea BN_CLICKED printr-un mesaj WM_COMMAND. In absenta stilului BS_NOTIFY, un asemenea control nu trimite nici un alt tip de notificare.

Macroul ON_BN_CLICKED din MFC leaga notificarile BN_CLICKED de functia membru din clasa fereastra parinte:

ON_BN_CLICKED(IDC_BUTTON, OnButtonClicked)


Functiile pentru BN_CLICKED nu au parametri si nu intorc valori.

Check Boxes


Check boxes sunt butoane create cu stilul BS_CHECKBOX, BS_AUTOCHECKBOX, BS_3STATE, sau BS_AUTO3STATE. Stilurile BS_CHECKBOX si BS_AUTOCHECKBOX pot presupune doua stari: checked si unchecked. Un check box trece in starea checked sau unchecked cu CButton::SetCheck


m_wndCheckBox.SetCheck (BST_CHECKED);    // Check

m_wndCheckBox.SetCheck (BST_UNCHECKED); // Uncheck


Pentru a determina daca un check box este in starea checked, folosim CButton::GetCheck. O valoare de retur egala cu BST_CHECKED inseamna ca chcek box-ul este in starea checked, iar BST_UNCHECKED este pt unchecked.

Check boxes trimit notificarile BN_CLICKED parintilor lor cind facem click in zona lor. Stilul BS_AUTOCHECKBOX face ca acest control sa lucreze ca un switch on/off automatizat in raspuns la even. click mouse. Stilul BS_CHECKBOX nu face acelasi lucru. Un exemplu de cod pentru un check box cu stilul BS_CHECKBOX si ce trebuie sa facem la BN_CLICKED:


void CMainWindow::OnCheckBoxClicked ()



Stilurile BS_3STATE si BS_AUTO3STATE creaza un check box care presupune o a treia stare numita nedeterminata (indeterminate), si controlul intra in aceasta stare cind facem clic pe un asemenea buton iar starea lui curenta este checked sau cind apelam SetCheck cu parametrul BST_INDETERMINATE:


m_wndCheckBox.SetCheck (BST_INDETERMINATE);


Un check box in starea indeterminate contine a grayed check mark. Aici pare sa lucreze o logica trivalenta "partiala", in sensul ca starea nu poate fi sigura nici checked nici unchecked. (Ex. selectam text in bold si nebold.)



Butoane Radio


Un buton radio este un control de tip buton cu stilul BS_RADIOBUTTON sau BS_AUTORADIOBUTTON. In mod normal butoanele radio lucreaza in grup, si reprezinta o lista de optiuni mutual exclusive. Cind selectam un buton radio cu stilul BS_AUTORADIOBUTTON va ramine activ numai butonul selectat, celelalte butoane din grup devenind inactive in mod automat. Daca folosim stilul BS_RADIOBUTTON, va trebui sa scriem noi cod pentru a dezactiva celelalte butoane, folosind functia CButton::SetCheck

Butoanele radio trimit notificarile BN_CLICKED parintilor lor, la fel ca mai sus.

Urmatorul cod trateaza BN_CLICKED:


void CMainWindow::OnRadioButton1Clicked ()



Deselectind (unchecking) celelalte butoane radio mentine exclusivitatea selectiei. Un handler (o fct.) pentru BN_CLICKED nu este necesar pentru butoanele cu stilul BS_AUTORADIOBUTTON. Pentru butoane radio cu stilul BS_AUTORADIOBUTTON pentru a deselecta corect alte butoane din grup, trebuie sa grupam butoanele in momentul crearii, a.i. W sa stie care butoane apartin grupului. Pentru a crea un grup d ebutoane radio cu stilul BS_AUTORADIOBUTTON urmam urmatoarea procedura (tehnica):







Clasa CEdit (CE)


CEdit din MFC incapsuleaza functionalitatea unui control de editare folosit pt. a edita text: pe o singura linie sau pe mai multe linii. Zona client din Notepad este un control de editare multilinie. Un control de editare este limitat la 60 KB text. Daca e nevoie de mai mult text vom folosi un control RICH EDIT (imbogatit).


Crearea unui control Edit


Daca m_wndEdit este un obiect CEdit instructiunea


m_wndEdit.Create (WS_CHILD ¦ WS_VISIBLE ¦ WS_BORDER ¦

ES_AUTOHSCROLL, rect, this, IDC_EDIT);


creaza un control single line care face scroll orizontal automat, daca textul nu incape in zona de afisare. Incluzind stilul ES_MULTILINE vom crea un CE multilinie:


m_wndEdit.Create (WS_CHILD ¦ WS_VISIBLE ¦ WS_BORDER ¦

WS_HSCROLL ¦ WS_VSCROLL ¦ ES_MULTILINE, rect, this, IDC_EDIT);


WS_HSCROLL si WS_VSCROLL adauga barele de scroll vertical si orizontal. Putem folosi CEdit::SetRect sau CEdit::SetRectNP pt. a defini zona editabila a controlului independent de marginile controlului. O utilizare pt. aceste functii este de a defini marimea paginii care ramine constanta chiar daca controlul este redimensionat. Putem folosi de asemenea CEdit::SetMargins pentru a specifica latimea (in pixeli) marginii stg si dreapta. Implicit latimile marginilor sunt 0.

Cind este prima data creat, un CE va accepta numai 30,000 caractere. Putem modifica acest lucru cu CEdit::LimitText sau CEdit::SetLimitText. Urmatoarea instructiune seteaza nr. max de car. la 32:


m_wndEdit.SetLimitText (32);


Cind folosim un CE multilinie, SetLimitText limiteaza cantitatea totala de text din control, deci nu lungimea fiecarei linii. In acest caz putem controla lungimea liniei numai manual.

O metoda este de a folosi SetFont pt a comuta fontul CE la un font fixed-pitch si CEdit::SetRect pt a specifica dreptunghiul de formatare a carui latime este un pic mai mare decit latimea caracterelor din font inmultita cu nr. de caractere dorit a se afisa pe o linie.


Edit Control Styles

Style

Description

ES_LEFT

Left-aligns text in the control.

ES_CENTER

Centers text in the control.

ES_RIGHT

Right-aligns text in the control.

ES_AUTOHSCROLL

Permits the edit control to scroll horizontally without a horizontal scroll bar. To add a horizontal scroll bar, include the style WS_HSCROLL.

ES_AUTOVSCROLL

Permits the edit control to scroll vertically without a vertical scroll bar. To add a vertical scroll bar, include the style WS_VSCROLL.

ES_MULTILINE

Creates a multiline edit control.

ES_LOWERCASE

Displays all characters in lowercase.

ES_UPPERCASE

Displays all characters in uppercase.

ES_PASSWORD

Displays asterisks instead of typed characters.

ES_READONLY

Creates an edit control whose text can't be edited.

ES_NOHIDESEL

Prevents the edit control from hiding the selection when the control loses the input focus.

ES_OEMCONVERT

Performs an ANSI-to-OEM-to-ANSI conversion on all characters typed into the control so that the application won't get unexpected results if it performs an ANSI-to-OEM conversion of its own. Obsolete.

ES_WANTRETURN

Programs the Enter key to insert line breaks instead of invoking the default push button for multiline edit controls used in dialog boxes.


O alta functie folositoare pt a initializa un CE este CEdit::SetTabStops, care seteaza spatiile dintre tab_uri. Implicit tab stopul este de 8 caractere. Ca si CListBox::SetTabStops CEdit::SetTabStops masoara distanta in unitati de dialog.

Inserarea si Regasirea Textului


Textul se insereaza cu SetWindowText si se regaseste cu GetWindowText CEdit mosteneste ambele functii din clasa de baza CWnd. Instructiunea


m_wndEdit.SetWindowText (_T ("Hello, MFC"));


insereaza textul "Hello, MFC" in controlul m_wndEdit, si


m_wndEdit.GetWindowText (string);


regaseste textul intr-un obiect CString numit string GetWindowText si SetWindowText lucreaza cu ambele tipuri de controale, single line si multiline. Textul inserat cu SetWindowText inlocuieste textul existent, iar GetWindowText returneaza tot textul din control, chiar daca acesta este pe mai multe linii. Pt. a stegte textul apelam SetWindowText cu un sir nul:


m_wndEdit.SetWindowText (_T (""));


Putem insera text fara a stege cel existent cu CEdit::ReplaceSel. Daca unul sau mai multe caractere sunt selectate cind apelam ReplaceSel, textul care se insereaza inlocuieste textul selectat, in caz contrar textul este inserat la pozitia curenta a cursorului (caret-ului).

Un control multiline insereaza line break automat. Daca dorim sa determinam line break-urile dintr-un text folosim CEdit::FmtLines pt a face enable soft line breaks inainte de apelul lui GetWindowText


m_wndEdit.FmtLines (TRUE);


Cu soft line breaks enabled, fiecare linie este delimitata cu doua CR (0x13) urmat de un LF (0x10). Pt. a invalida soft line break folosim FmtLines( FALSE):


m_wndEdit.FmtLines (FALSE);


CR introdus in text la apasarea tastei <Enter> sunt semnificate de o pereche CR/LF. FmtLines nu afecteaza modul de afisare al textului intr-un CE multilinie, ci afecteaza numai modul cum este memorat intern textul si formateaza textul regasit cu GetWindowText

Pentru a citi exact o linie de text dintr-un control multilinie folosim CEdit::GetLine GetLine copie continutul unei linii intr-un buffer pe care trebuie sa-l alocam si apoi furnizam functiei adresa acestuia. Linia este identificata de un index 0-based. Instructiunea:


m_wndEdit.GetLine (0, pBuffer, nBufferSize);


copie prima linie din control in zona data de pBuffer, iar par. 3 indica dimensiunea buff. in bytes. GetLine returneaza numarul de octeti copiati in buffer. Putem determina dinaninte marimea necesara a buff. cu fct. CEdit::LineLength, iar numarul de linii din control il det. cu fct. CEdit::GetLineCount GetLineCount nu returneaza niciodata 0, chiar daca nu exista text valoarea returnata este 1.

Clear, Cut, Copy, Paste, and Undo


CEdit furnizeaza functii pentru operatiile enumerate mai sus. Instructiunea:


m_wndEdit.Clear ();


sterge textul selectat fara a afecta continutul clipboard-ului.Instructiunea:


m_wndEdit.Cut ();


sterge textul selectat si il copie in clipboard.Instructiunea:


m_wndEdit.Copy ();


copie textul selectat in clipboard fara a-l sterge.

Putem interoga CE pt. selectia curenta cu un apel al fct. CEdit::GetSel, care returneza o valoare DWORD ce contine doi intregi pe 16 biti ce specifica indexul de inceput si indexul de sfarsit al selectiei. Daca indecsii sunt egali nu exista text selectat. Exista o forma a fct. GetSel care copie indecsii in doi intregi ale caror adrese sunt pasate ca parametrii prin referinta. Putem adauga urmatoare functie IsTextSelected, la clasa controlului de editare derivat din CEdit pentru a determina daca exista sau nu text selectat in control:


BOOL CMyEdit::IsTextSelected ()



CEdit::Cut and CEdit::Copy nu fac nimic daca nu este text selectat. Textul poate fi selectat prin program cu CEdit::SetSel. Instructiunea:


m_wndEdit.SetSel (100, 150);


selecteaza 50 de caractere incepind cu al 101-lea caracter si o face vizibila in view daca aceasta nu este vizibila (se face scroll automat). Pt. a preveni defilarea (scrolling), vom folosi si al 3-lea param. al functiei cu valoarea TRUE.

Cind facem selectii prin program intr0un control multilinie, este necesar adesea sa convertim un numar de linie si posibil un offset din interiorul acestei linii intr-un index pe care-l vom folosi in SetSel. Functia CEdit::LineIndex accepta un numar de linie 0-based si returneaza indexul primului caracter din acea linie. In ex. care urmeaza se determina index-ul primului caracter din linia 8 (LineIndex), apoi determinam lungimea liniei si selectam tot textul care se gaseste in acea linie (SetSel):


int nStart = m_wndEdit.LineIndex (7);

int nLength = m_wndEdit.LineLength (nStart);

m_wndEdit.SetSel (nStart, nStart + nLength);


CEdit furnizeaza fct. LineFromChar pt. a calcula numarul liniei plecind de la index-ul unui caracter.

CEdit::Paste pastes text intr-un CE.


m_wndEdit.Paste ();


Daca clipboard-ul nu contine text, CEdit::Paste nu are efect. Daca nu exista text selectat cind se apeleaza Paste se insereaza textul din clipboard la pozitia curenta a caret-ului. Daca exista o selectie, atunci textul din clipboard inlocuieste selectia existenta. Putem determina din timp daca exista text in clipboard printr-un apel al fct. ::IsClipboardFormatAvailable. Instructiunea:


BOOL bCanPaste = ::IsClipboardFormatAvailable (CF_TEXT);


seteaza bCanPaste la o val. # 0 daca exista text in clipboard sau 0 in caz contrar. O alta trasatura a unui CE este posibilitatea roll back-ului (undo). to nonzero if text is available from the clipboard, and 0 if it isn't, reface ultima stergere:

Edit controls also feature a built-in undo capability that "rolls back" the previous editing operation. The statement


m_wndEdit.Undo ();


undoes the last operation, provided that the operation can be undone. Se poate determina din timp daca am putea apela You can determine ahead of time whether calling Undo prinapelul fct. will accomplish anything with CEdit::CanUndo O alta fct.A related function CEdit::EmptyUndoBuffer reseteaza manual flag-ul pentru undo, a.i., urmatoarele apeluri la Undo nu vor face nimic. manually resets the undo flag so that subsequent calls to Undo will do nothing (and calls to CanUndo will return FALSE) until another editing operation is performed.


Notificarile Controlului de EditareEdit Control Notifications


Edit controls send notifications to their parents to report various input events. In app. MFC, notificarile sunt mapate cu macro-uri de forma In MFC applications, these notifications are mapped to handling functions with ON_EN in harta de mesaje a clasei.message map macros. Edit control notifications and the corresponding message map macros are summarized in the table below.

A common use for EN_CHANGE notifications is to dynamically update other controls as text is entered into an edit control.In ex. urm. se trateaza notificarea (mesaj) EN_CHANGE a unui CE. Un control de tip push buton (m_wndPushButton este facut enable/disable dupa cum exista/nu exista text in CE cu ID=IDC_EDIT si dat de ob. The following code updates a push button m_wndPushButton) as text is entered into an edit control m_wndEdit , ID=IDC_EDIT)

Stilurile se dau in functia This restriction effectively limits the user's selection to items appearing in the list box.

The style flags you pass to Create or CreateEx determine what type of combo box you create. CBS_SIMPLE creates a simple combo box, CBS_DROPDOWN creates a drop-down combo box, and CBS_DROPDOWNLIST creates a drop-down list combo box. Alte stiluri exista pentru cosmetizarea CB. Other styles control additional aspects of the combo box's appearance and behavior, as shown in the table below. Many of these styles will look familiar because they're patterned after list box and edit control styles. CBS_AUTOHSCROLL, for example, does the same thing for the edit control portion of a combo box control that ES_AUTOHSCROLL does for a stand-alone edit control. Cind cream un CB trebuie sa punem stilul When you create a combo box control, don't forget to include the style WS_VSCROLL daca dorim scroll vertical if you want the list box to have a vertical scroll bar and WS_BORDER if you want the control's border to be visible IfDaca m_wndComboBox iseste un a obiect CComboBox object the statementinstructiunea:


m_wndComboBox.Create (WS_CHILD ¦ WS_VISIBLE ¦ WS_BORDER ¦

WS_VSCROLL ¦ CBS_DROPDOWNLIST ¦ CBS_SORT, rect, this,

IDC_COMBOBOX);



ceara un CB drop-down list care contine bara pt. scroll vertical.creates a drop-down list combo box whose list box contains a vertical scroll bar when the number of items in the list box exceeds the number of items that can be displayed and that automatically sorts the items added to it. Dimensiunea controlului (dreptunghiul) trebuie sa fie destul de mare pt. a afisa tot textul. The control rectangle you specify in the call to CComboBox::Create should be large enough to encompass the list box part of the control as well as the edit box.


Combo Box Styles

Style

Description

CBS_AUTOHSCROLL

Enables horizontal scrolling in the edit control portion of a combo box.

CBS_DISABLENOSCROLL

Disables the combo box list box's scroll bar when it isn't needed. Without this style, an unneeded scroll bar is hidden rather than disabled.

CBS_DROPDOWN

Creates a drop-down combo box.

CBS_DROPDOWNLIST

Creates a drop-down list combo box.

CBS_HASSTRINGS

Creates a combo box that "remembers" the strings added to it. Conventional combo boxes have this style by default; owner-draw combo boxes don't.

CBS_LOWERCASE

Forces all text in the combo box to lowercase.

CBS_NOINTEGRALHEIGHT

Prevents the combo box's list box height from having to be an exact multiple of the item height.

CBS_OEMCONVERT

A combo box whose edit control performs an ANSI-to-OEM-to-ANSI conversion on all characters so that the application won't get unexpected results if it performs an ANSI-to-OEM conversion of its own. Obsolete.

CBS_OWNERDRAWFIXED

Creates an owner-draw combo box whose items are all the same height.

CBS_OWNERDRAWVARIABLE

Creates an owner-draw combo box whose items can vary in height.

CBS_SIMPLE

Creates a simple combo box.

CBS_SORT

Automatically sorts items as they are added.

CBS_UPPERCASE

Forces all text in the combo box to uppercase.


Exista asemanari intre fct din CE si LB.Not surprisingly, the list of CComboBox member functions reads a lot like the list of member functions for CEdit and CListBox

Adaugare art se face cu Items are added to a combo box, for example, with CComboBox::AddString andsi CComboBox::InsertString

and Nr. max. de car. pt. CE al CB este setat cu the maximum character count for a combo box's edit control is set with CComboBox::LimitText Fct. The GetWindowText andsi SetWindowText functions that lucreaza pt. CE al CB. CComboBox inherits from CWnd get and set the text in the edit control.

Functii specifice:Functions unique to combo boxes include GetLBText care regaseste textul unui art. identificat printr-un index 0-based.

which retrieves the text of an item identified by a 0-based index; GetLBTextLen returneaza lung. unui art., in caractere;

which returns the length of an item, in characters; ShowDropDown afiseaza sau ascunde un CB which hides or displays the drop-down list

box; and GetDroppedState whichreturneaza o valoare ce indica daca CB returns a value indicating whether the drop-down list este afisat. is currently displayed.


Notificari Combo Box Notifications


Combo boxes send notifications to their parents much as edit controls and list boxes do. The following table lists the notifications the parent can expect, the corresponding MFC message-map macros, and the types of combo boxes the notifications apply to.

Combo Box Notifications

Notification

Message-Macro Map

Simple

Drop-Down

Drop-Down List

CBN_DROPDOWN
Sent when the drop-down list is displayed.

ON_CBN_DROPDOWN




CBN_CLOSEUP
Sent when the drop-down list is closed.

ON_CBN_CLOSEUP




CBN_DBLCLK
Sent when an item is double-clicked.

ON_CBN_DBLCLK




CBN_SELCHANGE
Sent when the selection changes.

ON_CBN_SELCHANGE




CBN_SELENDOK
Sent when a selection is made.

ON_CBN_SELENDOK




CBN_SELENDCANCEL
Sent when a selection is canceled.

ON_CBN_SELENDCANCEL




CBN_EDITUPDATE
Sent when the text in the edit control is about to change.

N_CBN_EDITUPDATE




CBN_EDITCHANGE
Sent when the text in the edit control has changed.

ON_CBN_EDITCHANGE




CBN_KILLFOCUS
Sent when the combo box loses the input focus.

ON_CBN_KILLFOCUS




CBN_SETFOCUS
Sent when the combo box receives the input focus.

ON_CBN_SETFOCUS




CBN_ERRSPACE
Sent when an operation fails because of insufficient memory.

ON_CBN_ERRSPACE





Nu toate notificarile se aplica la toate tipurile de CB. Not all notifications apply to all combo box types.

Notificarile CBN_DROPDOWN andsi CBN_CLOSEUP notifications, for example, nu sunt trimise la un CB simpla aren't sent to CBS_SIMPLE) pt. ca un asemenea CB este deschis tot timpul. combo boxes because a simple combo box's list box doesn't open and close. By the same token,

CB cu stilurile CBS_DROPDOWN andsi CBS_DROPDOWNLIST-style combo boxes don't receive nu primesc notificarea CBN_DBLCLK pt. ca pe art. din lista nu se poate face dublu clic. (LB asociat CB se inchide dupa primul clic).notifications because the items in their lists can't be double-clicked. (Why? Because the list box closes after the first click.)

Notificarile CBN_EDITUPDATE andsi CBN_EDITCHANGE notifications are sunt echivalente cu equivalent to EN_UPDATE andsi EN_CHANGE trime de CE, si notifications sent by edit controls, and CBN_SELCHANGE este la fel cu is to combo boxes as LBN_SELCHANGE pt. LB.

is to list boxes.

One nuance you should be aware of Cind procesam when processing notificarea CBN_SELCHANGE notifications is that when a notification arrives CE asociat poate sa nu fie actualizat cu selectia din LB asociat. the edit control might not have been updated to match the list box selection. Therefore, you should use Va trebui sa folosim GetLBText pentru a regasi noul text selectat in loc de to retrieve the newly selected text instead of GetWindowText

Indexul art. selectat il gasim cu You can get the index of the selected item with CComboBox::GetCurSel


Clasa The CScrollBar Class


MFC's Clasa CScrollBar incapsuleaza controlul scroll bar creat din class encapsulates scroll bar controls created from the "SCROLLBAR" WNDCLASS. Controalele scroll bar sunt identice in cea mai mare parte cu "ferestrele" scroll bar. In timp ce ferestrele Scroll bar controls are identical in most respects to the "window" scroll bars used in Chapter 2's Accel application. But whereas window scroll bars sunt create cu stilurile are created by adding WS_VSCROLL andsi WS_HSCROLL flags to the window style controalele scroll bar controls sunt create explicit cu are created explicitly with CScrollBar::Create Barele scroll window sint lipite de fereastra principala, controalele scroll bar pot fi plasate oriunde in fereastra si pot fi setate la orice latime si inaltime. And though a window scroll bar runs the full length of the window's client area and is inherently glued to the window border, scroll bar controls can be placed anywhere in the window and can be set to any height and width.


You create vertical scroll bars by specifying the styleStil SBS_VERT pentru CSB vertical si and horizontal scroll bars by specifying SBS_HORZ pentru orizontal IfDaca m_wndVScrollBar andsi m_wndHScrollBar sunt obiecte are CScrollBar objects, the statements instructiunile:


m_wndVScrollBar.Create (WS_CHILD ¦ WS_VISIBLE ¦ WS_BORDER ¦

SBS_VERT, rectVert, this, IDC_VSCROLLBAR);

m_wndHScrollBar.Create (WS_CHILD ¦ WS_VISIBLE ¦ WS_BORDER ¦

SBS_HORZ, rectHorz, this, IDC_HSCROLLBAR);


creaza doua controale CSB, unul vertical si unul orizontal. create two scroll bar controls, one vertical and the other horizontal.

Obtinerea dim. standard folosite de W se obtin printr-un apel al fct.You can query Windows for the standard width of a vertical scroll bar or the standard height of a horizontal scroll bar with the API ::GetSystemMetrics API function The following code fragment sets nWidth and nHeight to the system's standard scroll bar width and height:


int nWidth = ::GetSystemMetrics (SM_CXVSCROLL);

int nHeight = ::GetSystemMetrics (SM_CYHSCROLL);


Ca alternativa la crearea CSB standard se poate specifica An alternative method for creating a scroll bar with a standard height or width is to specify the style SBS_TOPALIGN, SBS_BOTTOMALIGN, SBS_LEFTALIGN, or SBS_RIGHTALIGN when creating it. SBS_LEFTALIGN and SBS_RIGHTALIGN align a vertical scroll bar control along the left or right border of the rectangle specified in the call to Create and assign it a standard width. SBS_TOPALIGN and SBS_BOTTOMALIGN align a horizontal scroll bar control along the top or bottom border of the rectangle and assign it a standard height.

Unlike the other classic controls, scroll bar controls don't send WM_COMMAND messages; they send WM_VSCROLL and WM_HSCROLL messages instead. MFC applications process these messages with OnVScroll and OnHScroll handlers, as described in Chapter 2. I didn't mention two scroll bar notification codes in Chapter 2 because they apply only to scroll bar controls. SB_TOP means that the user pressed the Home key while the scroll bar had the input focus, and SB_BOTTOM means the user pressed End.

MFC's CScrollBar class includes a handful of functions for manipulating scroll bars, most of which should seem familiar to you because they work just like the similarly named CWnd functions. CScrollBar::GetScrollPos and CScrollBar::SetScrollPos get and set the scroll bar's thumb position. CScrollBar::GetScrollRange and CScrollBar::SetScrollRange get and set the scroll bar range. You use CScrollBar::SetScrollInfo to set the range, position, and thumb size in one step. For details, refer to the discussion of CWnd::SetScrollInfo in Chapter 2.



Document Info


Accesari: 1620
Apreciat: hand-up

Comenteaza documentul:

Nu esti inregistrat
Trebuie sa fii utilizator inregistrat pentru a putea comenta


Creaza cont nou

A fost util?

Daca documentul a fost util si crezi ca merita
sa adaugi un link catre el la tine in site


in pagina web a site-ului tau.




eCoduri.com - coduri postale, contabile, CAEN sau bancare

Politica de confidentialitate | Termenii si conditii de utilizare




Copyright © Contact (SCRIGROUP Int. 2024 )