May 12, 2024, 04:02:35 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


API Combobox

Started by definitelyokay, September 28, 2009, 12:55:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

definitelyokay

September 28, 2009, 12:55:21 PM Last Edit: October 02, 2009, 02:22:01 PM by JosephE
I've been enjoying EB lately, but have encountered a problem.

I found this link here: Listing all available fonts in a combobox.

Now, I've re-written it (for the sake of code-formatting), and would like to turn that functionality into a dll. Here's what I'm working on:

From another language, call the EB dll that makes a combobox with a list of fonts.
Pass it the window handle, and the coordinates for the control.
Be able to get the selected font from the control.

Of course, I'll work on the DLL once I get the demo working just right.

I've included my project so far. I've got the original combobox from the example (for testing), and a win32 created combobox that will be used in the DLL.

The line that seems to be giving me problems is this one:

_SendMessage(hCB, CB_ADDSTRING, 0, lpelfe.elfFullName) 'Should be equivilant to AddString, but doesn't seem to work.

From what I understand and what MSDN says, CB_ADDSTRING should add a string to the combobox. But it doesn't seem to be working.

And, on the side, why does my combobox look 10 years old? It doesn't have the cool xp/vista/win7 style. It looked like it walked out of windows 95/98 or something. ::)

Any tips or help would be very much appreciated! :)

I bet I'm just missing something simple...

(EDIT: removed broken code - see later postings for working code)

sapero

