webview/webview

Windows platform coding issues and window initialization issues

yongchengzhang opened this issue · 3 comments

Encoding issues:APIs related to the windows platform only support char and wchar_t type strings (ansii, unicode encoding) and do not support utf8 encoding. Therefore, for the widen_string and narrow_string functions, cp needs to be set to CP_ACP. Otherwise, after calling webview_set_title in languages other than English, the window The title cannot be displayed properly.

Window initialization problem: The windows currently created by default do not support the width, height and other parameters of the incoming window. As a result, after webview_create, the window size is adjusted through webview_set_size. The window size will have an obvious adjustment process. At the same time, the window after initialization does not default to Supports centered display. Taking windows as an example, if you set the window to be centered through SetWindowPos, there will be an obvious process of moving the window position.

Encoding issues

I'm not currently seeing the encoding issues.

I modified the basic example for C like this:

--- basic.c     2023-11-29 15:56:19.810600600 +0900
+++ basic.new.c 2023-11-29 15:52:09.401328600 +0900
@@ -16,9 +16,9 @@
 int main() {
 #endif
   webview_t w = webview_create(0, NULL);
-  webview_set_title(w, "Basic Example");
+  webview_set_title(w, "こんにちは, 你好, 안녕하세요, привет");
   webview_set_size(w, 480, 320, WEBVIEW_HINT_NONE);
-  webview_set_html(w, "Thanks for using webview!");
+  webview_set_html(w, "こんにちは, 你好, 안녕하세요, привет");
   webview_run(w);
   webview_destroy(w);
   return 0;

image

Can you provide an example to demonstrate the encoding problem?

I tested this on Windows 10 (compiled with GCC 8.3).

Window initialization problem

Is this code a good example for showing the problem?

#include "webview.h"
#include <stddef.h>

#include <windows.h>

LRESULT lpfnWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
  switch (msg) {
  case WM_CLOSE:
    PostQuitMessage(0);
    break;
  default:
    return DefWindowProcW(hwnd, msg, wp, lp);
  }
  return 0;
}

int main() {
  HINSTANCE hInstance = GetModuleHandle(0);

  WNDCLASSEXW wc;
  ZeroMemory(&wc, sizeof(WNDCLASSEX));
  wc.cbSize = sizeof(WNDCLASSEX);
  wc.hInstance = hInstance;
  wc.lpszClassName = L"app_window";
  wc.lpfnWndProc = lpfnWndProc;
  RegisterClassExW(&wc);

  HWND window = CreateWindowW(L"app_window", L"", WS_OVERLAPPEDWINDOW, 100, 100,
                              480, 320, NULL, NULL, hInstance, NULL);

  ShowWindow(window, SW_SHOW);
  UpdateWindow(window);

  webview_t w = webview_create(0, &window);
  webview_set_title(w, "Example");
  //webview_set_size(w, 480, 320, WEBVIEW_HINT_NONE); // Problem in screenshot exists with and without this line
  webview_set_html(w, "Hello");
  webview_run(w);
  webview_destroy(w);
}

image