No announcement yet.

MsgBox prevents "invlaid page fault"

  • Filter
  • Time
  • Show
Clear All
new posts

  • MsgBox prevents "invlaid page fault"

    I have made a tab control, using the code from Jim Huguley's
    MsgExe.Bas and it works beutifully. (Thanks, Jim -- you do say
    "any comments welcome" )

    This tab control has three tab sheets, of which the third one has
    another tab control with four tab sheets, all of which works
    very well indeed. Until I started sub-classing the text boxes on
    the various tab sheets.

    The code now bombs as it is, giving an "illegal operation" --

    invalid page fault in module <unknown> at 0000:00000013.

    If the MsgBox AFTER is made active, it shows up before the
    "illegal operation". When the rem'd items are activated it works
    as expected without any trouble.

    The m$ is made up of the several strings shown which contain the
    str$ form of a largish number of text boxes (317 of them, which
    are used elsewhere to distinguish between those containing money
    values and those containing times in hours/minutes format

    The reverse procedure (un-subclassing) use the same method.

    This demonstrates what? The power of the MsgBox statement? Any
    ideas are welcome!

    m$=Trim$(DsMainCst$)+" " _
        +Trim$(DsPrfsCst$)+" " _
        +Trim$(DsPrfsTme$)+" " _
        +Trim$(DsFilmCst$)+" " _
        +Trim$(DsPhtsCst$)+" " _
        +Trim$(DsPhtsTme$)+" "
    'n&=Tally(m$, " ")
    'Dim tst&(n&)
    't$="Sequence test"+Chr$(10)
    'While Val(m$)>0
    ' Incr x&
    ' tst&(x&)=Val(m$)
    ' m$=Right$(m$,Len(m$)-Instr(m$," "))
    ' Wend
    'Array Sort tst&(1) For x&
    'For i&=2 To x&
    ' If tst&(i&)-tst&(i&-1)<>1 Then t$=t$+Str$(i&)+Str$(tst&(i&-1))+Str$(tst&(i&))+Chr$(10)
    ' Next
    'MsgBox(Str$(x&)+" / "+t$)
      While Val(m$)>0
       m$=Right$(m$,Len(m$)-Instr(m$," "))
       hCtl&=GetDlgItem(hDlg&, n&)
     Case %WM_DESTROY
      DeleteObject RmFont&
    '  m$=Trim$(DsMainCst$)+" "
    '  m$=m$+Trim$(DsPrfsCst$)+" "
    '  m$=m$+Trim$(DsPrfsTme$)+" "
    '  m$=m$+Trim$(DsFilmCst$)+" "
    '  m$=m$+Trim$(DsPhtsCst$)+" "
    '  m$=m$+Trim$(DsPhtsTme$)+" "
      m$=Trim$(DsMainCst$)+" " _
        +Trim$(DsPrfsCst$)+" " _
        +Trim$(DsPrfsTme$)+" " _
        +Trim$(DsFilmCst$)+" " _
        +Trim$(DsPhtsCst$)+" " _
        +Trim$(DsPhtsTme$)+" "
      While Val(m$)>0
       m$=Right$(m$, Len(m$)-Instr(m$," "))
       Control Handle hDlg&, n& To hCtl&
       SetWindowLong hCtl&,%GWL_WNDPROC, MainWndProc&

  • #2
    Dieny --
    Msgbox, SetWindowText inside CallBack change regular sequence/results of messages.
    To avoid this it's necessary to write log to external file or (like below) into console window.
       #Compile Exe
       #Register None
       #Dim All
       #Include "Win32Api.Inc"
       Sub CPrint (SOut As String)
          Static hConsole As Long, cWritten As Long
          If hConsole = 0 Then AllocConsole: hConsole = GetStdHandle(-11&)
          WriteConsole hConsole, ByCopy sOut + $CrLf, Len(sOut) + 2, cWritten, ByVal 0&
       End Sub
       CallBack Function DlgProc
          CPrint "CbMsg = &H" + Hex$(CbMsg) + _
                 " CbCtl = &H" + Hex$(CbCtl) + " " + _
                 " CbWParam = &H" + Hex$(CbWparam) + " " + _
                 " CbLparam = &H" + Hex$(CbLparam)
       End Function
       Function PbMain
          Local hDlg As Long
          CPrint "Started at " + Time$
          Dialog New 0, "CPrint", , , 80, 60, %WS_CAPTION Or %WS_SYSMENU To hDlg
          Control Add TextBox, hdlg, 101, "", 10, 5, 60, 12
          Control Add Button, hdlg, 102, "Button", 10, 25, 60, 12
          Dialog Show Modal hDlg, Call DlgProc
       End Function
    E-MAIL: [email protected]


    • #3
      Thanks, Semen -- but I was not concerned about the messagebox --
      rather that the thing gave the error WITHOUT it.

      Anyway, it is solved -- all those tab sheets are different
      "parents" to the controls on each, and I had done the
      sub-classsing as if all were on the first (primary) parent.

      Now it works very well! Thanks, anyway!



      • #4
        I too use Jim's code, works BEAUTIFULLY!!!
        I tend not to use the handles in the array form, rather asssign them as like hTab1, hTab2 etc, only because I experienced this headache a long time ago..

        But the TAb controls ROCK!

        Now, one question for YOU!

        How do you get it so y ou can use the alt-xxxx key with it?
        Ie if one of my tabs is labeled "&Security", I should be able to do Alt-S but I can't.


        mailto:[email protected][email protected]</A>
        Scott Turchin
        MCSE, MCP+I
        True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi


        • #5
          Scott, the answer is -- I don't. Having only just got so far
          as to get the thing to do its essential basics, esoterics such
          as accelerators has not been touched yet. The subject of tab
          controls is conspicuous by its absence in the Petzold book, so
          I don't even know where to turn. The API help tells a bit about
          ACCEL structures in general, and I guess that will have to be
          the way for me. Perhaps the Recor & Newcomer book? I don't have
          that one.



          • #6
            Accelerators are definitely a good way to solve this issue...

            You can create an accelerator table in a resource file (and use LoadAccelerators()) or dynamically create one using CreateAcceleratorTable().

            The keystrokes are translated in the message loop with a call to TranslateAccelerator(). This means you need to initiate your own message pump so you can embed this call into the loop. Finally, you must explicitly destroy the tabel with a call to DestroyAcceleratorTable().

            WIN32.HLP should describe the process sufficiently, since that was the reference I used to implement them in one of my own apps. Also see

            Since an accelerator will send a %WM_COMMAND message to the main dialog callback, you'll just show the new tab page (modeless dialog) and hide the previous one as necessary...

            However, the key to getting the keyboard interface to a tab control to work correctly is to ensure that the main dialog is the parent of *all* of the tab page dialogs and the tab control itself.

            Comparitively, VB sets the parent of the tab page dialogs to the tab control itself, but unless you use the former procedure and set the tab page dialogs to include the %DS_CONTROL style (and the parent to include the extended style %WS_EX_CONTROLPARENT) then the TAB order will not switch correctly between the tab pages and the buttons (OK, CANCEL, etc) on the main dialog itself.

            PowerBASIC Support
            mailto:[email protected][email protected]</A>
            mailto:[email protected]