Überprüfen ob Button vorhanden
-
Hi,
wie kann ich programmiertechnisch überprüfen, bevor ich mit Button.Create(..) einen Button erzeuge, ob ein Button bereits existiert bzw. ob er auf der Oberfläche ist.ich erzeuge mir die Buttons zur Laufzeit so:
Button2.Create (_T("2"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(20,100,100,150),this,IDC_BUTTON2);
Button2.ShowWindow(SW_SHOW);Es ist aber so, daß die Funktion in der dieser Aufruf verpackt ist,
öfters aufgerufen wird und ich deshalb überprüfen muss, ob dieser Button schon auf der Oberfläche vorhanden ist, da mir sonst das Programm abstürzt.Bin für jeden Tipp dankbar !
-
Setze eine boolvariable auf true wenn du den Button erzeugst
-
probiere mal mit oder mit was ähnlichem
CWnd::GetDlgItem
CWnd* GetDlgItem( int nID ) const;void CWnd::GetDlgItem( int nID, HWND* phWnd ) const;
Return Value
A pointer to the given control or child window. If no control with the integer ID given by the nID parameter exists, the value is NULL.
The returned pointer may be temporary and should not be stored for later use.
Parameters
nID
Specifies the identifier of the control or child window to be retrieved.
phWnd
A pointer to a child window.
Remarks
Retrieves a pointer to the specified control or child window in a dialog box or other window. The pointer returned is usually cast to the type of control identified by nID.