Create two buttons that interact with an editbox

This is a discussion on Create two buttons that interact with an editbox within the Windows Programming forums, part of the Platform Specific Boards category; Hi all I hope in an answer that could help me about my problem because I'm going crazy. I'm creating ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    45

    Arrow Create two buttons that interact with an editbox

    Hi all I hope in an answer that could help me about my problem because I'm going crazy.
    I'm creating a GUI in Visual C++ .NET and I'd like to split the "Spin Control" in two buttons.

    I created an editbox with a spin, only to test the code, and the result is this:
    See Image1

    Here the code that I wrote:
    The spin control:
    Code:
    CSpinButtonCtrl *spin = (CSpinButtonCtrl*)GetDlgItem(IDC_SPIN_ROTOR_TEST);
             spin->SetRange(0, 25);
    	 spin->SetPos(0);
    GetDlgItem(IDC_ROTORTEXT)->SetWindowText("A");
    The letters in the editbox:
    Code:
    void CTestDlg::onShowposSpinStr(NMHDR* pNMHDR, LRESULT* pResult)
    {
    	int nNewPos;
    	char szNumber[][16] =
    	{ 
    		"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "W", "V", "X", "Y", "Z"
    	};
    	NM_UPDOWN *pNMUpDown = (NM_UPDOWN*) pNMHDR;
    
    	nNewPos = pNMUpDown->iPos + pNMUpDown->iDelta;
    
    	if(nNewPos >= 0 && nNewPos <= 25)
    	{
    		GetDlgItem(IDC_ROTOR3TEXT)->SetWindowText(szNumber[nNewPos]);
    	}
    	*pResult = 0;
    }
    But now I have to split the spin into two buttons that interact with the editbox, to increase/decrease the letters, like this:
    See Image2

    I have no idea on how I can do this...
    Please someone help me, I'm desperate.

  2. #2
    Registered User
    Join Date
    Jul 2005
    Posts
    45

    Arrow

    This morning I splitted the spin control in two buttons, here is the code:

    Code:
    void CTestDlg::OnBnClickedButtonUp()
    {
    	int rl=GetDlgItemInt(IDC_EDIT3TEXT);
    	rl=rl+1;
    	SetDlgItemInt(IDC_EDIT3TEXT,rl);
    }
    
    void CTestDlg::OnBnClickedButtonDown()
    {
    	int rl=GetDlgItemInt(IDC_EDIT3TEXT);
    	rl=rl-1;
    	SetDlgItemInt(IDC_EDIT3TEXT,rl);
    }
    But I need to display letters into the editbox not the numbers.
    Obviously I need letters from A to Z.
    Someone could help me to intergrate the code of the function that I created to display the letters in the first post and this?

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    45
    Any help?!

  4. #4
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    This should work:

    Code:
    /* Declare varibles */
    char szSelection[1];
    int nLetterNum;
    	char szNumber[][16] =
    	{ 
    		"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "W", "V", "X", "Y", "Z"
    	};
    Code:
    /* If Button the upper button is pressed: */
    nLetterNum++;
    szSelection[0] = (szNumber[nLetterNum]);
    SetWindowText(hNumberEdit, szSelection);
    Code:
    /* If Button the lower button is pressed: */
    nLetterNum--;
    szSelection[0] = (szNumber[nLetterNum]);
    SetWindowText(hNumberEdit, szSelection);
    This script asumes your EditBox's handle is hNumberEdit
    I haven't tried this script out yet, I am just saying that this should work.

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    45
    Do you mean something like this?

    Code:
    void CTestDlg::OnBnClickedButtonUp()
    {
    /* Declare varibles */
    	char szSelection[1];
    	int nLetterNum;
    	char szNumber[][16] =
    	{ 
    		"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "W", "V", "X", "Y", "Z"
    	};
    	
    /* If Button the upper button is pressed: */
    	nLetterNum++;
    	szSelection[0] = (szNumber[nLetterNum]);
    	SetWindowText(hNumberEdit, szSelection);
    }
    Sorry but I'm trying to understand!

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    try...


    Code:
    //declare array of 26 items. Each item (element) has space for one character and the terminator
    char szNumber[26][2] =
    { 
           "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "W", "V", "X", "Y", "Z"
    };
    
    //just use array to set the text, no need to copy to another string
    SetWindowText(hNumberEdit, szNumber[nLetterNum]);
    //or
    SetDlgItemText(IDC_EDIT3TEXT,szNumber[nLetterNum]);
    >>szSelection[1];

    need one for storage (the character) and one for the terminator so minimum is 2.

    or just use char cSelection;

    (sz in hungarian notation means a null terminated string IIRC)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User
    Join Date
    Jul 2005
    Posts
    45
    I tried this, but I did some mistake I think:

    Code:
    void CTestDlg::OnBnClickedButtonUp()
    {
    /* Declare varibles */
    	char szSelection;
    	int nLetterNum;
    	char szNumber[26][2] =
    	{ 
    		"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "W", "V", "X", "Y", "Z"
    	};
    	
    /* If Button the upper button is pressed: */
    	nLetterNum++;
    	szSelection = (szNumber[nLetterNum]);
    //	SetWindowText(hNumberEdit, cSelection);
    	SetDlgItemText(IDC_EDIT3TEXT,szNumber[nLetterNum]);
    }
    But I receive this error:
    error C2440: '=' : cannot convert from 'char [2]' to 'char'
    in this line:
    Code:
    szSelection = (szNumber[nLetterNum]);
    I did a cast like this:
    Code:
    szSelection = (char)(szNumber[nLetterNum]);
    no error, but the button doesn't work!

  8. #8
    Registered User
    Join Date
    Jul 2005
    Posts
    45
    Hey gurus, help this poor n00b

  9. #9
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139

    Post

    You need to declare your variables outside of the button procedure. Declare your "int m_nLetterNum;" as a member of your dialog class. Then modify this variable in your button click events. szNumer should be a class variable or even constant, too.

    PHP Code:
    void CTestDlg::OnBnClickedButtonUp()
    {
        
    // ADD a check for upper and lower bounds of m_nLetterNum

        
    m_nLetterNum++;

        
    SetDlgItemTextIDC_EDIT3TEXTm_szNumber[m_nLetterNum] );
    }

    void CTestDlg::OnBnClickedButtonDown()
    {
        
    // ADD a check for upper and lower bounds of m_nLetterNum

        
    m_nLetterNum--;

        
    SetDlgItemTextIDC_EDIT3TEXTm_szNumber[m_nLetterNum] );

    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OwnerDrawn Radio Buttons?
    By Devil Panther in forum Windows Programming
    Replies: 0
    Last Post: 02-11-2006, 10:02 AM
  2. Cannot create MDI Client Win
    By JaWiB in forum Windows Programming
    Replies: 1
    Last Post: 10-31-2005, 09:05 PM
  3. Replies: 2
    Last Post: 08-25-2005, 03:09 PM
  4. Replies: 3
    Last Post: 07-23-2005, 08:00 AM
  5. Create two buttons that interact with an editbox
    By Arkanos in forum C++ Programming
    Replies: 4
    Last Post: 07-11-2005, 01:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21