windows message & dialog boxes

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
Roe5685
Posts: 71
Joined: Nov 07, 2011 0:36
Location: NY

windows message & dialog boxes

Post by Roe5685 »

My private business ( not pleasure! ) programs all done with FB work at the command line in windows 7 64 bit ultimate, win 8 64 bit and server 2008.
you enter name of program then add tons of switches.
there is very little dialog as the program runs and then program announces the answers are in file xxxx.
all of this works well. It does not have to look pretty.
they are simple utility files manipulating lots of data.
By chance we found code in Free Basic site for a Windows Message Box.
It is extremely simple code. You enter several lines of text using the chr$(13) to start a new line.
We now use them where we need to interact with the user.
They allow us to give the user several lines of up to date data then he can say yes or no using the mouse.

What we would like: Some simple code to increase size and change position of message box, edit font size and so forth.
Some simple code to create a dialog box where user can input one of 4 or 5 choices and can write in some data.
Like I said these boxes only need to be functional. They are simple utilities programs.

Thanks,
Roe5685
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: windows message & dialog boxes

Post by TJF »

Roe5685 wrote:... user can input one of 4 or 5 choices and can write in some data.
What kind of data? Text, Images, files, ... Clipboard support, printing, helpfiles?

I recommend to specify your needs well befor you search for the matching toolkit / code. You'd be on the safe side by using GTK+, but it's some work to get started.
Roe5685
Posts: 71
Joined: Nov 07, 2011 0:36
Location: NY

Re: windows message & dialog boxes

Post by Roe5685 »

just data. words and numbers and names.
I put the data over sevearal lines for reader to look at using message box.
but I need a better message box so to speak.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: windows message & dialog boxes

Post by MichaelW »

For simple dialogs basing the dialog on an in-memory template works well. This is a quick modification of an existing demo that I hope will provide some useful information.

Code: Select all

''=============================================================================
#include "dialogs.bas"

''------------------------------------------------------
'' Dialogs.bas is available here:
'' http://www.freebasic.net/forum/viewtopic.php?t=5667
''------------------------------------------------------

''=============================================================================

#define IDC_BTN1  1001
#define IDC_BTN2  1002
#define IDC_LBL1  1003
#define IDC_LBL2  1004
#define IDC_EDIT1 1005
#define IDC_EDIT2 1006

''=============================================================================

''----------------------------------------------------
'' This function demonstrates how to create a logical
'' font based on a point size and typeface name.
''----------------------------------------------------

function MakeFont( byval pointSize as integer, _
                   byref fontName as string ) as HFONT

    dim as integer lpy, nHeight

    lpy =  GetDeviceCaps( GetDC(0), LOGPIXELSY )
    nHeight = lpy * pointSize / 72

    return CreateFont( nHeight, 0, NULL, NULL, FW_NORMAL, NULL, NULL, NULL, _
                       DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, _
                       PROOF_QUALITY, DEFAULT_PITCH or FF_DONTCARE, _
                       strptr(fontName) )
end function

''=============================================================================

function DialogProc( byval hwndDlg as  HWND, _
                     byval uMsg as UINT, _
                     byval wParam as WPARAM, _
                     byval lParam as LPARAM ) as integer

    static as HWND hwndEdit2
    static as HFONT hFont1

    select case uMsg

        case WM_INITDIALOG

            ''-----------------------------------------------------
            '' Create a font and send the handle to the first edit
            '' control in a WM_SETFONT message.
            ''-----------------------------------------------------

            hFont1 = MakeFont( 20, "Arial Bold" )

            SendDlgItemMessage( hwndDlg, IDC_EDIT1, WM_SETFONT, _
                                cast(LPARAM,hFont1), 0 )

            ''------------------------------------------------------
            '' Save the handle for the read-only edit control so it
            '' will be available to the WM_CTLCOLORSTATIC handler.
            ''------------------------------------------------------

            hwndEdit2 = GetDlgItem( hwndDlg, IDC_EDIT2 )


        case WM_CTLCOLORSTATIC

            ''--------------------------------------------------------
            '' Change the background for the read-only edit control,
            '' which by default is too dark for easy reading, to a
            '' more normal white. The test of the handle is necessary
            '' because this message is called for static controls as
            '' well as read-only edit controls, and we wish to change
            '' the background only for the read-only edit control,
            '' and not for the two RText static controls that contain
            '' the edit control labels.
            ''--------------------------------------------------------

            if lParam = hwndEdit2 then

                return cast(integer,GetStockObject( WHITE_BRUSH ))

            end if

        case WM_COMMAND

            ''--------------------------------------------------------------
            '' To detect a button click it's only necessary to match wParam
            '' to the button control ID. This works because the control ID
            '' is stored in the low-order word of wParam and notification
            '' code in the high-order word, and the value of the BN_CLICKED
            '' notification is zero.
            ''--------------------------------------------------------------

            select case wParam

                case IDC_BTN1

                    MessageBox( hwndDlg, "Button 1 clicked", "Test", MB_OK )

                case IDC_BTN2

                    MessageBox( hwndDlg, "Button 2 clicked", "Test", MB_OK )

                ''------------------------------------------
                '' This allows the user to close the dialog
                '' by pressing the Escape key.
                ''------------------------------------------

                case IDCANCEL

                    DestroyWindow( hwndDlg )

            end select

        case WM_CLOSE

            DestroyWindow( hwndDlg )

        case WM_DESTROY

            DeleteObject( hFont1 )
            PostQuitMessage( null )

    end select

    return 0

