Jump to content

$WM_NOTIFY problem


philw
 Share

Recommended Posts

I'm trying to set up a list so that when an item is double clicked a function is triggered. There are a number of items on the forum using $WM_NOTIFY, which I've tried to copy. However the problem is that when the list is double clicked the function $WM_NOTIFY() function doesn't seem to be called.

Code extract is as follows:

#include <WindowsConstants.au3>
#include <ScrollBarConstants.au3>
#include <ProgressConstants.au3>
#include <ListboxConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>
#include <String.au3>
#include <Array.au3>
#include <File.au3>
#include <Misc.au3>

; ===============================================
; set mode
; ===============================================

Opt("GUIOnEventMode",1)

; ===============================================
; set up variables
; ===============================================

Dim $darray[10000000]
Dim $transarray[10000000]
Dim $transarray1[1000]
Dim $transarray2[1000]
Dim $transarray3[1000]
Dim $transarray4[1000]
Dim $filedata[6]
Dim $tagfiledata[6]
Dim $fontdata[8]
Dim $tagarray[3]
Dim $tagarray1[3]
Dim $select[2]

Global $winflag=1,$fileflag=0,$selectflag=0,$searchflag,$autoflag,$selectall
Global $response,$dstr,$tempstr,$datastr,$transformstr
Global $d,$ct,$select1,$select2
Global $line,$start,$end,$startpos,$endpos
Global $FileArray,$drive,$directory,$file="",$fileh,$filepath="",$filename="",$name,$type
Global $tagdrive,$tagdirectory,$tagfile="",$tagfileh,$tagfilepath="",$tagfilename="",$tagname,$tagtype
Global $transdrive,$transdirectory,$transfile="",$transfileh,$transfilepath="",$transfilename="",$transname,$transtype
Global $userfont,$fontfamily,$fontsize,$fontweight,$fontcolor,$colorref
Global $undoselect1,$undoselect2,$undoselect3,$undoselect4,$undoscroll1,$undoscroll2
Global $str1,$str2,$tstr1,$tstr2,$tag1,$tag2,$offset
Global $hWindow,$winsize,$winw,$winh,$hEdit
Global $filemenu,$fileopen,$filesave,$filesaveas,$fileclose,$filetags
Global $editmenu,$editcut,$editcopy,$editpaste,$editall,$editfrom,$editto,$editundo
Global $searchmenu,$searchfind,$searchnext,$searchfindline,$searchnextline,$searchmarker,$searchnextmarker
Global $htmlmenu,$htmlremove,$htmlrestore,$htmlformat,$htmlclean,$htmlremovetags,$htmltotext,$tagmenu,$htmladdhtml,$id
Global $class,$lt,$gt,$amp,$nbsp,$stylerule,$comment,$htmldivide,$htmlpreview,$optionsauto
Global $optionsmenu,$optionsfont
Global $hEditWindow,$hEdit1,$EditButton1,$EditButton2,$EditButton3
Global $hSearchWindow,$SearchLabel1,$SearchInput1,$SearchCheckbox1,$SearchLabel2,$SearchInput2,$SearchButton1
Global $SearchButton2,$SearchButton3
Global $hEditWindow,$hEdit1,$EditButton1,$EditButton2,$EditButton3
Global $ems="remove",$name,$type,$doctype,$selected
Global $atitle,$afilepath,$afilename,$afilenumber=-1,$afiletype,$astylesrc,$alinktext
Global $flen,$case=0,$mode,$fct
Global $dblclk=False

; ===============================================
; create main window
;===============================================

$hWindow=GUICreate("Xedit",750,460,-1,-1,$WS_OVERLAPPEDWINDOW)
$winsize=WinGetClientSize($hWindow)
$winw=$winsize[0]
$winh=$winsize[1]

GUISetOnEvent($GUI_EVENT_MAXIMIZE,"WindowResize",$hWindow)
GUISetOnEvent($GUI_EVENT_RESTORE,"WindowResize",$hWindow)
GUISetOnEvent($GUI_EVENT_RESIZED,"WindowResize",$hWindow)
GUISetOnEvent($GUI_EVENT_CLOSE,"CloseWindow",$hWindow)

; ===============================================
; create main window edit controls
; ===============================================

$hEdit=GUICtrlCreateEdit("",0,0,548,440,BitOR($ES_MULTILINE,$WS_VSCROLL,$ES_WANTRETURN,$ES_NOHIDESEL))
If @OSTYPE="WIN32_NT" Then
  GUICtrlSendMsg($hEdit,$EM_SETLIMITTEXT,4000000,0)
Else
  GUICtrlSendMsg($hEdit,$EM_SETLIMITTEXT,65535,0)
EndIf
GUICtrlSetState($hEdit,$GUI_ENABLE)
GUICtrlSetState($hEdit,$GUI_FOCUS)

$hList=GUICtrlCreateList("",550,0,200,410,$WS_VSCROLL)
GUICtrlSetState($hList,$GUI_ENABLE)

$button1=GUICtrlCreateButton("Line",565,410,50,20)
$button2=GUICtrlCreateButton("Group",625,410,50,20)
$button3=GUICtrlCreateButton("Block",685,410,50,20)


GUICtrlSetOnEvent($Button2,"HtmlTagGroup")

; ===============================================
; set up file menu
; ===============================================

$filemenu=GUICtrlCreateMenu("&File")
$filetags=GUICtrlCreateMenuItem("Load tags  ctrl  l",$filemenu)
GUICtrlSetOnEvent($filetags,"FileOpenTagFile")

