buttons

This is a discussion on buttons within the Windows Programming forums, part of the Platform Specific Boards category; this may sound stupid but im new at this so when yoiu make a button how do you make a ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    224

    buttons

    this may sound stupid but im new at this so when yoiu make a button how do you make a function to use it preferably not in a class
    Code:
    CreateWindowEx(0,                     
                          "BUTTON",                                               
                          "DEFAULT PUSH BUTTON",                                 
    
              WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,                             10,                   
                          10,              
                           200,                                   
                           30,  
                           NULL,
                           hInst, 
                           NULL);
    Last edited by c++.prog.newbie; 02-22-2002 at 11:18 AM.

  2. #2
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    Hmm, by function to use it i am assuming you are asking how do you handle it when its pressed...

    For starters you havnt assigned your button with an ID which you need to do to handle it.

    Correct Way:

    Code:
    #define ID_BUTTON 2556
    
    HWND hWndButton = CreateWindow("BUTTON", "My Button", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,
    10, 10, 65, 15, hWnd, (HMENU)ID_BUTTON, hInstance, 0);

    Ok your button now has an ID, now you handle a message when its pressed, more specifically WM_COMMAND.

    Do this in your main message loop:

    Code:
    case WM_COMMAND:
    {
    switch(wParam)
    {
    case ID_BUTTON:
    {
    //executed when your butttons pressed
    MessageBox(hWnd, "Button was clicked!!!", "Event...", MB_OK);
    }
    
    }
    }



    Hope that helps,
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    224
    #define ID_BUTTON 2556

    HWND hWndButton = CreateWindow

    ok 2 things
    1)were do i put this
    2)the tutorials i read didnt say anything about #define or
    HWND hWndButton = CreateWindow
    so what does it do/what is it used for
    (HWND hWndButton = CreateWindow...)

    thanx in advanced

  4. #4
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    hey,

    the #define should go at the top of your code just under the headers.


    The HWND hWndButton simply defines a handle to your button, in this case hWndButton.

    Also you can put this code in WM_CREATE message or just under where you create your main window.

    I think thats all you need

    Also maybe you should invest in a book....

    Hope that helps
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  5. #5
    AuC
    AuC is offline
    Registered User AuC's Avatar
    Join Date
    Feb 2002
    Posts
    4
    Place

    HWND hWndButton = CreateWindow("BUTTON", "My Button", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,
    10, 10, 65, 15, hWnd, (HMENU)ID_BUTTON, hInstance, 0);

    into WM_CREATE of your window.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 04-09-2009, 03:31 AM
  2. Ownerdraw buttons (2)
    By maes in forum Windows Programming
    Replies: 7
    Last Post: 09-11-2003, 06:50 AM
  3. Radio Buttons in Visual C++ 6
    By Ripper1 in forum Windows Programming
    Replies: 22
    Last Post: 05-16-2003, 08:54 AM
  4. (Ken Fitlike) buttons
    By jdinger in forum C++ Programming
    Replies: 4
    Last Post: 03-15-2002, 01:21 PM
  5. Grouping radio buttons
    By Bazz in forum Windows Programming
    Replies: 1
    Last Post: 08-28-2001, 08:15 AM

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