April 29, 2024, 03:59:55 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Call a window which has no focus

Started by JoaoAfonso, December 14, 2008, 09:52:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JoaoAfonso

Good morning.

I have another simple question to make: if I minimize one of my programs to system tray, how can I call it again using a key (example: "F1")? I worked with @idkeydown and getkeystate before, but those commands need my program being the one with the focus...

Thanks in advance
JoÃÆ'ƒÂÃ,£o Afonso
Viriato
-----------------
Iberia MUD
www.iberiamud.com
iberiamud.com:5900

JoaoAfonso

After search abit more, I found out a solution that can do what I wanted to test, what is called a keyboard hook (got it from disable_keys.iba, from the old IB archive).

'#ifndef _WIN32_WINNT
'#define _WIN32_WINNT 0x0400
'#include <Windows.h>
$include "windows.inc"

type KBDLLHOOKSTRUCT
   int vkCode
   int scanCode
   int flags
   int time
   pointer dwExtraInfo
endtype

const LLKHF_ALTDOWN = (0x2000 >> 8)
const WH_KEYBOARD_LL = 13

'LRESULT CALLBACK LowLevelKeyboardProc(int nCode,
'   WPARAM wParam, LPARAM lParam) {
sub LowLevelKeyboardProc(nCode:int, wParam:uint, lParam:pointer)

'   bool fEatKeystroke = FALSE;
   int fEatKeystroke:fEatKeystroke = false

'   if (nCode == HC_ACTION) {
   if (nCode = HC_ACTION)
'      switch (wParam) {
      select (wParam)
'      case WM_KEYDOWN:  case WM_SYSKEYDOWN:
'      case WM_KEYUP:    case WM_SYSKEYUP:
      case WM_KEYDOWN
      case& WM_SYSKEYDOWN
      case& WM_KEYUP
      case& WM_SYSKEYUP
'         PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) lParam;
         KBDLLHOOKSTRUCT p : p = *<KBDLLHOOKSTRUCT>lParam
         
'         fEatKeystroke =
'            ((p->vkCode == VK_TAB) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
'            ((p->vkCode == VK_ESCAPE) &&
'            ((p->flags & LLKHF_ALTDOWN) != 0)) ||
'            ((p->vkCode == VK_ESCAPE) && ((GetKeyState(VK_CONTROL) &
'             0x8000) != 0)) ||
'             ((p->vkCode == VK_DELETE) ((GetKeyState(VK_CONTROL) &
'             0x8000) != 0) && (p->flags & LLKHF_ALTDOWN != 0)) ;
         fEatKeystroke = _
            ((p.vkCode = VK_TAB) and ((p.flags & LLKHF_ALTDOWN) <> 0)) or _
            ((p.vkCode = VK_ESCAPE) and ((p.flags & LLKHF_ALTDOWN) <> 0)) or _
            ((p.vkCode = VK_ESCAPE) and ((_GetKeyState(VK_CONTROL) & 0x8000) <> 0))
'         break;
'      }
      endselect
'   }
   endif
   if (fEatKeystroke) then return 1 else return _CallNextHookEx(NULL, nCode, wParam, lParam)
'   return(fEatKeystroke ? 1 : CallNextHookEx(NULL, nCode, wParam,
'          lParam));
'}
endsub

'/////////////////////////////////////////////////////////////////////////


'int WINAPI WinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int) {

'   // Install the low-level keyboard & mouse hooks
'   HHOOK hhkLowLevelKybd  = SetWindowsHookEx(WH_KEYBOARD_LL,
'      LowLevelKeyboardProc, hinstExe, 0);
   int hhkLowLevelKybd
   hhkLowLevelKybd = _SetWindowsHookEx(WH_KEYBOARD_LL, &LowLevelKeyboardProc, _GetModuleHandle(NULL), 0)

'   // Keep this app running until we're told to stop
'   MessageBox(NULL,
'      TEXT("Alt+Esc, Ctrl+Esc, and Alt+Tab are now disabled.\n")
'      TEXT("Click \"Ok\" to terminate this application and re-enable
'            these keys."),
'      TEXT("Disable Low-Level Keys"), 4);
   messagebox(Null, "Alt+Esc, Ctrl+Esc, and Alt+Tab are now disabled.\n" + _
      "Click \"Ok\" to terminate this application and re-enable these keys.", "Disable Low-Level Keys", 0)
   _UnhookWindowsHookEx(hhkLowLevelKybd)

'   return(0);
'}
'#endif


JoÃÆ'ƒÂÃ,£o Afonso
Viriato
-----------------
Iberia MUD
www.iberiamud.com
iberiamud.com:5900