Announcement

Collapse

Maintenance

The forum could be offline for 30-60 minutes in the very near future for maintenance (said 3pm Pacific). I was behind on getting this notice. I do apologize.
See more
See less

Best Technique to refresh a DIALOG

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

  • Michael Mattias
    replied
    >MACRO CONTROL MOVE = CONTROL SET LOC

    :doh:

    Leave a comment:


  • StanHelton
    replied
    Originally posted by Michael Mattias View Post
    >It's CONTROL SET LOC

    I kind of like the sound of 'CONTROL MOVE' better.
    MACRO CONTROL MOVE = CONTROL SET LOC

    Leave a comment:


  • Rodney Hicks
    replied
    I want to refresh the dialog screen because the button images need to be in a re-sorted order.
    DIALOG REDRAW

    Rod

    Leave a comment:


  • Michael Mattias
    replied
    >It's CONTROL SET LOC

    I kind of like the sound of 'CONTROL MOVE' better.

    Leave a comment:


  • Christopher Becker
    replied
    I just realized I posted this PBWin question in the Console Compiler forum. Sorry, guys, sick pregnant wife and sick 5-year old mean no sleep for me!

    Leave a comment:


  • Christopher Becker
    replied
    Rtfm...

    Michael, you're right. It's CONTROL SET LOC hDlg, id&, x&, y&

    Couldn't be easier. Sorry I missed it. Usually I exhaust the Help Screens before posting here. Thanks for the point.

    Leave a comment:


  • Michael Mattias
    replied
    Not a DDT guy but I'm sure there is some kind of "CONTROL MOVE" command.....

    MCM

    Leave a comment:


  • Christopher Becker
    replied
    Moving controls ?

    Michael, thanks for the reply. You said, "Move the controls to their new position based on the new sort order and repainting is automatic."

    Do you mean just another "CONTROL LABEL ADD" statement?

    Let me show what I'm doing:

    handle = LoadImage( "x.bmp", etc...)
    CONTROL ADD LABEL, hDialog, xButtonID, xPos, yPos, etc...
    CONTROL SEND hDialog, xButtonID, %STM_SETIMAGE, %IMAGE_BITMAP, handle

    This draws the clickable "x.bmp" image at xPos, yPos. Now, if I want to keep everything the same, except move its position, can I just send another CONTROL ADD LABEL statement with new xPos, yPos? I played with that idea a little but could not get it to move. I even tried adding a CONTROL REDRAW statement. What am I missing?

    These updates will be infrequent, so I'm not worried about flicker.

    Leave a comment:


  • Chris Boss
    replied
    It may be better to simulate multiple buttons using a Graphic control.

    Here is an example:

    Code:
    ' ***************************************************************
    '   This code can be used Royalty Free and Freely Distributed !
    ' ***************************************************************
    #COMPILE EXE
    #REGISTER NONE
    #DIM ALL          '  This is helpful to prevent errors in coding
    #INCLUDE "win32api.inc"   ' Must come first before other include files !
    ' *************************************************************
    '                  Constants and Declares (#1)
    ' *************************************************************
    DECLARE SUB LIB_InitFonts()
    DECLARE SUB LIB_InitColors()
    DECLARE SUB LIB_DeleteBrushes()
    %FORM1_GRAPHIC1             = 100
    %FORM1_RSBUTTON           = 105
    ' --------------------------------------------------
    DECLARE SUB ShowDialog_Form1(BYVAL hParent&)
    DECLARE CALLBACK FUNCTION Form1_DLGPROC
    ' --------------------------------------------------
    DECLARE CALLBACK FUNCTION CBF_FORM1_RSBUTTON()
    '
    ' *************************************************************
    '               Application Globals Variables (#2)
    ' *************************************************************
    '
    GLOBAL App_Brush&()
    GLOBAL App_Color&()
    GLOBAL App_Font&()
    GLOBAL hForm1&    ' Dialog handle
    '
    ' *************************************************************
    '                    Application Entrance
    ' *************************************************************
    '
    FUNCTION PBMAIN
        LOCAL Count&
        LIB_InitColors
        LIB_InitFonts
        ShowDialog_Form1 0
        DO
            DIALOG DOEVENTS TO Count&
        LOOP UNTIL Count&=0
        LIB_DeleteBrushes
    END FUNCTION
    '
    ' *************************************************************
    '                    Application Dialogs (#3)
    ' *************************************************************
    '
    %ButtonRows    =    10
    %ButtonCols    =    10
    '
    GLOBAL XRatio!, YRatio!
    '
    SUB SetAPIScale(BYVAL hDlg&, BYVAL IDNum&, BYVAL W&, BYVAL H&)
         LOCAL hCtrl&, R AS RECT
         CONTROL HANDLE hDlg&, IDNum& TO hCtrl&
         GetClientRect hCtrl&, R
         XRatio!=R.nRight/W&
         YRatio!=R.nBottom/H&
    END SUB
    FUNCTION API_X(BYVAL X&) AS LONG
         FUNCTION=XRatio!*X&
    END FUNCTION
    FUNCTION API_Y(BYVAL Y&) AS LONG
         FUNCTION=YRatio!*Y&
    END FUNCTION
    SUB DrawFakeButtons(BYVAL hDlg&, BYVAL IDNum&)
         LOCAL hCtrl&, R&, C&, X&, Y&, V1&, V2&, V3&, MyColor&, hDC&, RR AS RECT
         CONTROL HANDLE hDlg&, IDNum& TO hCtrl&
         GRAPHIC ATTACH hDlg&, IDNum&, REDRAW
         GRAPHIC SCALE (0,0) - (%ButtonRows*10,%ButtonCols*10)
         SetAPIScale hDlg&, IDNum&,%ButtonRows*10,%ButtonCols*10
         GRAPHIC GET DC TO hDC&
         FOR R&=1 TO %ButtonRows
              FOR C&=1 TO %ButtonCols
                   ' draw button here
                   X&=(C&-1)*10
                   Y&=(R&-1)*10
                   V1&=RND(32,255)
                   V2&=RND(128,255)
                   V3&=RND(32,255)
                   MyColor&=RGB(V1&,V2&,V3&)
                   RR.nLeft=API_X(X&)
                   RR.nRight=RR.nLeft+API_X(10)
                   RR.nTop=API_Y(Y&)
                   RR.nBottom=RR.nTop+API_Y(10)
                   DrawFrameControl hDC&, BYVAL VARPTR(RR), %DFC_BUTTON, %DFCS_BUTTONPUSH
                   GRAPHIC BOX (X&+1,Y&+1)-(X&+9,Y&+9), 0, MyColor&, MyColor&
              NEXT C&
         NEXT R&
         GRAPHIC REDRAW
    END SUB
    SUB ShowDialog_Form1(BYVAL hParent&)
        LOCAL Style&, ExStyle&
        LOCAL N&, CT&        '  Variables used for Reading Data in Arrays for Listbox and Combobox
        '   hParent& = 0 if no parent Dialog
        Style& = %WS_POPUP OR %DS_MODALFRAME OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %DS_CENTER
        ExStyle& = 0
        DIALOG NEW hParent&, "Your Dialog", 0, 0,  325,  266, Style&, ExStyle& TO hForm1&
        CONTROL ADD GRAPHIC, hForm1&,  %FORM1_GRAPHIC1,  "", 8, 7, 309, 224
        DrawFakeButtons hForm1&, %FORM1_GRAPHIC1
        CONTROL ADD "Button", hForm1&,  %FORM1_RSBUTTON,  "Resort Fake Buttons", 227, 244, 91, 15, _
            %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP CALL CBF_FORM1_RSBUTTON
        DIALOG SHOW MODELESS hForm1& , CALL Form1_DLGPROC
    END SUB
    '
    ' *************************************************************
    '                             Dialog Callback Procedure
    '                             for Form Form1
    '                             uses Global Handle - hForm1&
    ' *************************************************************
    '
    GLOBAL Original_Address AS DWORD
    '
    FUNCTION Graphic_SubClassProc(BYVAL hWnd&, BYVAL Msg&, BYVAL wParam&, BYVAL lParam&) AS LONG
         SELECT CASE Msg&
              CASE %WM_DESTROY
                   SetWindowLong hWnd&, %GWL_WNDPROC, Original_Address
              CASE %WM_LBUTTONUP
                   LOCAL X&, Y&, R&, C&, RR AS RECT, V&
                   X&=LOWRD(lParam&)
                   Y&=HIWRD(lParam&)
                   GetClientRect hWnd&, RR
                   R&=INT(Y&/INT(RR.nBottom/%ButtonRows))+1
                   C&=INT(X&/INT(RR.nRight/%ButtonCols))+1
                   MSGBOX "Button:  Row:"+STR$(R&)+" Column:"+STR$(C&)
              CASE ELSE
         END SELECT
         FUNCTION=CallWindowProc(Original_Address, hWnd&, Msg&, wParam&, lParam&)
    END FUNCTION
    '
    CALLBACK FUNCTION Form1_DLGPROC
        LOCAL hCtrl&
        SELECT CASE CBMSG
            CASE %WM_INITDIALOG
                   CONTROL HANDLE hForm1&,  %FORM1_GRAPHIC1 TO hCtrl&
                   Original_Address=SetWindowLong(hCtrl&, %GWL_WNDPROC, CODEPTR(Graphic_SubClassProc))
            CASE ELSE
        END SELECT
    END FUNCTION
    '
    ' *******************************************************************
    ' *                         Library Code   *
    ' ********************************************************************
    '
    SUB LIB_InitFonts()
        REDIM App_Font(0 TO 5)
        App_Font(0)=GetStockObject(%SYSTEM_FONT)
        App_Font(1)=GetStockObject(%SYSTEM_FIXED_FONT)
        App_Font(2)=GetStockObject(%ANSI_VAR_FONT)
        App_Font(3)=GetStockObject(%ANSI_FIXED_FONT)
        App_Font(4)=GetStockObject(%DEFAULT_GUI_FONT)    ' MS Sans Serif
        App_Font(5)=GetStockObject(%OEM_FIXED_FONT)      ' Terminal Font
        ' Fonts 0 to 5 do not need to be deleted since they are System Fonts
    END SUB
    '
    ' -------------------------------------------------------------
    '
    SUB LIB_InitColors()
        DATA         0,  8388608,    32768,  8421376,      196,  8388736,    16512, 12895428
        DATA   8421504, 16711680,    65280, 16776960,      255, 16711935,    65535, 16777215
        DATA  10790052, 16752768, 10551200, 16777120, 10526975, 16752895, 10551295, 13948116
        DATA  11842740, 16768188, 14483420, 16777180, 14474495, 16768255, 14483455, 15000804
        LOCAL T&, RGBVal&
        REDIM App_Brush&(0 TO 31)
        REDIM App_Color&(0 TO 31)
        FOR T&=0 TO 31
            RGBVal&=VAL(READ$(T&+1))
            App_Brush&(T&)=CreateSolidBrush(RGBVal&)
            App_Color&(T&)=RGBVal&
        NEXT T&
    END SUB
    '
    ' -------------------------------------------------------------
    '
    SUB LIB_DeleteBrushes()
        LOCAL T&
        FOR T&=0 TO 31
            DeleteObject App_Brush&(T&)
        NEXT T&
    END SUB
    '
    ' ------------------------------------------------
    '
    CALLBACK FUNCTION CBF_FORM1_RSBUTTON
        IF CBCTLMSG=%BN_CLICKED THEN
              DrawFakeButtons hForm1&, %FORM1_GRAPHIC1
        END IF
    END FUNCTION
    By subclassing the Graphic control you cna test for button clicks.
    Attached Files

    Leave a comment:


  • Michael Mattias
    replied
    Considered using a listview control in small icon mode?

    There are 'arrange' commands for the listview (LVM_SETITEMPOSITION) which do this kind of thing quite efficiently;
    and, you can use a single image list to hold all the image handles.

    Plus, it would allow the user to do his own arranging of icons on the screen.

    It's a thought.

    Leave a comment:


  • Michael Mattias
    replied
    Move the controls to their new position based on the new sort order and repainting is automatic.

    However, I think for this many controls I'd use the BeginDeferWindowPos/DeferWindowPos/EndDeferWindowPos sequence to avoid flicker.

    MCM

    Leave a comment:


  • Christopher Becker
    started a topic Best Technique to refresh a DIALOG

    Best Technique to refresh a DIALOG

    Hi everyone. I'm using PB/Win 8. I have an application that first creates about 100 small bitmap images, then adds them to a DIALOG as CONTROLs (clickable buttons). The user can add new CONTROLS (clickable buttons), but when this happens, I want to refresh the dialog screen because the button images need to be in a re-sorted order.

    The question: what's the best technique to refresh the DIALOG? Use DIALOG END and re-create it? Or use GRAPHICS to overwrite the screen and re-draw the image buttons? If I re-draw the buttons, will there be an issue of using CONTROL ADD with the same id# more than once?

    I'm reluctant to use DIALOG END because it would be triggered from deep inside a CALLBACK function, but the main DIALOG SHOW statement is the last line way up in PBMAIN(). It would take some work to loop back to it.

    Thanks.
    Christopher
Working...
X