Thread: An Easy Windows GUI Question

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    27

    An Easy Windows GUI Question

    Hello there,

    I was trying to build a standard calculator version. The standard calculator is just like the calculator that comes with MS Windows.

    As you can observe, there are 17 buttons. I am too lazy to copy and paste the function CreateWindow() 17 times ( note: there are 4 differences for each - namely the x and y coordinates, the name (LPCSTR) and the hMenu parameters - ). So I have written a general formula for them and put it in loops:
    Code:
                            char numbers[10] = "741852963";
    			int i = 0, j = 1, counter = 0;
    			while(i<3)
    			{
    				while(j<4)
    				{
    					window = CreateWindow("button", (LPCSTR)numbers[counter], WS_VISIBLE|WS_CHILD, 35*i+5, 35*j+10, 30, 30, wnd, (HMENU)(UINT_PTR)counter, NULL, NULL);
    					j += 1;
    					counter += 1;
    				}
    				i += 1;
    				j = 1;
    			}
    but nothing happened!!!

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    27
    Thanks guys... I have found a solution to the problem..
    Here's the code after the modifications:
    Code:
                            char numbers[] = "7410852.963=/*-+";
    			char temp[2];
    			int i = 0, j = 1, counter = 0;
    			while(i<4)
    			{
    				while(j<5)
    				{
    					sprintf(temp, "%c", numbers[counter]);
    					window = CreateWindow("button", temp, WS_VISIBLE|WS_CHILD, 35*i+5, 35*j+10, 30, 30, wnd, (HMENU)(UINT_PTR)counter, NULL, NULL);
    					j += 1;
    					counter += 1;
    				}
    				i += 1;
    				j = 1;
    			}
    and thanks again

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I doubt that "(LPCSTR)numbers[counter]" is at all what you want for that parameter, since it is unlikely that anything meaningful (to you) is stored at address 0x00000007 (for instance).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Easy question for you!
    By pobri19 in forum C++ Programming
    Replies: 1
    Last Post: 07-19-2008, 10:45 PM
  2. easy question
    By mrsirpoopsalot in forum C Programming
    Replies: 5
    Last Post: 09-07-2006, 05:47 AM
  3. probably a very easy question...
    By s_siouris in forum C Programming
    Replies: 2
    Last Post: 09-05-2006, 10:13 AM
  4. 4 easy question
    By Zeratulsdomain in forum C++ Programming
    Replies: 2
    Last Post: 10-15-2005, 10:43 PM
  5. Easy question, (should be) easy answer... ;-)
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-12-2002, 09:36 PM