EditBoxes

This is a discussion on EditBoxes within the Windows Programming forums, part of the Platform Specific Boards category; im having some problems with editboxes they dont seem to stay checked how can i fix this? Code: #include <windows.h> ...

  1. #1
    Banned
    Join Date
    Oct 2004
    Posts
    250

    EditBoxes

    im having some problems with editboxes they dont seem to stay checked how can i fix this?
    Code:
    #include <windows.h>
    #define BOX0 500
    #define BUTTON1 501
    #define GBOX3 502
    
    const char g_szClassName[] = "myWindowClass";
    
    // Step 4: the Window Procedure
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch(msg)
        {
    	case WM_CREATE:
    		CreateWindowEx(0,
    			TEXT("BUTTON"),
    			TEXT("Generate Random Cords"),
    			WS_CHILD|WS_VISIBLE|BS_CHECKBOX,
    			10,
    			10,
    			200,
    			50,
    			hwnd,
    			(HMENU)BOX0,
    			NULL,
    			NULL);
    		CreateWindowEx(0,
    			TEXT("BUTTON"),
    			TEXT("Start"),
    			WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
    			250,
    			10,
    			100,
    			40,
    			hwnd,
    			(HMENU)BUTTON1,
    			NULL,
    			NULL);
    		CreateWindowEx(0,
    			TEXT("BUTTON"),
    			TEXT("Results"),
    			WS_CHILD|WS_VISIBLE|BS_GROUPBOX,
    			100,
    			100,
    			400,
    			400,
    			hwnd,
    			(HMENU)GBOX3,
    			NULL,
    			NULL);
    		return 0;
    	case WM_COMMAND:
    		switch(LOWORD(wParam))
    		{
    		case BOX0:
    			MessageBox(NULL,"Checked","Message",MB_OK);
    			break;
    			return 0;
    		case BUTTON1:
    			if(BOX0 == BST_CHECKED)
    			{
    				MessageBox(NULL,"Box Checked","Message", MB_OK);
    			}
    			else
    			{
    				MessageBox(NULL,"box unchecked","Message",MB_OK);
    			}
    			break;
    		}
    		return 0;
            case WM_CLOSE:
                DestroyWindow(hwnd);
            break;
            case WM_DESTROY:
                PostQuitMessage(0);
            break;
            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX wc;
        HWND hwnd;
        MSG Msg;
    
        //Step 1: Registering the Window Class
        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = g_szClassName;
        wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    
        if(!RegisterClassEx(&wc))
        {
            MessageBox(NULL, "Window Registration Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
        // Step 2: Creating the Window
        hwnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            g_szClassName,
            "CordGen",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, 500, 500,
            NULL, NULL, hInstance, NULL);
    
        if(hwnd == NULL)
        {
            MessageBox(NULL, "Window Creation Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
    
        while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return Msg.wParam;
    }
    Last edited by cgod; 11-27-2004 at 05:15 PM.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Checkboxes are not 'editboxes'.

    BS_AUTOCHECKBOX.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Banned
    Join Date
    Oct 2004
    Posts
    250
    thanks, would you happen to know how i could make the window so it cant be resized by the user?

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Banned
    Join Date
    Oct 2004
    Posts
    250
    i got one last problem im having trouble with generating random numbers and sending them to the EditBox
    Code:
    #include <windows.h>
    #include <ctime>
    #include <iostream>
    using namespace std;
    
    
    #define BOX0 500
    #define BUTTON1 501
    #define GBOX3 502
    #define EDIT5 503
    #define BUTTON7 505
    
    const char g_szClassName[] = "WindowClass";
    
    // Step 4: the Window Procedure
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch(msg)
        {
    	case WM_CREATE:
    		CreateWindowEx(0,
    			TEXT("BUTTON"),
    			TEXT("Generate Random Cords"),
    			WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,
    			10,
    			10,
    			200,
    			50,
    			hwnd,
    			(HMENU)BOX0,
    			NULL,
    			NULL);
    		CreateWindowEx(0,
    			TEXT("BUTTON"),
    			TEXT("Start"),
    			WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
    			250,
    			10,
    			100,
    			40,
    			hwnd,
    			(HMENU)BUTTON1,
    			NULL,
    			NULL);
    		CreateWindowEx(0,
    			TEXT("BUTTON"),
    			TEXT("Results"),
    			WS_CHILD|WS_VISIBLE|BS_GROUPBOX,
    			10,
    			150,
    			350,
    			200,
    			hwnd,
    			(HMENU)GBOX3,
    			NULL,
    			NULL);
    		CreateWindowEx(0,
    			TEXT("EDIT"),
    			NULL,
    			WS_CHILD|WS_VISIBLE|WS_BORDER,
    			30,
    			170,
    			300,
    			130,
    			hwnd,
    			(HMENU)EDIT5,
    			NULL,
    			NULL);
    		CreateWindowEx(0,
    			TEXT("BUTTON"),
    			TEXT("Quit"),
    			WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
    			370,
    			10,
    			100,
    			40,
    			hwnd,
    			(HMENU)BUTTON7,
    			NULL,
    			NULL);
    		return 0;
    	case WM_COMMAND:
    		switch(LOWORD(wParam))
    		{
    		case BUTTON1:
    
            srand ((unsigned) time (0));
            int number = rand()%250;
    
    			SetDlgItemText(hwnd,EDIT5,number);
    			break;
    		case BUTTON7:
    			SendMessage(hwnd,WM_CLOSE,0,0);
    			return 0;
    			break;
    		}
    		return 0;
    		break;
            case WM_CLOSE:
                DestroyWindow(hwnd);
            break;
            case WM_DESTROY:
                PostQuitMessage(0);
            break;
            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX wc;
        HWND hwnd;
        MSG Msg;
    
        //Step 1: Registering the Window Class
        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+0);
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = g_szClassName;
        wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    
        if(!RegisterClassEx(&wc))
        {
            MessageBox(NULL, "Window Registration Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
        // Step 2: Creating the Window
        hwnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            g_szClassName,
            "CordGen",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, 500, 400,
            NULL, NULL, hInstance, NULL);
    
        if(hwnd == NULL)
        {
            MessageBox(NULL, "Window Creation Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
    
        while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return Msg.wParam;
    }
    Code:
    --------------------Configuration: tesy - Win32 Release--------------------
    Compiling...
    main.cpp
    C:\C++\tesy\main.cpp(90) : error C2664: 'SetDlgItemTextA' : cannot convert parameter 3 from 'int' to 'const char *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    C:\C++\tesy\main.cpp(92) : error C2360: initialization of 'number' is skipped by 'case' label
            C:\C++\tesy\main.cpp(88) : see declaration of 'number'
    Error executing cl.exe.
    
    tesy.exe - 2 error(s), 0 warning(s)

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    If you wish to declare a variable in side a case you need to use brackets. If you want to set the text of a dialog box control to a number, you can use the SetDlgItemInt() function.

    Code:
    		case BUTTON1:
    		{
    			srand ((unsigned) time (0));
    			int number = rand()%250;
    			SetDlgItemInt(hwnd,EDIT5,number);
    			break;
    		}

  7. #7
    Banned
    Join Date
    Oct 2004
    Posts
    250
    would you happen to know how i could add text to a editbox without deleating the old text?

  8. #8
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Ummm........picky....

    Check the button has recieved a BN_CLICKED msg.
    case BUTTON1:
    if (BN_CLICKED == HIWORD(wParam))

    You should only 'seed' (srand) once, put it in the init function.
    Else the random number will be the same if the time is the same. Probably not going to happen in this app.

    edit: I think this another thread?
    Last edited by novacain; 11-28-2004 at 09:48 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 Editboxs bleeding into each other?
    By Hiyo in forum Windows Programming
    Replies: 3
    Last Post: 11-27-2006, 10:43 AM
  2. Text Colour for Editboxes
    By cerion in forum Windows Programming
    Replies: 21
    Last Post: 10-08-2001, 11:35 AM
  3. Editboxes and their text, HELP!
    By cerion in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2001, 02:54 PM

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