end function

''=============================================================================

dim as LPDLGTEMPLATE lpdt
dim as HWND hDlg
dim as MSG wMsg

''-------------------------------------------------
'' For a modeless dialog the WS_VISIBLE style must
'' be specified for the dialog to be visible.
''-------------------------------------------------

Dialog( 6, 0, 0, 120, 90, _
        "Test", _
        lpdt, _
        WS_OVERLAPPED or WS_SYSMENU or WS_VISIBLE or DS_SETFONT or DS_CENTER, _
        20, "Comic Sans MS" )

RText( IDC_LBL1,     12, 11, 23, 8, "Label1:" )
EditText( IDC_EDIT1, 38, 11, 65, 8, "", _
          WS_BORDER or ES_AUTOHSCROLL or WS_TABSTOP )

RText( IDC_LBL2,     12, 33, 23, 8, "Label2:" )
EditText( IDC_EDIT2, 38, 33, 65, 8, "123456789", _
          WS_BORDER or ES_READONLY )

PushButton( IDC_BTN1, 13, 56,  40, 12, "Button&1", WS_TABSTOP )
PushButton( IDC_BTN2, 64, 56,  40, 12, "Button&2", WS_TABSTOP )

hDlg = CreateModelessDialog( 0, @DialogProc, 0, lpdt )

do while GetMessage( @wMsg, null, 0, 0 ) <> 0

    IsDialogMessage( hDlg,  @wMsg )

loop

''=============================================================================
I forgot to add, in the comments, that the controls default to the dialog font, and that unless the dialog style includes the DS_SETFONT style and a font size is specified in the template, the dialog will use a system-defined font.
Nothoro
Posts: 6
Joined: Apr 13, 2014 7:36

Re: windows message & dialog boxes

Post by Nothoro »

2019, A little late, but yes, thank you. This helped me.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: windows message & dialog boxes

Post by MrSwiss »

Nothoro wrote:2019, A little late, but yes, thank you. This helped me.
Its of no use to do it, if the people in question, have left the forum, long ago.

Therefore, 'bumping' old threads is discuraged (plse. stop doing it).
Nothoro
Posts: 6
Joined: Apr 13, 2014 7:36

Re: windows message & dialog boxes

Post by Nothoro »

MrSwiss wrote:
Nothoro wrote:2019, A little late, but yes, thank you. This helped me.
Its of no use to do it, if the people in question, have left the forum, long ago.

Therefore, 'bumping' old threads is discuraged (plse. stop doing it).
Wow, ok then.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: windows message & dialog boxes

Post by counting_pine »

MrSwiss wrote:Its of no use to do it, if the people in question, have left the forum, long ago.

Therefore, 'bumping' old threads is discuraged (plse. stop doing it).
MrSwiss, please don't take it upon yourself to admonish new forum users.
I'm sure they're well intentioned, but posts like this are detrimental to the atmosphere in the forum.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: windows message & dialog boxes

Post by MrSwiss »

counting_pine wrote:MrSwiss, please don't take it upon yourself to admonish new forum users.
Well, just to give you something to consider too:
New user: TheRaven, on the 9th in this section alone, did it 8 times, the same day ...

I just think, that such must be acted upon, in a very timely manner, otherwise people
become accustomed to think, that it is OK to do so. Apart from the fact of creating a
precedence case (dangerous).
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: windows message & dialog boxes

Post by counting_pine »

I'll consider what you've said, but I would still rather you didn't get involved.
It would be better for you just to report posts you consider problematic, and let us choose how to deal with it.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: windows message & dialog boxes

Post by MrSwiss »

OK, you've got it, I'll report it, in future.
I've actually thought up to this day, that you're preferring "self regulation", in the forum.
Post Reply