Thread: WS_HSCROLL in ES_READONLY edit box error

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    71

    WS_HSCROLL in ES_READONLY edit box error

    Well, I decided to make a base converter for practice... since im fairly new to win32. It works perfectly, I also wanted to put restrictions on my edit boxes, So I put ES_READONLY on them (I would rather of been able to bin edit box handle 1 or 0's, and hex 1-f but I dont know how , so tell me this to if you can =P), but I want a scroll bar on my binary edit box because it can long easily. I did so, but everytime I scroll over, it jumps back to the start... so I can't see whats past it the end of my edit box...

    my code:

    Code:
    #include <windows.h>
    #define ID_HWND_DEC 10010
    #define ID_HWND_OCT 10011
    #define ID_HWND_HEX 10012
    #define ID_HWND_BIN 10013
    #define ID_HWND_BUTTON 20000
    
    const char g_ClassName[]="hwnd window class name";
    
    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
        switch(msg)
        {
            case WM_CLOSE:
                 DestroyWindow(hwnd);
                 break;
                 
            case WM_DESTROY:
                 PostQuitMessage(0);
                 break;
            
            case WM_COMMAND:
                 {
                    switch(HIWORD(wParam))
                    {
                        case BN_CLICKED:
                             int x;
                             char hex[MAX_PATH];
                             char oct[MAX_PATH];
                             char bin[MAX_PATH];
                             
                             x = GetDlgItemInt(hwnd,ID_HWND_DEC,NULL,true);
                             
                             SetDlgItemText(hwnd,ID_HWND_HEX,itoa(x,hex,16));
                             SetDlgItemText(hwnd,ID_HWND_OCT,itoa(x,oct,8));
                             SetDlgItemText(hwnd,ID_HWND_BIN,itoa(x,bin,2));
                        break;
                    }
                 }
            break;
            
            case WM_CREATE:
                 {
                 HWND hEdit_Bin;
                 HWND hEdit_Oct;
                 HWND hEdit_Hex;
                 HWND hEdit_Dec;
                 static HWND hButton;
                 HFONT hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
                 
                 hEdit_Dec = CreateWindowEx(WS_EX_CLIENTEDGE,
                                            "EDIT",
                                            "",
                                            WS_CHILD|WS_VISIBLE|ES_NUMBER,
                                            30,30,
                                            100,20,
                                            hwnd,
                                            (HMENU)ID_HWND_DEC,
                                            GetModuleHandle(NULL),
                                            NULL);
                 
                 hEdit_Oct = CreateWindowEx(WS_EX_CLIENTEDGE,
                                            "EDIT",
                                            "",
                                            WS_CHILD|WS_VISIBLE|ES_READONLY,
                                            30,90,
                                            100,20,
                                            hwnd,
                                            (HMENU)ID_HWND_OCT,
                                            GetModuleHandle(NULL),
                                            NULL);
                 
                 
                 hEdit_Hex = CreateWindowEx(WS_EX_CLIENTEDGE,
                                            "EDIT",
                                            "",
                                            WS_CHILD|WS_VISIBLE|ES_READONLY,
                                            160,90,
                                            100,20,
                                            hwnd,
                                            (HMENU)ID_HWND_HEX,
                                            GetModuleHandle(NULL),
                                            NULL);
                                            
                 hEdit_Bin = CreateWindowEx(WS_EX_CLIENTEDGE,
                                            "EDIT",
                                            "",
                                            WS_CHILD|WS_VISIBLE|ES_READONLY|WS_HSCROLL,
                                            160,30,
                                            100,40,
                                            hwnd,
                                            (HMENU)ID_HWND_BIN,
                                            GetModuleHandle(NULL),
                                            NULL);
                 
                 SendMessage(GetDlgItem(hwnd,ID_HWND_HEX),WM_SETFONT,(WPARAM)hfDefault,MAKELPARAM(false,0));
                 SendMessage(GetDlgItem(hwnd,ID_HWND_DEC),WM_SETFONT,(WPARAM)hfDefault,MAKELPARAM(false,0));
                 SendMessage(GetDlgItem(hwnd,ID_HWND_OCT),WM_SETFONT,(WPARAM)hfDefault,MAKELPARAM(false,0));
                 SendMessage(GetDlgItem(hwnd,ID_HWND_BIN),WM_SETFONT,(WPARAM)hfDefault,MAKELPARAM(false,0));
                 
                 hButton = CreateWindowEx(0,
                                          "BUTTON",
                                          "Convert",
                                          WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
                                          95,130,
                                          100,20,
                                          hwnd,
                                          (HMENU)ID_HWND_BUTTON,
                                          GetModuleHandle(NULL),
                                          NULL);
                 
                 SendMessage(GetDlgItem(hwnd,ID_HWND_BUTTON),WM_SETFONT,(WPARAM)hfDefault,MAKELPARAM(false,0));
                 }
            break;
            
            default:
                 return DefWindowProc(hwnd,msg,wParam,lParam);
        }
    }
    
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR nCmdLine,
                       int nCmdShow)
    {
        HWND hwnd;
        WNDCLASSEX wc;
        MSG Message;
        
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.cbWndExtra = 0;
        wc.cbClsExtra = 0;
        wc.hbrBackground = CreateSolidBrush(RGB(0,0,100));
        wc.hCursor = LoadCursor(NULL,IDC_ARROW);
        wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
        wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
        wc.lpszClassName = g_ClassName;
        wc.lpszMenuName = NULL;
        wc.lpfnWndProc = WndProc;
        wc.hInstance = hInstance;
        wc.style = CS_DBLCLKS;
        
        RegisterClassEx(&wc);
        
        hwnd = CreateWindowEx(WS_EX_TOOLWINDOW,
                              g_ClassName,
                              "Base Converter",
                              WS_SYSMENU,
                              CW_USEDEFAULT,CW_USEDEFAULT,
                              300,200,
                              HWND_DESKTOP,
                              NULL,
                              hInstance,
                              NULL);
                              
        ShowWindow(hwnd,nCmdShow);
        UpdateWindow(hwnd);
        
        while(GetMessage(&Message,NULL,0,0)>0)
        {
            TranslateMessage(&Message);
            DispatchMessage (&Message);
        }
        
        return Message.wParam;
    }

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Looked at ES_AUTOHSCROLL ?


    In your WM_COMMAND switch you are not testing for the control that generatd the message, only that it has a HIWORD = 0 (as BN_CLICKED == 0)

    STN_CLICKED also = 0

    So are SB_HORZ = 0 and SB_LINELEFT =0 ect......

    so any command msg with a HIWORD = 0 will trigger your edit to update.

    Look at the code I posted in your 'Control message handling' thread.



    MSDN
    "SB_LINELEFT
    Decrements the scroll box position; scrolls toward the left end of the data by one unit. "
    "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

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    71

    Well, i tried using...

    I tried using GET_WM_COMMAND_ID and CMD to be more specific on what messages to handle... but i still get the same problem =/. Also, if I wanted it to convert the second the person entered a virtual key i would just use virtual key messages?

    I also want to be able to allow access to the hex/binary and octal groups but i dont know how to restrict them from only being able to input the right digits.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Your callback does not return a value.
    For msgs you process you should return a value as defined in that msgs help.
    All WM_COMMAND msgs should return 0 if processed.

    If you do not process a msg ensure that you call the default processing. So all command msgs you do not specifically process need to be routed through the DefWindowProc().


    >>i dont know how to restrict them from only being able to input the right digits.

    To change the default behavior of a control is called 'subclassing'.

    Use the EN_CHANGE msg. Test each character added and only allow valid ones.

    ie on WM_COMMAND->EN_CHANGE->right edit
    Get the edit text,
    filter bad chars
    and set the edit text.
    "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

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    71

    thanks

    Ya, I found out that all I forgot to do was enabled ES_MULTILINE =/, that fixed my problem... Also I really needed to know about ES_CHANGE for my new project.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM