Core Function GUIWndProc
From Sputnik Wiki
(Difference between revisions)
(→Examples) |
m (1 revision) |
||
(5 intermediate revisions by one user not shown) | |||
Line 20: | Line 20: | ||
Success: Returns 1. | Success: Returns 1. | ||
+ | |||
Failure: Returns 0. | Failure: Returns 0. | ||
Line 49: | Line 50: | ||
GUILoad( $Window ); | GUILoad( $Window ); | ||
// Add a MsgFilter to Design Window | // Add a MsgFilter to Design Window | ||
− | GUIWndProc($Window, | + | GUIWndProc($Window, 'WndProc($HWND, $MSG, $WPARAM, $LPARAM);'); |
// Keep the GUI running as long as long as the window is open | // Keep the GUI running as long as long as the window is open | ||
Line 60: | Line 61: | ||
// $LPARAM | // $LPARAM | ||
// All them names should be familiar to you | // All them names should be familiar to you | ||
− | Function WndProc() | + | Function WndProc($HWND, $MSG, $WPARAM, $LPARAM) |
{ | { | ||
+ | // Uncomment to show all messages | ||
+ | //println("HWND: " . $HWND . " | MSG: " . $MSG . " | WParam: " . $WParam . " | LParam: " . $LParam); | ||
// Get a message when user tries to move the Design window | // Get a message when user tries to move the Design window | ||
if ($MSG == 0x0046) # WM_WINDOWPOSCHANGING | if ($MSG == 0x0046) # WM_WINDOWPOSCHANGING | ||
{ | { | ||
− | |||
− | |||
− | |||
// Uncomment to see how to read from the memory pointer | // Uncomment to see how to read from the memory pointer | ||
//println("X: " . PTRRead( $LParam, "i", 8 )); | //println("X: " . PTRRead( $LParam, "i", 8 )); | ||
Line 81: | Line 81: | ||
DLLStructSetData($Struct, "y", 0); | DLLStructSetData($Struct, "y", 0); | ||
} | } | ||
− | return 0; // If you return HIGHER than 0 the | + | return 0; // If you return HIGHER than 0 the WindProc callback will be removed |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 12:37, 14 June 2015
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($HWND, $MSG, $WPARAM, $LPARAM);'); // 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($HWND, $MSG, $WPARAM, $LPARAM) { // Uncomment to show all messages //println("HWND: " . $HWND . " | MSG: " . $MSG . " | WParam: " . $WParam . " | LParam: " . $LParam); // Get a message when user tries to move the Design window if ($MSG == 0x0046) # WM_WINDOWPOSCHANGING { // 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 WindProc callback will be removed }