Thread: HotKey control

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    35

    HotKey control

    HI! I'd like to use Hot key control (HOTKEY_CLASS). I call function SendMessage to obtain hotkey -
    Code:
    DWORD dw = SendMessage(hHKwnd, HKM_GETHOTKEY, 0, 0);
    Then i want to register this hot key -
    Code:
    RegisterHotKey(hWnd, 0, HIWORD(dw), LOWORD(dw));
    And when I receive WM_HOTKEY message nothing happens. I think i don't use correctly dw variable.
    Tell me, please, where is my mistake.
    Thanks!
    im from LMoldovaZ

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    If you use HKM_GETHOKEY then use HKM_SETHOTKEY and not RegisterHotKey as you have done. In any event, HKM_GETHOTKEY returns a WORD which would require use of LOBYTE and HIBYTE macros to get at the relevant key data.

    This msdn page contains more information and specific examples.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    35
    Thanks a lot! Finally it works!
    im from LMoldovaZ

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    35
    Again problem =(
    After i get hotkey, i write it to file.

    Code:
    w = SendDlgItemMessage(hDlg, id, HKM_GETHOTKEY, 0, 0);
    ltoa(w, c2, 10);
    WriteFile(hFile, c2, strlen(c2), &dw, NULL);
    Next time, when my application sarts, i read data from file, and then transform it back to WORD(to int), and try to put into HotKey control:
    Code:
    WORD w;
    ...
    ReadFile(hFile, cCont, GetFileSize(hFile, 0), &dw, NULL);
    w = atoi(cCont);
    SendDlgItemMessage(hDlg, EB_OPEN, HKM_SETHOTKEY, HIWORD(w), LOWORD(w));
    After this operations my HotKey control became empty. Where is the problem?
    im from LMoldovaZ

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The HKM_SETKEYWORD message requires the lParam to be zero. If you refer back to the example page I linked to earlier in this thread, you'll see that you don't have to do anything special with the return value from HKM_GETKEYWORD to use it with HKM_SETKEYWORD, eg:
    Code:
    SendDlgItemMessage(hDlg, EB_OPEN, HKM_SETHOTKEY, w, 0);
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (Multiline) Edit Control Limit
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-17-2008, 11:56 AM
  2. line number on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2008, 07:58 AM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM