1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_WIN_MESSAGE_WINDOW_H_
6 #define BASE_WIN_MESSAGE_WINDOW_H_
10 #include "base/base_export.h"
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/strings/string16.h"
15 #include "base/threading/non_thread_safe.h"
20 // Implements a message-only window.
21 class BASE_EXPORT MessageWindow
: public base::NonThreadSafe
{
23 // Used to register a process-wide message window class.
26 // Implement this callback to handle messages received by the message window.
27 // If the callback returns |false|, the first four parameters are passed to
28 // DefWindowProc(). Otherwise, |*result| is returned by the window procedure.
29 typedef base::Callback
<bool(UINT message
,
32 LRESULT
* result
)> MessageCallback
;
37 // Creates a message-only window. The incoming messages will be passed by
38 // |message_callback|. |message_callback| must outlive |this|.
39 bool Create(const MessageCallback
& message_callback
);
41 // Same as Create() but assigns the name to the created window.
42 bool CreateNamed(const MessageCallback
& message_callback
,
43 const string16
& window_name
);
45 HWND
hwnd() const { return window_
; }
47 // Retrieves a handle of the first message-only window with matching
49 static HWND
FindWindow(const string16
& window_name
);
52 // Give |WindowClass| access to WindowProc().
53 friend class WindowClass
;
55 // Contains the actual window creation code.
56 bool DoCreate(const MessageCallback
& message_callback
,
57 const wchar_t* window_name
);
59 // Invoked by the OS to process incoming window messages.
60 static LRESULT CALLBACK
WindowProc(HWND hwnd
, UINT message
, WPARAM wparam
,
63 // Invoked to handle messages received by the window.
64 MessageCallback message_callback_
;
66 // Handle of the input window.
69 DISALLOW_COPY_AND_ASSIGN(MessageWindow
);
75 #endif // BASE_WIN_MESSAGE_WINDOW_H_