Thread: buttons (very lame newbie question)

  1. #1
    Registered User
    Join Date
    Mar 2002

    buttons (very lame newbie question)

    I feel a fool for even asking this question but I'm trying to move from console C programming to programming the windows api. I've been banging my head against the keyboard while reading Petzold. I've got a window, a button and when you click the button a message pops up. Now what I want is TWO buttons, one called hi and one called bye. when you click hi you get the message hello and when you click bye you get the message goodbye. Here's what I'm working on:

     LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    		static HWND  hwndButton;
    	case WM_CREATE:
    		hwndButton = CreateWindow(  
        "BUTTON",   // predefined class 
        "hi",       // button text 
        WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON	,  // styles 
        // Size and position values are given explicitly, because 
        // the CW_USEDEFAULT constant gives zero values for buttons. 
        50,         // starting x position 
        60,         // starting y position 
        50,        // button width 
        20,        // button height 
        hwnd,       // parent window 
        NULL,       // No menu 
        (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), 
        NULL);      // pointer not needed 
    case WM_COMMAND :
    MessageBox (NULL, TEXT ("hello."),
                          TEXT ("hello"), MB_ICONERROR) ;
    I know how to put another button on the window, but from there I'm lost!

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Something like this:
       case IDButton1: //This is the ID of button 1, the "hi"
       case IDButton2: //This is the ID of button 2, the "bye"

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  3. confusion with integers (newbie question)
    By imortal in forum C Programming
    Replies: 7
    Last Post: 12-06-2002, 04:09 PM
  4. Beginner on Win32 apps, lame question.
    By Templario in forum C Programming
    Replies: 3
    Last Post: 11-06-2002, 08:39 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM