How can we manage the wndproc function of the applications we run using the Win32 api? The software language I use is Go.
I tried more than one method but couldn't do it. Can you help?
I am learning the HANDLE (HWND) value of notepad application with Microsoft Spy ++
Then I watch the changes on Notepad ++ over SPY ++.
Just like with Spy ++, please help me manage the custom WNPROC function I wrote.
func main() {
hwnd := w32.HWND(3736818)
go SetWindowLongTest(w32.HWND(hwnd))
time.Sleep(99999 * time.Second)
}
func SetWindowLongTest(hwnd w32.HWND) {
result, err := win.SetWindowLongPtr(win.HWND(hwnd), win.GWL_WNDPROC, syscall.NewCallback(MyNewWndProc))
if err != nil {
fmt.Println("SetWindowLongPtr", err)
}
fmt.Println(result)
}
func MyNewWndProc(hwnd w32.HWND, uMsg uint, wParam w32.WPARAM, lParam w32.LPARAM) uintptr {
fmt.Println(uMsg)
fmt.Println("myNewWndProc", hwnd)
return 0
}
Result:
PS C:\Users\Cingozr\go\src> go run .\main.go
SetWindowLongPtr Access is denied.
0
Method 2:
func main() {
hwnd := w32.HWND(3736818)
go SetClassLongTest(w32.HWND(hwnd))
time.Sleep(99999 * time.Second)
}
func SetClassLongTest(hwnd w32.HWND) {
result, err := w32.SetClassLongPtrW(hwnd, -24, syscall.NewCallback(MyNewWndProc))
if err != nil {
fmt.Println("SetClassLongPtrW Err", err)
}
fmt.Println("SetClassLongPtrW", result)
}
func MyNewWndProc(hwnd w32.HWND, uMsg uint, wParam w32.WPARAM, lParam w32.LPARAM) uintptr {
fmt.Println(uMsg)
fmt.Println("myNewWndProc", hwnd)
return 0
}
Result:
PS C:\Users\Cingozr\go\src> go run .\main.go
SetClassLongPtrW Err Access is denied.
SetClassLongPtrW 0