Activation for mouse and keyboard

This is a discussion on Activation for mouse and keyboard within the Windows Programming forums, part of the Platform Specific Boards category; Hello... I am with problems in the attached code to this menssagem. My intention is to create a class with ...

  1. #1
    A.I Programmer
    Join Date
    Mar 2007
    Location
    Teresina - Brazil
    Posts
    47

    Activation for mouse and keyboard

    Hello...

    I am with problems in the attached code to this menssagem. My intention is to create a class with option to drag and drop, I implemented this with WM_NCHITTEST.

    I am trying to create a way to keep only one active window for time, and I'm not obtaining, I think that for bad use of the messagens WM_ACTIVATE, WM_NCACTIVATE, WM_ACTIVATEAPP, WM_MOUSEACTIVATE, WM_SETFOCUS and WM_KILLFOCUS.

    I desire to activate the windows by input of the mouse and of the keyboard (a window for time).

    I appreciate any aid...
    Attached Files Attached Files

  2. #2
    A.I Programmer
    Join Date
    Mar 2007
    Location
    Teresina - Brazil
    Posts
    47
    I made, I want only one opinion about code.

    Code:
    #include <windows.h>
    
    #define CHILDCLASS   "CHILDCLASS"
    #define INACTIVATE   0
    #define ACTIVATE     1
    
    LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK ChildWinProc(HWND, UINT, WPARAM, LPARAM);
    BOOL InitChildControl();
    
    char szClassName[ ] = "WindowsApp";
    
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    
    {
       HWND hwnd;
       MSG messages;
       WNDCLASSEX wincl;
    
       wincl.hInstance = hThisInstance;
       wincl.lpszClassName = szClassName;
       wincl.lpfnWndProc = WindowProc;
       wincl.style = CS_DBLCLKS;
       wincl.cbSize = sizeof (WNDCLASSEX);
    
       wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
       wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
       wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
       wincl.lpszMenuName = NULL;
       wincl.cbClsExtra = 0;
       wincl.cbWndExtra = 0;
       wincl.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
    
       if(!RegisterClassEx(&wincl))
         return 0;
    
       if(!InitChildControl())
         return 0;
    
       hwnd = CreateWindowEx (
              0,
              szClassName,
              "Windows App",
              WS_OVERLAPPEDWINDOW,
              CW_USEDEFAULT,
              CW_USEDEFAULT,
              544,
              375,
              HWND_DESKTOP,
              NULL,
              hThisInstance,
              NULL
              );
    
       ShowWindow (hwnd, nFunsterStil);
    
       while(GetMessage(&messages, NULL, 0, 0))
       {
          if(!IsDialogMessage(hwnd,&messages))
          {
             TranslateMessage(&messages);
             DispatchMessage(&messages);
          }
       }
    
       return messages.wParam;
    }
    
    LRESULT CALLBACK ChildWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
       static RECT rc;
       long ActParamAnt;
       long ActParam = ActParamAnt = GetWindowLongPtr(hwnd, GWL_USERDATA);
    
       switch(message)
       {
          case WM_PAINT:
          {
             PAINTSTRUCT ps;
    
             GetClientRect(hwnd,&rc);
    
             if(BeginPaint(hwnd,&ps))
             {
                if(ActParam == ACTIVATE)
                {
                   FillRect(ps.hdc,&rc,(HBRUSH)4);
    
                   SetBkMode(ps.hdc,TRANSPARENT);
                   DrawText(ps.hdc,"ACTIVE",6,&rc,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
                }
                else
                {
                   FillRect(ps.hdc,&rc,(HBRUSH)13);
    
                   SetBkMode(ps.hdc,TRANSPARENT);
                   DrawText(ps.hdc,"INACTIVE",8,&rc,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
                }
    
                EndPaint(hwnd,&ps);
             }
          }break;
    
          case WM_MOUSEACTIVATE:
          {
             if(LOWORD(lParam) == HTNOWHERE)
             {
                ActParam = INACTIVATE;
                SetFocus(hwnd);
                InvalidateRect(hwnd,NULL,TRUE);
    
                return MA_NOACTIVATE;
             }
             else
             {
                ActParam = ACTIVATE;
                SetFocus(hwnd);
                InvalidateRect(hwnd,NULL,TRUE);
    
                return MA_ACTIVATE;
             }
          }break;
    
          case WM_SETFOCUS:
          {
             ActParam = ACTIVATE;
             InvalidateRect(hwnd,NULL,TRUE);
          }break;
    
          case WM_KILLFOCUS:
          {
             ActParam = INACTIVATE;
             InvalidateRect(hwnd,NULL,TRUE);
          }break;
    
          case WM_NCLBUTTONDBLCLK:
          {
             return 0;
          }break;
    
          case WM_NCHITTEST:
          {
             return HTCAPTION;
          }break;
    
          default:
            return DefWindowProc(hwnd, message, wParam, lParam);
       }
       
       if(ActParamAnt != ActParam)SetWindowLongPtr(hwnd, GWL_USERDATA, ActParam);
         return 0;
    }
    
    BOOL InitChildControl()
    {
       WNDCLASSEX Wnd;
    
       Wnd.cbSize = sizeof(WNDCLASSEX);
       Wnd.lpszClassName = CHILDCLASS;
       Wnd.lpfnWndProc = ChildWinProc;
       Wnd.hInstance = GetModuleHandle(NULL);
       Wnd.style = CS_HREDRAW|CS_VREDRAW;
       Wnd.hIcon = LoadIcon (NULL, IDI_APPLICATION);
       Wnd.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
       Wnd.hCursor = LoadCursor (NULL, IDC_ARROW);
       Wnd.lpszMenuName = NULL;
       Wnd.cbClsExtra = 0;
       Wnd.cbWndExtra = 0;
       Wnd.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
    
       if(!RegisterClassEx(&Wnd))
       {
          return FALSE;
       }
    
       return TRUE;
    }
    
    LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
       static HWND Control[4];
    
       switch (message)
       {
          case WM_CREATE:
          {
             Control[0] = CreateWindow(CHILDCLASS,"",WS_CHILD|WS_VISIBLE|WS_TABSTOP,10,10,85,25,hwnd,NULL,GetModuleHandle(NULL),NULL);
             Control[1] = CreateWindow(CHILDCLASS,"",WS_CHILD|WS_VISIBLE|WS_TABSTOP,110,10,85,25,hwnd,NULL,GetModuleHandle(NULL),NULL);
             Control[2] = CreateWindow(CHILDCLASS,"",WS_CHILD|WS_VISIBLE|WS_TABSTOP,210,10,85,25,hwnd,NULL,GetModuleHandle(NULL),NULL);
             Control[3] = CreateWindow(CHILDCLASS,"",WS_CHILD|WS_VISIBLE|WS_TABSTOP,310,10,85,25,hwnd,NULL,GetModuleHandle(NULL),NULL);
          }break;
    
          case WM_DESTROY:
            PostQuitMessage (0);
            break;
    
          default:
            return DefWindowProc(hwnd, message, wParam, lParam);
       }
    
       return 0;
    }
    bye

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting keyboard and mouse in linux
    By sameer.nalwade in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 04:24 AM
  2. Keyboard port using other that a keyboard
    By antoinelac in forum C++ Programming
    Replies: 4
    Last Post: 06-12-2008, 03:46 PM
  3. Keyboard focus without activation?
    By kgen in forum Windows Programming
    Replies: 3
    Last Post: 01-07-2008, 02:25 PM
  4. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  5. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 04:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21