Thread: 'getintchar' Project

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    41

    Question 'getintchar' Project

    I've made this program that shows the ACSII value and the character, heres a pic from the DOS version:

    http://subsoap.com/ck/getintchar.PNG
    NOTE: thats the old version that shows the line feed (10)

    I'm learning WinAPI and I want to get this string from a edit box then put the string into a varaible then every char in the string I want to convert to a int, so that when theres a 'c' in the string it has it as '99'.

    heres some of the code for it:
    Code:
    BOOL bSuccess;
    int nTimes = GetDlgItemInt(hwnd, IDC_NUMBER, &bSuccess, FALSE);
    if(bSuccess) 
    {
        	// Then we get the string they entered
        	// First we need to find out how long it is so that we can
        	// allocate some memory
        
        int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_TEXT));
        if(len > 0)
        {
        	// Now we allocate, and get the string into our buffer
        
        	int i,mychr;
        	str buf;
    
        	buf = (str)GlobalAlloc(GPTR, len + 1);
        	GetDlgItemText(hwnd, IDC_TEXT, buf, len + 1);
    
        	// Now we add the string to the list box however many times
    	    // the user asked us to.
    
    	    for(;*buf;){
        		int mychr=(int)*buf;
        		SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)mychr);
        		//SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)buf);
        	}
    
    	/*for(i = 0;i < nTimes; i++)
    	{
    		int index = SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)buf);
    
    		// Here we are associating the value nTimes with the item 
    		// just for the heck of it, we'll use it to display later.
    		// Normally you would put some more useful data here, such
    		// as a pointer.
    		SendDlgItemMessage(hwnd, IDC_LIST, LB_SETITEMDATA, (WPARAM)index, (LPARAM)nTimes);
    	}*/
    
    	// Dont' forget to free the memory!
        	GlobalFree((HANDLE)buf);
        }
        else 
        {
    	MessageBox(hwnd, "You didn't enter anything!", "Warning", MB_OK);
        }
        //and the rest of the stuff..
    }
    I also need add a new item into the list that has the int number AND the char it belongs too*, don't know how I'll do this..

    *the dos version of showing the int and the char:
    Code:
        int mychr;
        while((mychr = getchar()) != 9) {
          if (mychr != 10) printf("\n%i\t%c",mychr,mychr); else nl;
        }
    I want to see for this WinAPI prog if I can do basicly the same with the list box BUT with the WinAPI version it's a string not a intso I'll need to covert it and show it with the character.

    HOPEFULLY this made sence/someone can help me.
    I CAN post the other code if needed.
    CK4R1 0U7
    Last edited by Budgiekarl; 04-21-2004 at 07:25 PM.
    THERE IS NO PLACE LIKE 127.0.0.1

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM