In-Memory Dialogs

Windows specific questions.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

Hello Jack,

the download link should work now

http://jafile.com/uploads/freebasic/dialogs.zip

Joshy
BurghHouse
Posts: 34
Joined: Jul 09, 2008 21:57
Contact:

Re: In-Memory Dialogs

Post by BurghHouse »

I use this library a lot - thanks - but there is one issue I can't solve.

When the dialog box is displayed the title line contains a blank icon. (the full title line is <blank icon> <Title text> <window control buttons _ - and x>)

I'd like the blank icon to be my program's icon (as displayed on its window) but I can't figure out how to achieve that.

I've waded through the library documentation and the Windows documentation (until my eyes burned) but I can’t find it.

It's either really easy or terribly complicated - if its' the former, please enlighten me.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: In-Memory Dialogs

Post by MichaelW »

Sorry about the slow response, I’ve been very busy with work recently. You can get a handle for the icon, by any of several methods, and then send it to the dialog window in a WM_SETICON message, specifying ICON_SMALL in wParam, something like this:

Code: Select all

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

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

  dim as HICON hIcon

  select case uMsg

    case WM_INITDIALOG

      hIcon = LoadImage( 0, "freebasic.ico", IMAGE_ICON,0,0, LR_LOADFROMFILE )

      SendMessage( hwndDlg, WM_SETICON, ICON_SMALL, cast(LPARAM,hIcon) )

    case WM_COMMAND

      select case wParam

        case IDCANCEL

          EndDialog( hwndDlg, null )

      end select

    case WM_CLOSE

      EndDialog( hwndDlg, null )

  end select

  return 0

end function

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

dim as LPDLGTEMPLATE lpdt
dim as HWND hDlg

Dialog( 0, 0, 0, 80, 60, "Test", lpdt, WS_OVERLAPPEDWINDOW or DS_CENTER )

CreateModalDialog( 0, @DialogProc, 0, lpdt )

''=============================================================================
And there are other methods.
BurghHouse
Posts: 34
Joined: Jul 09, 2008 21:57
Contact:

Re: In-Memory Dialogs

Post by BurghHouse »

Many thanks. So simple .... !
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: In-Memory Dialogs

Post by nimdays »

Nice and simple :)
Ed Davis
Posts: 37
Joined: Jul 28, 2008 23:24

Re: In-Memory Dialogs

Post by Ed Davis »

Has anyone gotten dialogs.bas to work with later versions of FreeBASIC?

With fbc 1.02.1 I get:

FreeBASIC Compiler - Version 1.02.1 (04-25-2015), built for win64 (64bit)
Copyright (C) 2004-2015 The FreeBASIC development team.
standalone

c:\bin\bas\fb\Dialogs>..\fbc ex1.bas
c:\bin\bas\fb\Dialogs\dialogs.bas(343) error 20: Type mismatch, before ')' in 'u
l = cast(ULONG,g_lpw) + 3'
c:\bin\bas\fb\Dialogs\dialogs.bas(346) error 28: Expected pointer, before ')' in
'g_lpw = cast(LPWORD,ul)'
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: In-Memory Dialogs

Post by MichaelW »

The problem is not with the version, but with the change to 64-bit code. Correcting the problem required only a small modification, new version in first post, but note that I had only a limited time to test. I should have anticipated this problem and corrected it years ago.
Ed Davis
Posts: 37
Joined: Jul 28, 2008 23:24

Re: In-Memory Dialogs

Post by Ed Davis »

MichaelW wrote:The problem is not with the version, but with the change to 64-bit code. Correcting the problem required only a small modification, new version in first post, but note that I had only a limited time to test. I should have anticipated this problem and corrected it years ago.
Thanks for the quick response.

(later)

Hmmm. I downloaded from the link in the first message. I noticed that the date of dialogs.bas inside the .zip is still 2009. I unzipped, and when I compiled, I get the same error.

Is it possible the .zip did not get updated?

