appbar.c 4.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/*
 * SHAppBarMessage implementation
 *
 * Copyright 2008 Vincent Povirk for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "config.h"

#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>

#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "shellapi.h"
#include "winuser.h"

#include "wine/debug.h"
#include "wine/unicode.h"

WINE_DEFAULT_DEBUG_CHANNEL(appbar);

39 40 41 42 43 44 45 46 47
struct appbar_data_msg  /* platform-independent data */
{
    ULONG     hWnd;
    UINT      uCallbackMessage;
    UINT      uEdge;
    RECT      rc;
    ULONGLONG lParam;
};

48 49
struct appbar_cmd
{
50 51 52
    ULONG  return_map;
    DWORD  return_process;
    struct appbar_data_msg abd;
53 54 55 56
};

struct appbar_response
{
57 58
    ULONGLONG result;
    struct appbar_data_msg abd;
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
};

/*************************************************************************
 * SHAppBarMessage            [SHELL32.@]
 */
UINT_PTR WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
{
    struct appbar_cmd command;
    struct appbar_response* response;
    HANDLE return_map;
    LPVOID return_view;
    HWND appbarmsg_window;
    COPYDATASTRUCT cds;
    DWORD_PTR msg_result;
    static const WCHAR classname[] = {'W','i','n','e','A','p','p','B','a','r',0};

    UINT_PTR ret = 0;

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    TRACE("msg=%d, data={cb=%d, hwnd=%p}\n", msg, data->cbSize, data->hWnd);

    /* These members are message dependent */
    switch(msg)
    {
    case ABM_NEW:
        TRACE("callback: %x\n", data->uCallbackMessage);
        break;

    case ABM_GETAUTOHIDEBAR:
        TRACE("edge: %d\n", data->uEdge);
        break;

    case ABM_QUERYPOS:
    case ABM_SETPOS:
        TRACE("edge: %d, rc: %s\n", data->uEdge, wine_dbgstr_rect(&data->rc));
        break;

    case ABM_GETTASKBARPOS:
        TRACE("rc: %s\n", wine_dbgstr_rect(&data->rc));
        break;

    case ABM_SETAUTOHIDEBAR:
        TRACE("edge: %d, lParam: %lx\n", data->uEdge, data->lParam);
        break;

    default:
        FIXME("unknown msg: %d\n", msg);
        break;
    }
107 108 109 110 111 112 113

    if (data->cbSize < sizeof(APPBARDATA))
    {
        WARN("data at %p is too small\n", data);
        return FALSE;
    }

114 115 116 117 118
    command.abd.hWnd = HandleToLong( data->hWnd );
    command.abd.uCallbackMessage = data->uCallbackMessage;
    command.abd.uEdge = data->uEdge;
    command.abd.rc = data->rc;
    command.abd.lParam = data->lParam;
119 120 121 122 123 124 125

    return_map = CreateFileMappingW(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, sizeof(struct appbar_response), NULL);
    if (return_map == NULL)
    {
        ERR("couldn't create file mapping\n");
        return 0;
    }
126
    command.return_map = HandleToUlong( return_map );
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151

    command.return_process = GetCurrentProcessId();

    appbarmsg_window = FindWindowW(classname, NULL);
    if (appbarmsg_window == NULL)
    {
        ERR("couldn't find appbar window\n");
        CloseHandle(return_map);
        return 0;
    }

    cds.dwData = msg;
    cds.cbData = sizeof(command);
    cds.lpData = &command;

    SendMessageTimeoutW(appbarmsg_window, WM_COPYDATA, (WPARAM)data->hWnd, (LPARAM)&cds, SMTO_BLOCK, INFINITE, &msg_result);

    return_view = MapViewOfFile(return_map, FILE_MAP_READ, 0, 0, sizeof(struct appbar_response));
    if (return_view == NULL)
    {
        ERR("MapViewOfFile failed\n");
        CloseHandle(return_map);
        return 0;
    }

152
    response = return_view;
153 154

    ret = response->result;
155 156 157 158 159 160 161 162
    if (ret)
    {
        data->hWnd = UlongToHandle( response->abd.hWnd );
        data->uCallbackMessage = response->abd.uCallbackMessage;
        data->uEdge = response->abd.uEdge;
        data->rc = response->abd.rc;
        data->lParam = response->abd.lParam;
    }
163 164 165 166 167 168
    UnmapViewOfFile(return_view);

    CloseHandle(return_map);

    return ret;
}