; ===============================================
; show main window
; ===============================================

GUISwitch($hWindow)
GUISetState(@SW_SHOW,$hWindow)

; ===============================================
; set up messaging
; ===============================================

GUIRegisterMsg($WM_NOTIFY,"WM_NOTIFY")

; ===============================================
; general functions
; ===============================================

Func WM_NOTIFY($hWnd,$MsgID,$wParam,$lParam)
  Local $tagNMHDR,$event,$hwndFrom,$code
  $tagNMHDR=DllStructCreate("int;int;int",$lParam)
  If @error Then Return 0
  $code=DllStructGetData($tagNMHDR,3)
  If $wParam=$hList And $code=-3 Then $dblclk=True
  Return $GUI_RUNDEFMSG
EndFunc

; -----------------------------------------------

Func WindowResize()
  $winsize=WinGetClientSize($hWindow)
  $winw=$winsize[0]
  $winh=$winsize[1]
  GUICtrlSetPos($hEdit,0,0,$winw-202,$winh)
  GUICtrlSetPos($hList,$winw-200,0,200,$winh-30)
  GUICtrlSetPos($button1,$winw-185,$winh-30,50,20)
  GUICtrlSetPos($button2,$winw-125,$winh-30,50,20)
  GUICtrlSetPos($button3,$winw-65,$winh-30,50,20)
EndFunc

; -----------------------------------------------

Func CloseWindow()   
  If _GUICtrlEdit_GetModify($hEdit) Then
    Message(260,"Warning","Changes have not been saved. Exit Xedit anyway?")
    If $response=7 Then
      Return
    EndIf
  EndIf
  Exit
EndFunc

; ===============================================
; file functions
; ===============================================

Func FileOpenTagFile()
  If $tagfilepath="" Then $tagfilepath="C:\"
  FileChangeDir($tagfilepath)
  $tagfile=FileOpenDialog("Open file...",@WorkingDir,"Txt (*.txt)",2)  
  If @error<>0 Then
    $dstr=""
    Return
  Else
    $tagfileh=FileOpen($tagfile,0)
    If $tagfileh<>-1 Then     
      $FileArray=_PathSplit($tagfile,$tagdrive,$tagdirectory,$tagname,$tagtype)  
      $tagfilepath=$tagdrive&$tagdirectory
      $tagfilename=$tagname&$tagtype
      $dstr=FileRead($tagfileh)
      FileClose($tagfileh)    
      If StringInStr($dstr,@CRLF)=0 Then
        $dstr=StringAddCR($dstr)
      EndIf
      $dstr=StringRegExpReplace($dstr,"\A +","")
      $dstr=StringRegExpReplace($dstr," +\Z","")
      $dstr=StringRegExpReplace($dstr,"(\r\n) +",@CRLF)
      $dstr=StringRegExpReplace($dstr," +(\r\n)",@CRLF)
      $dstr=StringRegExpReplace($dstr,"> +<","><")
      $dstr=StringRegExpReplace($dstr,"\A(\r\n){1,}","")
      $dstr=StringRegExpReplace($dstr,"(\r\n){1,}\Z","")
      $dstr=StringRegExpReplace($dstr,"(\r\n){3,}",@CRLF&@CRLF)
      $dstr=StringRegExpReplace($dstr,"(\r\n)","|")
      GUICtrlSetData($hList,"")
      GUICtrlSetData($hList,$dstr)
    EndIf
  EndIf
EndFunc

; -----------------------------------------------

Func FileSaveChanges()
  If _GUICtrlEdit_GetModify($hEdit) Then
    Message(260,"Warning","Changes have not been saved. Close the current file anyway?")
    GUICtrlSetState($hEdit,$GUI_FOCUS)
    If $response=7 Then
      Return 0
    Else
      _GUICtrlEdit_SetModify($hEdit,0)
      Return 1
    EndIf
  EndIf
  Return 1
EndFunc

; ===============================================
; tag functions
; ===============================================

Func HtmlTagGroup()
  Msgbox(0,"","ok")
EndFunc

; ===============================================
; idle loop
; ===============================================

While 1  
  Sleep(100)
  If $dblclk Then HtmlTagGroup()
WEnd

; ---------------------------------------------

File > Load tags loads a short text file into the right-hand window - normally something like:

<h2></h2>

<h3></h3>

<h4></h4>

and double clicking an item in this window is supposed to trigger $WM_NOTIFY.

Can anyone see what I'm doing wrong?

Thanks!

Edited by philw
Link to comment
Share on other sites

Link to comment
Share on other sites

I can't immediately see anything wrong but please fix your code tags. Also try using a MsgBox() to do a bit of debugging for yourself.

Code tags fixed! The example I borrowed the code from works beautifully, so must be something in my script...

Link to comment
Share on other sites

Solved! YellowLab provided the solution here. I should have used $WM_COMMAND instead of $WM_NOTIFY, and included <GUIListBox.au3>.

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
  #forceref $hWnd, $iMsg
  Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
  If Not IsHWnd($hList) Then $hWndListBox = GUICtrlGetHandle($hList)
  $hWndFrom = $ilParam
  $iIDFrom = BitAND($iwParam, 0xFFFF)
  $iCode = BitShift($iwParam, 16)
  Switch $hWndFrom
    Case $hWndListBox
      Switch $iCode
        Case $LBN_DBLCLK
        If Not $dblclk Then $dblclk = 1
      EndSwitch
  EndSwitch
  Return $GUI_RUNDEFMSG
EndFunc

works nicely!

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...