CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Join Date
    Nov 2010
    Posts
    10

    [RESOLVED] ListView Hotkeys with Checkbox.

    How would one go about creating a hotkey that checks/unchecks the checkboxes of a listview and activates an assembly script?

    STYLES: ListView_SetExtendedListViewStyle(hWndListView, LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES);

    Solution and Example code for others:
    Code:
    INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 
    {
      switch(uMsg) 
      {
      case WM_INITDIALOG:
        //Register ListViews
        InitListView(hwndDlg, IDC_LIST1);
        InitListView1(hwndDlg, IDC_LIST2);
        //Register Hotkeys
        RegisterHotKey(hwndDlg, IDC_HK1, MOD_SHIFT , VK_F1 );
        break;
    
      case WM_HOTKEY: {
        //GodMode 
        switch( wParam ) {
          case IDC_HK1: {
            GodExit ^= true;
            ListView_SetCheckState( GetDlgItem( hwndDlg, IDC_LIST1 ), 0, GodExit );
            break;
          } default: {
            return false;
          }
        }
    
        return true;
      }
    Last edited by TodayISawMyHeroFall; November 23rd, 2010 at 08:59 AM.

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: ListView Hotkeys

    Quote Originally Posted by TodayISawMyHeroFall
    How would one go about creating a hotkey that checks/unchecks the checkboxes of a listview
    The one seems never need the one. From MSDN
    You can obtain the state of the check box for a given item with ListView_GetCheckState. To set the check state, use ListView_SetCheckState. If this style is set, the list-view control automatically toggles the check state when the user clicks the check box or presses the space bar.
    Quote Originally Posted by TodayISawMyHeroFall
    and activates an assembly script?
    Never heard about assembly script.
    Last edited by Igor Vartanov; November 20th, 2010 at 12:13 PM.
    Best regards,
    Igor

  3. #3
    Join Date
    Nov 2010
    Posts
    10

    Re: ListView Hotkeys

    Ok so..

    ListView_GetCheckState(hWndListView, 0);
    ListView_SetCheckState(hWndListView, 0, 0);

    Now how do I get a Registered Hotkey to check/uncheck it?

    Edit:
    case WM_HOTKEY:
    //GodMode
    if (wParam == IDC_HK1)
    {
    if (GodExit == FALSE)
    {
    GodExit = TRUE;
    ListView_SetCheckState(hWndListView, 0, 0);
    }
    else if )GodExit == True)
    {
    GodExit = FALSE;
    ListView_SetCheckState(hWndListView, 0, 1);

    Doesn't work..
    Last edited by TodayISawMyHeroFall; November 23rd, 2010 at 04:50 AM.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ListView Hotkeys

    Quote Originally Posted by TodayISawMyHeroFall View Post
    Ok so..

    ListView_GetCheckState(hWndListView, 0);
    ListView_SetCheckState(hWndListView, 0, 0);

    Now how do I get a Registered Hotkey to check/uncheck it?
    1. ListView_GetCheckState(hWndListView, 0); is not a user action, so why implement any "hot key" for it?
    2. You don't need to call
    Code:
    ListView_SetCheckState(hWndListView, 0, 0);
    as a response to "hot key" because List Control will make all needed actions for you after use presses the space bar (and Igor has already pointed it out!).
    Victor Nijegorodov

  5. #5
    Join Date
    Nov 2010
    Posts
    10

    Re: ListView Hotkeys

    I'm not quite understanding you.. Could you dumb it down for me alittle bit more? Also, Example code would help greatly!

    Edit:
    What I currently have atm and isn't working..

    Code:
    INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 
    {
      switch(uMsg) 
      {
      case WM_INITDIALOG:
        //Register ListViews
        InitListView(hwndDlg, IDC_LIST1);
        InitListView1(hwndDlg, IDC_LIST2);
        //Register Hotkeys
        RegisterHotKey(hwndDlg, IDC_HK1, MOD_SHIFT , VK_F1 );
        break;
    
      case WM_HOTKEY:
        //GodMode
        if (wParam == IDC_HK1)
        {
          if (GodExit == FALSE)
          {
            GodExit = TRUE;
            ListView_GetCheckState(hwndDlg, 0);
            ListView_SetCheckState(hwndDlg, 0, 0);
          }
          else if (GodExit == TRUE)
          {
            GodExit = FALSE;
            ListView_GetCheckState(hwndDlg, 0);
            ListView_SetCheckState(hwndDlg, 0, 1);
          }
        }
    I'm SO confused lol!
    Last edited by TodayISawMyHeroFall; November 23rd, 2010 at 05:20 AM.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ListView Hotkeys

    Quote Originally Posted by TodayISawMyHeroFall View Post
    Also, Example code would help greatly!
    Again: you don't need any code to check/uncheck list control item. Please, read the post#2 carefully!
    Victor Nijegorodov

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ListView Hotkeys

    Quote Originally Posted by TodayISawMyHeroFall View Post
    ... Edit:
    What I currently have atm and isn't working..
    I see you have edited your previous posts...
    Please, edit them once more to add Code tags around code snippets. Otherwise your code is absolutely unreadable!
    Victor Nijegorodov

  8. #8
    Join Date
    Nov 2010
    Posts
    10

    Re: ListView Hotkeys

    Quote Originally Posted by VictorN View Post
    Again: you don't need any code to check/uncheck list control item. Please, read the post#2 carefully!
    I want to add Shift+F1 to activate/de-active the checkbox in row 1 of my listview.

    Quote Originally Posted by VictorN View Post
    I see you have edited your previous posts...
    Please, edit them once more to add Code tags around code snippets. Otherwise your code is absolutely unreadable!

    Done.

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ListView Hotkeys

    Quote Originally Posted by TodayISawMyHeroFall View Post
    What I currently have atm and isn't working..
    What "isn't working"?
    Did you debug your code?
    Victor Nijegorodov

  10. #10
    Join Date
    Nov 2010
    Posts
    10

    Re: ListView Hotkeys

    Compiles but does nothing.

    Code:
    WM_HOTKEY: 
    //GodMode 
    if (wParam == IDC_HK1) 
    { 
      if (GodExit == FALSE) 
      { 
        GodExit = TRUE;
        ListView_SetCheckState(GetDlgItem(hwndDlg, IDC_LIST1), 0, 1); 
      } 
      else if 
        (GodExit == TRUE) 
      { 
        GodExit = FALSE;
        ListView_SetCheckState(GetDlgItem(hwndDlg, IDC_LIST1), 0, 1);
      } 
    }

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ListView Hotkeys

    Quote Originally Posted by TodayISawMyHeroFall View Post
    Compiles but does nothing.

    Code:
    WM_HOTKEY: 
    //GodMode 
    if (wParam == IDC_HK1) 
    { 
      if (GodExit == FALSE) 
      { 
        GodExit = TRUE;
        ListView_SetCheckState(GetDlgItem(hwndDlg, IDC_LIST1), 0, 1); 
      } 
      else if 
        (GodExit == TRUE) 
      { 
        GodExit = FALSE;
        ListView_SetCheckState(GetDlgItem(hwndDlg, IDC_LIST1), 0, 1);
      } 
    }
    Well, again:
    Quote Originally Posted by VictorN View Post
    Did you debug your code?
    Victor Nijegorodov

  12. #12
    Join Date
    Nov 2010
    Posts
    10

    Re: ListView Hotkeys

    Quote Originally Posted by VictorN View Post
    Well, again:
    No. Hold up!
    Last edited by TodayISawMyHeroFall; November 23rd, 2010 at 08:38 AM.

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ListView Hotkeys

    Quote Originally Posted by TodayISawMyHeroFall View Post
    I want to add Shift+F1 to activate/de-active the checkbox in row 1 of my listview.
    BTW, don't you know that Shift+F1 is used in Windows (by default) for Context-Sensitive Help?
    Victor Nijegorodov

  14. #14
    Join Date
    Nov 2010
    Posts
    10

    Re: ListView Hotkeys

    Fixed. Check my first post edit for the solution.

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: [RESOLVED] ListView Hotkeys

    Quote Originally Posted by TodayISawMyHeroFall View Post
    Fixed. Check my first post edit for the solution.
    OK, I am now trying to check it:
    Quote Originally Posted by TodayISawMyHeroFall View Post
    How would one go about creating a hotkey that checks/unchecks the checkboxes of a listview and activates an assembly script?

    STYLES: ListView_SetExtendedListViewStyle(hWndListView, LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES);

    Solution and Example code for others:
    Code:
    INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 
    {
      switch(uMsg) 
      {
      case WM_INITDIALOG:
        //Register ListViews
        InitListView(hwndDlg, IDC_LIST1);
        InitListView1(hwndDlg, IDC_LIST2);
        //Register Hotkeys
        RegisterHotKey(hwndDlg, IDC_HK1, MOD_SHIFT , VK_F1 );
        break;
    
      case WM_HOTKEY: {
        //GodMode 
        switch( wParam ) {
          case IDC_HK1: {
            GodExit ^= true;
            ListView_SetCheckState( GetDlgItem( hwndDlg, IDC_LIST1 ), 0, GodExit ); 
            break;
          } default: {
            return false;
          }
        }
    
        return true;
      }
    Well, in this example you always check/uncheck the first (and only the first) item.
    And, BTW, what does "activates an assembly script" mean?
    Victor Nijegorodov

Page 1 of 2 12 LastLast

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

Featured