Changeset 2084 for trunk/src


Ignore:
Timestamp:
Dec 16, 1999, 1:11:49 AM (26 years ago)
Author:
sandervl
Message:

sendmessage + hook updates + misc fixes

Location:
trunk/src/user32
Files:
2 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/HOOK.CPP

    r949 r2084  
    1 /* $Id: HOOK.CPP,v 1.5 1999-09-15 23:18:47 sandervl Exp $ */
     1/* $Id: HOOK.CPP,v 1.6 1999-12-16 00:11:44 sandervl Exp $ */
    22
    33/*
    4  * Win32 hook API functions for OS/2
    5  *
    6  * Copyright 1998 Sander van Leeuwen
     4 * Windows hook functions
     5 *
     6 * Copyright 1999 Sander van Leeuwen (OS/2 Port)
     7 *
     8 * Port of Wine code (windows\hook.c; dated 990920)
     9 * All 16 bits code removed
     10 *
     11 * Copyright 1994, 1995 Alexandre Julliard
     12 *                 1996 Andrew Lewycky
     13 *
     14 * Based on investigations by Alex Korobka
    715 *
    816 *
    917 * Project Odin Software License can be found in LICENSE.TXT
    10  *
    11  */
     18 */
     19
     20/*
     21 * Warning!
     22 * A HHOOK is a 32-bit handle for compatibility with Windows 3.0 where it was
     23 * a pointer to the next function. Now it is in fact composed of a USER heap
     24 * handle in the low 16 bits and of a HOOK_MAGIC value in the high 16 bits.
     25 */
     26
    1227#include <os2win.h>
    13 #include <stdarg.h>
    14 #include "misc.h"
    15 #include "hooks.h"
    16 
    17 //******************************************************************************
    18 //******************************************************************************
    19 HHOOK WIN32API SetWindowsHookExA(int idHook, HOOKPROC hkprc, HINSTANCE hmod, DWORD dwThreadId)
    20 {
    21  HHOOK    rc;
    22  HOOKPROC_O32 os2hkprc;
    23 
    24     switch(idHook) {
    25         case WH_CALLWNDPROC:
    26                 os2hkprc = HkWindow::GetOS2Hook();
    27                 break;
    28         case WH_CBT:
     28#include "hook.h"
     29#include "win.h"
     30#include "queue.h"
     31#include "task.h"
     32#include "winproc.h"
     33#include "debugtools.h"
     34#include <misc.h>
     35#include <heapstring.h>
     36#include <vmutex.h>
     37#include <wprocess.h>
     38
     39DEFAULT_DEBUG_CHANNEL(hook)
     40
     41#include "pshpack1.h"
     42
     43  /* Hook data (pointed to by a HHOOK) */
     44typedef struct
     45{
     46    HANDLE     next;               /* 00 Next hook in chain */
     47    HOOKPROC   proc;               /* 04 Hook procedure (original) */
     48    INT        id;                 /* 08 Hook id (WH_xxx) */
     49    DWORD      ownerThread;        /* 0C Owner thread (0 for system hook) */
     50    HMODULE    ownerModule;        /* 10 Owner module */
     51    DWORD      flags;              /* 14 flags */
     52    DWORD      magic;              /* 18 magic dword */
     53} HOOKDATA;
     54
     55#include "poppack.h"
     56
     57#define HOOK_MAGIC1  ((int)'H' | (int)'K' << 8)  /* 'HK' */
     58#define HOOK_MAGIC ((HOOK_MAGIC1<<16)|HOOK_MAGIC1) // 'HKHK'
     59
     60#define CHECK_MAGIC(a) ((a != 0) && (((HOOKDATA *)a)->magic == HOOK_MAGIC))
     61
     62//Global DLL Data
     63#pragma data_seg(_GLOBALDATA)
     64static HANDLE HOOK_systemHooks[WH_NB_HOOKS] = { 0 };
     65static VMutex systemHookMutex(TRUE);
     66#pragma data_seg()
     67static HANDLE HOOK_threadHooks[WH_NB_HOOKS] = { 0 };
     68static VMutex threadHookMutex;
     69
     70typedef VOID (*HOOK_MapFunc)(INT, INT, WPARAM *, LPARAM *);
     71typedef VOID (*HOOK_UnMapFunc)(INT, INT, WPARAM, LPARAM, WPARAM,
     72                               LPARAM);
     73
     74/***********************************************************************
     75 *           HOOK_Map32ATo32W
     76 */
     77static void HOOK_Map32ATo32W(INT id, INT code, WPARAM *pwParam,
     78                             LPARAM *plParam)
     79{
     80    if (id == WH_CBT && code == HCBT_CREATEWND)
     81    {
     82        LPCBT_CREATEWNDA lpcbtcwA = (LPCBT_CREATEWNDA)*plParam;
     83        LPCBT_CREATEWNDW lpcbtcwW = (LPCBT_CREATEWNDW)HeapAlloc(GetProcessHeap(), 0,
     84                                                                sizeof(*lpcbtcwW) );
     85        lpcbtcwW->lpcs = (CREATESTRUCTW*)HeapAlloc( GetProcessHeap(), 0, sizeof(*lpcbtcwW->lpcs) );
     86
     87        lpcbtcwW->hwndInsertAfter = lpcbtcwA->hwndInsertAfter;
     88        *lpcbtcwW->lpcs = *(LPCREATESTRUCTW)lpcbtcwA->lpcs;
     89
     90        if (HIWORD(lpcbtcwA->lpcs->lpszName))
    2991        {
    30                 HkCBT *hkhook = new HkCBT(0, hkprc, hmod, dwThreadId);;
    31 #ifdef DEBUG
    32                 WriteLog("OS2SetWindowsHookExA WH_CBT %X, %X, %X, %X\n", idHook, hkprc, hmod, dwThreadId);
     92            lpcbtcwW->lpcs->lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
     93                                                    lpcbtcwA->lpcs->lpszName );
     94        }
     95        else
     96          lpcbtcwW->lpcs->lpszName = (LPWSTR)lpcbtcwA->lpcs->lpszName;
     97
     98        if (HIWORD(lpcbtcwA->lpcs->lpszClass))
     99        {
     100            lpcbtcwW->lpcs->lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
     101                                                   lpcbtcwA->lpcs->lpszClass );
     102        }
     103        else
     104          lpcbtcwW->lpcs->lpszClass = (LPCWSTR)lpcbtcwA->lpcs->lpszClass;
     105        *plParam = (LPARAM)lpcbtcwW;
     106    }
     107    return;
     108}
     109
     110
     111/***********************************************************************
     112 *           HOOK_UnMap32ATo32W
     113 */
     114static void HOOK_UnMap32ATo32W(INT id, INT code, WPARAM wParamOrig,
     115                               LPARAM lParamOrig, WPARAM wParam,
     116                               LPARAM lParam)
     117{
     118    if (id == WH_CBT && code == HCBT_CREATEWND)
     119    {
     120        LPCBT_CREATEWNDW lpcbtcwW = (LPCBT_CREATEWNDW)lParam;
     121        if (HIWORD(lpcbtcwW->lpcs->lpszName))
     122            HeapFree( GetProcessHeap(), 0, (LPWSTR)lpcbtcwW->lpcs->lpszName );
     123        if (HIWORD(lpcbtcwW->lpcs->lpszClass))
     124            HeapFree( GetProcessHeap(), 0, (LPWSTR)lpcbtcwW->lpcs->lpszClass );
     125        HeapFree( GetProcessHeap(), 0, lpcbtcwW->lpcs );
     126        HeapFree( GetProcessHeap(), 0, lpcbtcwW );
     127    }
     128    return;
     129}
     130
     131
     132/***********************************************************************
     133 *           HOOK_Map32WTo32A
     134 */
     135static void HOOK_Map32WTo32A(INT id, INT code, WPARAM *pwParam,
     136                             LPARAM *plParam)
     137{
     138    if (id == WH_CBT && code == HCBT_CREATEWND)
     139    {
     140        LPCBT_CREATEWNDW lpcbtcwW = (LPCBT_CREATEWNDW)*plParam;
     141        LPCBT_CREATEWNDA lpcbtcwA = (LPCBT_CREATEWNDA)HeapAlloc(GetProcessHeap(), 0,
     142                                                                sizeof(*lpcbtcwA) );
     143        lpcbtcwA->lpcs = (CREATESTRUCTA*)HeapAlloc( GetProcessHeap(), 0, sizeof(*lpcbtcwA->lpcs) );
     144
     145        lpcbtcwA->hwndInsertAfter = lpcbtcwW->hwndInsertAfter;
     146        *lpcbtcwA->lpcs = *(LPCREATESTRUCTA)lpcbtcwW->lpcs;
     147
     148        if (HIWORD(lpcbtcwW->lpcs->lpszName))
     149          lpcbtcwA->lpcs->lpszName = HEAP_strdupWtoA( GetProcessHeap(), 0,
     150                                                    lpcbtcwW->lpcs->lpszName );
     151        else
     152          lpcbtcwA->lpcs->lpszName = (LPSTR)lpcbtcwW->lpcs->lpszName;
     153
     154        if (HIWORD(lpcbtcwW->lpcs->lpszClass))
     155          lpcbtcwA->lpcs->lpszClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
     156                                                   lpcbtcwW->lpcs->lpszClass );
     157        else
     158          lpcbtcwA->lpcs->lpszClass = (LPSTR)lpcbtcwW->lpcs->lpszClass;
     159        *plParam = (LPARAM)lpcbtcwA;
     160    }
     161    return;
     162}
     163
     164
     165/***********************************************************************
     166 *           HOOK_UnMap32WTo32A
     167 */
     168static void HOOK_UnMap32WTo32A(INT id, INT code, WPARAM wParamOrig,
     169                               LPARAM lParamOrig, WPARAM wParam,
     170                               LPARAM lParam)
     171{
     172    if (id == WH_CBT && code == HCBT_CREATEWND)
     173    {
     174        LPCBT_CREATEWNDA lpcbtcwA = (LPCBT_CREATEWNDA)lParam;
     175        if (HIWORD(lpcbtcwA->lpcs->lpszName))
     176            HeapFree( GetProcessHeap(), 0, (LPSTR)lpcbtcwA->lpcs->lpszName );
     177        if (HIWORD(lpcbtcwA->lpcs->lpszClass))
     178            HeapFree( GetProcessHeap(), 0, (LPSTR)lpcbtcwA->lpcs->lpszClass );
     179        HeapFree( GetProcessHeap(), 0, lpcbtcwA->lpcs );
     180        HeapFree( GetProcessHeap(), 0, lpcbtcwA );
     181    }
     182    return;
     183}
     184
     185
     186/***********************************************************************
     187 *           Map Function Tables
     188 */
     189static const HOOK_MapFunc HOOK_MapFuncs[3][3] =
     190{
     191    { NULL, NULL,             NULL },
     192    { NULL, NULL,             HOOK_Map32ATo32W },
     193    { NULL, HOOK_Map32WTo32A, NULL }
     194};
     195
     196static const HOOK_UnMapFunc HOOK_UnMapFuncs[3][3] =
     197{
     198    { NULL, NULL,               NULL },
     199    { NULL, NULL,               HOOK_UnMap32ATo32W },
     200    { NULL, HOOK_UnMap32WTo32A, NULL }
     201};
     202
     203
     204/***********************************************************************
     205 *           Internal Functions
     206 */
     207
     208/***********************************************************************
     209 *           HOOK_GetNextHook
     210 *
     211 * Get the next hook of a given hook.
     212 */
     213static HANDLE HOOK_GetNextHook( HANDLE hook )
     214{
     215    HOOKDATA *data = (HOOKDATA *)hook;
     216
     217    if (!data || !hook) return 0;
     218    if (data->next) return data->next;
     219    if (!data->ownerThread) return 0;  /* Already system hook */
     220
     221    /* Now start enumerating the system hooks */
     222    return HOOK_systemHooks[data->id - WH_MINHOOK];
     223}
     224
     225
     226/***********************************************************************
     227 *           HOOK_GetHook
     228 *
     229 * Get the first hook for a given type.
     230 */
     231static HANDLE HOOK_GetHook( INT id, DWORD threadId )
     232{
     233  MESSAGEQUEUE *queue;
     234  HANDLE hook = 0;
     235  THDB *thdb;
     236   
     237    thdb = GetTHDBFromThreadId(threadId);
     238    if(thdb) {
     239        hook = thdb->hooks[id - WH_MINHOOK];
     240    }
     241    if (!hook) hook = HOOK_systemHooks[id - WH_MINHOOK];
     242
     243    return hook;
     244}
     245
     246
     247/***********************************************************************
     248 *           HOOK_SetHook
     249 *
     250 * Install a given hook.
     251 */
     252static HHOOK HOOK_SetHook( INT id, LPVOID proc, INT type,
     253                           HMODULE hModule, DWORD dwThreadId )
     254{
     255  HOOKDATA *data;
     256  THDB     *thdb;
     257 
     258    if ((id < WH_MINHOOK) || (id > WH_MAXHOOK) || !proc )
     259    {
     260        SetLastError(ERROR_INVALID_PARAMETER);
     261        return 0;
     262    }
     263
     264    dprintf(("Setting hook %d: %08x %04x %08lx\n",
     265             id, (UINT)proc, hModule, dwThreadId ));
     266
     267#ifndef __WIN32OS2__
     268    /* Create task queue if none present */
     269    GetFastQueue16();
     270
     271    if (id == WH_JOURNALPLAYBACK) EnableHardwareInput16(FALSE);
    33272#endif
    34                 return((HHOOK)hkhook);
     273
     274
     275    if (dwThreadId)  /* Task-specific hook */
     276    {
     277        if ((id == WH_JOURNALRECORD) || (id == WH_JOURNALPLAYBACK) ||
     278            (id == WH_SYSMSGFILTER)) {
     279                SetLastError(ERROR_INVALID_PARAMETER);
     280                return 0;  /* System-only hooks */
    35281        }
    36         case WH_DEBUG:
    37                 os2hkprc = HkDebug::GetOS2Hook();       
    38                 break;
    39         case WH_JOURNALPLAYBACK:
    40                 os2hkprc = HkJrnlPlayback::GetOS2Hook();       
    41                 break;
    42         case WH_JOURNALRECORD:
    43                 os2hkprc = HkJrnlRecord::GetOS2Hook(); 
    44                 break;
    45         case WH_GETMESSAGE:
    46                 os2hkprc = HkGetMessage::GetOS2Hook(); 
    47                 break;
    48         case WH_MOUSE:
    49                 os2hkprc = HkMouse::GetOS2Hook();       
    50                 break;
    51         case WH_KEYBOARD:
    52                 os2hkprc = HkKeyboard::GetOS2Hook();   
    53                 break;
    54         case WH_SHELL:
    55                 os2hkprc = HkShell::GetOS2Hook();       
    56                 break;
    57         case WH_SYSMSGFILTER:
    58                 os2hkprc = HkSysMsgFilter::GetOS2Hook();       
    59                 break;
    60         case WH_MSGFILTER:
    61                 os2hkprc = HkMsgFilter::GetOS2Hook();   
    62                 break;
    63     }
    64 
    65     rc = O32_SetWindowsHookEx(idHook, os2hkprc, hmod, dwThreadId);
    66 
    67     if(rc) {
    68       switch(idHook) {
    69         case WH_CALLWNDPROC:
    70                 new HkWindow(rc, hkprc, hmod, dwThreadId);
    71                 break;
    72         case WH_CBT:
    73                 break;
    74         case WH_DEBUG:
    75                 new HkDebug(rc, hkprc, hmod, dwThreadId);;     
    76                 break;
    77         case WH_JOURNALPLAYBACK:
    78                 new HkJrnlPlayback(rc, hkprc, hmod, dwThreadId);;       
    79                 break;
    80         case WH_JOURNALRECORD:
    81                 new HkJrnlRecord(rc, hkprc, hmod, dwThreadId);;
    82                 break;
    83         case WH_GETMESSAGE:
    84                 new HkGetMessage(rc, hkprc, hmod, dwThreadId);;
    85                 break;
    86         case WH_MOUSE:
    87                 new HkMouse(rc, hkprc, hmod, dwThreadId);;     
    88                 break;
    89         case WH_KEYBOARD:
    90                 new HkKeyboard(rc, hkprc, hmod, dwThreadId);;   
    91                 break;
    92         case WH_SHELL:
    93                 new HkShell(rc, hkprc, hmod, dwThreadId);;     
    94                 break;
    95         case WH_SYSMSGFILTER:
    96                 new HkSysMsgFilter(rc, hkprc, hmod, dwThreadId);;       
    97                 break;
    98         case WH_MSGFILTER:
    99                 new HkMsgFilter(rc, hkprc, hmod, dwThreadId);; 
    100                 break;
    101       }
    102     }
    103 #ifdef DEBUG
    104     WriteLog("OS2SetWindowsHookExA %X, %X, %X, %X, returned %X\n", idHook, hkprc, hmod, dwThreadId, rc);
     282    }
     283
     284    /* Create the hook structure */
     285
     286    data = (HOOKDATA *) HeapAlloc(GetProcessHeap(), 0, sizeof(HOOKDATA));
     287    data->proc        = (HOOKPROC)proc;
     288    data->id          = id;
     289    data->ownerThread = dwThreadId;
     290    data->ownerModule = hModule;
     291    data->flags       = type;
     292    data->magic       = HOOK_MAGIC;
     293
     294    /* Insert it in the correct linked list */
     295    if(dwThreadId)
     296    {
     297        thdb = GetTHDBFromThreadId(dwThreadId);
     298        if(!thdb) {
     299                dprintf(("HOOK_SetHook: can't find thread database for thread %x", dwThreadId));
     300                return 0;
     301        }
     302        threadHookMutex.enter();
     303        data->next = thdb->hooks[id - WH_MINHOOK];
     304        thdb->hooks[id - WH_MINHOOK] = (DWORD)data;
     305        threadHookMutex.leave();
     306    }
     307    else
     308    {
     309        systemHookMutex.enter();
     310        data->next = HOOK_systemHooks[id - WH_MINHOOK];
     311        HOOK_systemHooks[id - WH_MINHOOK] = (HANDLE)data;
     312        systemHookMutex.leave();
     313    }
     314
     315    return (HHOOK)data;
     316}
     317
     318
     319/***********************************************************************
     320 *           HOOK_RemoveHook
     321 *
     322 * Remove a hook from the list.
     323 */
     324static BOOL HOOK_RemoveHook( HOOKDATA *data )
     325{
     326  HOOKDATA *prevHook;
     327  THDB     *thdb;
     328  VMutex   *hookMutex;
     329
     330    dprintf(("Removing hook %08x\n", data));
     331   
     332    if (data->flags & HOOK_INUSE)
     333    {
     334        /* Mark it for deletion later on */
     335        dprintf(("Hook still running, deletion delayed\n" ));
     336        data->flags |= HOOK_DELAYED_DELETE;
     337        return TRUE;
     338    }
     339
     340#ifndef __WIN32OS2__
     341    if (data->id == WH_JOURNALPLAYBACK) EnableHardwareInput16(TRUE);
    105342#endif
    106     return(rc);
    107 }
    108 //******************************************************************************
    109 //******************************************************************************
    110 HHOOK WIN32API SetWindowsHookA(int idHook, HOOKPROC hkprc)
    111 {
    112  HHOOK rc;
    113 
    114     rc = SetWindowsHookExA(idHook, hkprc, NULL, 0);
    115 #ifdef DEBUG
    116     WriteLog("OS2SetWindowsHookA %X, %X, returned %X\n", idHook, hkprc, rc);
     343     
     344    /* Remove it from the linked list */
     345
     346    if (data->ownerThread)
     347    {
     348        thdb = GetTHDBFromThreadId(data->ownerThread);
     349        if(!thdb) {
     350                dprintf(("HOOK_RemoveHook: can't find thread database for thread %x", data->ownerThread));
     351                return FALSE;
     352        }
     353        hookMutex = &threadHookMutex;
     354        hookMutex->enter();
     355        prevHook = (HOOKDATA *)thdb->hooks[data->id - WH_MINHOOK];
     356    }
     357    else {
     358        hookMutex = &systemHookMutex;
     359        hookMutex->enter();
     360        prevHook = (HOOKDATA *)HOOK_systemHooks[data->id - WH_MINHOOK];
     361    }
     362    while (prevHook && prevHook != data)
     363        prevHook = (HOOKDATA *)prevHook->next;
     364
     365    if (!prevHook) {
     366        hookMutex->leave();
     367        return FALSE;
     368    }
     369    prevHook = (HOOKDATA *)data->next;
     370    hookMutex->leave();
     371
     372    HeapFree(GetProcessHeap(), 0, (LPVOID)data );
     373    return TRUE;
     374}
     375
     376
     377/***********************************************************************
     378 *           HOOK_FindValidHook
     379 */
     380static HANDLE HOOK_FindValidHook( HANDLE hook )
     381{
     382    HOOKDATA *data;
     383
     384    for (;;)
     385    {
     386        if (!(data = (HOOKDATA *)hook)) return 0;
     387        if (data->proc) return hook;
     388        hook = data->next;
     389    }
     390}
     391
     392
     393/***********************************************************************
     394 *           HOOK_CallHook
     395 *
     396 * Call a hook procedure.
     397 */
     398static LRESULT HOOK_CallHook( HANDLE hook, INT fromtype, INT code,
     399                              WPARAM wParam, LPARAM lParam )
     400{
     401    MESSAGEQUEUE *queue;
     402    HANDLE prevHook;
     403    HOOKDATA *data = (HOOKDATA *)hook;
     404    LRESULT ret;
     405
     406    WPARAM wParamOrig = wParam;
     407    LPARAM lParamOrig = lParam;
     408    HOOK_MapFunc MapFunc;
     409    HOOK_UnMapFunc UnMapFunc;
     410
     411    MapFunc = HOOK_MapFuncs[fromtype][data->flags & HOOK_MAPTYPE];
     412    UnMapFunc = HOOK_UnMapFuncs[fromtype][data->flags & HOOK_MAPTYPE];
     413
     414    if (MapFunc)
     415      MapFunc( data->id, code, &wParam, &lParam );
     416
     417    /* Now call it */
     418
     419    data->flags |= HOOK_INUSE;
     420
     421    dprintf2(("Calling hook %04x: %d %08x %08lx\n", hook, code, wParam, lParam ));
     422
     423    ret = data->proc(code, wParam, lParam);
     424
     425    data->flags &= ~HOOK_INUSE;
     426
     427    if (UnMapFunc)
     428      UnMapFunc( data->id, code, wParamOrig, lParamOrig, wParam, lParam );
     429
     430    if(data->flags & HOOK_DELAYED_DELETE) HOOK_RemoveHook( data );
     431
     432    return ret;
     433}
     434
     435/***********************************************************************
     436 *           Exported Functions & APIs
     437 */
     438
     439/***********************************************************************
     440 *           HOOK_IsHooked
     441 *
     442 * Replacement for calling HOOK_GetHook from other modules.
     443 */
     444BOOL HOOK_IsHooked( INT id )
     445{
     446    /* Hmmm. Use GetThreadQueue(0) instead of GetFastQueue() here to
     447       avoid queue being created if someone wants to merely check ... */
     448
     449    return HOOK_GetHook( id, GetCurrentThreadId() ) != 0;
     450}
     451
     452/***********************************************************************
     453 *           HOOK_CallHooks32A
     454 *
     455 * Call a hook chain.
     456 */
     457LRESULT HOOK_CallHooksA( INT id, INT code, WPARAM wParam,
     458                           LPARAM lParam )
     459{
     460    HANDLE hook;
     461
     462    if (!(hook = HOOK_GetHook( id, GetCurrentThreadId() ))) return 0;
     463    if (!(hook = HOOK_FindValidHook(hook))) return 0;
     464    return HOOK_CallHook( hook, HOOK_WIN32A, code, wParam, lParam );
     465}
     466
     467/***********************************************************************
     468 *           HOOK_CallHooks32W
     469 *
     470 * Call a hook chain.
     471 */
     472LRESULT HOOK_CallHooksW( INT id, INT code, WPARAM wParam,
     473                           LPARAM lParam )
     474{
     475    HANDLE hook;
     476
     477    if (!(hook = HOOK_GetHook( id, GetCurrentThreadId() ))) return 0;
     478    if (!(hook = HOOK_FindValidHook(hook))) return 0;
     479    return HOOK_CallHook( hook, HOOK_WIN32W, code, wParam,
     480                          lParam );
     481}
     482
     483
     484#if 0
     485/***********************************************************************
     486 *           HOOK_ResetQueueHooks
     487 */
     488void HOOK_ResetQueueHooks( HQUEUE hQueue )
     489{
     490    MESSAGEQUEUE *queue;
     491
     492    if ((queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue )) != NULL)
     493    {
     494        HOOKDATA*       data;
     495        HHOOK           hook;
     496        int             id;
     497        for( id = WH_MINHOOK; id <= WH_MAXHOOK; id++ )
     498        {
     499            hook = queue->hooks[id - WH_MINHOOK];
     500            while( hook )
     501            {
     502                if( (data = (HOOKDATA *)hook) )
     503                {
     504                  data->ownerQueue = hQueue;
     505                  hook = data->next;
     506                } else break;
     507            }
     508        }
     509
     510        QUEUE_Unlock( queue );
     511    }
     512}
    117513#endif
    118     return(rc);
    119 }
    120 //******************************************************************************
    121 //******************************************************************************
    122 HHOOK WIN32API SetWindowsHookExW(int idHook, HOOKPROC hkprc, HINSTANCE hmod, DWORD dwThreadId)
    123 {
    124 #ifdef DEBUG
    125     WriteLog("OS2SetWindowsHookExW\n");
    126 #endif
    127     return(SetWindowsHookExA(idHook, hkprc, hmod, dwThreadId));
    128 }
    129 //******************************************************************************
    130 //******************************************************************************
    131 BOOL WIN32API UnhookWindowsHookEx(HHOOK hook)
    132 {
    133 #ifdef DEBUG
    134     WriteLog("OS2UnhookWindowsHookEx\n");
    135 #endif
    136    
    137     if(HkWindow::UnHookWindowsHook(hook) == FALSE)
    138      if(HkCBT::UnHookWindowsHook(hook) == TRUE) {
    139         return(TRUE);
    140      }
    141      else
    142       if(HkGetMessage::UnHookWindowsHook(hook) == FALSE)
    143        if(HkMsgFilter::UnHookWindowsHook(hook) == FALSE)
    144         if(HkSysMsgFilter::UnHookWindowsHook(hook) == FALSE)
    145          if(HkMouse::UnHookWindowsHook(hook) == FALSE)
    146           if(HkKeyboard::UnHookWindowsHook(hook) == FALSE)
    147            if(HkShell::UnHookWindowsHook(hook) == FALSE)
    148             if(HkDebug::UnHookWindowsHook(hook) == FALSE)
    149              if(HkJrnlPlayback::UnHookWindowsHook(hook) == FALSE)
    150               if(HkJrnlRecord::UnHookWindowsHook(hook) == FALSE) {
    151                 dprintf(("Hook %X not found!\n", hook));
    152               }
    153     return O32_UnhookWindowsHookEx(hook);
    154 }
    155 //******************************************************************************
    156 //******************************************************************************
    157 BOOL WIN32API UnhookWindowsHook(int nCode, HOOKPROC hkproc)
    158 {
    159  HHOOK hook = 0;
    160    
    161     switch(nCode) {
    162         case WH_CALLWNDPROC:
    163                 hook = HkWindow::FindHookProc(hkproc); 
    164                 break;
    165         case WH_CBT:
    166                 hook = HkCBT::FindHookProc(hkproc);
    167                 break;
    168         case WH_DEBUG:
    169                 hook = HkDebug::FindHookProc(hkproc);   
    170                 break;
    171         case WH_JOURNALPLAYBACK:
    172                 hook = HkJrnlPlayback::FindHookProc(hkproc);   
    173                 break;
    174         case WH_JOURNALRECORD:
    175                 hook = HkJrnlRecord::FindHookProc(hkproc);     
    176                 break;
    177         case WH_GETMESSAGE:
    178                 hook = HkGetMessage::FindHookProc(hkproc);     
    179                 break;
    180         case WH_MOUSE:
    181                 hook = HkMouse::FindHookProc(hkproc);   
    182                 break;
    183         case WH_KEYBOARD:
    184                 hook = HkKeyboard::FindHookProc(hkproc);       
    185                 break;
    186         case WH_SHELL:
    187                 hook = HkShell::FindHookProc(hkproc);
    188                 break;
    189         case WH_SYSMSGFILTER:
    190                 hook = HkSysMsgFilter::FindHookProc(hkproc);   
    191                 break;
    192         case WH_MSGFILTER:
    193                 hook = HkMsgFilter::FindHookProc(hkproc);       
    194                 break;
    195     }
    196 #ifdef DEBUG
    197     WriteLog("OS2UnhookWindowsHook %X\n", hook);
    198 #endif
    199     if(hook == 0)
    200         return(FALSE);
    201 
    202     return O32_UnhookWindowsHookEx(hook);
    203 }
    204 //******************************************************************************
    205 //******************************************************************************
    206 LRESULT WIN32API CallNextHookEx(HHOOK arg1, int arg2, WPARAM arg3, LPARAM  arg4)
    207 {
    208  HkCBT *hook;
    209 
    210 #ifdef DEBUG
    211     WriteLog("OS2CallNextHookEx\n");
    212 #endif
    213     if((hook = HkCBT::FindHook(arg1)) != NULL) {
    214                 return hook->CallNextHook(arg1, arg2, arg3, arg4);
    215     }
    216     else        return O32_CallNextHookEx(arg1, arg2, arg3, arg4);
    217 }
    218 //******************************************************************************
    219 //TODO
    220 //******************************************************************************
    221 BOOL WIN32API CallMsgFilterA( LPMSG msg, int nCode)
    222 {
    223 #ifdef DEBUG
    224     WriteLog("USER32:  CallMsgFilterA\n");
    225 #endif
    226 #if 0
    227     if(HkSysMsgFilter::OS2HkCBTProc(msg->hwnd, nCode, 0, (LPARAM)msg))
    228         return TRUE;
    229 
    230     return HkMsgFilter::OS2HkCBTProc(hwnd, Msg, wParam, lParam);
    231 #else
    232     return 0;
    233 #endif
    234 }
    235 //******************************************************************************
    236 //TODO
    237 //******************************************************************************
    238 BOOL WIN32API CallMsgFilterW( LPMSG msg, int nCode)
    239 {
    240 #ifdef DEBUG
    241     WriteLog("USER32:  CallMsgFilterW\n");
    242 #endif
    243 #if 0
    244     if(HkSysMsgFilter::OS2HkCBTProc(msg->hwnd, nCode, 0, (LPARAM)msg))
    245         return TRUE;
    246 
    247     return HkMsgFilter::OS2HkCBTProc(hwnd, Msg, wParam, lParam);
    248 #else
    249     return 0;
    250 #endif
    251 }
    252 //******************************************************************************
    253 //******************************************************************************
     514
     515/***********************************************************************
     516 *           HOOK_FreeModuleHooks
     517 */
     518void HOOK_FreeModuleHooks( HMODULE hModule )
     519{
     520 /* remove all system hooks registered by this module */
     521
     522  HOOKDATA*     hptr;
     523  HHOOK         hook, next;
     524  int           id;
     525
     526  for( id = WH_MINHOOK; id <= WH_MAXHOOK; id++ )
     527    {
     528       hook = HOOK_systemHooks[id - WH_MINHOOK];
     529       while( hook )
     530          if( (hptr = (HOOKDATA *)hook) )
     531            {
     532              next = hptr->next;
     533              if( hptr->ownerModule == hModule )
     534                {
     535                  hptr->flags &= HOOK_MAPTYPE;
     536                  HOOK_RemoveHook(hptr);
     537                }
     538              hook = next;
     539            }
     540          else hook = 0;
     541    }
     542}
     543
     544/***********************************************************************
     545 *           HOOK_FreeQueueHooks
     546 */
     547void HOOK_FreeQueueHooks( DWORD threadId )
     548{
     549  /* remove all hooks registered by this queue */
     550
     551  HOOKDATA*     hptr = NULL;
     552  HHOOK         hook, next;
     553  int           id;
     554
     555  for( id = WH_MINHOOK; id <= WH_MAXHOOK; id++ )
     556    {
     557       hook = HOOK_GetHook( id, threadId );
     558       while( hook )
     559        {
     560          next = HOOK_GetNextHook(hook);
     561
     562          hptr = (HOOKDATA *)hook;
     563          if( hptr && hptr->ownerThread == threadId )
     564            {
     565              hptr->flags &= HOOK_MAPTYPE;
     566              HOOK_RemoveHook(hptr);
     567            }
     568          hook = next;
     569        }
     570    }
     571}
     572
     573
     574/***********************************************************************
     575 *           SetWindowsHook32A   (USER32.525)
     576 */
     577HHOOK WINAPI SetWindowsHookA( INT id, HOOKPROC proc )
     578{
     579    return SetWindowsHookExA( id, proc, 0, GetCurrentThreadId() );
     580}
     581
     582/***********************************************************************
     583 *           SetWindowsHook32W   (USER32.528)
     584 */
     585HHOOK WINAPI SetWindowsHookW( INT id, HOOKPROC proc )
     586{
     587    return SetWindowsHookExW( id, proc, 0, GetCurrentThreadId() );
     588}
     589
     590/***********************************************************************
     591 *           SetWindowsHookEx32A   (USER32.526)
     592 */
     593HHOOK WINAPI SetWindowsHookExA( INT id, HOOKPROC proc, HINSTANCE hInst,
     594                                  DWORD dwThreadId )
     595{
     596    return HOOK_SetHook( id, proc, HOOK_WIN32A, hInst, dwThreadId );
     597}
     598
     599/***********************************************************************
     600 *           SetWindowsHookEx32W   (USER32.527)
     601 */
     602HHOOK WINAPI SetWindowsHookExW( INT id, HOOKPROC proc, HINSTANCE hInst,
     603                                  DWORD dwThreadId )
     604{
     605    return HOOK_SetHook( id, proc, HOOK_WIN32W, hInst, dwThreadId );
     606}
     607
     608/***********************************************************************
     609 *           UnhookWindowsHook32   (USER32.557)
     610 */
     611BOOL WINAPI UnhookWindowsHook( INT id, HOOKPROC proc )
     612{
     613    HANDLE hook = HOOK_GetHook( id, GetCurrentThreadId() );
     614
     615    dprintf(("UnhookWindowsHook: %d %08lx\n", id, (DWORD)proc ));
     616
     617    while (hook)
     618    {
     619        HOOKDATA *data = (HOOKDATA *)hook;
     620        if (data->proc == proc) break;
     621        hook = HOOK_GetNextHook( hook );
     622    }
     623    if (!hook) return FALSE;
     624    return HOOK_RemoveHook( (HOOKDATA *)hook );
     625}
     626
     627
     628/***********************************************************************
     629 *           UnhookWindowHookEx32   (USER32.558)
     630 */
     631BOOL WINAPI UnhookWindowsHookEx( HHOOK hhook )
     632{
     633    if (CHECK_MAGIC(hhook) == FALSE)
     634        return FALSE;
     635
     636    return HOOK_RemoveHook( (HOOKDATA *)hhook );
     637}
     638
     639/***********************************************************************
     640 *           CallNextHookEx32    (USER32.17)
     641 *
     642 * There aren't ANSI and UNICODE versions of this.
     643 */
     644LRESULT WINAPI CallNextHookEx( HHOOK hhook, INT code, WPARAM wParam,
     645                                 LPARAM lParam )
     646{
     647    HANDLE next;
     648    INT fromtype;       /* figure out Ansi/Unicode */
     649    HOOKDATA *oldhook;
     650
     651    if (CHECK_MAGIC(hhook) == FALSE)
     652        return FALSE;
     653
     654    if (!(next = HOOK_GetNextHook( hhook ))) return 0;
     655
     656    oldhook = (HOOKDATA *)hhook ;
     657    fromtype = oldhook->flags & HOOK_MAPTYPE;
     658
     659    return HOOK_CallHook( next, fromtype, code, wParam, lParam );
     660}
     661
     662
     663/***********************************************************************
     664 *           CallMsgFilter32A   (USER32.15)
     665 */
     666/*
     667 * FIXME: There are ANSI and UNICODE versions of this, plus an unspecified
     668 * version, plus USER (the 16bit one) has a CallMsgFilter32 function.
     669 */
     670BOOL WINAPI CallMsgFilterA( LPMSG msg, INT code )
     671{
     672    if (GetSysModalWindow()) return FALSE;      /* ??? */
     673    if (HOOK_CallHooksA( WH_SYSMSGFILTER, code, 0, (LPARAM)msg ))
     674      return TRUE;
     675    return HOOK_CallHooksA( WH_MSGFILTER, code, 0, (LPARAM)msg );
     676}
     677
     678
     679/***********************************************************************
     680 *           CallMsgFilter32W   (USER32.16)
     681 */
     682BOOL WINAPI CallMsgFilterW( LPMSG msg, INT code )
     683{
     684    if (GetSysModalWindow()) return FALSE;      /* ??? */
     685    if (HOOK_CallHooksW( WH_SYSMSGFILTER, code, 0, (LPARAM)msg ))
     686      return TRUE;
     687    return HOOK_CallHooksW( WH_MSGFILTER, code, 0, (LPARAM)msg );
     688}
     689
  • trunk/src/user32/Makefile

    r2033 r2084  
    1 # $Id: Makefile,v 1.47 1999-12-09 00:53:36 sandervl Exp $
     1# $Id: Makefile,v 1.48 1999-12-16 00:11:45 sandervl Exp $
    22
    33#
     
    3131OBJS =  user32.obj loadres.obj \
    3232        dde.obj win32wndhandle.obj wsprintf.obj winmouse.obj \
    33         icon.obj hook.obj hooks.obj winmenu.obj winkeyboard.obj \
     33        icon.obj hook.obj winmenu.obj winkeyboard.obj \
    3434        defwndproc.obj syscolor.obj char.obj initterm.obj \
    3535        uitools.obj unknown.obj spy.obj wndmsg.obj display.obj \
     
    9696syscolor.obj: syscolor.cpp syscolor.h
    9797dde.obj: dde.cpp
    98 hook.obj: hook.cpp hooks.h
     98hook.obj: hook.cpp $(PDWIN32_INCLUDE)\win\hook.h
    9999defwndproc.obj: defwndproc.cpp syscolor.h win32wmdiclient.h win32wbase.h win32wnd.h win32dlg.h
    100 hooks.obj: hooks.cpp hooks.h
    101100initterm.obj: initterm.cpp $(PDWIN32_INCLUDE)\spy.h pmwindow.h initterm.h
    102101uitools.obj: uitools.cpp win32wbase.h
     
    130129pmframe.obj: pmframe.cpp win32class.h win32wbase.h pmframe.h win32wndchild.h
    131130win32class.obj: win32class.cpp win32class.h win32wbase.h win32dlg.h gen_object.h $(PDWIN32_INCLUDE)\heapshared.h oslibwin.h win32wndchild.h $(PDWIN32_INCLUDE)\win\winproc.h
    132 win32wbase.obj:   win32wbase.cpp win32class.h win32wbase.h win32dlg.h gen_object.h $(PDWIN32_INCLUDE)\heapshared.h oslibwin.h win32wndchild.h  $(PDWIN32_INCLUDE)\winres.h oslibres.h win32wndhandle.h oslibdos.h dc.h pmframe.h win32wdesktop.h controls.h winmouse.h $(PDWIN32_INCLUDE)\win\winproc.h
     131win32wbase.obj:   win32wbase.cpp win32class.h win32wbase.h win32dlg.h gen_object.h $(PDWIN32_INCLUDE)\heapshared.h oslibwin.h win32wndchild.h  $(PDWIN32_INCLUDE)\winres.h oslibres.h win32wndhandle.h oslibdos.h dc.h pmframe.h win32wdesktop.h controls.h winmouse.h $(PDWIN32_INCLUDE)\win\winproc.h $(PDWIN32_INCLUDE)\win\hook.h
    133132win32wbasepos.obj: win32wbasepos.cpp win32class.h win32wbase.h win32dlg.h gen_object.h $(PDWIN32_INCLUDE)\heapshared.h oslibwin.h win32wndchild.h  $(PDWIN32_INCLUDE)\winres.h oslibres.h win32wndhandle.h oslibdos.h dc.h pmframe.h win32wdesktop.h
    134133win32wnd.obj:   win32wnd.cpp win32class.h win32wbase.h win32wnd.h win32dlg.h gen_object.h $(PDWIN32_INCLUDE)\heapshared.h oslibwin.h win32wndchild.h  $(PDWIN32_INCLUDE)\winres.h oslibres.h win32wndhandle.h oslibdos.h oslibmenu.h
  • trunk/src/user32/pmwindow.cpp

    r2076 r2084  
    1 /* $Id: pmwindow.cpp,v 1.64 1999-12-14 19:13:19 sandervl Exp $ */
     1/* $Id: pmwindow.cpp,v 1.65 1999-12-16 00:11:45 sandervl Exp $ */
    22/*
    33 * Win32 Window Managment Code for OS/2
     
    214214  if(msg == WIN32APP_POSTMSG && (ULONG)mp1 == WIN32PM_MAGIC) {
    215215        //win32 app user message
    216         win32wnd->PostMessage((POSTMSG_PACKET *)mp2);
    217         return (MRESULT)0;
     216        return (MRESULT)win32wnd->PostMessage((POSTMSG_PACKET *)mp2);;
    218217  }
    219218  switch( msg )
     
    417416        break;
    418417    }
    419 
     418    case WM_MINMAXFRAME:
     419    {
     420        dprintf(("OS2: WM_MINMAXFRAME"));
     421        break;
     422    }
    420423    case WM_OWNERPOSCHANGE:
    421424    {
  • trunk/src/user32/user32.cpp

    r1963 r2084  
    1 /* $Id: user32.cpp,v 1.58 1999-12-03 20:40:09 phaller Exp $ */
     1/* $Id: user32.cpp,v 1.59 1999-12-16 00:11:45 sandervl Exp $ */
    22
    33/*
     
    26762676/* Hook Functions */
    26772677
    2678 /*****************************************************************************
    2679  * Name      : BOOL WIN32API SetWindowsHookW
    2680  * Purpose   : The SetWindowsHook function is not implemented in the Win32 API.
    2681  *             Win32-based applications should use the SetWindowsHookEx function.
    2682  * Parameters:
    2683  * Variables :
    2684  * Result    :
    2685  * Remark    : ARGH ! MICROSOFT !
    2686  * Status    : UNTESTED STUB
    2687  *
    2688  * Author    : Patrick Haller [Thu, 1998/02/26 11:55]
    2689  *****************************************************************************/
    2690 HHOOK WIN32API SetWindowsHookW(int nFilterType, HOOKPROC pfnFilterProc)
    2691 
    2692 {
    2693   return (FALSE);
    2694 }
    2695 
    2696 /* CB: move to ShowWindow() */
    2697 
    2698 /*****************************************************************************
    2699  * Name      : BOOL WIN32API ShowWindowAsync
    2700  * Purpose   : The ShowWindowAsync function sets the show state of a window
    2701  *             created by a different thread.
    2702  * Parameters: HWND hwnd     handle of window
    2703  *             int  nCmdShow show state of window
    2704  * Variables :
    2705  * Result    : If the window was previously visible, the return value is TRUE.
    2706  *             If the window was previously hidden, the return value is FALSE.
    2707  * Remark    :
    2708  * Status    : UNTESTED STUB
    2709  *
    2710  * Author    : Patrick Haller [Thu, 1998/02/26 11:55]
    2711  *****************************************************************************/
    2712 BOOL WIN32API ShowWindowAsync (HWND hWnd,
    2713                                int  nCmdShow)
    2714 {
    2715   dprintf(("USER32:ShowWindowAsync (%08xh,%08x) not implemented.\n",
    2716          hWnd,
    2717          nCmdShow));
    2718 
    2719   return (FALSE);
    2720 }
    2721 
    27222678/* CB: move to MDI */
    27232679
  • trunk/src/user32/win32dlg.cpp

    r2033 r2084  
    1 /* $Id: win32dlg.cpp,v 1.36 1999-12-09 00:53:37 sandervl Exp $ */
     1/* $Id: win32dlg.cpp,v 1.37 1999-12-16 00:11:46 sandervl Exp $ */
    22/*
    33 * Win32 Dialog Code for OS/2
     
    217217
    218218    if (hUserFont)
    219         SendMessageA(WM_SETFONT, (WPARAM)hUserFont, 0 );
     219        SendInternalMessageA(WM_SETFONT, (WPARAM)hUserFont, 0 );
    220220
    221221    /* Create controls */
     
    226226        hwndFocus = GetNextDlgTabItem( getWindowHandle(), 0, FALSE );
    227227
    228         if (SendMessageA(WM_INITDIALOG, (WPARAM)hwndFocus, param))
     228        if (SendInternalMessageA(WM_INITDIALOG, (WPARAM)hwndFocus, param))
    229229             SetFocus(hwndFocus);
    230230
     
    262262    /* Owner must be a top-level window */
    263263    if(getOwner() == NULL) {
    264      topOwner = windowDesktop;
     264         topOwner = windowDesktop;
    265265    }
    266266    else topOwner = getOwner()->GetTopParent();
     
    295295          if (!OSLibWinPeekMsg(&msg,0,0,0,MSG_NOREMOVE))
    296296          {
    297             if(!(getStyle() & DS_NOIDLEMSG))
    298               topOwner->SendMessageA(WM_ENTERIDLE,MSGF_DIALOGBOX,getWindowHandle());
    299             OSLibWinGetMsg(&msg,0,0,0);
    300           } else OSLibWinPeekMsg(&msg,0,0,0,MSG_REMOVE);
     297                if(!(getStyle() & DS_NOIDLEMSG))
     298                    topOwner->SendMessageA(WM_ENTERIDLE,MSGF_DIALOGBOX,getWindowHandle());
     299                OSLibWinGetMsg(&msg,0,0,0);
     300          }
     301          else  OSLibWinPeekMsg(&msg,0,0,0,MSG_REMOVE);
    301302
    302303          if(msg.message == WM_QUIT)
    303304          {
    304             dprintf(("Win32Dialog::doDialogBox: received  WM_QUIT"));
    305             break;
     305                dprintf(("Win32Dialog::doDialogBox: received  WM_QUIT"));
     306                break;
    306307          }
    307308          if (!IsDialogMessageA( getWindowHandle(), &msg))
    308309          {
    309             TranslateMessage( &msg );
    310             DispatchMessageA( &msg );
     310                TranslateMessage( &msg );
     311                DispatchMessageA( &msg );
    311312          }
    312           if (dialogFlags & DF_END) break;
     313          if (dialogFlags & DF_END)
     314                break;
    313315        }
    314316#else
     
    332334            else {
    333335                if(!(getStyle() & DS_NOIDLEMSG)) {
    334                     topOwner->SendMessageA(WM_ENTERIDLE, MSGF_DIALOGBOX, getWindowHandle());
     336                    topOwner->SendInternalMessageA(WM_ENTERIDLE, MSGF_DIALOGBOX, getWindowHandle());
    335337                }
    336338            }
     
    10301032    {
    10311033    case DWL_DLGPROC:
    1032             oldval = (LONG)WINPROC_GetProc(Win32DlgProc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
     1034        oldval = (LONG)WINPROC_GetProc(Win32DlgProc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
    10331035        WINPROC_SetProc((HWINDOWPROC *)&Win32DlgProc, (WNDPROC)value, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A, WIN_PROC_WINDOW);
    10341036        return oldval;
     
    10531055    {
    10541056    case DWL_DLGPROC:
    1055             return (ULONG)WINPROC_GetProc(Win32DlgProc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
     1057        return (ULONG)WINPROC_GetProc(Win32DlgProc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
    10561058    case DWL_MSGRESULT:
    10571059        return msgResult;
  • trunk/src/user32/win32wbase.cpp

    r2076 r2084  
    1 /* $Id: win32wbase.cpp,v 1.110 1999-12-14 19:13:19 sandervl Exp $ */
     1/* $Id: win32wbase.cpp,v 1.111 1999-12-16 00:11:46 sandervl Exp $ */
    22/*
    33 * Win32 Window Base Class for OS/2
     
    1111 *
    1212 * TODO: Not thread/process safe
    13  * TODO: Calling window handler directly from SendMessageA/W can cause problems
    14  *       for GetMessageTime/Pos & InSendMessage
    1513 *
    1614 * Project Odin Software License can be found in LICENSE.TXT
     
    2826#include <winres.h>
    2927#include "wndmsg.h"
    30 #include "hooks.h"
    3128#include "oslibwin.h"
    3229#include "oslibutil.h"
     
    4441#include <wprocess.h>
    4542#include "winmouse.h"
     43#include <win\hook.h>
    4644
    4745#define HAS_DLGFRAME(style,exStyle) \
     
    8179
    8280static fDestroyAll = FALSE;
     81//For quick lookup of current process id
     82static ULONG currentProcessId = -1;
    8383
    8484//******************************************************************************
     
    145145  fNoSizeMsg       = FALSE;
    146146  fIsDestroyed     = FALSE;
     147  fDestroyWindowCalled = FALSE;
    147148  fCreated         = FALSE;
    148149  fTaskList        = FALSE;
     
    203204
    204205  ownDC              = 0;
     206
     207  if(currentProcessId == -1)
     208  {
     209        currentProcessId = GetCurrentProcessId();
     210  }
     211  dwThreadId         = GetCurrentThreadId();
     212  dwProcessId        = currentProcessId;
    205213}
    206214//******************************************************************************
     
    461469  windowClass->IncreaseWindowCount();
    462470
     471  if (HOOK_IsHooked( WH_CBT ))
     472  {
     473        CBT_CREATEWNDA cbtc;
     474        LRESULT ret;
     475
     476        cbtc.lpcs = cs;
     477        cbtc.hwndInsertAfter = hwndLinkAfter;
     478        ret = HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, getWindowHandle(), (LPARAM)&cbtc);
     479        if(ret)
     480        {
     481            dprintf(("CBT-hook returned 0!!"));
     482            SetLastError(ERROR_CAN_NOT_COMPLETE); //todo: wrong error
     483            return FALSE;
     484        }
     485  }
     486
    463487  /* Correct the window style */
    464488  if (!(cs->style & WS_CHILD))
     
    510534  }
    511535
    512   if(((cs->style & 0xC0000000) == WS_OVERLAPPED) && ((cs->style & WS_CAPTION) == WS_CAPTION) && owner == NULL)
     536  if(((dwStyle & 0xC0000000) == WS_OVERLAPPED) && ((dwStyle & WS_CAPTION) == WS_CAPTION) && owner == NULL
     537     && dwStyle & WS_SYSMENU)
    513538  {
    514             fTaskList = TRUE;
     539        fTaskList = TRUE;
    515540  }
    516541
     
    697722  fNoSizeMsg = FALSE;
    698723
    699   if(SendMessageA(WM_NCCREATE, 0, (LPARAM)cs) )
     724  if(SendInternalMessageA(WM_NCCREATE, 0, (LPARAM)cs) )
    700725  {
    701726        fCreated = TRUE;
     
    704729
    705730//        OffsetRect(&rectWindow, maxPos.x - rectWindow.left, maxPos.y - rectWindow.top);
    706         if( (SendMessageA(WM_CREATE, 0, (LPARAM)cs )) != -1 )
     731        if( (SendInternalMessageA(WM_CREATE, 0, (LPARAM)cs )) != -1 )
    707732        {
    708733            if(!(flags & WIN_NEED_SIZE)) {
    709                 SendMessageA(WM_SIZE, SIZE_RESTORED,
     734                SendInternalMessageA(WM_SIZE, SIZE_RESTORED,
    710735                                MAKELONG(rectClient.right-rectClient.left,
    711736                                         rectClient.bottom-rectClient.top));
    712                 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
     737                SendInternalMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
    713738            }
    714739
     740            if( getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
     741            {
     742                /* Notify the parent window only */
     743                SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_CREATE, getWindowId()), (LPARAM)getWindowHandle());
     744                if(!::IsWindow(getWindowHandle()))
     745                {
     746                    dprintf(("Createwindow: WM_PARENTNOTIFY destroyed window"));
     747                    goto end;
     748                }
     749            }
     750
    715751            if (cs->style & WS_VISIBLE) ShowWindow( sw );
    716752
    717 #if 0
    718753            /* Call WH_SHELL hook */
    719 
    720             if (!(dwStyle & WS_CHILD) && !owner)
    721                 HOOK_CallHooks16( WH_SHELL, HSHELL_WINDOWCREATED, hwnd, 0 );
    722 #endif
     754            if (!(getStyle() & WS_CHILD) && !owner)
     755                HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWCREATED, getWindowHandle(), 0 );
     756
    723757            SetLastError(0);
    724758            return TRUE;
     
    727761  dprintf(("Window creation FAILED (NCCREATE cancelled creation)"));
    728762  SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
     763end:
    729764  return FALSE;
    730765}
     
    755790
    756791    fIsDestroyed = TRUE;
    757     //According to the SDK, WM_PARENTNOTIFY messages are sent to the parent (this window)
    758     //before any window destruction has begun
    759     child = (Win32BaseWindow *)getFirstChild();
    760     while(child) {
    761         child->NotifyParent(WM_DESTROY, 0, 0);
    762 
    763         child = (Win32BaseWindow *)child->getNextChild();
     792
     793    if(fDestroyWindowCalled == FALSE)
     794    {//this window was destroyed because DestroyWindow was called for it's parent
     795     //so: send a WM_PARENTNOTIFY now as that hasn't happened yet
     796        if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
     797        {
     798            if(getParent())
     799            {
     800                    /* Notify the parent window only */
     801                    getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
     802            }
     803            else    DebugInt3();
     804        }
    764805    }
    765806    SendInternalMessageA(WM_DESTROY, 0, 0);
     807    SendInternalMessageA(WM_NCDESTROY, 0, 0);
    766808
    767809    if (hwndHorzScroll && OSLibWinQueryWindow(hwndHorzScroll,QWOS_PARENT) == OSLibWinQueryObjectWindow()) OSLibWinDestroyWindow(hwndHorzScroll);
     
    828870    return SendInternalMessageA(WM_MOVE, 0, MAKELONG((USHORT)x, (USHORT)y));
    829871}
     872//******************************************************************************
     873//******************************************************************************
     874#if 0
     875ULONG Win32BaseWindow::MsgMinMax()
     876{
     877
     878}
     879#endif
    830880//******************************************************************************
    831881//******************************************************************************
     
    901951{
    902952 ULONG rc, curprocid, procidhwnd = -1, threadidhwnd = 0;
     953
    903954
    904955    //According to SDK docs, if app returns FALSE & window is being deactivated,
     
    11511202
    11521203        /* Activate the window if needed */
    1153     if(isSubclassedOS2Wnd()) {
    1154         Win32BaseWindow *parentwnd = GetWindowFromOS2FrameHandle(OSLibWinQueryWindow(OS2Hwnd, QWOS_PARENT));
    1155         if(parentwnd) {
    1156             hwndTop = (parentwnd->GetTopParent()) ? parentwnd->GetTopParent()->getWindowHandle() : 0;
    1157         }
    1158         else    hwndTop = 0;
    1159     }
    1160     else    hwndTop = (GetTopParent()) ? GetTopParent()->getWindowHandle() : 0;
     1204        if(isSubclassedOS2Wnd()) {
     1205                Win32BaseWindow *parentwnd = GetWindowFromOS2FrameHandle(OSLibWinQueryWindow(OS2Hwnd, QWOS_PARENT));
     1206                if(parentwnd) {
     1207                        hwndTop = (parentwnd->GetTopParent()) ? parentwnd->GetTopParent()->getWindowHandle() : 0;
     1208                }
     1209                else    hwndTop = 0;
     1210        }
     1211        else    hwndTop = (GetTopParent()) ? GetTopParent()->getWindowHandle() : 0;
    11611212
    11621213        if (hwndTop && getWindowHandle() != GetActiveWindow())
    11631214        {
    1164                 LONG ret = SendMessageA(WM_MOUSEACTIVATE, hwndTop,
    1165                                         MAKELONG( HTCLIENT, win32msg ) );
     1215                LONG ret = SendInternalMessageA(WM_MOUSEACTIVATE, hwndTop,
     1216                                                MAKELONG( HTCLIENT, win32msg ) );
    11661217
    11671218#if 0
     
    14471498
    14481499    case SC_CLOSE:
    1449         return SendMessageA(WM_CLOSE, 0, 0);
     1500        return SendInternalMessageA(WM_CLOSE, 0, 0);
    14501501
    14511502#if 0
     
    16271678        {
    16281679            if(getParent()) {
    1629                 LRESULT rc = getParent()->SendMessageA(WM_MOUSEACTIVATE, wParam, lParam );
     1680                LRESULT rc = getParent()->SendInternalMessageA(WM_MOUSEACTIVATE, wParam, lParam );
    16301681                if(rc)  return rc;
    16311682            }
     
    16391690        {
    16401691            if(getParent()) {
    1641                 LRESULT rc = getParent()->SendMessageA(WM_SETCURSOR, wParam, lParam);
     1692                LRESULT rc = getParent()->SendInternalMessageA(WM_SETCURSOR, wParam, lParam);
    16421693                if(rc)  return rc;
    16431694            }
     
    16651716
    16661717        if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
    1667             SendMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
     1718            SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
    16681719
    16691720        if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
     
    16721723            else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
    16731724
    1674             SendMessageA(WM_SIZE, wp, MAKELONG(rectClient.right  - rectClient.left,
     1725            SendInternalMessageA(WM_SIZE, wp, MAKELONG(rectClient.right  - rectClient.left,
    16751726                                               rectClient.bottom - rectClient.top));
    16761727        }
     
    17791830          // key matches siblings mnemonic, send mouseclick
    17801831          if (mnemonic == (char) wParam) {
    1781             siblingWindow->SendMessageA (BM_CLICK, 0, 0);
     1832            siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
    17821833          }
    17831834
     
    18731924LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
    18741925{
     1926 POSTMSG_PACKET *packet;
     1927
     1928    //if the destination window is created by this process & thread, call window proc directly
     1929    if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
     1930        return SendInternalMessageA(Msg, wParam, lParam);
     1931    }
     1932    //otherwise use WinSendMsg to send it to the right process/thread
     1933    packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
     1934    packet->Msg = Msg;
     1935    packet->wParam = wParam;
     1936    packet->lParam = lParam;
     1937    packet->fUnicode = FALSE;
     1938    return OSLibSendMessage(getOS2WindowHandle(), WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
     1939}
     1940//******************************************************************************
     1941//******************************************************************************
     1942LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
     1943{
     1944 POSTMSG_PACKET *packet;
     1945
     1946    //if the destination window is created by this process & thread, call window proc directly
     1947    if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
     1948        return SendInternalMessageA(Msg, wParam, lParam);
     1949    }
     1950    //otherwise use WinSendMsg to send it to the right process/thread
     1951    packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
     1952    packet->Msg = Msg;
     1953    packet->wParam = wParam;
     1954    packet->lParam = lParam;
     1955    packet->fUnicode = TRUE;
     1956    return OSLibSendMessage(getOS2WindowHandle(), WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
     1957}
     1958//******************************************************************************
     1959//Called as a result of an OS/2 message or called from a class method
     1960//******************************************************************************
     1961LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
     1962{
    18751963 LRESULT rc;
    18761964 BOOL    fInternalMsgBackup = fInternalMsg;
    18771965
    1878   //SvL: Some Wine controls send WM_COMMAND messages when they receive the focus -> apps don't like to
    1879   //     receive those before they get their WM_CREATE message
    1880   //NOTE: May need to refuse more messages
    1881   if(fCreated == FALSE && Msg == WM_COMMAND) {
    1882         dprintf(("SendMessageA BEFORE creation! %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
    1883         return 0;
    1884   }
    1885 
    1886   DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, FALSE);
    1887 
    1888   if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
    1889         return(0);
    1890   }
    1891   fInternalMsg = FALSE;
     1966  DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
     1967
     1968  CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE);
     1969
     1970  fInternalMsg = TRUE;
    18921971  switch(Msg)
    18931972  {
     
    18991978                        break;
    19001979                }
    1901                 NotifyParent(Msg, wParam, lParam);
    1902 
    19031980                rc = 0;
    19041981                break;
    19051982        }
    1906         case WM_SETTEXT:
    1907                 rc = CallWindowProcA(win32wndproc, getWindowHandle(), WM_SETTEXT, wParam, lParam);
    1908                 break;
    1909 
    19101983        case WM_LBUTTONDOWN:
    19111984        case WM_MBUTTONDOWN:
     
    19161989
    19171990        case WM_DESTROY:
    1918                 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
    19191991                rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
    19201992                break;
     
    19282000}
    19292001//******************************************************************************
    1930 //******************************************************************************
    1931 LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
     2002//Called as a result of an OS/2 message or called from a class method
     2003//******************************************************************************
     2004LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
    19322005{
    19332006 LRESULT rc;
    19342007 BOOL    fInternalMsgBackup = fInternalMsg;
    19352008
    1936   //SvL: Some Wine controls send WM_COMMAND messages when they receive the focus -> apps don't like to
    1937   //     receive those before they get their WM_CREATE message
    1938   //NOTE: May need to refuse more messages
    1939   if(fCreated == FALSE && Msg == WM_COMMAND) {
    1940         dprintf(("SendMessageA BEFORE creation! %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
    1941         return 0;
    1942   }
    1943 
    1944   DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, FALSE);
    1945 
    1946   if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
    1947         return(0);
    1948   }
    1949   fInternalMsg = FALSE;
     2009  DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
     2010
     2011  CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE);
     2012
     2013  fInternalMsg = TRUE;
    19502014  switch(Msg)
    19512015  {
     
    19572021                        break;
    19582022                }
    1959                 NotifyParent(Msg, wParam, lParam);
    1960 
    19612023                rc = 0;
    19622024                break;
    19632025        }
    1964         case WM_SETTEXT:
    1965                 rc = CallWindowProcW(win32wndproc, getWindowHandle(), WM_SETTEXT, wParam, lParam);
    1966                 break;
    1967 
    19682026        case WM_LBUTTONDOWN:
    19692027        case WM_MBUTTONDOWN:
     
    19742032
    19752033        case WM_DESTROY:
    1976                 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
    1977                 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
    1978                 break;
    1979 
    1980         default:
    1981                 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
    1982                 break;
    1983   }
    1984   fInternalMsg = fInternalMsgBackup;
    1985   return rc;
    1986 }
    1987 //******************************************************************************
    1988 //Called as a result of an OS/2 message
    1989 //******************************************************************************
    1990 LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
    1991 {
    1992  LRESULT rc;
    1993  BOOL    fInternalMsgBackup = fInternalMsg;
    1994 
    1995   DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
    1996 
    1997   if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
    1998         return(0);
    1999   }
    2000   fInternalMsg = TRUE;
    2001   switch(Msg)
    2002   {
    2003         case WM_CREATE:
    2004         {
    2005                 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
    2006                         dprintf(("WM_CREATE returned -1\n"));
    2007                         rc = -1; //don't create window
    2008                         break;
    2009                 }
    2010                 NotifyParent(Msg, wParam, lParam);
    2011                 rc = 0;
    2012                 break;
    2013         }
    2014         case WM_LBUTTONDOWN:
    2015         case WM_MBUTTONDOWN:
    2016         case WM_RBUTTONDOWN:
    2017                 NotifyParent(Msg, wParam, lParam);
    2018                 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
    2019                 break;
    2020 
    2021         case WM_DESTROY:
    2022                 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
    2023                 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
    2024                 break;
    2025 
    2026         default:
    2027                 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
    2028                 break;
    2029   }
    2030   fInternalMsg = fInternalMsgBackup;
    2031   return rc;
    2032 }
    2033 //******************************************************************************
    2034 //Called as a result of an OS/2 message
    2035 //todo, unicode msgs (WM_SETTEXT etc)
    2036 //******************************************************************************
    2037 LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
    2038 {
    2039  LRESULT rc;
    2040  BOOL    fInternalMsgBackup = fInternalMsg;
    2041 
    2042   DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
    2043 
    2044   if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
    2045         return(0);
    2046   }
    2047   fInternalMsg = TRUE;
    2048   switch(Msg)
    2049   {
    2050         case WM_CREATE:
    2051         {
    2052                 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
    2053                         dprintf(("WM_CREATE returned -1\n"));
    2054                         rc = -1; //don't create window
    2055                         break;
    2056                 }
    2057                 NotifyParent(Msg, wParam, lParam);
    2058                 rc = 0;
    2059                 break;
    2060         }
    2061         case WM_LBUTTONDOWN:
    2062         case WM_MBUTTONDOWN:
    2063         case WM_RBUTTONDOWN:
    2064                 NotifyParent(Msg, wParam, lParam);
    2065                 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
    2066                 break;
    2067 
    2068         case WM_DESTROY:
    2069                 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
    20702034                rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
    20712035                break;
     
    20792043//******************************************************************************
    20802044//******************************************************************************
     2045void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
     2046{
     2047 CWPSTRUCT cwp;
     2048
     2049    cwp.lParam  = lParam;
     2050    cwp.wParam  = wParam;
     2051    cwp.message = Msg;
     2052    cwp.hwnd    = getWindowHandle();
     2053
     2054    switch(hooktype) {
     2055    case WH_CALLWNDPROC:
     2056        if(fUnicode) {
     2057             HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
     2058        }
     2059        else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
     2060        break;
     2061    }
     2062}
     2063//******************************************************************************
     2064//******************************************************************************
    20812065BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
    20822066{
     
    21272111//******************************************************************************
    21282112//******************************************************************************
    2129 void Win32BaseWindow::PostMessage(POSTMSG_PACKET *packet)
    2130 {
     2113ULONG Win32BaseWindow::PostMessage(POSTMSG_PACKET *packet)
     2114{
     2115 ULONG rc;
     2116
    21312117    if(packet == NULL)
    2132         return;
     2118        return 0;
    21332119
    21342120    if(packet->fUnicode) {
    2135             SendMessageW(packet->Msg, packet->wParam, packet->lParam);
    2136     }
    2137     else    SendMessageA(packet->Msg, packet->wParam, packet->lParam);
     2121            rc = SendInternalMessageW(packet->Msg, packet->wParam, packet->lParam);
     2122    }
     2123    else    rc = SendInternalMessageA(packet->Msg, packet->wParam, packet->lParam);
    21382124
    21392125    free(packet);
    2140 }
    2141 //******************************************************************************
    2142 //Send message to window of another process
    2143 //******************************************************************************
    2144 LRESULT Win32BaseWindow::SendMessageToProcess(UINT msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
    2145 {
    2146  POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
    2147 
    2148     dprintf(("SendMessageToProcess %x %x %x %x", getOS2WindowHandle(), msg, wParam, lParam));
    2149     packet->Msg = msg;
    2150     packet->wParam = wParam;
    2151     packet->lParam = lParam;
    2152     packet->fUnicode = fUnicode;
    2153     return OSLibSendMessage(getOS2WindowHandle(), WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
     2126    return rc;
    21542127}
    21552128//******************************************************************************
     
    21602133 Win32BaseWindow *window;
    21612134 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
    2162  DWORD processid, myprocessid;
    21632135
    21642136    dprintf(("BroadCastMessageA %x %x %x", msg, wParam, lParam, GetFS()));
    2165     myprocessid = GetCurrentProcessId();
    21662137
    21672138    for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
     
    21722143
    21732144                if(type == BROADCAST_SEND) {
    2174                         GetWindowThreadProcessId(hwnd, &processid);
    2175                         if(processid == myprocessid) {
    2176                             window->SendMessageA(msg, wParam, lParam);
    2177                         }
    2178                         else {
    2179                             window->SendMessageToProcess(msg, wParam, lParam, FALSE);
    2180                         }
     2145                        window->SendInternalMessageA(msg, wParam, lParam);
    21812146                }
    21822147                else    window->PostMessageA(msg, wParam, lParam);
     
    21932158 Win32BaseWindow *window;
    21942159 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
    2195  DWORD processid, myprocessid;
    21962160
    21972161
    21982162    dprintf(("BroadCastMessageW %x %x %x", msg, wParam, lParam));
    2199     myprocessid = GetCurrentProcessId();
    22002163
    22012164    for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
     
    22062169
    22072170                if(type == BROADCAST_SEND) {
    2208                         GetWindowThreadProcessId(hwnd, &processid);
    2209                         if(processid == myprocessid) {
    2210                             window->SendMessageW(msg, wParam, lParam);
    2211                         }
    2212                         else {
    2213                             window->SendMessageToProcess(msg, wParam, lParam, TRUE);
    2214                         }
     2171                        window->SendInternalMessageW(msg, wParam, lParam);
    22152172                }
    22162173                else    window->PostMessageW(msg, wParam, lParam);
     
    22212178}
    22222179//******************************************************************************
    2223 //TODO: do we need to inform the parent of the parent (etc) of the child window?
    22242180//******************************************************************************
    22252181void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
     
    22352191                parentwindow = window->getParent();
    22362192                if(parentwindow) {
    2237                         if(Msg == WM_CREATE || Msg == WM_DESTROY) {
    2238                                 parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), (LPARAM)getWindowHandle());
    2239                         }
    2240                         else    parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
     2193                        parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
    22412194                }
    22422195        }
     
    22832236    if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
    22842237//TODO: Wine does't send these. Correct?
    2285 //        SendMessageA(WM_SETICON, ICON_BIG, hIcon);
     2238//        SendInternalMessageA(WM_SETICON, ICON_BIG, hIcon);
    22862239        return TRUE;
    22872240    }
     
    23092262            wParam = SIZE_MINIMIZED;
    23102263
    2311         SendMessageA(WM_SIZE, wParam,
     2264        SendInternalMessageA(WM_SIZE, wParam,
    23122265                     MAKELONG(rectClient.right-rectClient.left,
    23132266                              rectClient.bottom-rectClient.top));
    2314         SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
     2267        SendInternalMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
    23152268    }
    23162269#else
    23172270    if(fFirstShow) {
    23182271        if(isFrameWindow() && IS_OVERLAPPED(getStyle()) && !isChild()) {
    2319                 SendMessageA(WM_SIZE, SIZE_RESTORED,
     2272                SendInternalMessageA(WM_SIZE, SIZE_RESTORED,
    23202273                                MAKELONG(rectClient.right-rectClient.left,
    23212274                                         rectClient.bottom-rectClient.top));
    2322                 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
     2275                SendInternalMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
    23232276
    23242277        }
     
    24912444}
    24922445//******************************************************************************
    2493 //Also destroys all the child windows (destroy parent, destroy children)
     2446//Also destroys all the child windows (destroy children first, parent last)
    24942447//******************************************************************************
    24952448BOOL Win32BaseWindow::DestroyWindow()
    24962449{
     2450    /* Call hooks */
     2451    if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
     2452    {
     2453        return FALSE;
     2454    }
     2455
     2456    if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
     2457    {
     2458        HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
     2459        /* FIXME: clean up palette - see "Internals" p.352 */
     2460    }
     2461
     2462    if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
     2463    {
     2464        if(getParent())
     2465        {
     2466             /* Notify the parent window only */
     2467             getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
     2468             if( !::IsWindow(getWindowHandle()) )
     2469             {
     2470                return TRUE;
     2471             }
     2472        }
     2473        else DebugInt3();
     2474    }
     2475    fDestroyWindowCalled = TRUE;
    24972476    return OSLibWinDestroyWindow(OS2HwndFrame);
    24982477}
     
    25902569        if (isIcon)
    25912570        {
    2592             SendMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
    2593             SendMessageA(WM_PAINTICON, 0, 0);
    2594         } else
    2595         {
    2596             SendMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
    2597             SendMessageA(WM_PAINT, 0, 0);
     2571            SendInternalMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
     2572            SendInternalMessageA(WM_PAINTICON, 0, 0);
     2573        }
     2574        else
     2575        {
     2576            SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
     2577            SendInternalMessageA(WM_PAINT, 0, 0);
    25982578        }
    25992579        O32_ReleaseDC(OS2Hwnd, hdc);
     
    29992979                ss.styleNew = value;
    30002980                dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
    3001                 SendMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
     2981                SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
    30022982                setExStyle(ss.styleNew);
    30032983                updateWindowStyle(ss.styleOld,getStyle());
    3004                 SendMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
     2984                SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
    30052985                return ss.styleOld;
    30062986        }
     
    30162996                        ss.styleNew = value | (ss.styleOld & (WS_VISIBLE | WS_CHILD));
    30172997                dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), getStyle(), value));
    3018                 SendMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
     2998                SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
    30192999                setStyle(ss.styleNew);
    30203000                updateWindowStyle(dwExStyle,ss.styleOld);
    3021                 SendMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
     3001                SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
    30223002#ifdef DEBUG
    30233003                PrintWindowStyle(ss.styleNew, 0);
     
    30273007        case GWL_WNDPROC:
    30283008                oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
    3029                 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A, WIN_PROC_WINDOW);
     3009                //WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A, WIN_PROC_WINDOW);
     3010                WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, WINPROC_GetProcType(win32wndproc), WIN_PROC_WINDOW);
    30303011                return oldval;
    30313012        case GWL_HINSTANCE:
  • trunk/src/user32/win32wbase.h

    r2076 r2084  
    1 /* $Id: win32wbase.h,v 1.53 1999-12-14 19:13:20 sandervl Exp $ */
     1/* $Id: win32wbase.h,v 1.54 1999-12-16 00:11:47 sandervl Exp $ */
    22/*
    33 * Win32 Window Base Class for OS/2
     
    4040
    4141#define WIN32APP_USERMSGBASE      0x1000
    42 #define WIN32APP_POSTMSG          0x6666
     42#define WIN32APP_POSTMSG          0x1000
    4343
    4444typedef struct
     
    4949        ULONG           fUnicode;
    5050} POSTMSG_PACKET;
    51 
    52 #define WM_WIN32_POSTMESSAGEA   0x4000
    53 #define WM_WIN32_POSTMESSAGEW   0x4001
    5451
    5552#define BROADCAST_SEND          0
     
    213210       LRESULT  SendMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
    214211       LRESULT  SendMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
    215        LRESULT  SendMessageToProcess(UINT msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode);
    216212       BOOL     PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
    217213       BOOL     PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
    218        void     PostMessage(POSTMSG_PACKET *packet);
     214       ULONG    PostMessage(POSTMSG_PACKET *packet);
    219215static BOOL     PostThreadMessageA(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam);
    220216static BOOL     PostThreadMessageW(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam);
    221217static LRESULT  BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam);
    222218static LRESULT  BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam);
     219       void     CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode = FALSE);
    223220
    224221       LRESULT  DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam);
     
    306303        BOOL    fNoSizeMsg;
    307304        BOOL    fIsDestroyed;
     305        BOOL    fDestroyWindowCalled;   //DestroyWindow was called for this window
    308306        BOOL    fCreated;
    309307        BOOL    fTaskList;              //should be listed in PM tasklist or not
    310308        BOOL    fParentDC;
    311309
     310        DWORD   dwThreadId;             //id of thread that created this window
     311        DWORD   dwProcessId;            //id of process that created this window
    312312        PVOID   pOldFrameProc;
    313313        ULONG   borderWidth;
  • trunk/src/user32/win32wbasepos.cpp

    r1490 r2084  
    1 /* $Id: win32wbasepos.cpp,v 1.6 1999-10-28 12:00:35 sandervl Exp $ */
     1/* $Id: win32wbasepos.cpp,v 1.7 1999-12-16 00:11:47 sandervl Exp $ */
    22/*
    33 * Win32 Window Base Class for OS/2 (nonclient/position methods)
     
    2828#include <spy.h>
    2929#include "wndmsg.h"
    30 #include "hooks.h"
    3130#include "oslibwin.h"
    3231#include "oslibutil.h"
     
    9493    if( dwStyle & WS_MINIMIZE )
    9594    {
    96         if( !SendMessageA(WM_QUERYOPEN, 0, 0L ) )
     95        if( !SendInternalMessageA(WM_QUERYOPEN, 0, 0L ) )
    9796        return (SWP_NOSIZE | SWP_NOMOVE);
    9897        swpFlags |= SWP_NOCOPYBITS;
     
    232231//    }
    233232
    234     SendMessageA(WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
     233    SendInternalMessageA(WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
    235234
    236235      /* Some sanity checks */
     
    276275        params.lppos = &winposCopy;
    277276   }
    278    result = SendMessageA(WM_NCCALCSIZE, calcValidRect,
     277   result = SendInternalMessageA(WM_NCCALCSIZE, calcValidRect,
    279278                         (LPARAM)&params );
    280279   *newClientRect = params.rgrc[0];
  • trunk/src/user32/win32wmdichild.cpp

    r2076 r2084  
    1 /* $Id: win32wmdichild.cpp,v 1.11 1999-12-14 19:13:20 sandervl Exp $ */
     1/* $Id: win32wmdichild.cpp,v 1.12 1999-12-16 00:11:48 sandervl Exp $ */
    22/*
    33 * Win32 MDI Child Window Class for OS/2
     
    3030#include <spy.h>
    3131#include "wndmsg.h"
    32 #include "hooks.h"
    3332#include <oslibwin.h>
    3433#include <oslibutil.h>
     
    231230        if (wParam == '-')
    232231        {
    233             SendMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
     232            SendInternalMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
    234233            return 0;
    235234        }
     
    268267        if (wParam == '-')
    269268        {
    270             SendMessageW(WM_SYSCOMMAND, SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
     269            SendInternalMessageW(WM_SYSCOMMAND, SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
    271270            return 0;
    272271        }
  • trunk/src/user32/win32wmdiclient.cpp

    r2040 r2084  
    1 /* $Id: win32wmdiclient.cpp,v 1.13 1999-12-09 10:59:05 sandervl Exp $ */
     1/* $Id: win32wmdiclient.cpp,v 1.14 1999-12-16 00:11:48 sandervl Exp $ */
    22/*
    33 * Win32 MDI Client Window Class for OS/2
     
    2626#include <spy.h>
    2727#include "wndmsg.h"
    28 #include "hooks.h"
    2928#include <oslibwin.h>
    3029#include <oslibutil.h>
     
    223222    case WM_NCACTIVATE:
    224223        if( activeChild )
    225             activeChild->SendMessageA(message, wParam, lParam);
     224            activeChild->SendInternalMessageA(message, wParam, lParam);
    226225        break;
    227226
     
    344343    {
    345344        prevActive->setStyle(prevActive->getStyle() | WS_SYSMENU);
    346         prevActive->SendMessageA( WM_NCACTIVATE, FALSE, 0L );
    347         prevActive->SendMessageA( WM_MDIACTIVATE, (WPARAM)prevActive->getWindowHandle(), (LPARAM)(child) ? child->getWindowHandle() : 0);
     345        prevActive->SendInternalMessageA( WM_NCACTIVATE, FALSE, 0L );
     346        prevActive->SendInternalMessageA( WM_MDIACTIVATE, (WPARAM)prevActive->getWindowHandle(), (LPARAM)(child) ? child->getWindowHandle() : 0);
    348347
    349348        /* uncheck menu item */
     
    386385    if( isActiveFrameWnd )
    387386    {
    388         child->SendMessageA( WM_NCACTIVATE, TRUE, 0L);
     387        child->SendInternalMessageA( WM_NCACTIVATE, TRUE, 0L);
    389388        if( GetFocus() == getWindowHandle())
    390             SendMessageA( WM_SETFOCUS, (WPARAM)getWindowHandle(), 0L );
     389            SendInternalMessageA( WM_SETFOCUS, (WPARAM)getWindowHandle(), 0L );
    391390        else
    392391            SetFocus( getWindowHandle() );
     
    394393
    395394    /* @@@PH prevActive may be NULL actually ?! */
    396     child->SendMessageA( WM_MDIACTIVATE,
     395    child->SendInternalMessageA( WM_MDIACTIVATE,
    397396                         prevActive ? (WPARAM)prevActive->getWindowHandle() : 0,
    398397                         child->getWindowHandle());
     
    602601}
    603602/**********************************************************************
    604  *                                      MDI_RestoreFrameMenu
     603 *                  MDI_RestoreFrameMenu
    605604 */
    606605BOOL Win32MDIClientWindow::restoreFrameMenu(Win32BaseWindow *child)
     
    611610
    612611    if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
    613             return 0;
     612        return 0;
    614613
    615614    /*
     
    621620
    622621    GetMenuItemInfoA(getParent()->GetMenu(),
    623                              0,
    624                              TRUE,
    625                              &menuInfo);
     622                     0,
     623                     TRUE,
     624                     &menuInfo);
    626625
    627626    RemoveMenu(getParent()->GetMenu(),0,MF_BYPOSITION);
     
    630629#if 0
    631630    if ((menuInfo.fType & MFT_BITMAP)           &&
    632             (LOWORD(menuInfo.dwTypeData)!=0)        &&
    633             (LOWORD(menuInfo.dwTypeData)!=hBmpClose) )
     631        (LOWORD(menuInfo.dwTypeData)!=0)        &&
     632        (LOWORD(menuInfo.dwTypeData)!=hBmpClose) )
    634633    {
    635634        DeleteObject((HBITMAP)LOWORD(menuInfo.dwTypeData));
     
    660659
    661660    if (getMaximizedChild())
    662         SendMessageA(WM_MDIRESTORE, (WPARAM)getMaximizedChild()->getWindowHandle(), 0);
     661        SendInternalMessageA(WM_MDIRESTORE, (WPARAM)getMaximizedChild()->getWindowHandle(), 0);
    663662
    664663    if (nActiveChildren == 0) return 0;
     
    706705
    707706    if (getMaximizedChild())
    708         SendMessageA(WM_MDIRESTORE, (WPARAM)getMaximizedChild()->getWindowHandle(), 0);
     707        SendInternalMessageA(WM_MDIRESTORE, (WPARAM)getMaximizedChild()->getWindowHandle(), 0);
    709708
    710709    if (nActiveChildren == 0) return;
  • trunk/src/user32/win32wnd.cpp

    r1490 r2084  
    1 /* $Id: win32wnd.cpp,v 1.2 1999-10-28 12:00:37 sandervl Exp $ */
     1/* $Id: win32wnd.cpp,v 1.3 1999-12-16 00:11:48 sandervl Exp $ */
    22/*
    33 * Win32 Window Class for OS/2
     
    2525#include <spy.h>
    2626#include "wndmsg.h"
    27 #include "hooks.h"
    2827#include <oslibwin.h>
    2928#include <oslibutil.h>
  • trunk/src/user32/window.cpp

    r2033 r2084  
    1 /* $Id: window.cpp,v 1.41 1999-12-09 00:53:38 sandervl Exp $ */
     1/* $Id: window.cpp,v 1.42 1999-12-16 00:11:48 sandervl Exp $ */
    22/*
    33 * Win32 window apis for OS/2
     
    394394{
    395395  Win32BaseWindow *window;
     396  BOOL rc;
    396397
    397398    window = Win32BaseWindow::GetWindowFromHandle(hwnd);
     
    401402        return 0;
    402403    }
    403     dprintf(("IsIconic %x", hwnd));
    404     return window->IsIconic();
     404    rc = window->IsIconic();
     405    dprintf(("IsIconic %x returned %d", hwnd, rc));
     406    return rc;
    405407}
    406408//******************************************************************************
     
    461463    dprintf(("ShowWindow %x", hwnd));
    462464    return window->ShowWindow(nCmdShow);
     465}
     466/*****************************************************************************
     467 * Name      : BOOL WIN32API ShowWindowAsync
     468 * Purpose   : The ShowWindowAsync function sets the show state of a window
     469 *             created by a different thread.
     470 * Parameters: HWND hwnd     handle of window
     471 *             int  nCmdShow show state of window
     472 * Variables :
     473 * Result    : If the window was previously visible, the return value is TRUE.
     474 *             If the window was previously hidden, the return value is FALSE.
     475 * Remark    :
     476 * Status    : UNTESTED STUB
     477 *
     478 * Author    : Patrick Haller [Thu, 1998/02/26 11:55]
     479 *****************************************************************************/
     480BOOL WIN32API ShowWindowAsync (HWND hwnd,
     481                               int  nCmdShow)
     482{
     483  dprintf(("USER32:ShowWindowAsync (%08xh,%08x) not correctly implemented.\n",
     484         hwnd,
     485         nCmdShow));
     486
     487  return ShowWindow(hwnd, nCmdShow);
    463488}
    464489//******************************************************************************
  • trunk/src/user32/windowmsg.cpp

    r2033 r2084  
    1 /* $Id: windowmsg.cpp,v 1.9 1999-12-09 00:53:38 sandervl Exp $ */
     1/* $Id: windowmsg.cpp,v 1.10 1999-12-16 00:11:49 sandervl Exp $ */
    22/*
    33 * Win32 window message APIs for OS/2
     
    2020#include <win32wbase.h>
    2121#include <win.h>
    22 #include <hooks.h>
    2322#include <heapstring.h>
    2423#include "oslibwin.h"
  • trunk/src/user32/winmenu.cpp

    r1732 r2084  
    1 /* $Id: winmenu.cpp,v 1.17 1999-11-14 12:00:01 sandervl Exp $ */
     1/* $Id: winmenu.cpp,v 1.18 1999-12-16 00:11:49 sandervl Exp $ */
    22
    33/*
     
    597597              UINT, arg3)
    598598{
    599     dprintf(("USER32:  OS2CheckMenuItem\n"));
    600599    if(hMenu == 0)
    601600    {
Note: See TracChangeset for help on using the changeset viewer.