R
R
Resolut2022-02-01 18:16:39
css
Resolut, 2022-02-01 18:16:39

win32api | python | How to create an application window, where to get wndProc?

In all documentation:

#get instance handle
    hInstance = win32api.GetModuleHandle()
 
    # the class name
    className = 'SimpleWin32'
 
 
    # create and initialize window class
    wndClass                = win32gui.WNDCLASS()
    wndClass.style          = win32con.CS_HREDRAW | win32con.CS_VREDRAW
    wndClass.lpfnWndProc    = wndProc # А вот тут показывает что неизвестный объект
    wndClass.hInstance      = hInstance
    wndClass.hIcon          = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
    wndClass.hCursor        = win32gui.LoadCursor(0, win32con.IDC_ARROW)
    wndClass.hbrBackground  = win32gui.GetStockObject(win32con.WHITE_BRUSH)
    wndClass.lpszClassName  = className

Where can I get wndProc?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
P
Peter, 2016-01-05
@tigroid3

Such a table is made without using the TABLE, TBODY, TR, TD tags.
In your example, it is better to make the lines through DIV, then all the questions "border-radius for tr" will disappear.
And already inside the line you can apply TABLE (if it's easier for you) with a fixed column width.
Although the columns can also be done through divs using the style: display: table-cell;

R
romy4, 2016-01-05
@romy4

and there exactly tr? did you look at the code?

K
Konstantin, 2016-01-05
@andronof

For point 2.
You can use htmlbook.ru/css/border-spacing or insert an empty tr between the products with the required height.
For point 1:
https://jsfiddle.net/2e7aLdag/

I
Igor Petrenko, 2016-01-05
@Igor_Petrenko

It seems to me that the border-radius is set on the span element, e.g.
In general, in tr, td, table, a rather meager set for styling.

V
Vindicar, 2022-02-01
@lxst

You're in luck, I did this recently.
You can’t just take and pass a Python function to WinAPI, since they have completely different call methods. You first need to describe the data type - a pointer to a function. More or less like this.

import ctypes
import ctypes.wintypes as w
LRESULT = w.LPARAM
WNDPROC = ctypes.WINFUNCTYPE(LRESULT, w.HWND, w.UINT, w.WPARAM, w.LPARAM)

After that, you can provide your window function like
def wnd_proc(hwnd: w.HWND, message: w.UINT, wParam: w.WPARAM, lParam: w.LPARAM) -> LRESULT:

And then you specify it in the window class:
wndСlass.lpfnWndProc = WNDPROC(wnd_proc)
But there is one more catch - there are a lot of window messages, and their set is different for different versions of Windows. There is a basic, more or less static set, but a lot of things can come in addition to them.
This is where DefWindowProc() comes to the rescue.
def wnd_proc(hwnd, message, wParam, lParam):
    if message == SOME_MESSAGE_YOU_WANT:  # отлавливаешь интересующие тебя сообщения
        DoStuff()  # и обрабатываешь их
        return 0  # не забудь вернуть 0 как признак успеха!
    # а все остальное отдаёшь в DefWindowProc()
    return user32.DefWindowProcW(hwnd, message, wParam, lParam)

Note that, like many WinAPI functions, DefWindowProc() comes in two forms - with the A suffix (one-byte ANSI encoding) and the W suffix (wide char, double-byte variant of Unicode). I do not recommend mixing, choose one suffix and stick to it throughout the program.
And another catch that almost drove me crazy - a variable with a window class MUST exist as long as the window exists. In other words, it should not be made local in the method - otherwise the python garbage collector will collect it later, which will be an unpleasant surprise for WinAPI. Catch an application crash.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question