Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Win32 Buttons, which is which? [solved]

Win32 Buttons, which is which? [solved]

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionhelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Groulien
    wrote on last edited by
    #1

    Hello everyone, I've been experimenting with C++ and how to build a form with it (without MFC). I've created two buttons at runtime with the following code: (I used a bit of copying and pasting)

    if (button1 == NULL)
    {
    button1 = ::CreateWindowEx(WS_EX_LEFT,L"button",L"Button1", WS_CHILD ,50,50,50,50,parent,NULL,::GetModuleHandle(NULL),NULL);
    SendMessage(button1, WM_SETFONT, (WPARAM)defFont, MAKELPARAM(TRUE, 0));
    ::ShowWindow(button1,SW_SHOW);
    }
    if (button2 == NULL)
    {
    button2 = ::CreateWindowEx(WS_EX_LEFT,L"button",L"Button2", WS_CHILD ,125,50,50,50,parent,NULL,::GetModuleHandle(NULL),NULL);
    SendMessage(button2, WM_SETFONT, (WPARAM)defFont, MAKELPARAM(TRUE, 0));
    ::ShowWindow(button2,SW_SHOW);

    }

    There's no problem with building the buttons, this is my WndProc:

    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    switch(msg)
    {
    case SW_SHOW:
    break;
    case WM_COMMAND:
    if (wParam == BN_CLICKED)
    {
    Triggered(L"1"); //Shows a messagebox.
    }
    break;
    case WM_SHOWWINDOW:
    Init(hwnd); //Builds the buttons here.
    break;
    case WM_CLOSE:
    DestroyWindow(hwnd);
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;

    }

    How can I tell which one sent the message? -- Nevermind, got it. lParam equals with the (LPARAM)handle of the button that sent it.

    modified on Tuesday, June 7, 2011 3:05 PM

    A T 2 Replies Last reply
    0
    • G Groulien

      Hello everyone, I've been experimenting with C++ and how to build a form with it (without MFC). I've created two buttons at runtime with the following code: (I used a bit of copying and pasting)

      if (button1 == NULL)
      {
      button1 = ::CreateWindowEx(WS_EX_LEFT,L"button",L"Button1", WS_CHILD ,50,50,50,50,parent,NULL,::GetModuleHandle(NULL),NULL);
      SendMessage(button1, WM_SETFONT, (WPARAM)defFont, MAKELPARAM(TRUE, 0));
      ::ShowWindow(button1,SW_SHOW);
      }
      if (button2 == NULL)
      {
      button2 = ::CreateWindowEx(WS_EX_LEFT,L"button",L"Button2", WS_CHILD ,125,50,50,50,parent,NULL,::GetModuleHandle(NULL),NULL);
      SendMessage(button2, WM_SETFONT, (WPARAM)defFont, MAKELPARAM(TRUE, 0));
      ::ShowWindow(button2,SW_SHOW);

      }

      There's no problem with building the buttons, this is my WndProc:

      LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
      {
      switch(msg)
      {
      case SW_SHOW:
      break;
      case WM_COMMAND:
      if (wParam == BN_CLICKED)
      {
      Triggered(L"1"); //Shows a messagebox.
      }
      break;
      case WM_SHOWWINDOW:
      Init(hwnd); //Builds the buttons here.
      break;
      case WM_CLOSE:
      DestroyWindow(hwnd);
      break;
      case WM_DESTROY:
      PostQuitMessage(0);
      break;
      default:
      return DefWindowProc(hwnd, msg, wParam, lParam);
      }
      return 0;

      }

      How can I tell which one sent the message? -- Nevermind, got it. lParam equals with the (LPARAM)handle of the button that sent it.

      modified on Tuesday, June 7, 2011 3:05 PM

      A Offline
      A Offline
      Albert Holguin
      wrote on last edited by
      #2

      When you call CreateWindowEx, the return is a handle to the button, that same handle can be used within the WPARAM or LPARAM to distinguish, or alternatively, if you have two button and you must distinguish, then they should probably be sending different messages.

      1 Reply Last reply
      0
      • G Groulien

        Hello everyone, I've been experimenting with C++ and how to build a form with it (without MFC). I've created two buttons at runtime with the following code: (I used a bit of copying and pasting)

        if (button1 == NULL)
        {
        button1 = ::CreateWindowEx(WS_EX_LEFT,L"button",L"Button1", WS_CHILD ,50,50,50,50,parent,NULL,::GetModuleHandle(NULL),NULL);
        SendMessage(button1, WM_SETFONT, (WPARAM)defFont, MAKELPARAM(TRUE, 0));
        ::ShowWindow(button1,SW_SHOW);
        }
        if (button2 == NULL)
        {
        button2 = ::CreateWindowEx(WS_EX_LEFT,L"button",L"Button2", WS_CHILD ,125,50,50,50,parent,NULL,::GetModuleHandle(NULL),NULL);
        SendMessage(button2, WM_SETFONT, (WPARAM)defFont, MAKELPARAM(TRUE, 0));
        ::ShowWindow(button2,SW_SHOW);

        }

        There's no problem with building the buttons, this is my WndProc:

        LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
        {
        switch(msg)
        {
        case SW_SHOW:
        break;
        case WM_COMMAND:
        if (wParam == BN_CLICKED)
        {
        Triggered(L"1"); //Shows a messagebox.
        }
        break;
        case WM_SHOWWINDOW:
        Init(hwnd); //Builds the buttons here.
        break;
        case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
        PostQuitMessage(0);
        break;
        default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;

        }

        How can I tell which one sent the message? -- Nevermind, got it. lParam equals with the (LPARAM)handle of the button that sent it.

        modified on Tuesday, June 7, 2011 3:05 PM

        T Offline
        T Offline
        Tarmo Kalda
        wrote on last edited by
        #3

        Another way is to create button window with id. button1 = ::CreateWindowEx(WS_EX_LEFT,L"button",L"Button1", WS_CHILD ,50,50,50,50,parent,(HMENU)100,::GetModuleHandle(NULL),NULL); button2 = ::CreateWindowEx(WS_EX_LEFT,L"button",L"Button2", WS_CHILD ,125,50,50,50,parent,(HMENU)200,::GetModuleHandle(NULL),NULL); Now you can distinguish which is which. case WM_COMMAND: if ((UINT)HIWORD(wParam) == BN_CLICKED) { switch (int)LOWORD(wParam): { case 100: Triggered(L"1"); //Shows a messagebox. break; case 200: Triggered(L"2"); //Shows a messagebox. break; } } break;

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups