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

JohnF

Quote from: xsilvergs on April 04, 2007, 12:44:46 PM
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

Just one line, yes.

Frankie has already answered your question but I would like to add that the compile errors are/can be used to debug your mistakes.

"Found int but expected HWND", that was a hint for you. Your identifier is an int, the handle of the edit control is a HWND.

John

xsilvergs

Sorry to be making such hard work of this.

If I look under the TAB main.rc, Dialog, I have DLG_MAIN, this carries all the buttons and editboxes

If I add this to my code

ShowWindow(GetDlgItem(DLG_MAIN, IDCDEPTH), SW_HIDE); I get this error message

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

Tony

xsilvergs

Well I've made it disapear with the line ShowWindow(GetDlgItem(hwndDlg, IDCDEPTH), SW_HIDE); . I don't understand hwndDlg but it works.

Thank you all for your help.

Tony

JohnF

You need to read up on this stuff. hwndDlg is the handle of your Dialog.

John

xsilvergs

John

You wouldn't know how much surfing I've done trying to find relevant material, there is to much on the net.

There is so much that says it's C# but the code is so different to what's in my program, much of the code I've seen is punctuated with full stops where mine here isn't.

Can you recommend something reading that is specific to what I'm using here please.

Thanks for your help.

Tony

JohnF

I would recommend reading Petzold's 'Programming Windows 3.1', you can often find it in libraries and if you are lucky there will even be a CD attached.

C# btw, is not the same as C.

John

xsilvergs

#21
Thanks for the book recommendation, we have a library here in Poole, I'll have a look at lunch time.

How easy is it to add bitmap images to buttons?

Tony

frankie

You can buy the book "Programming windows" through the net. Look at the Petzold's site:
http://www.charlespetzold.com/pw5/
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

JohnF

Quote from: xsilvergs on April 05, 2007, 08:35:58 AM
Thanks for the book recommendation, we have a library here in Poole, I'll have a look at lunch time.

How easy is it to add bitmap images to buttons?

Tony

Not difficult.

SendMessage(hBut, (UINT)BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp);

John

xsilvergs

Couldn't find book in library so will order from t'internet.

John, thank you for code sample, my intention is to show a button that has a bitmap instead of the normal text. I've read another article here http://www.smorgasbordet.com/forum/index.php?PHPSESSID=becb9f3b89b4072209043fab894a4d53&topic=532.0 and I think the second post in it seems more fitting to what I'd like to do. There seems to be three stages, LoadBitmap, GetDlgItem and SendMessage.

Rightly or wrongly in the main.rc I have a folder called Bitmap, in it is a resource IDR_BMP_ONE which points to a file C:\Program Files\PellesC\Projects\ButtonPic\victor.bmp .

I've written this:
LoadBitmapW(ghInstance, MAKEINTRESOURCE(IDR_BMP_ONE));
GetDlgItem(hwndDlg, ID_BUTONE);
SendMessage(HWND(ID_BUTONE), BM_SETIMAGE, IMAGE_BITMAP,IDR_BMP_ONE);

And I get these errors;
C:\Program Files\PellesC\Projects\ButtonPic\main.c(124): error #2066: Illegal use of type name 'HWND'.
C:\Program Files\PellesC\Projects\ButtonPic\main.c(124): error #2068: Found 'struct HWND__ *' expected a function.
C:\Program Files\PellesC\Projects\ButtonPic\main.c(124): error #2140: Type error in argument 1 to 'SendMessageW'; found 'void' expected 'struct HWND__ *'.

I think I understand what each line code is trying to do but don't understand C yet.

Is it possible for anyone to give me some help please?

Thanks again

Tony


JohnF

#25
Tony,

===================
I've written this:
LoadBitmapW(ghInstance, MAKEINTRESOURCE(IDR_BMP_ONE));
GetDlgItem(hwndDlg, ID_BUTONE);
SendMessage(HWND(ID_BUTONE), BM_SETIMAGE, IMAGE_BITMAP,IDR_BMP_ONE);
===================

Here is the corrected code. Why are you using LoadBitmapW() ? If you are compiling UNICODE the compiler will sort out which API's to use, weather UNICODE or not.


HBITMAP hBitmap = LoadBitmap(ghInstance, MAKEINTRESOURCE(IDR_BMP_ONE));

HWND hBut = GetDlgItem(hwndDlg, ID_BUTONE);

SendMessage(hBut, (UINT)BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap);


Try to understand what's required. For example you had put the identifier IDR_BMP_ONE instead of the handle to the bitmap that is returned from LoadBitmap. Also ID_BUTONE in the SendMessage API where it required the handle to the button not an identifier.

Here, you are trying to cast an int (ID_BUTONE), to a HWND

SendMessage(HWND(ID_BUTONE), BM_SETIMAGE, IMAGE_BITMAP,IDR_BMP_ONE);

Plus, casting is this way, (HWND)type not the way you had it.

John

xsilvergs

Hi John thanks for code.

Prior to this the only coding I've done is for PIC micro's which I have no problems with but C is so different. The code I'd written didn't look right as I couldn't see where the data would be stored, with PIC's I'd put it in a register. I can see from your code where it is held. Hopefully when I get the book things will be clearer.

Any way I've placed your code in just after the case WM_INITDIALOG, no errors now but for some reason my .bmp doesn't appear on the button.

Any ideas?

Tony

JohnF

Tony,

You could check the return values of the function calls. Can you use the PellesC debugger yet?

John

xsilvergs

If it's just a case of Project, Debug ButtonPic.exe i get a message saying no debug info. If I ok this on the debug tab I see this:
Starting remote debug server
Creating remote process ButtonPic.exe
Process B2DEF46A started
Thread B2E990AA started
Loading ButtonPic.exe at 00010000
Loading shutil.dll at 02D20000
Loading tshres.dll at 7FFE0000
Loading commctrl.dll at 02DE0000
Loading oleaut32.dll at 027D0000
Loading ossvcs.dll at 02750000
Loading aygshell.dll at 02D70000
Loading ole32.dll at 02800000
Loading coredll.dll at 01F60000

Where are the return values? and what should I look for?

JohnF

#29
zip up your project and send it to me.

EDIT: I forgot to say that when creating the button you must include the BS_BITMAP style.

Example

CONTROL "OK", ID, "Button", WS_TABSTOP | BS_BITMAP, 118, 174, 40, 14


John