Core Function GUIWndProc
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> GUIWndProc( <gui>, <command> ) </pre> === Description === Use a function to receive all the WindProc messages windows sends to the GUI window (HWND, MSG, WPARAM, LPARAM)....") |
(→Examples) |
||
Line 28: | Line 28: | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
DLLStructCreateDef("WindowPos", | DLLStructCreateDef("WindowPos", | ||
− | + | @" | |
− | + | ptr hwnd; | |
− | + | ptr hwndInsertAfter; | |
− | + | int x; | |
− | + | int y; | |
− | + | int cx; | |
− | + | int cy; | |
− | + | uint flags | |
− | + | "); | |
// Create the MDI GUI | // Create the MDI GUI |
Revision as of 10:52, 28 March 2012
GUIWndProc( <gui>, <command> )
Contents |
Description
Use a function to receive all the WindProc messages windows sends to the GUI window (HWND, MSG, WPARAM, LPARAM).
Parameters
gui
The GUI to link the WindProc to.
command
Either a command to execute or a function to call etc.
Return Value
Success: Returns 1. Failure: Returns 0.
Examples
This example uses the WindProc to capture the WM_WINDOWPOSCHANGING message and stop it from allowing the window to be moved
DLLStructCreateDef("WindowPos", @" ptr hwnd; ptr hwndInsertAfter; int x; int y; int cx; int cy; uint flags "); // Create the MDI GUI $GUI = GUICreate("MDIWindow", "GUI", 800, 600); // Show the MDI GUI GUILoad( $GUI ); // Create the Design Window $Window = GUICreate("Window", "GUI", 640, 482, 0, 0); GUIMDIParent($Window, $GUI); // Show the Design Window GUILoad( $Window ); // Add a MsgFilter to Design Window GUIWndProc($Window, "WndProc();"); // Keep the GUI running as long as long as the window is open While ( GUIStatus( $GUI ) ) DoEvents( ); // When you create a WndProc 4 variables are automatically created for you // $HWND // $MSG // $WPARAM // $LPARAM // All them names should be familiar to you Function WndProc() { // Get a message when user tries to move the Design window if ($MSG == 0x0046) # WM_WINDOWPOSCHANGING { // Uncomment to show all messages //println("HWND: " . $HWND . " | MSG: " . $MSG . " | WParam: " . $WParam . " | LParam: " . $LParam); // Uncomment to see how to read from the memory pointer //println("X: " . PTRRead( $LParam, "i", 8 )); //println("Y: " . PTRRead( $LParam, "i", 12 )); // Heres the best way to read the pointer by converting it into a Structure $Struct = PTRToDLLStruct("WindowPos", $LParam); println("X: " . DLLStructGetData($Struct, "x")); println("Y: " . DLLStructGetData($Struct, "y")); // Set the new coordinates for the Design window to 0, 0 this will prevent it from being moved DLLStructSetData($Struct, "x", 0); DLLStructSetData($Struct, "y", 0); } return 0; // If you return HIGHER than 0 the msgfilter will be removed }