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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. push button

push button

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
6 Posts 2 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.
  • A Offline
    A Offline
    ask_you
    wrote on last edited by
    #1

    i have created a push button using Create Window. Now 1. how do i write text on the button? 2. how do i handle the button WM_COMMAND? the code snippet is: WNDCLASS wc; memset(&wc, 0, sizeof(WNDCLASS)); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC) WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = GetModuleHandle(NULL); wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); wc.lpszClassName = "WndClassName"; if(!RegisterClass(&wc)) { MessageBox(NULL,"Failed To Register The Window class.","ERROR",MB_OK|MB_ICONEXCLAMATION); return (NULL); } HWND hWindow = CreateWindowEx(NULL, "WndClassName","DialogClassSample",WS_OVERLAPPEDWINDOW | WS_VISIBLE,0, 0, 320, 200, NULL, NULL, GetModuleHandle(NULL), NULL); HWND ButtonWindow = CreateWindow("BUTTON",NULL, BS_TEXT|BS_PUSHBUTTON|WS_VISIBLE|WS_CHILD,50,50,30,20,hWindow,NULL,NULL,NULL); MSG msg; BOOL bDone = FALSE; while(!bDone) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if (msg.message==WM_QUIT) { bDone = TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } }

    N 1 Reply Last reply
    0
    • A ask_you

      i have created a push button using Create Window. Now 1. how do i write text on the button? 2. how do i handle the button WM_COMMAND? the code snippet is: WNDCLASS wc; memset(&wc, 0, sizeof(WNDCLASS)); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC) WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = GetModuleHandle(NULL); wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); wc.lpszClassName = "WndClassName"; if(!RegisterClass(&wc)) { MessageBox(NULL,"Failed To Register The Window class.","ERROR",MB_OK|MB_ICONEXCLAMATION); return (NULL); } HWND hWindow = CreateWindowEx(NULL, "WndClassName","DialogClassSample",WS_OVERLAPPEDWINDOW | WS_VISIBLE,0, 0, 320, 200, NULL, NULL, GetModuleHandle(NULL), NULL); HWND ButtonWindow = CreateWindow("BUTTON",NULL, BS_TEXT|BS_PUSHBUTTON|WS_VISIBLE|WS_CHILD,50,50,30,20,hWindow,NULL,NULL,NULL); MSG msg; BOOL bDone = FALSE; while(!bDone) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if (msg.message==WM_QUIT) { bDone = TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } }

      N Offline
      N Offline
      Nilesh K
      wrote on last edited by
      #2

      1. SetWindowText should help you put the text over the button 2. You need to give your Window Procedure where in you can handle the messages (In a way that we use to do in SDK)

      - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

      A 1 Reply Last reply
      0
      • N Nilesh K

        1. SetWindowText should help you put the text over the button 2. You need to give your Window Procedure where in you can handle the messages (In a way that we use to do in SDK)

        - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

        A Offline
        A Offline
        ask_you
        wrote on last edited by
        #3

        My Window procedure is: LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch (uMsg) { case WM_COMMAND: { PostQuitMessage(0); return 0; } break; case WM_CLOSE: { PostQuitMessage(0); return 0; } break; } return DefWindowProc(hWnd,uMsg,wParam,lParam); } Here i have handled the WM_COMMAND message. but my problem is if i create 2 push buttons and i want seperate handling for the buttons, how do i distinguish the WM_COMMAND of one button from the WM_COMMAND of the second button?

        N 1 Reply Last reply
        0
        • A ask_you

          My Window procedure is: LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch (uMsg) { case WM_COMMAND: { PostQuitMessage(0); return 0; } break; case WM_CLOSE: { PostQuitMessage(0); return 0; } break; } return DefWindowProc(hWnd,uMsg,wParam,lParam); } Here i have handled the WM_COMMAND message. but my problem is if i create 2 push buttons and i want seperate handling for the buttons, how do i distinguish the WM_COMMAND of one button from the WM_COMMAND of the second button?

          N Offline
          N Offline
          Nilesh K
          wrote on last edited by
          #4

          1.Low-order of WParam would be having the button identifier, compare that with the list of id's that you gave at the time of creation 2. Compare your button handle with in coming hwnd parameter:)

          - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

          A 1 Reply Last reply
          0
          • N Nilesh K

            1.Low-order of WParam would be having the button identifier, compare that with the list of id's that you gave at the time of creation 2. Compare your button handle with in coming hwnd parameter:)

            - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

            A Offline
            A Offline
            ask_you
            wrote on last edited by
            #5

            how do i compare low-order of WParam. i did not create any list of ids. i checked the low-order of WParam. it outputs 0. Secondly, how do i compare the handle. The button handle is declared in WinMain() and i need to compare in WndProc(i m not able to get the button handle in WinProc)

            N 1 Reply Last reply
            0
            • A ask_you

              how do i compare low-order of WParam. i did not create any list of ids. i checked the low-order of WParam. it outputs 0. Secondly, how do i compare the handle. The button handle is declared in WinMain() and i need to compare in WndProc(i m not able to get the button handle in WinProc)

              N Offline
              N Offline
              Nilesh K
              wrote on last edited by
              #6

              1. The LOWORD macro retrieves the low-order word from the specified value. 2. Instead of using createwindow try using create of CWnd this would allow you to set the control's id. Store thos id's in some array and check them in your wndproc function.

              - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

              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