another noob question;\

This is a discussion on another noob question;\ within the C++ Programming forums, part of the General Programming Boards category; how can i make a button in c++ ?, heh....

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    12

    another noob question;\

    how can i make a button in c++ ?, heh.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,607
    Code:
    class Button
    {
        int m_x, m_y, m_w, m_h;
        string m_txt;
    public:
        Button(int x, int y, int w, int h, const string &txt);
        ~Button();
    
        //etc..
    };//Button
    gg

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    12

    still can't get it right:(

    now i have this:

    Code:
    #include <windows.h>
    
    /* Declare Windows procedure */
    LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
    /* Make the class name into a global variable */
    char szClassName[ ] = "WindowsApp";
    int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
    
    {
        HWND hwnd;               /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
        wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
        wincl.cbSize = sizeof(WNDCLASSEX);
    
        /* Use default icon and mouse-pointer */
        wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL; /* No menu */
        wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
        wincl.cbWndExtra = 0;                      /* structure or the window instance */
        /* Use light-gray as the background of the window */
        wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
    
        /* Register the window class, if fail quit the program */
        if(!RegisterClassEx(&wincl)) return 0;
    
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx(
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "Windows App",         /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               544,                 /* The programs width */
               375,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
        /* Make the window visible on the screen */
        ShowWindow(hwnd, nFunsterStil);
        /* Run the message loop. It will run until GetMessage( ) returns 0 */
        while(GetMessage(&messages, NULL, 0, 0))
        {
               /* Translate virtual-key messages into character messages */
               TranslateMessage(&messages);
               /* Send message to WindowProcedure */
               DispatchMessage(&messages);
        }
    
        /* The program return-value is 0 - The value that PostQuitMessage( ) gave */
        return messages.wParam;
    }
    
    /* This function is called by the Windows function DispatchMessage( ) */
    LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {
               case WM_DESTROY:
               PostQuitMessage(0);        /* send a WM_QUIT to the message queue */
               break;
               default:                   /* for messages that we don't deal with */
               return DefWindowProc(hwnd, message, wParam, lParam);
        }
        return 0;
    }
    class Button
    {
        int m_x, m_y, m_w, m_h;
        string m_txt;
    public:
        Button(int x, int y, int w, int h, const string &txt);
        ~Button();
    
        //etc..
    };//Button
    it didn't make a button

  4. #4
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Sigh.

    Do you know what a class is and how it works / is used?
    Do not make direct eye contact with me.

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    12

    nope

    n/t

  6. #6
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Code:
    HWND hButton=CreateWindow("BUTTON", "Button Text", WS_CHILD | WS_VISIBLE,
                 0, 0, 50,50, hMain, NULL, hInst, NULL);
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  7. #7
    Registered User
    Join Date
    Jul 2003
    Posts
    12

    still can't get it right ;\

    could anyone give me the FULL EXACT code please, then i can look though and try to learn it.

    the best thing i made it in c++ was:

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
    int a, b;
    cout<<"enter a starting number.";
    cin>>a;
    cout<<"enter a finishing number.";
    cin>>b;
    while (a<=b)
    {
    cout<<"character is:"<<char(a);
    }
    system("hold");
    return 0;
    }

  8. #8
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109

    Re: still can't get it right ;\

    Originally posted by Pheonix
    could anyone give me the FULL EXACT code please, then i can look though and try to learn it.

    the best thing i made it in c++ was:

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
    int a, b;
    cout<<"enter a starting number.";
    cin>>a;
    cout<<"enter a finishing number.";
    cin>>b;
    while (a<=b)
    {
    cout<<"character is:"<<char(a);
    }
    system("hold");
    return 0;
    }
    you'll have a lot to learn about the language then before you should start worrying about windows programming.

  9. #9
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    http://www.winprog.org/tutorial/
    Great site, it will tell you everything. Read through it, try something, then come back to us with ERRORS.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  10. #10
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787

    Re: still can't get it right ;\

    Originally posted by Pheonix
    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
    int a, b;
    cout<<"enter a starting number.";
    cin>>a;
    cout<<"enter a finishing number.";
    cin>>b;
    while (a<=b)
    {
    cout<<"character is:"<<char(a);
    }
    system("hold");
    return 0;
    }
    isn't that just an infinite loop using old standards? what you wanted goes something like this:
    Code:
    #include <iostream> //iostream.h is antiquated
    
    //use the following (3) instead of "using namespace std;"
    using std::cin;
    using std::cout;
    using std::endl;
    
    int main()
    {
       int a, b;
       cout<<"enter a starting number: "; //don't forget they have to enter a  number
       cin>>a;
       cout<<"enter a finishing number: "; //the way you had it the input would look messy
       cin>>b;
    
       //consider putting a check in here (a<b)
    
       for(a;a<=b;a++) //for loop would be better - you need to increment
          cout<<"character is:"<<static_cast<char>(A)<<endl; //use instead of old "char(a)"
       
       cout<<"Press any key to continue . . ."; //system("hold"); is non-standard
       cin.get();
       return 0;
    }
    but i still fail to see how that comes remotely close to windows programming... it looks like a looping tutorial or something...
    Last edited by major_small; 10-27-2003 at 06:59 AM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  11. #11
    Registered User
    Join Date
    Jul 2003
    Posts
    12

    yeah it was..

    it was a looping tutorial, i knew how to use loops though because i've used other ones before, these are the same.

    i forgot to add:

    Code:
    while (a<=b)
    {
    a=a+1
    }

  12. #12
    Registered User
    Join Date
    Jul 2003
    Posts
    12
    Originally posted by bennyandthejets
    http://www.winprog.org/tutorial/
    Great site, it will tell you everything. Read through it, try something, then come back to us with ERRORS.
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick noob question
    By thanatos1 in forum C# Programming
    Replies: 2
    Last Post: 06-17-2009, 08:28 PM
  2. another noob question
    By clb2003 in forum C Programming
    Replies: 4
    Last Post: 02-12-2009, 12:28 PM
  3. Noob printf question
    By lolguy in forum C Programming
    Replies: 3
    Last Post: 12-14-2008, 07:08 PM
  4. Very noob question :(.
    By GamerProduction in forum Tech Board
    Replies: 4
    Last Post: 04-14-2007, 05:40 AM
  5. Noob question ( little dos program )
    By Demon1s in forum C++ Programming
    Replies: 13
    Last Post: 04-04-2003, 08:28 PM

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