Announcement

Collapse
No announcement yet.

COMMUNICATE WITH 2ND GRAPHIC WINDOW

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • COMMUNICATE WITH 2ND GRAPHIC WINDOW

    Hi,

    I have been using bitmaps for pop up boxes, but they do not
    completely erase after use and leave a mark on main bitmap. I
    thought I could use a second window(as pop up) - so I tried, but the 2nd
    window does not receive key presses or mouse click? I did a
    "GRAPHIC ATTACH hWin1, 0 for 2nd/pop up window for my code, but
    it doesn't "GRAPHIC PRINT" to the window? and I can't exit?
    Also, re created a second function for both the Mouse Button
    down and the Virtualkey function.

    ------------------

  • #2
    brent,

    soundsl like a coding problem. need to see the code to se what you are attempting.

    added:
    see this link for some possible hints: http://www.powerbasic.com/support/pb...ad.php?t=16959
    ------------------
    rick angell

    [this message has been edited by richard angell (edited november 19, 2005).]
    Rick Angell

    Comment


    • #3
      Hi Rick,

      In PBMAIN, have following code:

      hGraphicWindowChild = GetWindow (hWin, %GW_CHILD)
      GraphicWindowChildOldProc = SetWindowLong (hGraphicWindowChild, %GWL_WNDPROC, CODEPTR(GraphicWindowChildNewProc))
      pOldCallbackFunc = SetWindowLong(hWin, %GWL_WNDPROC, CODEPTR(NewCallbackFunc))

      Then I call a SUB and create small pop up window with handle hWin1:

      GRAPHIC WINDOW "",364,160,280,258 TO hWin1
      hGraphicWindowChild = GetWindow (hWin1, %GW_CHILD)
      GraphicWindowChildOldProc = SetWindowLong (hGraphicWindowChild, %GWL_WNDPROC, CODEPTR(GraphicWindowChildNewProc))
      pOldCallbackFunc = SetWindowLong(hWin1, %GWL_WNDPROC, CODEPTR(NewCallbackFunc))
      GRAPHIC ATTACH hWin1, 0

      But, until I changed GRAPHIC SET POS() to match smaller window positions, New smaller window,
      just sat there and would not respond? Even tried GRAPHIC SCALE()-(), but did not work?

      So, my conclusion is that in future, if I want to use another window, code will have to match
      window size?



      ------------------

      Comment


      • #4
        First, I just hacked up the other example a bit to show that you can do this ... and hacked is the word ... just to show some principles. You code seems to get mixed up a bit, maybe buy comparing this sample the lights wit turn up a bit.

        Gotta run 'til later or tommorrow though, C 'ya!

        Code:
        #COMPILE EXE
        #DIM ALL
        %USEMACROS = 1
        #INCLUDE "Win32API.inc"
        
           GLOBAL hGW, hGWC,GWold AS DWORD
           GLOBAL hMyPopUp,hPopUpSC,pOldPopUpCB AS DWORD
           GLOBAL Xm,Ym AS LONG   'mouse position
           GLOBAL Bt AS LONG      'indicates mouse button or motion, not used in this demo
          '---------------------------------------------------------------------
                
          '---------------------------------------------------------------------
            SUB PopLClick(hPopUp AS DWORD)
                GRAPHIC ATTACH hPopUp, 0
                GRAPHIC FONT "Arial",14, 1
                GRAPHIC SET POS (10,10)
                GRAPHIC PRINT "THE POPUP"
           END SUB
         '---------------------------------------------------------------------
           SUB PopRClick(hPopUp AS DWORD)
                GRAPHIC ATTACH hPopUp, 0
                GRAPHIC FONT "Arial",14, 1
                GRAPHIC SET POS (10,10)
                GRAPHIC PRINT "Will proceed to terminate"
                SLEEP 500
                SendMessage hPopUp,%WM_DESTROY,0,0
           END SUB
         '---------------------------------------------------------------------
           SUB MyPopUp()
                GRAPHIC WINDOW "My Popup",364,160,280,258 TO hMyPopUp
                hPopUpSC = GetWindow (hMyPopUp, %GW_CHILD)
                pOldPopUpCB = SetWindowLong(hPopUpSC, %GWL_WNDPROC, CODEPTR(GWnew))
           END SUB
         '---------------------------------------------------------------------
           SUB LMouseClick (hGWSC AS DWORD)     'you have to attach using the correct handle
               GRAPHIC ATTACH hGWSC,0           'but the rest of this sub is just to show
               GRAPHIC COLOR  %RED,%GREEN       'that you can print and draw
               GRAPHIC CLEAR
               GRAPHIC SET POS (10,10)
               GRAPHIC PRINT "Ouch! My Left Button is Sore, try the Right Button"
               GRAPHIC WIDTH 5
               GRAPHIC LINE (10,40)-(300,40)
               GRAPHIC WIDTH 1
           END SUB
         '---------------------------------------------------------------------
           SUB RMouseClick (hGWSC AS DWORD)
               GRAPHIC ATTACH hGWSC,0
               GRAPHIC COLOR %GREEN,%RED
               GRAPHIC CLEAR
               GRAPHIC SET POS (10,10)
               GRAPHIC PRINT "Ouch! My Right Button is Sore, try the Left Button"
               GRAPHIC WIDTH 5
               GRAPHIC LINE (10,40)-(300,40)
               GRAPHIC WIDTH 1
               IF hPopUpSC = 0 THEN MyPopUp
           END SUB
         '---------------------------------------------------------------------
           FUNCTION GWnew (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
              LOCAL lResult AS LONG
        
              lResult = CallWindowProc(GWold, hWnd, wMsg, wParam, lParam)
              Xm = LO(WORD,lParam) : Ym = HI(WORD,lParam)
        
              SELECT CASE wMsg
              CASE %WM_NCHITTEST
               IF lResult = %HTTRANSPARENT THEN lResult = %HTCLIENT
               Bt = -1
              CASE %WM_MOUSEMOVE
               IF hPopUpSC <> 0 AND hWnd = hGWC THEN EXIT FUNCTION
               SetWindowText GetParent(hWnd), "Move:          X = " + FORMAT$(Xm) + "    Y = " + FORMAT$(Ym)
               Bt = 0
              CASE %WM_LBUTTONDOWN
               SetWindowText GetParent(hWnd), "Left click:     X = " + FORMAT$(Xm) + "    Y = " + FORMAT$(Ym)
               Bt = 1
               IF hWnd = hGWC THEN
                    LMouseClick hWnd
                    IF hPopUpSC <> 0 THEN SetWindowPos hMyPopUp,%HWND_TOPMOST,364,160,280,258,%SWP_NOMOVE
               ELSE
                    PopLClick  hWnd
               END IF
              CASE %WM_RBUTTONDOWN
               SetWindowText GetParent(hWnd), "Right click:   X = " + FORMAT$(Xm) + "    Y = " + FORMAT$(Ym)
               Bt = 2
               IF hWnd = hGWC THEN
                    RMouseClick hWnd
                    IF hPopUpSC <> 0 THEN SetWindowPos hMyPopUp,%HWND_TOPMOST,364,160,280,258,%SWP_NOMOVE
               ELSE
                    PopRClick  hWnd
               END IF
              CASE %WM_DESTROY          'system menu X clicked
                  IF hWnd = hGWC THEN
                      SetWindowLong hWnd, %GWL_WNDPROC, GWold
                      GRAPHIC ATTACH hGW, 0
                      GRAPHIC WINDOW END
                      hGWC = 0
                      CONSOLE SET FOCUS
                  ELSE
                      SetWindowLong hWnd, %GWL_WNDPROC, pOldPopUpCB
                      GRAPHIC ATTACH hMyPopUp, 0
                      GRAPHIC WINDOW END
                      hPopUpSC = 0
                  END IF
                  
              END SELECT
              FUNCTION = lResult
           END FUNCTION
         '---------------------------------------------------------------------
        
            FUNCTION PBMAIN
        
              GRAPHIC WINDOW " ", 0, 0, 800, 600 TO hGW
              GRAPHIC ATTACH hGW, 0
        
              hGWC =  GetWindow(hGW, %GW_CHILD)
              GWold = SetWindowLong(hGWC, %GWL_WNDPROC, CODEPTR(GWnew))
              PRINT "Right Click in main window to display popup, if not 'up'"
              PRINT "Right Click in the popup window to terminate it"
              PRINT "Left Click in the popup window to see it respond"
              PRINT "Press any key to Terminate, "
              WAITKEY$
              IF hPopUpSC <> 0 THEN
                      SetWindowLong hPopUpSC, %GWL_WNDPROC, pOldPopUpCB
                      GRAPHIC ATTACH hMyPopUp, 0
                      GRAPHIC WINDOW END
              END IF
              IF hGWC <> 0 THEN
                  PRINT "Terminating in the Console Window"
                  SetWindowLong hGWC, %GWL_WNDPROC, GWold
                  GRAPHIC ATTACH hGW, 0
                  GRAPHIC WINDOW END
              END IF
            END FUNCTION

        ------------------
        Rick Angell
        Rick Angell

        Comment


        • #5
          Rick,

          Tried your code, but my program doesn't quite work the same way.
          In my 2nd post it works. I have a small window pop up(hWin1) and
          enter search word, then code merely changes to hWin(main big window)
          and checks search word. If there is a problem not finding it,
          then code ATTACH hWin1, 0 and goto: back to small window. Keypresses
          and mouse clicks and movement work as expected.

          Problem now is, after studing and trying your code, I realized
          that my "x" button on main window destroys screen, but program
          is still running underneath and I get unexpected SHELL out to
          another program every 25 secs? My usual way to exit is when user
          presses my programed exit button, focus goes to end of function
          were files are closed and "END FUNCTION". But with title bar "x"
          button, program keeps running in the background and I have to
          bring up task manager to get it to quit?

          ------------------

          Comment


          • #6
            In order to do this kind of situation you need to consider where you shutdown the subclassed GW's. Since I had the console showing a user could potentially exit form there as well as the system menu X for the GW's The GW's are easy enough, add the code in the WM_DESTROY filter as shown, make sure that if the pop-up has it's own system menu, it also removes its subclass and ends itself. In my testing I found that having multiple exits covered did not leave things running. You'd need to post a lot more code for us to see where things are missing getting the message.

            ------------------
            Rick Angell
            Rick Angell

            Comment


            • #7
              Rick,

              I tried umteen different senarios and can't get program to exit
              with the "x" button on title bar? Here is the mess that I have,
              hope you can make sense of it:
              Code:
              #COMPILER PBCC 4
               #COMPILE EXE
               #CONSOLE OFF   'Enable or disable auto-creation of a console window upon execution of the program.
               #REGISTER NONE
              
                  GLOBAL GraphicWindowChildOldProc  AS DWORD 'NEEDED FOR FUNCTION GRAPHICWINDOWCHILDNEWPROC
                  'GLOBAL pOldCallbackFunc AS DWORD           'NEEDED FOR FUNCTION NEWCALLBACKFUNC
                  %CCWIN = 1
                  #INCLUDE "C:\PBCC40\WINAPI\WIN32API.INC"   'NEEDED FOR BEEP TO WORK
               
              
                   FUNCTION GraphicWindowChildNewProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                    DIM lResult  AS LOCAL LONG
                    GLOBAL hGraphicWindowChild AS DWORD 'DIM hGraphicWindowChild AS LOCAL  DWORD
                    'GLOBAL pOldCallbackFunc AS DWORD
                    DIM Colx AS GLOBAL LONG  '(MOUSE CURSOR POS, OF COLUMN 'added by me
                    DIM Rowy AS GLOBAL LONG  '(MOUSE CURSOR POS, OF ROW    'added by me
                    DIM LCLK AS GLOBAL STRING, RCLK AS GLOBAL STRING       'NOT USED 'added by me
                    DIM KM AS GLOBAL LONG                     '(LFT CLK = 1, RGT CLK = 2) 'added by me for lft clk
                    DIM hWin AS GLOBAL DWORD
                    'DIM hWin1 AS GLOBAL DWORD
                    'DIM MOUSEPTR AS GLOBAL LONG, MYCURSOR AS GLOBAL LONG
                    lResult = CallWindowProc (GraphicWindowChildOldProc, hWnd, wMsg, wParam, lParam)
              
                    SELECT CASE wMsg
                       CASE %WM_NCHITTEST
                          IF lResult = %HTTRANSPARENT THEN lResult = %HTCLIENT
              
                       CASE %WM_MOUSEMOVE
                          'SetWIndowText GetParent(hWnd), "Move: X = " + FORMAT$(LOWRD(lParam)) + " Y = " + FORMAT$(HIWRD(lParam))
                          Colx = (LOWRD(lParam)): Rowy = (HIWRD(lParam)) 'added to get column and row by me
                       CASE %WM_LBUTTONDOWN
                          'SetWIndowText GetParent(hWnd), "Left click : X = " + FORMAT$(LOWRD(lParam)) + " Y = " + FORMAT$(HIWRD(lParam))
                          KM = 1 'LCLK = "LFT CLK": KM = 1
                       CASE %WM_RBUTTONDOWN
                          'SetWIndowText GetParent(hWnd), "Right click : X = " + FORMAT$(LOWRD(lParam)) + " Y = " + FORMAT$(HIWRD(lParam))
                          KM = 2 'RCLK = "RGT CLK": KM = 2
                       CASE %WM_DESTROY          'system menu X clicked
                        IF hWnd = hWin THEN
                            SetWindowLong hWnd, %GWL_WNDPROC, hGraphicWindowChild 'GraphicWindowChildOldProc 'Semen GWold
                            GRAPHIC ATTACH hWin, 0
                            GRAPHIC WINDOW END
                            'SetWindowLong hWnd, %GWL_WNDPROC, pOldCallbackFunc 'Greg
                            'GRAPHIC ATTACH hWin, 0
                            'GRAPHIC WINDOW END
                            hWin = 0
                        END IF
              
                    END SELECT
                    FUNCTION = lResult
              
                   END FUNCTION
              Code:
                  DEFLNG A-Z
                  FUNCTION WINMAIN (BYVAL hCurInstance  AS LONG, _
                                    BYVAL hPrevInstance AS LONG, _
                                    BYVAL lpszCmdLine   AS ASCIIZ PTR, _
                                    BYVAL nCmdShow      AS LONG) _
                                    EXPORT AS LONG
                  'FUNCTION PBMAIN() AS LONG
                                    LOCAL Day AS STRING 'ADDED TO GET DAY
                                    Day = PARSE$(DayofTheWeek,1)'OF WEEK
                    DIM hWin AS GLOBAL DWORD        'so you don't have to create another Window(flashes)
                    DIM hWin1 AS GLOBAL DWORD
                    DIM hbmp AS GLOBAL DWORD
                    DIM hbmp1 AS GLOBAL DWORD
                    DIM hGraphicWindowChild                     AS LOCAL  DWORD
                    DIM nWidth                                  AS LOCAL  SINGLE
                    DIM nHeight                                 AS LOCAL  SINGLE
                    GLOBAL pOldCallbackFunc AS DWORD
                    GLOBAL KA&
                    DIM KPRS AS GLOBAL STRING * 1
                    GLOBAL ncWidth&, ncHeight&
                    DESKTOP GET CLIENT TO ncWidth&, ncHeight&
                    GRAPHIC WINDOW "MyBook1",0,0,ncWidth&, ncHeight& TO hWin 'hGW
                    GRAPHIC SET POS ((ncWidth&-nWidth!)/2,ncHeight&/2 - nHeight!/2)
              
                    hGraphicWindowChild = GetWindow (hWin, %GW_CHILD)
                    GraphicWindowChildOldProc = SetWindowLong (hGraphicWindowChild, %GWL_WNDPROC, CODEPTR(GraphicWindowChildNewProc))
                    pOldCallbackFunc = SetWindowLong(hWin, %GWL_WNDPROC, CODEPTR(NewCallbackFunc))
              
                  IF KE& = 68 THEN
              	CALL REDBOX
                  ELSEIF KE& = WHATEVER THEN
              	 CALL WHATEVER
                  ELSEIF KE& = 88 THEN '<X>  'EXIT BUTTON 
                    CLOSE #nFile  
                  END IF	
                 END FUNCTION
              Code:
                   FUNCTION NewCallbackFunc (BYVAL hWnd AS DWORD, BYVAL Msg AS DWORD, BYVAL wParam AS DWORD, BYVAL lPARAM AS LONG) AS LONG
                   DIM gVirtKey AS GLOBAL LONG
                   IF Msg = %WM_CHAR THEN
                    gVirtKey = wParam
                    'DKK$ = TRIM$(STR$(gVirtKey))
                    'KA& = VAL(DKK$): DKK$ = "": KPRS$ = CHR$(KA&)
                    KA& = gVirtKey: KPRS = CHR$(KA&)
                   ELSEIF Msg = %WM_KEYDOWN THEN  'gets key <B> etc only when shift is down
                    gVirtKey = wParam
                    'DKK$ = TRIM$(STR$(gVirtKey)): KE& = VAL(DKK$): KA& = 0
                    KE& = gVirtKey: KA& = 0
                   ELSEIF Msg = %WM_DESTROY THEN
                    IF hWnd = hWin THEN
                   '  'SetWindowLong hWnd, %GWL_WNDPROC, GraphicWindowChildOldProc 'Semen GWold
                     SetWindowLong hWnd, %GWL_WNDPROC, pOldCallbackFunc 'Greg
                     GRAPHIC ATTACH hWin, 0
                     GRAPHIC WINDOW END
                     hWin = 0
                    END IF
                   END IF
                    FUNCTION = CallWindowProc(pOldCallbackFunc, hWnd, Msg, wParam, lParam)
                   END FUNCTION
              '===================================================================================================================


              ------------------


              [This message has been edited by BRENT GARDNER (edited November 24, 2005).]

              Comment


              • #8
                The basic problem with using cut and paste is that first it helps to get a good sense of program structure. This is why you see many samples that are complete when posted, although not all. It would be really good to spend some time just looking at the structure of the PB supplied and even download samples so the idea of structure will be yours too. This will help you and also help fellow PB'ers help you more quickly as you learn the product. What follows is not a "bible", just a general idea of how many programs are organized:

                <U>Compiler Directives</U>
                e.g.
                #COMPILE EXE
                #DIM ALL

                <U>Standard includes </U>
                e.g.
                #INCLUDE "Win32API.inc"

                <U>Equates</U>
                <U>Globals</U>
                <U>Function Declarations</U>
                Note: if you do not use function declarations the functions need to be defined before they are called. So you would have any worker functions used by a call bakc to appear before the callback, then the callbacks, then the MAIN function.
                <U>The Subs and Functions of your program.</U>

                Giving a program "good form" helps to see where you can avoid unpredictable" results, not to mention just crash and burning! Using the #DIM ALL compiler directive helps avoid variable conflict and misuse, for example declaring a variable as both GLOBAL and LOCAL, like hGraphicWindowChild in your listing. I've gotta run for now, some day job work is waiting, However other's might be able to jump in here. If not why not try shaping a copy of the code into the general form listed or one you can copy from the forums or PB. Then plug the code in and try to collect the globals together. Put in the #DIM ALL and iterate at compiling until it starts to tick. Then you should also see some insight as to where problems may lie.


                ------------------
                Rick Angell
                Rick Angell

                Comment


                • #9
                  The program was originally structured to run without a title bar.
                  This may be the problem. There were no "WM_DESTROY" message
                  handling. I just added to functions were I though they should be.
                  Maybe I'll have to go without title bar - cause I have no idea
                  how to get to exit with title bar "x".

                  ------------------

                  Comment


                  • #10
                    cause I have no idea how to get to exit with title bar "x".
                    That action will send you a WM_SYSCOMMAND message with an SC_CLOSE notification.

                    (Note you'll get the same message & notification if user hits Alt+F4)

                    You can do whatever you want when you detect it.





                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      WM_DESTROY results after the WM_SYSCOMMAND with the SC_CLOSE notification. AFAIK all winows being closed see this message, regardless of how the shut down porcess started. It is where many examples release the subclassing and end bitmaps, and graphic windows. Here, you are subclassing a PB GRAPHIC WINDOW. so the WM_DESTROY is going to happen in the sub-class before the private code really sees it. GRAPHIC WINDOW END invokes the process for the hiden private callback, which may have more things to do which only PB personnel could shed light on. Just passing by though, look at the code more later.

                      ------------------
                      Rick Angell
                      Rick Angell

                      Comment


                      • #12
                        Brent,

                        I've been looking at your code a bit during a break, will have more time later this week. One thing your code is perhaps confusing is that you need 2 GW's, one is the main window, the other is the small pop-up. I only see one window in your post. A pop-up would typically be created when you need it, otherwise with you are trying to achieve is similar to a modeless window.

                        So you would want to have a GetWindow followed by a SetWindowLong after the particuar GW, main or pop-up is created.

                        After you subclass the primary GW, then decide to either create the pop-up at that point or at the first need for it. If you maintain the user's last input you can optionally destroy the pop-up between uses, recreating it if needed again. Only you have an idea of the frequency of use. In the create once scenario though you just need check to see if the handle is assigned or is 0 to determine to create and/or show it.

                        My example showed how one subclass callback function could sort things out, but it could be 2 separate CBs as well. Note the example I posted was modified from another posted example, to show mainly the interactivity for mouse,keys and flip/flop between the main GW and the pop-up GW, which is what you were asking about.

                        ------------------
                        Rick Angell
                        Rick Angell

                        Comment


                        • #13
                          Rick,

                          I only want to exit mainprogram when there are no small pop up
                          windows active. The pop up windows are created as needed and
                          I put title bar back on them to see if they would quite properely
                          and they did. So, just mainprogram will not quit from the "x"
                          buttom on title bar. I tried to catch the alt + f4 key whick
                          shows as "115", but doesn't work because program window quits
                          and keeps running in background?

                          ------------------

                          Comment


                          • #14
                            "I only want to exit mainprogram when there are no small pop up
                            windows active. "

                            That's why you can check to see if pop-ups are still active in the Main GW's subclass's WM_DESTROY message, and also in the console, if used, as posted. When you terminate any GW, it's handle should be then revert to the value 0. So if the GW's handll is > 0, the GW still needs to be to be shut down. First though you should remove the subclassing and close it through the normal GRAPHIC ATTACH and GRAPHIC WINDOW END sequence. This way the GW's private callback can terminate properly. No memory leaks, no tail ends still running doing nothing



                            ------------------
                            Rick Angell
                            Rick Angell

                            Comment


                            • #15
                              I guess no one knows how to get title "x" to work properely with
                              the structure of my program (I sure don't). Only reason to have
                              title bar is so user can minimize or move if it becomes necessary.
                              If there is a way to simply gray out "x" button, so it is not
                              active - that would do the job?

                              ------------------

                              Comment


                              • #16
                                I guess no one knows how to get title "x" to work properely with the structure of my program (I sure don't).
                                ??? What's "properly?"

                                That said, I'm not so sure you can even detect actions from the <U>console</U> window the same as you can detect them on a "program-created" window.

                                Were you to create your own window instead of using the console window, you will be able to process WM_SYSCOMMAND/WM_CLOSE and prevent the user from ending when he shouldn't.

                                Consoles are different animals from 'regular' windows and dialogs. Maybe Perfect Sync's Console Tools product has a solution.



                                [This message has been edited by Michael Mattias (edited November 23, 2005).]
                                Michael Mattias
                                Tal Systems (retired)
                                Port Washington WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment


                                • #17
                                  Brent,

                                  Please be clear about the "x". Do you mean the console window? That will be difficult. I've already posted an example that worked here for a GW.

                                  ------------------
                                  Rick Angell

                                  [This message has been edited by Richard Angell (edited November 23, 2005).]
                                  Rick Angell

                                  Comment


                                  • #18
                                    I guess no one knows how to get title "x" to work properely with
                                    the structure of my program (I sure don't).
                                    3 problems:

                                    1) I can't follow code posts without code tags so
                                    2) I can't see how your program is structured
                                    3) At least some of the global variables you use aren't declared in the code you posted, so it won't compile

                                    If there is a way to simply gray out "x" button, so it is not
                                    active - that would do the job?
                                    Yes, there is - but I don't think that's what you want to do. If you want the application to close completely, you will have to process the %WM_SYSCOMMAND message in your graphic window callback as suggested, as follows:

                                    Code:
                                    CASE %WM_SYSCOMMAND
                                        IF (wParam AND &HFFF0)=%SC_CLOSE THEN
                                            ' execute code here, or set a global flag that says get out to the rest of the app
                                        END IF
                                    You can disable the 'X' in the console:

                                    Code:
                                    EnableMenuItem GetSystemMenu(CONSHNDL, 0), %SC_CLOSE, %MF_BYCOMMAND OR %MF_GRAYED
                                    And you can disable the 'X' in the Graphic window by substituting it's window handle in:

                                    Code:
                                    EnableMenuItem GetSystemMenu(hWnd, 0), %SC_CLOSE, %MF_BYCOMMAND OR %MF_GRAYED
                                    You can also block the 'X' on the graphic window like this:

                                    Code:
                                    CASE %WM_SYSCOMMAND
                                        IF (wParam AND &HFFF0)=%SC_CLOSE THEN
                                            FUNCTION=1
                                            EXIT FUNCTION
                                        END IF
                                    ------------------


                                    [This message has been edited by Adam J. Drake (edited November 24, 2005).]
                                    Adam Drake
                                    PowerBASIC

                                    Comment


                                    • #19
                                      Adam,

                                      You make life so much easier. Your solutions are very easy to
                                      understand and work perfectly - Thank You!

                                      1) I can't follow code posts without code tags so
                                      2) I can't see how your program is structured
                                      3) At least some of the global variables you use aren't declared in the code you posted, so it won't compile

                                      3: #COMPILER PBCC 4
                                      #COMPILE EXE
                                      #CONSOLE OFF 'Enable or disable auto-creation of a console window upon execution of the program.
                                      #REGISTER NONE

                                      GLOBAL GraphicWindowChildOldProc AS DWORD 'NEEDED FOR FUNCTION GRAPHICWINDOWCHILDNEWPROC
                                      ' DECLARE IS BEFORE WINMAIN FUNCTION
                                      DECLARE FUNCTION NewCallbackFunc(BYVAL hWnd AS DWORD, BYVAL Msg AS DWORD, BYVAL wParam AS DWORD, BYVAL lPARAM AS LONG) AS LONG

                                      I don't have a callback, cause this is in PBCC4 WITH GRAPHICS.
                                      I'll try to add code tags, but I just cut and pasted segments because of
                                      size of program.

                                      Happy Thanksgiving!

                                      P.S.
                                      Just noticed that by using %wm_sys command in mouse function and
                                      virtkey function it works fine for main program, but the little
                                      pop up boxes don't close? So, I think I'll just use then EnableMenuItem
                                      which grays out "x" button.
                                      ------------------




                                      [This message has been edited by BRENT GARDNER (edited November 24, 2005).]

                                      Comment


                                      • #20
                                        Brent,

                                        For the popup if you do not want a caption, and simply set the caption to "" in the GRAPHIC WINDOW set up, you get no caption bar or "x" to worry about anyway. I think you already noticed that.

                                        But when using #CONSOLE OFF, you need a way to exit the program. If you choose to remove the main GW's "x' from consideration, and use some key or key combo to quit, then you will still need to end the subclassing and properly end the GW or you'll likley have some nice memory leaks.

                                        ------------------
                                        Rick Angell



                                        [This message has been edited by Richard Angell (edited November 24, 2005).]
                                        Rick Angell

                                        Comment

                                        Working...
                                        X