Results 1 to 14 of 14

Thread: Backspace is pressed

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Backspace is pressed

    How do I know when the Backspace is pressed in a combobox?
    Baaaaaaaaah

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    you should get a WM_KEYDOWN 8
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Yes I should, but I is a combobox so I don't get that message. I may need to subclass it but I don't know.
    Baaaaaaaaah

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    yeah, that would do
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    What do you mean you don't know how to subclass it. It is not VB.
    Just handle that message in the WindowProc.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  6. #6
    Megatron
    Guest
    Try this:

    Add these to your globals
    Code:
    LRESULT CALLBACK ComboBoxProc(HWND, UINT, WPARAM, LPARAM); 		
    WNDPROC wOldProc;
    Add these to the WM_CREATE and WM_CLOSE events of your main WinProc.
    Code:
    case WM_CREATE: 
    {
    	hCbo = CreateWindowEx(NULL, "ComboBox", NULL, CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE, 32, 32, 128, 128, hWnd, NULL,gInst,NULL);
    	SendMessage(hCbo, CB_ADDSTRING, 0, (LPARAM) "Zero");
    	SendMessage(hCbo, CB_ADDSTRING, 0, (LPARAM) "One");
    	SendMessage(hCbo, CB_ADDSTRING, 0, (LPARAM) "Two");
                    // Subclass it
    	wOldProc = (WNDPROC)SetWindowLong(hCbo, GWL_WNDPROC, (LONG) &ComboBoxProc);
    	return 0;
    }
    case WM_CLOSE:
    	SetWindowLong(hCbo, GWL_WNDPROC, (LONG)wOldProc);
    	DestroyWindow(hWnd);
    	return 0;
    This will be your ComBox procedure:
    Code:
    LRESULT CALLBACK ComboBoxProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	if( (uMsg == WM_KEYDOWN) && (wParam == 8) )
    	{
    		// Add code here
    		MessageBox(NULL, "Backspace pressed", NULL, NULL);
    	}
    
    	return CallWindowProc(wOldProc, hWnd, uMsg, wParam, lParam);
    }

  7. #7
    Megatron
    Guest
    Originally posted by Vlatko
    What do you mean you don't know how to subclass it. It is not VB.
    Just handle that message in the WindowProc.
    No, you can't capture the messages of the combobox from the window procedure of the parent.

  8. #8

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Thanks megatron. I think I was doing some think wrong when handling the "WM_KEYDOWN" message after subclassing.
    It is almost autocomplete now but there is just one more problem:

    First look at the image

    I have some words in the combobox like "C:\", "C:\windows". When I type "C", it completes with the mathcing word which is "C:\", and then it heighlights ":\" as it does in the other autocomplete comboboxes.

    Now the problem is that I can't move the caret using the left/right arrow keys...you know

    Here is the code I am using in the CB_EDITUPDATE message that actually completes the word:

    PHP Code:
               char edtext[2];
               
    USHORT theindex;
               
            case 
    CBN_EDITCHANGE:
                if(!
    isback)
                {
                    
    GetWindowText(cbhwndedtextGetWindowTextLength(cbhwnd) + 1);
                    if(
    SendMessage(cbhwndCB_FINDSTRING, (WPARAM)-1, (LPARAM)(LPCSTR)edtext) != CB_ERR)
                    {
                        
    theindex GetWindowTextLength(cbhwnd);
                        
    SendMessage(cbhwnd,CB_SETCURSELSendMessage(cbhwndCB_FINDSTRING, (WPARAM)-1, (LPARAM)(LPCSTR)edtext), 0);
                        
    SendMessage(cbhwndCB_SETEDITSEL,0MAKELPARAM(theindex,GetWindowTextLength(cbhwnd)));
                    }
                }
                
           return 
    TRUE
    isback is a global variable that tells if the backspace is pressed or not. Here is code that I am using to tell if it is pressed or not using the subclassing technique:

    PHP Code:
    switch(msg)
        {
        case 
    WM_KEYDOWN:
            if(
    wparam == 8)
            {
                
    isback TRUE;
            }
            else
            {
                
    isback FALSE;
            }
            return 
    0;
        } 
    So, why can't I move the caret using the arrow keys so that I don't have to type the whole word if it highlights it?
    Attached Images Attached Images  
    Baaaaaaaaah

  9. #9

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    It is ok now. I used the message "WM_KEYUP" instead of "WM_KEYDOWN" and it is all working now

    Thanks a lot!
    Baaaaaaaaah

  10. #10

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Ohhh NO!

    I got the caret thingy working but then I lots the backspace handling. How do I get both at a time?

    I am using the same code except that I am handling the "WM_KEYUP" message instead of "WM_KEYDOWN"
    Baaaaaaaaah

  11. #11
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    No, you can't capture the messages of the combobox from the window procedure of the parent.
    I know that Megatron. I didn't mean the WindowProc of the parent but the combobox's own procedure.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  12. #12

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    this thread is stopped Come on guys, it is not finished yet. I still have the above problem
    Baaaaaaaaah

  13. #13
    Lively Member
    Join Date
    Dec 2000
    Location
    Indiana
    Posts
    73

    Subclassing isnt working right

    For some reason, my subclassing isnt working right. I'm trying to do this too, but for some reason, it isnt working. Code:
    Code:
    #include <windows.h>
    
    const char g_szClassName[] = "myWindowClass";
    
    #define IDC_COMBOBOX	9001
    #define FixFonts(control) {SendDlgItemMessage(hwnd, control, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0));}
    
    HINSTANCE hInstance;
    WNDPROC wOldProc;
    
    LRESULT CALLBACK ComboBoxProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	switch(uMsg)
    	{
    	case WM_KEYUP:
    		MessageBox(hwnd,"","",0);
    		break;
    	default:
    		return(DefWindowProc(hwnd,uMsg,wParam,lParam));
    	}
    	return(0);
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch(msg)
        {
            case WM_CLOSE:
    			SetWindowLong(GetDlgItem(hwnd,IDC_COMBOBOX), GWL_WNDPROC, (LONG)wOldProc);
                DestroyWindow(hwnd);
    			break;
            case WM_DESTROY:
                PostQuitMessage(0);
    			break;
    		case WM_CREATE:
    			CreateWindow("COMBOBOX","",WS_CHILD | WS_VISIBLE | CBS_DROPDOWN,0,0,100,100,hwnd,(HMENU)IDC_COMBOBOX,hInstance,0);
    			FixFonts(IDC_COMBOBOX);
    			SendMessage(GetDlgItem(hwnd,IDC_COMBOBOX), CB_ADDSTRING, 0, (LPARAM) "Zero");
    			SendMessage(GetDlgItem(hwnd,IDC_COMBOBOX), CB_ADDSTRING, 0, (LPARAM) "One");
    			SendMessage(GetDlgItem(hwnd,IDC_COMBOBOX), CB_ADDSTRING, 0, (LPARAM) "Two");
    			wOldProc = (WNDPROC)SetWindowLong(GetDlgItem(hwnd,IDC_COMBOBOX), GWL_WNDPROC, (LONG) &ComboBoxProc);
    			SetWindowLong(GetDlgItem(hwnd,IDC_COMBOBOX), GWL_STYLE	, WS_CHILD | WS_VISIBLE | CBS_DROPDOWN);
    			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;
        ::hInstance=hInstance;
        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_BTNFACE+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;
        }
    
        hwnd = CreateWindowEx(
            0,
            g_szClassName,
            "Autocomplete Combobox Test",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
            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))
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return Msg.wParam;
    }
    Any ideas?

  14. #14

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Try this code. I have put the comments on which line is added or changed:

    PHP Code:
    #include <windows.h>

    const char g_szClassName[] = "myWindowClass";

    #define IDC_COMBOBOX    9001
    #define FixFonts(control) {SendDlgItemMessage(hwnd, control, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0));}

    HINSTANCE hInstance;
    WNDPROC wOldProc;
    //A new declaration for the Handle of the editbox in the combobox
    HWND edhwnd;

    LRESULT CALLBACK ComboBoxProc(HWND hwndUINT uMsgWPARAM wParamLPARAM lParam)
    {
        switch(
    uMsg)
        {
        case 
    WM_KEYUP:
            
    MessageBox(hwnd,"","",0);
            break;
        default:
            return 
    CallWindowProc(wOldProchwnd,uMsg,wParam,lParam); //Changed to CallWindowProc
        
    }
        return(
    0);
    }

    LRESULT CALLBACK WndProc(HWND hwndUINT msgWPARAM wParamLPARAM lParam)
    {
        switch(
    msg)
        {
            case 
    WM_CLOSE:
                
    //This is also changed. Changed the handle to editbox handle
                
    SetWindowLong(edhwndGWL_WNDPROC, (LONG)wOldProc);
                
    DestroyWindow(hwnd);
                break;
            case 
    WM_DESTROY:
                
    PostQuitMessage(0);
                break;
            case 
    WM_CREATE:
                
    CreateWindow("COMBOBOX","",WS_CHILD WS_VISIBLE CBS_DROPDOWN,0,0,100,100,hwnd,(HMENU)IDC_COMBOBOX,hInstance,0);
                
    FixFonts(IDC_COMBOBOX);
                
    SendMessage(GetDlgItem(hwnd,IDC_COMBOBOX), CB_ADDSTRING0, (LPARAM"Zero");
                
    SendMessage(GetDlgItem(hwnd,IDC_COMBOBOX), CB_ADDSTRING0, (LPARAM"One");
                
    SendMessage(GetDlgItem(hwnd,IDC_COMBOBOX), CB_ADDSTRING0, (LPARAM"Two");
                
    //New Stuff Added here
                //We get the handle of the editbox in the combobox because that
                //is the window in which WM_KEYUP message occurs
                
    POINT pt;
                
    pt.3;
                
    pt.3;
                
    edhwnd ChildWindowFromPoint(GetDlgItem(hwnd,IDC_COMBOBOX), pt);
                
    //-----------------------------------------------------------
                //Now we use the editbox handle - not the combobox handle
                
    wOldProc = (WNDPROC)SetWindowLong(edhwndGWL_WNDPROC, (LONG) &ComboBoxProc);
                
    SetWindowLong(GetDlgItem(hwnd,IDC_COMBOBOX), GWL_STYLE    GetWindowLong(GetDlgItem(hwnd,IDC_COMBOBOX), GWL_STYLE) | WS_CHILD WS_VISIBLE CBS_DROPDOWN); //Changed this line
                
    break;
            default:
                return 
    DefWindowProc(hwndmsgwParamlParam);
        }
        return 
    0;
    }

    int WINAPI WinMain(HINSTANCE hInstanceHINSTANCE hPrevInstance,
        
    LPSTR lpCmdLineint nCmdShow)
    {
        
    WNDCLASSEX wc;
        
    HWND hwnd;
        
    MSG Msg;
        ::
    hInstance=hInstance;
        
    wc.cbSize        sizeof(WNDCLASSEX);
        
    wc.style         0;
        
    wc.lpfnWndProc   WndProc;
        
    wc.cbClsExtra    0;
        
    wc.cbWndExtra    0;
        
    wc.hInstance     hInstance;
        
    wc.hIcon         LoadIcon(NULLIDI_APPLICATION);
        
    wc.hCursor       LoadCursor(NULLIDC_ARROW);
        
    wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
        
    wc.lpszMenuName  NULL;
        
    wc.lpszClassName g_szClassName;
        
    wc.hIconSm       LoadIcon(NULLIDI_APPLICATION);

        if(!
    RegisterClassEx(&wc))
        {
            
    MessageBox(NULL"Window Registration Failed!""Error!",
                
    MB_ICONEXCLAMATION MB_OK);
            return 
    0;
        }

        
    hwnd CreateWindowEx(
            
    0,
            
    g_szClassName,
            
    "Autocomplete Combobox Test",
            
    WS_OVERLAPPEDWINDOW,
            
    CW_USEDEFAULTCW_USEDEFAULT240120,
            
    NULLNULLhInstanceNULL);

        if(
    hwnd == NULL)
        {
            
    MessageBox(NULL"Window Creation Failed!""Error!",
                
    MB_ICONEXCLAMATION MB_OK);
            return 
    0;
        }

        
    ShowWindow(hwndnCmdShow);
        
    UpdateWindow(hwnd);

        while(
    GetMessage(&MsgNULL00))
        {
            
    TranslateMessage(&Msg);
            
    DispatchMessage(&Msg);
        }
        return 
    Msg.wParam;
    }
    //-------------------------------------------------------------------------------- 
    Baaaaaaaaah

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width