I tried downloading again just to make sure, but it appears I'm getting the old .zip file. If you put a new one up, I guess it could be some sort of cache issue on my end...
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: In-Memory Dialogs

Post by MichaelW »

Ed Davis wrote: Hmmm. I downloaded from the link in the first message. I noticed that the date of dialogs.bas inside the .zip is still 2009. I unzipped, and when I compiled, I get the same error.

Is it possible the .zip did not get updated?
I have nothing to do with the zip archive and no control over it. What I updated was the code in the first code block in the first post of this thread.

And I forgot to add that I tested the 64-bit functionality with compiler version 1.02.0 (03-23-2015), built for win64 (64bit).
Kot
Posts: 336
Joined: Dec 28, 2006 10:34

Re: In-Memory Dialogs

Post by Kot »

When I try to use dialogs.bas with EZTerm http://www.freebasic.net/forum/viewtopi ... ght=ezterm I get the error:
dialogs.bas(129) error 57: Type mismatch, at parameter 3 of MULTIBYTETOWIDECHAR() in 'asciistring, _'
How can I fix it?
FreeBASIC Compiler - Version 1.05.0 (01-31-2016), built for win32 (32bit)
win7 64bit
Pierre Bellisle
Posts: 56
Joined: Dec 11, 2016 17:22

Re: In-Memory Dialogs

Post by Pierre Bellisle »

Hi Kot,

Try something like this...

Pierre

Code: Select all

   
    gpWord += MultiByteToWideChar(CP_ACP, _
                                  MB_PRECOMPOSED, _
                                  Cast(LPCSTR, StrPtr(asciiString)), _
                                  -1, _
                                  Cast(LPWSTR, gpWord), _
                                  Len(asciiString) + 2)
                                  
Kot
Posts: 336
Joined: Dec 28, 2006 10:34

Re: In-Memory Dialogs

Post by Kot »

Thanks, it worked :)
Macq
Posts: 24
Joined: Feb 18, 2021 4:01
Location: Queensland, Australia

Re: In-Memory Dialogs

Post by Macq »

>fbc64 --version
FreeBASIC Compiler - Version 1.09.0 (2021-12-31), built for win64 (64bit)
Copyright (C) 2004-2021 The FreeBASIC development team.
standalone

>fbc64 Button_grid_demo.bas
dialogs.bas(131) error 58: Type mismatch, at parameter 3 of MULTIBYTETOWIDECHAR() in 'asciistring, _'

To get it to compile I had to copy asciiString to a Zstring:

Code: Select all

sub GenUstring( byref asciiString as string )

  '' If asciiString is null, skip the first element of
  '' the array, leaving it set to zero (no string).
  ''
  if asciiString = "" then
    g_lpw += 1
  else
    dim as ZString * 256 ZasciiString
    ZasciiString = asciiString
    '' CP_ACP specifies that the function should use
    '' the current system ANSI code page to perform
    '' the conversion to Unicode.
    ''
    g_lpw += MultiByteToWideChar( CP_ACP, _
                                  MB_PRECOMPOSED, _
                                  @Zasciistring, _
                                  -1, _
                                  cast(LPWSTR,g_lpw), _
                                  len(asciiString) + 2 )
  end if

end sub

No doubt there is a more elegant solution.
softfoot
Posts: 34
Joined: Aug 31, 2020 3:45

Re: In-Memory Dialogs

Post by softfoot »

This is just what I need --- but sadly the link to the zip file is broken :-(
Many thanks for a great post.
Dave
softfoot
Posts: 34
Joined: Aug 31, 2020 3:45

Re: In-Memory Dialogs

Post by softfoot »

OK I have modified the grid of buttons example to give me what I basicaly want.

I would like to put some text BESIDE each button - I have looked for an example of writing to the main area of the dialog but have been unable to find anything. I happily admit to being a newbie at this so any advice is very welcome.

Thanks in advance,
Dave
Post Reply