Jump to content

This script won't give result in WM_CREATE


kcvinu
 Share

Recommended Posts

Hi all,

 I am playing with this script. It only responds to WM_PAINT message. And it is not quitting when i click the close button. Please look at the script.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $g_hProcOld, $g_hNewProc
Local $hForm1, $g_bExit = False

Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
$hForm1 = GUICreate("Hello Program", 550, 306, 277, 153)

Local $hLabel1 = GUICtrlCreateLabel("Hello from AutoIt", 200, 120, 136, 17)
GUICtrlSetOnEvent(-1, "Label1Click")

Local $hBtn = GUICtrlCreateButton("Click", 100, 100, 86, 57)
GUICtrlSetOnEvent(-1, "BtClick")

$g_hNewProc = DllCallbackRegister('_WndProc', 'LRESULT', 'hwnd;uint;wparam;lparam')
$g_hProcOld = _WinAPI_SetWindowLong($hForm1, $GWL_WNDPROC,DllCallbackGetPtr($g_hNewProc))

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(10)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

#Region ctrl funcs
Func Label1Click()

EndFunc

Func BtClick()

EndFunc
#EndRegion ctrl funcs

DllCallbackFree($g_hNewProc)

Func _WndProc($hWnd, $iMsg, $wParam, $lParam)
    Switch $iMsg
        Case $WM_CLOSE
           _WinAPI_DestroyWindow($hForm1)

        Case $WM_CREATE
            ConsoleWrite("Just Created" & @CRLF)

        Case $WM_PAINT
            ConsoleWrite("Wondow Painted" & @CRLF)
            
        Case $WM_KEYDOWN
            ConsoleWrite("key pressed" & @CRLF)

    EndSwitch
    Return _WinAPI_CallWindowProc($g_hProcOld,$hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WndProc

 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

1 hour ago, kcvinu said:

... And it is not quitting when i click the close button.

I can't believe you are wondering about and can't find it. Using Opt("GUIOnEventMode", 1) and trying GuiGetMsg to listen which events are fired not works.  Just use GUISetOnEvent.

Edited by AutoBert
Link to comment
Share on other sites

@AutoBert , Thanks , My mistake. It now quits when i click the x button. But what about the WM_CREATE and WM_KEYDOWN messages. 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

40 minutes ago, kcvinu said:

@AutoBert , Thanks , My mistake. It now quits when i click the x button. But what about the WM_CREATE and WM_KEYDOWN messages. 

I never worked with _WinAPI_SetWindowLong or DllCallbackRegister, but i don't believe WM_CREATE can be catched for a GUI which already created.

Edited by AutoBert
Link to comment
Share on other sites

The WM_KEYDOWN is working only when i use _WinAPI_DefWindowProc instead of _WinAPI_CallWindowProc in _WndProc function. But then the script resists to stop. 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...