5 #define WIN32_LEAN_AND_MEAN
7 #undef WIN32_LEAN_AND_MEAN
12 #include "Ecore_WinCE.h"
13 #include "ecore_wince_private.h"
15 /*============================================================================*
17 *============================================================================*/
24 typedef BOOL (__stdcall *UnregisterFunc1Proc)(UINT, UINT);
27 _ecore_wince_hardware_keys_register(HWND window)
30 UnregisterFunc1Proc unregister_fct;
33 core_dll = LoadLibrary(L"coredll.dll");
36 ERR("LoadLibrary() failed");
40 unregister_fct = (UnregisterFunc1Proc)GetProcAddress(core_dll, L"UnregisterFunc1");
43 ERR("GetProcAddress() failed");
44 FreeLibrary(core_dll);
48 for (i = 0xc1; i <= 0xcf; i++)
50 unregister_fct(MOD_WIN, i);
51 RegisterHotKey(window, i, MOD_WIN, i);
54 FreeLibrary(core_dll);
64 /*============================================================================*
66 *============================================================================*/
68 /*============================================================================*
70 *============================================================================*/
73 * @addtogroup Ecore_WinCE_Group Ecore_WinCE library
79 * @brief Creates a new window.
81 * @param parent The parent window.
82 * @param x The x coordinate of the top-left corner of the window.
83 * @param y The y coordinate of the top-left corner of the window.
84 * @param width The width of the window.
85 * @param height The height of hte window.
86 * @return A newly allocated window.
88 * This function creates a new window which parent is @p parent. @p width and
89 * @p height are the size of the window content (the client part),
90 * without the border and title bar. @p x and @p y are the system
91 * coordinates of the top left cerner of the window (that is, of the
92 * title bar). This function returns a newly created window on
93 * success, and @c NULL on failure.
95 EAPI Ecore_WinCE_Window *
96 ecore_wince_window_new(Ecore_WinCE_Window *parent,
102 struct _Ecore_WinCE_Window *w;
106 INF("creating window");
108 w = (struct _Ecore_WinCE_Window *)calloc(1, sizeof(struct _Ecore_WinCE_Window));
111 ERR("malloc() failed");
118 rect.bottom = height;
119 if (!AdjustWindowRectEx(&rect, WS_CAPTION | WS_SYSMENU | WS_VISIBLE, FALSE, WS_EX_TOPMOST))
121 ERR("AdjustWindowRectEx() failed");
126 window = CreateWindowEx(WS_EX_TOPMOST,
127 ECORE_WINCE_WINDOW_CLASS,
129 WS_CAPTION | WS_SYSMENU | WS_VISIBLE,
131 rect.right - rect.left, rect.bottom - rect.top,
132 parent ? ((struct _Ecore_WinCE_Window *)parent)->window : NULL,
133 NULL, _ecore_wince_instance, NULL);
136 ERR("CreateWindowEx() failed");
141 if (!_ecore_wince_hardware_keys_register(window))
143 ERR("_ecore_wince_hardware_keys_register() failed");
144 DestroyWindow(window);
152 if (!SetWindowLong(window, GWL_USERDATA, (LONG)w) && (GetLastError() != 0))
154 ERR("SetWindowLong() failed");
155 DestroyWindow(window);
160 w->pointer_is_in = 0;
166 * @brief Free the given window.
168 * @param window The window to free.
170 * This function frees @p window. If @p window is @c NULL, this
171 * function does nothing.
174 ecore_wince_window_free(Ecore_WinCE_Window *window)
178 INF("destroying window");
180 DestroyWindow(((struct _Ecore_WinCE_Window *)window)->window);
185 * @brief Return the window HANDLE associated to the given window.
187 * @param window The window to retrieve the HANDLE from.
189 * This function returns the window HANDLE associated to @p window. If
190 * @p window is @c NULL, this function returns @c NULL.
193 ecore_wince_window_hwnd_get(Ecore_WinCE_Window *window)
198 return ((struct _Ecore_WinCE_Window *)window)->window;
202 * @brief Move the given window to a given position.
204 * @param window The window to move.
205 * @param x The x coordinate of the destination position.
206 * @param y The y coordinate of the destination position.
208 * This function move @p window to the new position of coordinates @p x
209 * and @p y. If @p window is @c NULL, or if it is fullscreen, or on
210 * error, this function does nothing.
213 ecore_wince_window_move(Ecore_WinCE_Window *window,
220 if (!window || ((struct _Ecore_WinCE_Window *)window)->fullscreen)
223 INF("moving window (%dx%d)", x, y);
225 w = ((struct _Ecore_WinCE_Window *)window)->window;
226 if (!GetWindowRect(w, &rect))
228 ERR("GetWindowRect() failed");
232 if (!MoveWindow(w, x, y,
233 rect.right - rect.left,
234 rect.bottom - rect.top,
237 ERR("MoveWindow() failed");
242 * @brief Resize the given window to a given size.
244 * @param window The window to resize.
245 * @param width The new width.
246 * @param height The new height.
248 * This function resize @p window to the new @p width and @p height.
249 * If @p window is @c NULL, or if it is fullscreen, or on error, this
250 * function does nothing.
253 ecore_wince_window_resize(Ecore_WinCE_Window *window,
258 struct _Ecore_WinCE_Window *w;
264 if (!window || ((struct _Ecore_WinCE_Window *)window)->fullscreen)
267 INF("resizing window (%dx%d)", width, height);
269 w = (struct _Ecore_WinCE_Window *)window;
270 if (!GetWindowRect(w->window, &rect))
272 ERR("GetWindowRect() failed");
281 rect.bottom = height;
282 if (!(style = GetWindowLong(w->window, GWL_STYLE)))
284 ERR("GetWindowLong() failed");
287 if (!(exstyle = GetWindowLong(w->window, GWL_EXSTYLE)))
289 ERR("GetWindowLong() failed");
292 if (!AdjustWindowRectEx(&rect, style, FALSE, exstyle))
294 ERR("AdjustWindowRectEx() failed");
298 if (!MoveWindow(w->window, x, y,
299 rect.right - rect.left,
300 rect.bottom - rect.top,
303 ERR("MoveWindow() failed");
308 * @brief Move and resize the given window to a given position and size.
310 * @param window The window to move and resize.
311 * @param x The x coordinate of the destination position.
312 * @param y The x coordinate of the destination position.
313 * @param width The new width.
314 * @param height The new height.
316 * This function resize @p window to the new position of coordinates @p x
317 * and @p y and the new @p width and @p height. If @p window is @c NULL,
318 * or if it is fullscreen, or on error, this function does nothing.
321 ecore_wince_window_move_resize(Ecore_WinCE_Window *window,
328 struct _Ecore_WinCE_Window *w;
332 if (!window || ((struct _Ecore_WinCE_Window *)window)->fullscreen)
335 INF("moving and resizing window (%dx%d %dx%d)", x, y, width, height);
337 w = ((struct _Ecore_WinCE_Window *)window);
341 rect.bottom = height;
342 if (!(style = GetWindowLong(w->window, GWL_STYLE)))
344 ERR("GetWindowLong() failed");
347 if (!(exstyle = GetWindowLong(w->window, GWL_EXSTYLE)))
349 ERR("GetWindowLong() failed");
352 if (!AdjustWindowRectEx(&rect, style, FALSE, exstyle))
354 ERR("AdjustWindowRectEx() failed");
358 if (!MoveWindow(w->window, x, y,
359 rect.right - rect.left,
360 rect.bottom - rect.top,
363 ERR("MoveWindow() failed");
368 * @brief Show the given window.
370 * @param window The window to show.
372 * This function shows @p window. If @p window is @c NULL, or on
373 * error, this function does nothing.
376 ecore_wince_window_show(Ecore_WinCE_Window *window)
380 INF("showing window");
382 if (!ShowWindow(((struct _Ecore_WinCE_Window *)window)->window, SW_SHOWNORMAL))
384 ERR("ShowWindow() failed");
387 if (!UpdateWindow(((struct _Ecore_WinCE_Window *)window)->window))
389 ERR("UpdateWindow() failed");
391 if (!SendMessage(((struct _Ecore_WinCE_Window *)window)->window, WM_SHOWWINDOW, 1, 0))
393 ERR("SendMessage() failed");
398 * @brief Hide the given window.
400 * @param window The window to show.
402 * This function hides @p window. If @p window is @c NULL, or on
403 * error, this function does nothing.
406 ecore_wince_window_hide(Ecore_WinCE_Window *window)
410 INF("hiding window");
412 if (!ShowWindow(((struct _Ecore_WinCE_Window *)window)->window, SW_HIDE))
414 ERR("ShowWindow() failed");
417 if (!SendMessage(((struct _Ecore_WinCE_Window *)window)->window, WM_SHOWWINDOW, 0, 0))
419 ERR("SendMessage() failed");
424 * @brief Set the title of the given window.
426 * @param window The window to set the title.
427 * @param title The new title.
429 * This function sets the title of @p window to @p title. If @p window
430 * is @c NULL, or if @p title is @c NULL or empty, or on error, this
431 * function does nothing.
434 ecore_wince_window_title_set(Ecore_WinCE_Window *window,
441 if (!title || !title[0]) return;
443 INF("setting window title");
445 wtitle = evil_char_to_wchar(title);
448 if (!SetWindowText(((struct _Ecore_WinCE_Window *)window)->window, wtitle))
450 ERR("SetWindowText() failed");
456 * @brief Set the graphic backend used for the given window.
458 * @param window The window.
459 * @param backend The backend.
461 * This function sets the graphic backend to use with @p window to
462 * @p backend. If @p window if @c NULL, this function does nothing.
464 * The valid values for @p backend are
466 * @li 0: automatic choice of the backend.
467 * @li 1: the framebuffer (fast but could be not well suported).
468 * @li 2: GAPI (less fast but almost always supported).
469 * @li 3: DirectDraw (less fast than GAPI but almost always
471 * @li 4: GDI (the slowest but always supported).
473 * The @p backend is used only in Evas and Ecore_Evas. So this
474 * function should not be called if Ecore_Evas is used.
477 ecore_wince_window_backend_set(Ecore_WinCE_Window *window,
480 struct _Ecore_WinCE_Window *w;
485 INF("setting backend");
487 w = (struct _Ecore_WinCE_Window *)window;
488 w->backend = backend;
492 * @brief Set the suspend callback used for the given window.
494 * @param window The window.
495 * @param suspend_cb The suspend callback.
497 * This function sets the suspend callback to use with @p window to
498 * @p suspend_cb. If @p window if @c NULL, this function does nothing.
500 * The @p suspend_cb is used only in Evas and Ecore_Evas. So this
501 * function should not be called if Ecore_Evas is used.
504 ecore_wince_window_suspend_set(Ecore_WinCE_Window *window, int (*suspend_cb)(int))
506 struct _Ecore_WinCE_Window *w;
511 INF("setting suspend callback");
513 w = (struct _Ecore_WinCE_Window *)window;
514 w->suspend = suspend;
518 * @brief Set the resume callback used for the given window.
520 * @param window The window.
521 * @param resume_cb The resume callback.
523 * This function sets the resume callback to use with @p window to
524 * @p resume_cb. If @p window if @c NULL, this function does nothing.
526 * The @p resume_cb is used only in Evas and Ecore_Evas. So this
527 * function should not be called if Ecore_Evas is used.
530 ecore_wince_window_resume_set(Ecore_WinCE_Window *window, int (*resume_cb)(int))
532 struct _Ecore_WinCE_Window *w;
537 INF("setting resume callback");
539 w = (struct _Ecore_WinCE_Window *)window;
544 * @brief Get the geometry of the given window.
546 * @param window The window to retrieve the geometry from.
547 * @param x The x coordinate of the position.
548 * @param y The x coordinate of the position.
549 * @param width The width.
550 * @param height The height.
552 * This function retrieves the position and size of @p window. @p x,
553 * @p y, @p width and @p height can be buffers that will be filled with
554 * the corresponding values. If one of them is @c NULL, nothing will
555 * be done for that parameter. If @p window is @c NULL, and if the
556 * buffers are not @c NULL, they will be filled with respectively 0,
557 * 0, the size of the screen and the height of the screen.
560 ecore_wince_window_geometry_get(Ecore_WinCE_Window *window,
570 INF("getting window geometry");
576 if (width) *width = GetSystemMetrics(SM_CXSCREEN);
577 if (height) *height = GetSystemMetrics(SM_CYSCREEN);
582 if (!GetClientRect(((struct _Ecore_WinCE_Window *)window)->window,
585 ERR("GetClientRect() failed");
589 if (width) *width = 0;
590 if (height) *height = 0;
595 w = rect.right - rect.left;
596 h = rect.bottom - rect.top;
598 if (!GetWindowRect(((struct _Ecore_WinCE_Window *)window)->window,
601 ERR("GetWindowRect() failed");
605 if (width) *width = 0;
606 if (height) *height = 0;
611 if (x) *x = rect.left;
612 if (y) *y = rect.top;
613 if (width) *width = w;
614 if (height) *height = h;
618 * @brief Get the size of the given window.
620 * @param window The window to retrieve the size from.
621 * @param width The width.
622 * @param height The height.
624 * This function retrieves the size of @p window. @p width and
625 * @p height can be buffers that will be filled with the corresponding
626 * values. If one of them is @c NULL, nothing will be done for that
627 * parameter. If @p window is @c NULL, and if the buffers are not
628 * @c NULL, they will be filled with respectively the size of the screen
629 * and the height of the screen.
632 ecore_wince_window_size_get(Ecore_WinCE_Window *window,
638 INF("getting window size");
642 if (width) *width = GetSystemMetrics(SM_CXSCREEN);
643 if (height) *height = GetSystemMetrics(SM_CYSCREEN);
648 if (!GetClientRect(((struct _Ecore_WinCE_Window *)window)->window,
651 ERR("GetClientRect() failed");
653 if (width) *width = 0;
654 if (height) *height = 0;
657 if (width) *width = rect.right - rect.left;
658 if (height) *height = rect.bottom - rect.top;
662 * @brief Set the given window to fullscreen.
664 * @param window The window.
665 * @param on EINA_TRUE for fullscreen mode, EINA_FALSE for windowed mode.
667 * This function set @p window to fullscreen or windowed mode. If @p on
668 * is set to EINA_TRUE, the window will be fullscreen, if it is set to
669 * EINA_FALSE, it will be windowed. If @p window is @c NULL or if the
670 * state does not change (like setting to fullscreen while the window
671 * is already fullscreen), this function does nothing.
674 ecore_wince_window_fullscreen_set(Ecore_WinCE_Window *window,
677 struct _Ecore_WinCE_Window *ew;
683 ew = (struct _Ecore_WinCE_Window *)window;
684 if (((ew->fullscreen) && (on)) ||
685 ((!ew->fullscreen) && (!on)))
688 INF("setting fullscreen: %s", on ? "yes" : "no");
690 ew->fullscreen = !!on;
695 /* save the position and size of the window */
696 if (!GetWindowRect(w, &ew->rect))
698 ERR("GetWindowRect() failed");
703 task_bar = FindWindow(L"HHTaskBar", NULL);
706 INF("FindWindow(): can not find task bar");
708 if (!ShowWindow(task_bar, SW_HIDE))
710 INF("ShowWindow(): task bar already hidden");
712 if (!EnableWindow(task_bar, FALSE))
714 INF("EnableWindow(): input already disabled");
717 /* style: visible + popup */
718 if (!SetWindowLong(w, GWL_STYLE, WS_POPUP | WS_VISIBLE))
720 INF("SetWindowLong() failed");
723 /* resize window to fit the entire screen */
724 if (!SetWindowPos(w, HWND_TOPMOST,
726 GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
727 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED))
729 INF("SetWindowPos() failed");
732 * It seems that SetWindowPos is not sufficient.
733 * Call MoveWindow with the correct size and force painting.
734 * Note that UpdateWindow (forcing repainting) is not sufficient
738 GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
741 INF("MoveWindow() failed");
747 task_bar = FindWindow(L"HHTaskBar", NULL);
750 INF("FindWindow(): can not find task bar");
752 if (!ShowWindow(task_bar, SW_SHOW))
754 INF("ShowWindow(): task bar already visible");
756 if (!EnableWindow(task_bar, TRUE))
758 INF("EnableWindow(): input already enabled");
761 /* style: visible + caption + sysmenu */
762 if (!SetWindowLong(w, GWL_STYLE, WS_CAPTION | WS_SYSMENU | WS_VISIBLE))
764 INF("SetWindowLong() failed");
766 /* restaure the position and size of the window */
767 if (!SetWindowPos(w, HWND_TOPMOST,
770 ew->rect.right - ew->rect.left,
771 ew->rect.bottom - ew->rect.top,
772 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED))
774 INF("SetWindowLong() failed");
777 * It seems that SetWindowPos is not sufficient.
778 * Call MoveWindow with the correct size and force painting.
779 * Note that UpdateWindow (forcing repainting) is not sufficient
784 ew->rect.right - ew->rect.left,
785 ew->rect.bottom - ew->rect.top,
788 INF("MoveWindow() failed");