Creating splitter
Juha-Pekka Ahto via python-win32 <[email protected]> Fri, 28 Mar 2025 06:36:00 +0200
| Newsgroups | gmane.comp.python.windows |
|---|---|
| Message-ID | <CANLpa_o7o7xGYUNc07Gg2GKc0+RZmV+Pv_qvSkwp5tBYkHKLtw@mail.gmail.com> |
--===============3449794323815770346==
Content-Type: multipart/alternative; boundary="0000000000001b6c2506315f9c09"
--0000000000001b6c2506315f9c09
Content-Type: text/plain; charset="UTF-8"
Good day,
I've been looking at the pywin32 coding, but feel stuck at implementing
correct approach on basics of window.
So far the basic is from an example that I found on internet.
The question is on how to start using WM_CREATE to define the basic layout
of window, for example splitter, buttons, boxes etc?
Any tips on how to strip C/C++ examples to more pywin32 like structures?
import win32gui
import win32con
class Window:
def window_proc(self, hwnd, msg, wparam, lparam):
match msg:
case win32con.WM_CREATE:
pass
case win32con.WM_CLOSE:
win32gui.DestroyWindow(hwnd)
case win32con.WM_DESTROY:
win32gui.PostQuitMessage(0)
return win32gui.DefWindowProc(hwnd, msg, wparam, lparam)
def create_window(self):
wc = win32gui.WNDCLASS()
wc.lpfnWndProc = self.window_proc
wc.lpszClassName = "PythonWindowClass"
wc.hbrBackground = win32gui.GetStockObject(win32con.WHITE_BRUSH)
wc.hCursor = win32gui.LoadCursor(None, win32con.IDC_ARROW)
class_atom = win32gui.RegisterClass(wc)
style = win32con.WS_OVERLAPPEDWINDOW | win32con.WS_CLIPCHILDREN
hwnd = win32gui.CreateWindow(
class_atom,
"Python Window",
style,
100, 100, 500, 400,
0, 0, 0, None
)
win32gui.ShowWindow(hwnd, win32con.SW_SHOWNORMAL)
win32gui.UpdateWindow(hwnd)
message = win32gui.GetMessage(None, 0, 0)
while message[0]:
win32gui.TranslateMessage(message[1])
win32gui.DispatchMessage(message[1])
message = win32gui.GetMessage(None, 0, 0)
if __name__ == "__main__":
app = Window()
app.create_window()
With best regards,
JP
--0000000000001b6c2506315f9c09
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Good day,</div><div><br></div><div>I've been look=
ing at the pywin32 coding, but feel stuck at implementing correct approach =
on basics of window.</div><div>So far the basic is from an example that I f=
ound on internet.</div><div><br></div><div>The question is on how to start =
using WM_CREATE to define the basic layout of window, for example splitter,=
buttons, boxes etc?</div><div>Any tips on how to strip C/C++ examples to m=
ore pywin32 like structures?</div><div><div style=3D"background-color:rgb(3=
0,31,34);color:rgb(188,190,196)"><pre style=3D"font-family:"JetBrains =
Mono",monospace"><span style=3D"color:rgb(207,142,109)">import </span>=
win32gui<br><span style=3D"color:rgb(207,142,109)">import </span>win32con<b=
r><br><span style=3D"color:rgb(207,142,109)">class </span>Window:<br> <s=
pan style=3D"color:rgb(207,142,109)">def </span><span style=3D"color:rgb(86=
,168,245)">window_proc</span>(<span style=3D"color:rgb(148,85,141)">self</s=
pan>, hwnd, msg, wparam, lparam):<br> <span style=3D"color:rgb(207,1=
42,109)">match </span>msg:<br> <span style=3D"color:rgb(207,142,=
109)">case </span>win32con.WM_CREATE:<br> <span style=3D"col=
or:rgb(207,142,109)">pass<br></span><span style=3D"color:rgb(207,142,109)">=
case </span>win32con.WM_CLOSE:<br> win32gui.Dest=
royWindow(hwnd)<br> <span style=3D"color:rgb(207,142,109)">case =
</span>win32con.WM_DESTROY:<br> win32gui.PostQuitMessage(<sp=
an style=3D"color:rgb(42,172,184)">0</span>)<br> <span style=3D"colo=
r:rgb(207,142,109)">return </span>win32gui.DefWindowProc(hwnd, msg, wparam,=
lparam)<br><br> <span style=3D"color:rgb(207,142,109)">def </span><span=
style=3D"color:rgb(86,168,245)">create_window</span>(<span style=3D"color:=
rgb(148,85,141)">self</span>):<br> wc =3D win32gui.WNDCLASS()<br> =
wc.lpfnWndProc =3D <span style=3D"color:rgb(148,85,141)">self</span>.w=
indow_proc<br> wc.lpszClassName =3D <span style=3D"color:rgb(106,171=
,115)">"PythonWindowClass"<br></span><span style=3D"color:rgb(106=
,171,115)"> </span>wc.hbrBackground =3D win32gui.GetStockObject(win3=
2con.WHITE_BRUSH)<br> wc.hCursor =3D win32gui.LoadCursor(<span style=
=3D"color:rgb(207,142,109)">None</span>, win32con.IDC_ARROW)<br><br> =
class_atom =3D win32gui.RegisterClass(wc)<br> style =3D win32con.WS=
_OVERLAPPEDWINDOW | win32con.WS_CLIPCHILDREN<br> hwnd =3D win32gui.C=
reateWindow(<br> class_atom,<br> <span style=3D"color=
:rgb(106,171,115)">"Python Window"</span>,<br> style,<=
br> <span style=3D"color:rgb(42,172,184)">100</span>, <span styl=
e=3D"color:rgb(42,172,184)">100</span>, <span style=3D"color:rgb(42,172,184=
)">500</span>, <span style=3D"color:rgb(42,172,184)">400</span>,<br> =
<span style=3D"color:rgb(42,172,184)">0</span>, <span style=3D"color:r=
gb(42,172,184)">0</span>, <span style=3D"color:rgb(42,172,184)">0</span>, <=
span style=3D"color:rgb(207,142,109)">None<br></span><span style=3D"color:r=
gb(207,142,109)"> </span>)<br><br> win32gui.ShowWindow(hwnd, =
win32con.SW_SHOWNORMAL)<br> win32gui.UpdateWindow(hwnd)<br><br> =
message =3D win32gui.GetMessage(<span style=3D"color:rgb(207,142,109)">N=
one</span>, <span style=3D"color:rgb(42,172,184)">0</span>, <span style=3D"=
color:rgb(42,172,184)">0</span>)<br> <span style=3D"color:rgb(207,14=
2,109)">while </span>message[<span style=3D"color:rgb(42,172,184)">0</span>=
]:<br> win32gui.TranslateMessage(message[<span style=3D"color:rg=
b(42,172,184)">1</span>])<br> win32gui.DispatchMessage(message[<=
span style=3D"color:rgb(42,172,184)">1</span>])<br> message =3D =
win32gui.GetMessage(<span style=3D"color:rgb(207,142,109)">None</span>, <sp=
an style=3D"color:rgb(42,172,184)">0</span>, <span style=3D"color:rgb(42,17=
2,184)">0</span>)<br><br><br><span style=3D"color:rgb(207,142,109)">if </sp=
an>__name__ =3D=3D <span style=3D"color:rgb(106,171,115)">"__main__&qu=
ot;</span>:<br> app =3D Window()<br> app.create_window()</pre></div>W=
ith best regards,</div><div>JP</div></div>
--0000000000001b6c2506315f9c09--
--===============3449794323815770346==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32
--===============3449794323815770346==--