Thread: Creating buttons using one console window

  1. #1
    Registered User
    Join Date
    Jul 2016
    Posts
    1

    Creating buttons using one console window

    Hi,
    I just wanted to create 4 buttons, x,y coordinates will set later.
    I created 4 buttons but when I run this program, it is showing 5 console windows to close each button as highlighted in red box of screnshot.

    how can make sure that when I RUN THIS PROGRAM, it should show only one console window with4 buttons

    Code:
    #include <Windows.h>
    
    
    int main()
    {
    MSG msg;
    HWND hWnd = CreateWindow(TEXT("button"), TEXT("START"), WS_VISIBLE | WS_POPUP | WS_CHILD | WS_TABSTOP | BS_BITMAP,
    50, 50, 150, 150, NULL, NULL, NULL, NULL);
       
    SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"STOP");
    hWnd = CreateWindow(TEXT("button"), TEXT("START"), WS_VISIBLE | WS_POPUP | WS_CHILD | WS_TABSTOP | BS_BITMAP,
    250, 250, 150, 150, NULL, NULL, NULL, NULL);
            
    SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"PAUSE");
    hWnd = CreateWindow(TEXT("button"), TEXT("START"), WS_VISIBLE | WS_POPUP | WS_CHILD | WS_TABSTOP | BS_BITMAP,
    350, 350, 150, 150, NULL, NULL, NULL, NULL);
            
    SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"EXIT");
    hWnd = CreateWindow(TEXT("button"), TEXT("START"), WS_VISIBLE | WS_POPUP | WS_CHILD | WS_TABSTOP | BS_BITMAP,
    450, 450, 150, 150, NULL, NULL, NULL, NULL);
    
    
    while (GetMessage(&msg, NULL, 0, 0))
    {
    ShowWindow(hWnd, SW_SHOW);
    UpdateWindow(hWnd);
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    return (int)msg.wParam;
    }
    Attached Images Attached Images Creating buttons using one console window-unsual-jpg 

  2. #2
    Registered User
    Join Date
    Dec 2010
    Location
    Trinidad, CO (log cabin in middle of nowhere)
    Posts
    148
    Console windows are for displaying text, not for hosting button controls.

    Nevertheless, console windows do possess a HWND which could be obtained through an Api call. I forget the exact name, something like GetConsoleWindow() or GetConsoleHandle() or something like that. Using that HWND you could set the console window as the parent of each button. But you are ignoring about half of the parameters of your CreateWindow() calls.

    I gotta say that's some of the wierdest Windows code I've ever seen. That's why nobody's answering you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a console window
    By arka.sharma in forum C Programming
    Replies: 4
    Last Post: 09-08-2011, 07:26 AM
  2. Creating Buttons By Clicking a Button
    By Revengeog in forum C++ Programming
    Replies: 0
    Last Post: 09-04-2009, 12:17 AM
  3. getting toolbar buttons onto a window
    By eth0 in forum Windows Programming
    Replies: 4
    Last Post: 02-24-2006, 12:59 PM
  4. Buttons Question in Window
    By Tronic in forum Windows Programming
    Replies: 8
    Last Post: 03-11-2005, 03:11 PM
  5. Window XP buttons
    By monkeymon in forum Windows Programming
    Replies: 7
    Last Post: 04-29-2002, 10:40 AM

Tags for this Thread