|
From: Vlada D. <dj...@im...> - 2003-04-18 12:58:00
|
Hi, everybody.
Here's another problem I'm having. I'm trying to create toolbar with my own
bitmap images, so I did the following:
1. I painted one 48x16 pixel bitmap using Paint, which should contain images
for 3 toolbar buttons
2. Defined ID for bitmap resource in header and added a line in .rc file
(ID_BITMAP BITMAP "image.bmp")
3. Finaly, I wrote a code to create toolbar.
--------begin code------
INITCOMMONCONTROLSEX icx;
icx.dwSize=sizeof(INITCOMMONCONTROLSEX);
icx.dwICC=ICC_BAR_CLASSES;
InitCommonControlsEx(&icx);
HWND hToolbar;
switch (message) /* handle the messages */
{
case WM_CREATE:
hToolbar=CreateWindowEx(WS_EX_CLIENTEDGE,TOOLBARCLASSNAME,NULL,WS_CHILD|WS_V
ISIBLE,0,0,0,0,
hwnd,(HMENU)ID_TOOLBAR,g_hInstance,NULL);
if(!hToolbar)
{
MessageBox(hwnd,"Couldn't create toolbar","Error",MB_OK);
return 0;
}
SendMessage(hToolbar,TB_BUTTONSTRUCTSIZE,(WPARAM)sizeof(TBBUTTON),0);
TBBUTTON tbb[3];
TBADDBITMAP tbab;
tbab.hInst=g_hInstance;;
tbab.nID=ID_BITMAP;
SendMessage(hToolbar,TB_ADDBITMAP,(WPARAM)3,(LPARAM)&tbab);
ZeroMemory(tbb,sizeof(tbb));
tbb[0].iBitmap=0;
tbb[0].fsState=TBSTATE_ENABLED;
tbb[0].fsStyle=TBSTYLE_BUTTON;
tbb[0].idCommand=ID_FILE_NEW;
>>>>>two more button definitions<<<<<<<
SendMessage(hToolbar,TB_ADDBUTTONS,sizeof(tbb)/sizeof(TBBUTTON),(LPARAM)&tbb
);
---end code----
The program compiled, but when I start it, I keep getting "acces violation"
message. I tried using a debugger, but it wont even start (or I dont know
how to use it). When I comment out the line where I send the TB_ADDBITMAP
button, the program works, but without images on buttons, so I suppose
there's something wrong about that .
Can somebody give me some advice what could be wrong, or direct me to some
link about using Dev-Cpp debugger?
------------
Vlada
|
|
From: Per W. <pw...@ia...> - 2003-04-18 16:03:21
|
First, if the toolbar was created with CreateWindowEx, you must send a
TB_BUTTONSTRUCTSIZE message before the TB_ADDBUTTONS.
Second - note the similarity of an array and a pointer. &myarray[0] is
same as myarray, i.e. a pointer to an entry. &myarray is a pointer to a
pointer to an entry. Should you really take the address of tbb as last
parameter of SendMessage().
/Per W
On Fri, 18 Apr 2003, Vlada Djurovic wrote:
> Hi, everybody.
>
> Here's another problem I'm having. I'm trying to create toolbar with my own
> bitmap images, so I did the following:
>
> 1. I painted one 48x16 pixel bitmap using Paint, which should contain images
> for 3 toolbar buttons
> 2. Defined ID for bitmap resource in header and added a line in .rc file
> (ID_BITMAP BITMAP "image.bmp")
> 3. Finaly, I wrote a code to create toolbar.
>
> --------begin code------
> INITCOMMONCONTROLSEX icx;
> icx.dwSize=sizeof(INITCOMMONCONTROLSEX);
> icx.dwICC=ICC_BAR_CLASSES;
> InitCommonControlsEx(&icx);
> HWND hToolbar;
>
> switch (message) /* handle the messages */
> {
> case WM_CREATE:
>
> hToolbar=CreateWindowEx(WS_EX_CLIENTEDGE,TOOLBARCLASSNAME,NULL,WS_CHILD|WS_V
> ISIBLE,0,0,0,0,
> hwnd,(HMENU)ID_TOOLBAR,g_hInstance,NULL);
> if(!hToolbar)
> {
> MessageBox(hwnd,"Couldn't create toolbar","Error",MB_OK);
> return 0;
> }
>
> SendMessage(hToolbar,TB_BUTTONSTRUCTSIZE,(WPARAM)sizeof(TBBUTTON),0);
>
> TBBUTTON tbb[3];
> TBADDBITMAP tbab;
>
>
>
> tbab.hInst=g_hInstance;;
> tbab.nID=ID_BITMAP;
> SendMessage(hToolbar,TB_ADDBITMAP,(WPARAM)3,(LPARAM)&tbab);
>
> ZeroMemory(tbb,sizeof(tbb));
>
> tbb[0].iBitmap=0;
> tbb[0].fsState=TBSTATE_ENABLED;
> tbb[0].fsStyle=TBSTYLE_BUTTON;
> tbb[0].idCommand=ID_FILE_NEW;
> >>>>>two more button definitions<<<<<<<
> SendMessage(hToolbar,TB_ADDBUTTONS,sizeof(tbb)/sizeof(TBBUTTON),(LPARAM)&tbb
> );
>
> ---end code----
>
> The program compiled, but when I start it, I keep getting "acces violation"
> message. I tried using a debugger, but it wont even start (or I dont know
> how to use it). When I comment out the line where I send the TB_ADDBITMAP
> button, the program works, but without images on buttons, so I suppose
> there's something wrong about that .
> Can somebody give me some advice what could be wrong, or direct me to some
> link about using Dev-Cpp debugger?
> ------------
> Vlada
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: vitamin <vit...@nc...> - 2003-04-18 18:24:46
|
If you want to show your bitmaps in your toolbar button
NOT use CreateToolbarEx() function
and NOT use SendMessage(hToolbar,TB_ADDBITMAP,(WPARAM)3,(LPARAM)&tbab);
ONLY standard toolbar buttons can normal execute.
I tried many times, and got no error, no warning, and only close
application.
I think that the commctrl.a maybe is old.
Only imagelist can run.
And need to add #define TB_SETIMAGELIST (WM_USER + 48) in your commctrl.h
void ToolBar::CreateToolBar(void)
{
_tbhwnd=CreateWindowEx(WS_EX_DLGMODALFRAME,TOOLBARCLASSNAME,NULL,
WS_CHILD|WS_VISIBLE|TBSTYLE_FLAT|CCS_ADJUSTABLE|CCS_NODIVIDER,
0,0,0,0,_hwnd,NULL,_hwnd.GetInstance(),NULL);
HIMAGELIST hImage;
HBITMAP hBitImage;
hBitImage = LoadBitmap(_hwnd.GetInstance(), MAKEINTRESOURCE(IDTB_BMP));
hImage = ImageList_Create(16, 16, ILC_COLOR32| ILC_MASK , 12, 1);
ImageList_AddMasked(hImage, hBitImage, RGB(255, 255, 255));
SendMessage(_tbhwnd, TB_SETIMAGELIST, (WPARAM)0, (WPARAM)hImage);
DeleteObject(hBitImage);
}
void ToolBar::InitToolBar(void)
{
tool_bar_buttons[0].iBitmap=0;
tool_bar_buttons[0].idCommand=CM_FILE_NEW;
tool_bar_buttons[0].fsState=TBSTATE_ENABLED;
tool_bar_buttons[0].fsStyle=TBSTYLE_BUTTON;
tool_bar_buttons[0].dwData =0;
tool_bar_buttons[0].iString=0;
tool_bar_buttons[1].iBitmap=1;
tool_bar_buttons[1].idCommand=CM_FILE_LOAD;
tool_bar_buttons[1].fsState=TBSTATE_ENABLED;
tool_bar_buttons[1].fsStyle=TBSTYLE_BUTTON;
tool_bar_buttons[1].dwData =0;
tool_bar_buttons[1].iString=0;
// and others
SendMessage(_tbhwnd,TB_ADDBUTTONS,17,(LPARAM)(LPTBBUTTON)&tool_bar_buttons);
}
|