Joseph, you need to call CreateComboBox before conComboLoadFonts (see in line 56).
If your calling CreateWindowEx from a dll, you probably need to include xp-style manifest in dll, as resource type 24, id 2 (1 in exe's). You can use the same manifest as you used for exe.
The window styles for your combobox are CBS_AUTOHSCROLL | CBS_HASSTRINGS | WS_CHILD | WS_VSCROLL | WS_VISIBLE | CBS_DROPDOWN.

aurelCB

Oh my Sapero is quicker but everything what he say is right.
I just made one simple combobox example:
' combobox example
Window w1
Int comboID
comboID = 10

OpenWindow w1, 0, 0, 600, 400,@minbox, 0, "Combobox example", &main
    SetwindowColor w1,rgb(220,220,230)

Control w1, @COMBOBOX, "", 10, 10, 210, 150, 0x50800603 | @VSCROLL | @CTCOMBOSORT, comboID
SetFont w1, "Verdana", 8, 400, 0, comboID

AddString w1,comboID,"One"
AddString w1,comboID,"Two"
AddString w1,comboID,"Three"

'conComboLoadFonts(w1, 10, 0)

'hCB = CreateComboBox(w1.hwnd, 150, 150, 230, 150, 20)
WaitUntil w1 = 0

End


Sub main

Select @class
Case @idclosewindow
CloseWindow w1
'Case @idcontrol


EndSelect
Return
EndSub



definitelyokay

Thanks Aston, for the little demo!

Quote from: sapero on September 28, 2009, 01:26:38 PM
Joseph, you need to call CreateComboBox before conComboLoadFonts (see in line 56).
If your calling CreateWindowEx from a dll, you probably need to include xp-style manifest in dll, as resource type 24, id 2 (1 in exe's). You can use the same manifest as you used for exe.
The window styles for your combobox are CBS_AUTOHSCROLL | CBS_HASSTRINGS | WS_CHILD | WS_VSCROLL | WS_VISIBLE | CBS_DROPDOWN.

Thank you so much! Of course I need to make my combobox before I use it. *slap myself*. It works just fine now using your style flags and ( | @CTCOMBOSORT to keep things tidy)

Ok, manifests, I've heard that before, but I never understood them. Will they change the visual style of the combobox? Do you mean that I can include a manifest as a resource? (I'm still figuring out projects/resources, etc)

sapero

September 28, 2009, 02:02:01 PM #4 Last Edit: September 28, 2009, 02:23:02 PM by sapero
Yes, open your project, click menu Resource/Add, Set ID to 1 (1 for exe, 2 for dll), type=custom, CustomType=24, Filename=C:\WINDOWS\WindowsShell.Manifest
CustomType is 24, because resource type RT_MANIFEST is 24.
(Filename path is valid at least on XP installed on C drive in default directory, this is ready to use manifest template for visual styles). This file is hidden, but you can copy it to your project directory, customize it and add as a resource.

You can also use the manifest file from ebasic /bin directory (ebdev.exe.manifest), just copy it to /yourproject/xpstyle.xml and customize <description> node text.
After you add the manifest to resources and compile the project, you can distribute your program without the file manifest. To enable visual styles you need only to have the manifest as a file, or in your resources.

definitelyokay

Sapero, your manifest thing worked perfectly! (as has everything else you've mentioned) Thanks a lot for explaining that for me.

I'd hate to pester ;), but would you (or anyone else) know how to change the font of my API combobox? I don't want to change the font for each item (I'll tackle that sometime when I get further along and make a full-fledged font-combobox), I just don't like the ugly "system" font.

I'm supposing the Win32 API has something like the SetFont command?

(I do have Sapero's include files installed, so if there's a function in there, I'm sure I have it)

LarryMc

It's not straight forward when doing it to a combobox you create yourself.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Joseph ...
If you want set font on Api created control you can use two ways for do this:
One is with :
SENDMESSAGE (win,WM_SETFONT, GetStockObject(DEFAULT_GUI_FONT),0,ID)
or much better:
'SetControlFont()
cfont=CreateFontA(fsize,0,0,0,700,1,0,0,1,0,0,0,2,"Times New Roman")
SENDMESSAGE (win,WM_SETFONT,cfont,0,ID)


Good luck... ;)
Aurel

definitelyokay

@ Larry: Yep, it's definitely not.

@ Aurel: Thank you very much! With a little modification, I got everything working!

Thanks everyone! Wouldn't have been able to do it without you all.

definitelyokay

September 29, 2009, 12:17:23 PM #9 Last Edit: October 02, 2009, 02:22:22 PM by JosephE
Ok, so I've finally decided what I need and started my DLL:

Rather than using a win32 api combobox, the program needs to call this dll and retrieve the number of fonts found.
For each font found, it can call the GetFontName function and get the name of the font with the specified 1-based index.

So my program properly returns the number of fonts, but it fails to store/retrieve the font in my Dynamic String Array pointer.
It kind of works, but not really. (As in it compiles without errors, but only returns the last listed font name)

I used this thread for reference, but I must not be doing it quite right.

My file is attached.

Help would be very much appreciated!

Thanks,

Joseph

(EDIT: removed broken code - see later postings for working code)

aurelCB

I recive error here:
Pointer FontList
QuoteCompiling...
FontList.eba
File: C:\Program Files\EBDev\projects\FontList.eba (9) syntax error - =
nasm: fatal: unable to open input file `C:\Program Files\EBDev\projects\FontList.a'
Error(s) in assembling "C:\Program Files\EBDev\projects\FontList.a"
So if i see right you use just one pionter not array of pointers?
But i'm not sure becose i dont understand EB quite well.I guess... ::)

LarryMc

September 29, 2009, 02:26:34 PM #11 Last Edit: September 29, 2009, 02:29:12 PM by Larry McCaughn
Zlatko - It compiled fine for me but I changed the program to not be a dll first.

Joseph

I don't see the problem but do have a couple of comments:
1.
Using the dynamic array scheme forces you to call LoadFonts twice.
Why not create a linked list then call LoadFonts just once and add to the LL in the LoadFonts routine.
that's what I've done before when enum fonts to load into a combobox

2.
You are passing win as an int.
if you pass your window as a window then you don't have to use the intermediate win int variables.
then when you need the window handle just use win.hwnd

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

definitelyokay

September 29, 2009, 03:14:25 PM #12 Last Edit: October 02, 2009, 02:22:39 PM by JosephE
Thanks Aurel and Larry.

@ Larry:

On #2 suggestion, I'm not so sure what you mean about passing window handles as ints. The program that calls this dll will pass the hwnd of a window so the dll can borrow it's device context for the font enumeration process.

On suggestion #1, I've included a linked-list version, but I still haven't gotten it to work. I don't know what I'm missing, but I will get this figured out. ::)

Thank you to everyone for all their help so far, I'm learning a lot.

(EDIT: removed broken code - see later postings for working code)

LarryMc

Several things are wrong.

you created your linklist inside a sub which makes it a local variable so it can't be seen in the other subs.

your addlist setup was all wrong

attached is a modified version of your program that finds 566 font entries on my computer and will print them all out.

from there you should be able to sort it out.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

definitelyokay

September 29, 2009, 04:48:49 PM #14 Last Edit: October 02, 2009, 02:22:57 PM by JosephE
Thank you Larry, I now understand about Linked lists. ;D

So I removed the window/console debugging from your program, and compiled it back as a dll, and the dll doesn't even make it inside the for/each loop that works just fine when compiled as your window program.

Apparently, linked lists do not work outside of a single sub in a DLL. Their scope appears to be warped.

Someone please correct me because I hope I am wrong.

Attached is one more file. :P

(EDIT: removed broken code - see later postings for working code)

LarryMc

September 29, 2009, 05:37:08 PM #15 Last Edit: September 29, 2009, 05:43:12 PM by Larry McCaughn
You might have to declare the linkedlist as global

try this:
change your declare to this:
global Pointer FontList
put this is your startup sub
FontList = ListCreate()

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

definitelyokay

September 29, 2009, 05:54:07 PM #16 Last Edit: October 02, 2009, 02:25:20 PM by JosephE
Larry, I've already said this once, and you've already discredited it, but I know it's true:

You're genius! ;D

Everything works just like it should. For the record, I've included the working file.

There's no way I could have done it without Larry, Sapero, and Aurel.

Thanks guys!

It's a new milestone in programming for me - I wrote my first working Dynamic Link Library.

EDIT: Code removed - see 3 posts down.

Brian

Joseph,

Any chance of a demo program, showing how to call and use your DLL?

Thanks,

Brian

definitelyokay

Good question.

Well, if you're using it in EB, there's no need to have it in DLL form. You can just include the functions.

I have written a program that uses it in Liberty BASIC (I wrote this because I needed it for an LB project), but I'll see If I can scratch one out for EBasic.

Thanks for asking!

I'll post back here when I get an example.

definitelyokay

Ok, here's a zip including the dll, the source, and an example emergence program with lots of comments.

If you can find a good use for it, please use it!

:)

Once again, thanks to all who helped.

Brian

Joseph,

Thanks for the source for the combobox. I've had a rummage around and found
this small program that displays all fonts. You can alter the flags to display just
Truetype, and use the up/down keys to move through the fonts

I think the code was originally from Ian Fletcher, but I have modified it a fair
bit since then for my own use

Enjoy,

Brian