buttons (very lame newbie question)

This is a discussion on buttons (very lame newbie question) within the Windows Programming forums, part of the Platform Specific Boards category; I feel a fool for even asking this question but I'm trying to move from console C programming to programming ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    5

    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:

    Code:
     LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(msg)
    	{
    		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 
    break;
    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
    Location
    Sweden
    Posts
    3,145
    Something like this:
    Code:
    switch(WM_COMMAND)
    {
       case IDButton1: //This is the ID of button 1, the "hi"
          MessageBox(...);
          break;
       case IDButton2: //This is the ID of button 2, the "bye"
          DestroyWindow(hwnd);
          break;
    }
    MagosX.com

    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, 03:09 PM
  4. Beginner on Win32 apps, lame question.
    By Templario in forum C Programming
    Replies: 3
    Last Post: 11-06-2002, 07:39 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM

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