News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Old Dog New tricks

Started by xsilvergs, March 28, 2007, 12:43:24 PM

Previous topic - Next topic

xsilvergs

Hi

I'm new to C and new to my pocketpc but old and a bit slow to learn so please be gentle.

I'm trying to write my first program for my pocketpc and run into a problem, I can add button and edit boxes and make things happen but my program requires a combobox.

Having added a combobox to the DLG_MAIN I've set it as a "Dropdown list" as I want the user to only use items in the list but how do I write/fill the list?

I've search the web for info but must be looking in the wrong places as I've not found anything related.

As I've said earlier I'm new to this so please be as clear as possible.

Thanks for help in advance.

JohnF

I don't do the pocketpc but assume it will be the same.

Fill in a  COMBOBOXEXITEM and send the info with SendMessage with the CBEM_INSERTITEM message.

COMBOBOXEXITEM cbei; // the struct
SendMessage(hwndCombo, CBEM_INSERTITEM, 0, (LPARAM)&cbei);

You may need to look at the MSDN library for more explanation.

http://msdn2.microsoft.com/en-us/library/ms771608.aspx

John

xsilvergs

Thanks for your reply, I've got it sorted now.

DMac

Check out this topic thread:
http://www.smorgasbordet.com/forum/index.php?topic=2062.0
I have posted a link there to a nice demo project using the combobox.
Regards,
David M.
No one cares how much you know,
until they know how much you care.

xsilvergs

Thank you for info.

I'm moving on very slowly but enjoying every moment, I now have another question now.

How do I use the TabControl as my project needs 3 tabs?

Thanks again

DMac

xsilvergs,

Here is a link to another useful demo and article on code project that makes using the tab control easy.

http://www.codeproject.com/win32/Win32SDK_C_TabCtrl.asp

regards,
DMac
No one cares how much you know,
until they know how much you care.

JohnF

David, allow me to make a suggestion, all your PellesC projects include the .tag file this makes the zip unnecessarily large.

John

DMac

John,

Thanks for pointing that out.

Usually I get rid of the exe and the object files but that one was not obvious to me.

In the future I'll leave the tag out of the zip.

regards,
D Mac
No one cares how much you know,
until they know how much you care.

xsilvergs

#8
Me again

Is there a list/tutorial for things like, GetDlgItemText as I don't really understand the commands?

Also I'd like to find out how to make the textbox visible and invisible in code, is this posible?

This is all for PPC.

xsilvergs

I'm still struggleing, I can't work out how to make an editbox invisible.

Can somebody please help?

JohnF

The ShowWindow() API will do it. Look it up on MSDN if you do not know the syntax.

John

xsilvergs

Hi John, thanks for reply.

I've looked at this http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/WindowsUserInterface/Windowing/Windows/WindowReference/WindowFunctions/ShowWindow.asp and am none this wiser although I can SW_HIDE.

The example I've been trying to use is from http://www.trajectorylabs.com/win32_dialog_based_application.html . They add a macro like this #define SetDlgItemFocus(hwnd,idCtl)  FORWARD_WM_NEXTDLGCTL((hwnd), GetDlgItem((hwnd),(idCtl)), TRUE, PostMessage) and then I do this SetDlgItemFocus(hwndDlg, IDC_OXY); and the focus is passed.

So for the showwindow I've added this #define SetDlgItemHide(hwnd,idCtl) FORWARD_WM_SHOWWINDOW((hwnd),GetDlgItem((hwnd),(idCtl)), TRUE, PostMessage) and tried adding this SetDlgItemHide(hwndDlg, IDCDEPTH); to implement it, but it doesn't work.

What am I doing wrong? Sorry to appear so stupid but this is my first attempt a writting in C.

Tony

JohnF

No need for all those macros - they seem to be confusing you.

On the Microsoft site you would have seen this

BOOL ShowWindow(     

    HWND hWnd,
    int nCmdShow
);

That is the syntax for ShowWindow, now the parameters are hWnd and nCmdShow. Looking down where the parameters are you can see SW_HIDE. Sounds appropriate. So,

ShowWindow(hEditControl, SW_HIDE);

Will do it for you. When you want to show the edit control again use SW_SHOW instead of SW_HIDE.

All controls are in fact windows, btw.

If you don't have the edit control handle use

HWND GetDlgItem(
    HWND hDlg,
    int nIDDlgItem
);

Where hDlg is the handle to the main window or the diloag box.

nIDDlgItem is the control identifier used when you created the control.

For example - if you created the edit window with CreateWindow the 10th parameter was the indentifier, the one before hInstance.

    hwnd = CreateWindowEx( "", "", "", "",
        0, 0, 0, 0, hwndParent, (HMENU)IDENTIFIER, hInstance, NULL);

Or if you used a dialog then there would have been something like this

CONTROL "", ID_FILTER, "Edit", ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 8, 20, 100, 12

Where ID_FILTER was the indentifier.

John

xsilvergs

John

Are you saying I only need to add one line to my code like this

ShowWindow(IDCDEPTH, SW_HIDE); where IDCDEPTH is my Editbox

When I do I get this error message

C:\Program Files\PellesC\Projects\Nitrox\main.c(248): error #2140: Type error in argument 1 to 'ShowWindow'; found 'int' expected 'struct HWND__ *'.

Tony



frankie

Retrieve the handle of the control window with GetDlgItem:
    ShowWindow(GetDlgItem(hDlg, IDCDEPTH), SW_HIDE);

Where  hDlg is the handle of your dialog.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide