{"id":394,"date":"2023-06-18T18:01:35","date_gmt":"2023-06-18T10:01:35","guid":{"rendered":"https:\/\/yhsbj.cn\/?p=394"},"modified":"2023-06-18T20:35:44","modified_gmt":"2023-06-18T12:35:44","slug":"golang%e5%88%9b%e5%bb%ba%e6%97%a0%e8%be%b9%e6%a1%86%e7%aa%97%e4%bd%93%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/yhsbj.cn\/index.php\/2023\/06\/18\/394\/","title":{"rendered":"Golang\u521b\u5efa\u65e0\u8fb9\u6846\u7a97\u4f53\u7a0b\u5e8f"},"content":{"rendered":"\n<p>1.\u4e3b\u8981\u6838\u5fc3\u5e93\u662f <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/energye\/energy\" data-type=\"URL\" data-id=\"https:\/\/github.com\/energye\/energy\" target=\"_blank\">https:\/\/github.com\/energye\/energy<\/a> <\/p>\n\n\n\n<p>2.\u53c2\u8003\u5b98\u7f51\u5b89\u88c5\u5b8cenergy\u5f00\u53d1\u73af\u5883\u540e\uff0c\u7f16\u5199golang\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package main\n\nimport (\n\t\"syscall\"\n\n\t\"github.com\/energye\/energy\/v2\/cef\"\n\t\"github.com\/energye\/energy\/v2\/cef\/ipc\"\n\t\"github.com\/energye\/energy\/v2\/cef\/ipc\/context\"\n\t\"github.com\/lxn\/win\"\n)\n\nvar (\n\torainWndProc uintptr\n)\n\nfunc main() {\n\tcef.GlobalInit(nil, nil)\n\tcefApp := cef.NewApplication()\n\t\/\/\u672c\u5730\u7f51\u9875\u8def\u5f84\n\tcef.BrowserWindow.Config.Url = \"http:\/\/localhost:3000\/\"\n\tcef.BrowserWindow.Config.EnableHideCaption = true\n\tcef.BrowserWindow.Config.Width = 1200\n\tcef.BrowserWindow.Config.Height = 800\n\n\t\/\/\u7a97\u4f53\u62d6\u62fd\n\tipc.On(\"window-drag\", func(context context.IContext) {\n\t\twin.ReleaseCapture()\n\t\twin.PostMessage(win.HWND(cef.BrowserWindow.MainWindow().Handle()), 274, 0xF010+0x0002, 0)\n\t})\n\t\/\/\u7a97\u4f53\u6700\u5c0f\u5316\u3001\u6700\u5927\u5316\u3001\u8fd8\u539f\n\tipc.On(\"window-state\", func(context context.IContext) {\n\t\tbw := cef.BrowserWindow.GetWindowInfo(context.BrowserId())\n\t\tstate := context.ArgumentList().GetIntByIndex(0)\n\t\tif state == 0 {\n\t\t\tbw.Minimize()\n\t\t} else if state == 1 {\n\t\t\tbw.Maximize()\n\t\t} else if state == 2 {\n\t\t\tbw.Restore()\n\t\t}\n\t})\n\t\/\/\u7a97\u4f53\u5173\u95ed\n\tipc.On(\"window-close\", func(context context.IContext) {\n\t\tbw := cef.BrowserWindow.GetWindowInfo(context.BrowserId())\n\t\tbw.CloseBrowserWindow()\n\t})\n\tcef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) {\n\t\tdefaultWndProcPtr := syscall.NewCallback(defaultWndProc)\n\t\torainWndProc = win.SetWindowLongPtr(win.HWND(cef.BrowserWindow.MainWindow().Handle()), win.GWLP_WNDPROC, defaultWndProcPtr)\n\t})\n\t\/\/Cef\u8fdb\u5165\u6d88\u606f\u5faa\u73af\n\tcef.Run(cefApp)\n}\n\nfunc defaultWndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) (result uintptr) {\n\tswitch msg {\n\tcase win.WM_SIZE:\n\t\tif wParam == 0 || wParam == 2 {\n\t\t\tipc.Emit(\"window-resize\", wParam)\n\t\t}\n\t}\n\treturn win.CallWindowProc(orainWndProc, hwnd, msg, wParam, lParam)\n}\n<\/pre>\n\n\n\n<p>3.\u7f16\u5199\u7f51\u9875\u4ee3\u7801\uff0c\u8fd9\u91cc\u4ee3\u7801\u7528\u5230<span class=\"has-inline-color has-vivid-red-color\">React + Ant Design<\/span><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import React, { useState, useRef, useEffect } from \"react\";\nimport { Layout, Menu, theme, Space, Button } from \"antd\";\nimport { UploadOutlined, UserOutlined, VideoCameraOutlined, MinusOutlined, BorderOutlined, CloseOutlined, SwitcherOutlined } from \"@ant-design\/icons\";\n\nconst { Header, Footer, Sider, Content } = Layout;\n\nconst App: React.FC = () => {\n  const {\n    token: { colorBgContainer },\n  } = theme.useToken();\n\n  const headRef = useRef&lt;any>();\n  const [windowIsMax, setWindowIsMax] = useState&lt;boolean>();\n  const [menuSelect, setMenuSelect] = useState&lt;string[]>([\"2\"]);\n\n  const windowClose = () => {\n    (window as any)?.ipc?.emit(\"window-close\");\n  };\n\n  const windowMin = () => {\n    (window as any)?.ipc?.emit(\"window-state\", [0]);\n  };\n\n  const windowMaxOrReset = () => {\n    (window as any)?.ipc?.emit(\"window-state\", [windowIsMax ? 2 : 1]);\n  };\n\n  const windowDrag = (e: React.MouseEvent&lt;any>) => {\n    if (e.target == headRef.current) {\n      (window as any)?.ipc?.emit(\"window-drag\", [windowIsMax ? 2 : 1]);\n    }\n  };\n\n  useEffect(() => {\n    (window as any)?.ipc?.on(\"window-resize\", function (status: any) {\n      setWindowIsMax(status == 2);\n    });\n  }, []);\n\n  return (\n    &lt;Layout style={{ width: \"100vw\", height: \"100vh\" }}>\n      &lt;Sider>\n        &lt;Menu\n          theme=\"dark\"\n          mode=\"inline\"\n          selectedKeys={menuSelect}\n          onSelect={(e) => setMenuSelect(e.selectedKeys)}\n          items={[UserOutlined, VideoCameraOutlined, UploadOutlined, UserOutlined].map((icon, index) => ({\n            key: String(index + 1),\n            icon: React.createElement(icon),\n            label: `nav ${index + 1}`,\n          }))}\n        \/>\n      &lt;\/Sider>\n      &lt;Layout>\n        &lt;Header ref={headRef} onMouseDown={windowDrag} style={{ padding: 0, background: colorBgContainer, height: \"40px\" }}>\n          &lt;Space size={0} style={{ float: \"right\" }}>\n            &lt;Button onClick={windowMin} style={{ verticalAlign: \"top\" }} type=\"text\" icon={&lt;MinusOutlined \/>}>&lt;\/Button>\n            &lt;Button onClick={windowMaxOrReset} style={{ verticalAlign: \"top\" }} type=\"text\" icon={windowIsMax ? &lt;SwitcherOutlined \/> : &lt;BorderOutlined \/>}>&lt;\/Button>\n            &lt;Button onClick={windowClose} style={{ verticalAlign: \"top\", color: \"#000000e0\" }} type=\"text\" icon={&lt;CloseOutlined \/>} danger>&lt;\/Button>\n          &lt;\/Space>\n        &lt;\/Header>\n        &lt;Content style={{ margin: \"24px 16px 0\" }}>\n          &lt;div style={{ padding: 24, minHeight: 360, background: colorBgContainer }}>content&lt;\/div>\n        &lt;\/Content>\n        &lt;Footer style={{ textAlign: \"center\" }}>Ant Design \u00a92023 Created by Ant UED&lt;\/Footer>\n      &lt;\/Layout>\n    &lt;\/Layout>\n  );\n};\n\nexport default App;\n<\/pre>\n\n\n\n<p>Golang\u65e0\u8fb9\u6846\u7a97\u4f53\u5df2\u7ecf\u5b9e\u73b0\uff0c\u4e0b\u9762\u622a\u56fe\u770b\u770b\u6548\u679c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/06\/\u5c4f\u5e55\u622a\u56fe-2023-06-18-175902-1024x674.png\" alt=\"\" class=\"wp-image-398\" width=\"782\" height=\"514\" srcset=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/06\/\u5c4f\u5e55\u622a\u56fe-2023-06-18-175902-1024x674.png 1024w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/06\/\u5c4f\u5e55\u622a\u56fe-2023-06-18-175902-300x198.png 300w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/06\/\u5c4f\u5e55\u622a\u56fe-2023-06-18-175902-768x506.png 768w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/06\/\u5c4f\u5e55\u622a\u56fe-2023-06-18-175902.png 1318w\" sizes=\"(max-width: 782px) 100vw, 782px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>1.\u4e3b\u8981\u6838\u5fc3\u5e93\u662f https:\/\/github.com\/energye\/energy 2.\u53c2\u8003\u5b98\u7f51\u5b89\u88c5\u5b8cene [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[54,52,55,53],"tags":[51,49,56,50],"_links":{"self":[{"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/posts\/394"}],"collection":[{"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/comments?post=394"}],"version-history":[{"count":5,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/posts\/394\/revisions"}],"predecessor-version":[{"id":402,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/posts\/394\/revisions\/402"}],"wp:attachment":[{"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/media?parent=394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/categories?post=394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/tags?post=394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}