Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Bitmaps on buttons using Win32/Dev-C++

This thread is locked; no one can reply to it. rss feed Print
Bitmaps on buttons using Win32/Dev-C++
23yrold3yrold
Member #1,134
March 2001
avatar

uuuhhhhh ... how? ;) y'know, like MSPaint's toolbar buttons. I assume I make them resource bitmaps, but can I assign a "clicked" and a "not clicked" image (like in Allegro's GUI) like I can assign the text using SetWindowText()? Or do I need to use an BS_OWNERDRAW button and do it the hard way?

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Pike
Member #249
April 2000
avatar

Create the button with the BS_BITMAP style, then send a BM_SETIMAGE message to it with the bitmap.
Eg:

hButton=CreateWindow("BUTTON","Button",WS_CHILD|WS_VISIBLE|BS_BITMAP,120,10,100,40,hWnd,(HMENU)504,hInstance,NULL);
SendMessage(hButton,BM_SETIMAGE,IMAGE_BITMAP,(long)LoadBitmap(hInstance,(LPSTR)IDB_BITMAP1));

I'm not sure about clicked/not clicked bitmaps, I've never tried that.

23yrold3yrold
Member #1,134
March 2001
avatar

Thanks; I'll try it :)

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

spellcaster
Member #1,493
September 2001
avatar

If you're using vc, you can simply click the "Bitmap" check box in the button prroperties. But you'll still need to send the BM_SETIMAGE message.

If yiu're going to use it for a floating tool window or something, it might be better to use a toolbar instead.

Oh, DevC++.. hm... You can create toolbars using:

1HWND CreateToolbarEx(
2 HWND hwnd,
3 DWORD ws,
4 UINT wID,
5 int nBitmaps,
6 HINSTANCE hBMInst,
7 UINT wBMID,
8 LPCTBBUTTON lpButtons,
9 int iNumButtons,
10 int dxButton,
11 int dyButton,
12 int dxBitmap,
13 int dyBitmap,
14 UINT uStructSize
15);
16 
17Creates a toolbar window and adds the specified buttons to the toolbar.
18 
19Returns the window handle to the toolbar if successful, or NULL otherwise. To get extended error information, callGetLastError.
20 
21hwnd
22Handle to the parent window for the toolbar.
23 
24ws
25Window styles for the toolbar. This parameter must specify at least the WS_CHILD style. It can also include a combination of styles as discussed in Toolbar Control and Button Styles.
26 
27wID
28Control identifier for the toolbar.
29 
30nBitmaps
31Number of button images contained in the bitmap specified by hBMInst and wBMID.
32 
33hBMInst
34Module instance with the executable file that contains the bitmap resource.
35 
36wBMID
37Resource identifier for the bitmap resource. If hBMInst is NULL, this parameter must be a valid bitmap handle.
38 
39lpButtons
40Address of an array of TBBUTTON structures that contain information about the buttons to add to the toolbar.
41 
42iNumButtons
43Number of buttons to add to the toolbar.
44 
45dxButton
46Width, in pixels, of the buttons to add to the toolbar.
47 
48dyButton
49Height, in pixels, of the buttons to add to the toolbar.
50 
51dxBitmap
52Width, in pixels, of the button images to add to the buttons in the toolbar.
53 
54dyBitmap
55Height, in pixels, of the button images to add to the buttons in the toolbar.
56 
57uStructSize
58Size of a TBBUTTON structure.

Check msdn.microsoft.com if you need more infos.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

23yrold3yrold
Member #1,134
March 2001
avatar

I've only recently discovered toolbars (Petzold skips them) but haven't tried yet. I've looked at MSDN; is there an offline version? Hell to navigate. I'll look at your code later; toolbars are beginning to sound like what I needed in the first place :) Now let's see if I can get them working .....

How come the docs for CreateToolbarEx() say [New - Windows NT]? I got a lot of "undeclared" errors when compiling a code snippet I found, and most of the unknown stuff seems to be Windows NT only, including CreateToolbarEx(). Sucky - poo ......
:(

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Go to: