Keyboard event handling on List view
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Keyboard event handling on List view

  1. #1
    Join Date
    Apr 2013
    Posts
    77

    Keyboard event handling on List view

    Hi all,
    In my win 32 application,I have adilaog box and inside that one list view control to display some records.I want to use Find dialogue box for this List view.
    1.How can i identify Cntrl+f event under LVN_KEYDOWN
    2.I registered the FINDMESSAGESTRING in Win main function.and written the handler for FR_FINDNXT on default case of DialogProc.But control is not going to this handler.
    Code:
    //Dialog procedure
    extern UINT uFindReplaceMsg; // message identifier FINDMSGSTRING decared and registerd in main file
    HWND HdlgFindOrReplce = NULL;     // handle to Find dialog box
    
    LRESULT CALLBACK DlgtProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    
     switch (uMsg)
    {
    case WM_INITDIALOG://setting the items & subitem values
    break;
    case WM_NOTIFY:
      switch(LOWORD(wParam))
     {
         case IDC_LISTVIEW:
          switch(((LPNMHDR)lParam)->code)
         {
             case LVN_KEYDOWN:
           //wat condition i have to write for Cntrl+F??
             //creating the find dialog box
              break;
           }
         break;
     }
    break;
    default:
      {
          LPFINDREPLACE lpfr;
          if ( uMsg == uFindReplaceMsg)
    		{
    			// Get pointer to FINDREPLACE structure from lParam.
    			lpfr = (LPFINDREPLACE)lParam;
    			// If the FR_DIALOGTERM flag is set, 
    			// invalidate the handle identifying the dialog box. 
    
    			if (lpfr->Flags & FR_DIALOGTERM)
    			{ 
    				HdlgFindOrReplce = NULL; 
    				return 0; 
    			} 
    
    			// If the FR_FINDNEXT flag is set, 
    			// call the application-defined search routine
    			// to search for the requested string. 
    			if ((lpfr->Flags & FR_FINDNEXT))
    			{//Handler of find next
    				}
       }
    }		
    }

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,266

    Re: Keyboard event handling on List view

    1) See Victor's response here from your other thread
    http://forums.codeguru.com/showthrea...dal-dialog-box
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Apr 2013
    Posts
    77

    Re: Keyboard event handling on List view

    Quote Originally Posted by 2kaud View Post
    1) See Victor's response here from your other thread
    http://forums.codeguru.com/showthrea...dal-dialog-box
    K.i got answer for my first question in another way.by using the structure NMLVKEYDOWN.What about my second problem?

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,286

    Re: Keyboard event handling on List view

    Quote Originally Posted by manjut19 View Post
    2.I registered the FINDMESSAGESTRING in Win main function.and written the handler for FR_FINDNXT on default case of DialogProc.But control is not going to this handler.
    Where and how did you register the FINDMESSAGESTRING? Show your code.
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 2013
    Posts
    77

    Re: Keyboard event handling on List view

    Quote Originally Posted by VictorN View Post
    Where and how did you register the FINDMESSAGESTRING? Show your code.
    Code:
    Main.cpp//Another file
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine,
                       int nCmdShow)
    {
        
    	//InitCommonControls();
    	WNDCLASSEX wcex;
        wcex.cbSize = sizeof(WNDCLASSEX);
        wcex.style          = CS_HREDRAW | CS_VREDRAW;;
        wcex.lpfnWndProc    = WndProc;
        wcex.cbClsExtra     = 0;
        wcex.cbWndExtra     = 0;
        wcex.hInstance      = hInstance;
        wcex.hIcon          = (HICON) LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1),IMAGE_ICON,32,32,0);
        wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
        wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+11);
        wcex.lpszMenuName   = MAKEINTRESOURCE (IDR_MENU1);
        wcex.lpszClassName  = szWindowClass;
       wcex.hIconSm        = (HICON) LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON2),IMAGE_ICON,32,32,0);
    	
        if (!RegisterClassEx(&wcex))
        {
            MessageBox(NULL,
                _T("Call to RegisterClassEx failed!"),
                _T("ladder editor"),
                NULL);
    
            return 1;
        }
    	
    	
    if(!SetUpMDIChildWindowClass(hInstance))
    		return 0;
    
    
        hInst = hInstance; // Store instance handle in our global variable
    
        
        HWND hWnd = CreateWindow(
            szWindowClass,
            szTitle,
            WS_OVERLAPPEDWINDOW   ,
            CW_USEDEFAULT, CW_USEDEFAULT,
            CW_USEDEFAULT, CW_USEDEFAULT,
            NULL,
            NULL,
            hInstance,
            NULL
        );
    
        if (!hWnd)
        {
            MessageBox(NULL,
                _T("Call to RegisterClassEx failed!"),
                _T("ladder editor"),
                NULL);
    
            return 1;
        }
    	
    	
    	g_hMainWindow = hWnd;
    	ShowWindow(hWnd,SW_MAXIMIZE);
        UpdateWindow(hWnd);
    	//Regestered FINDMSGSTRING
    	uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);
    	// Main message loop:
        MSG msg;
    
    	
        while (GetMessage(&msg, NULL, 0, 0))
        {
    		 TranslateMessage(&msg); 
    		 DispatchMessage(&msg);
    	}
    
    	return (int) msg.wParam;
    }
    Last edited by manjut19; August 22nd, 2013 at 04:48 AM.

  6. #6
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,286

    Re: Keyboard event handling on List view

    OK!
    Did you debug your code to be sure uFindReplaceMsg is a valid message ID?
    Are you sure your find/replace dialog sends messages to your main dialog?
    Victor Nijegorodov

  7. #7
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,266

    Re: Keyboard event handling on List view

    "When the dialog box is open, your main message loop must include a call to the IsDialogMessage function. Pass a handle to the dialog box as a parameter in the IsDialogMessage call. This ensures that the dialog box correctly processes keyboard messages."

    http://msdn.microsoft.com/en-us/libr...x#finding_text
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  8. #8
    Join Date
    Apr 2013
    Posts
    77

    Re: Keyboard event handling on List view

    Quote Originally Posted by VictorN View Post
    OK!
    Did you debug your code to be sure uFindReplaceMsg is a valid message ID?
    Are you sure your find/replace dialog sends messages to your main dialog?
    Yes I debugged the code uFindReplaceMsg getting a valid message id.There are only 2 buttons on my Find dialog box,FinNext and Cancel,Cancel is closing the dailog box(Find),But FindNext is not giving any notification
    Last edited by manjut19; August 22nd, 2013 at 06:40 AM.

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,927

    Re: Keyboard event handling on List view

    Quote Originally Posted by manjut19 View Post
    But FindNext is not giving any notification
    Well, now it's time to show your code for "giving a notification".
    Best regards,
    Igor

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center