Archived

This topic is now archived and is closed to further replies.

Win32 Common Controls

This topic is 5849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to use Win32 Common Controls (such as a status bar, toolbar, etc) without MFC? I''ve been trying to do it, but I''m having trouble getting my project to include AFXCMN.H. It keeps saying that I can''t include Windows.h with MFC. But I''m not using MFC!

Share this post


Link to post
Share on other sites
AFXCMN is an MFC header file for MFC common controls, that''s why it thinks you''re trying to use MFC!

The fact that AFXCMN.H is in the MFC\ folder of the MSVC installation, and the fact that it contains C++ classes like CStatusBarCtrl rather than function definitions should be quite a strong hint of this!

Many of the simpler common controls can indeed be used without MFC. Internet explorer updates also contain many other common controls you can use in your code without using MFC.

If you have MSDN from MS Visual C++, look in the following location in the help:

MSDN Library Visual Studio 6.0 ->
Platform SDK ->
User Interface Services ->
Shell and Common Controls ->
Common Controls

That contains all the documentation you require to use common controls without MFC!.

The same documentation is available on the http://msdn.microsoft.com site. If you''re an MSDN subscriber, the location will differ slightly.


--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
i was wondering about something similar. i use mfc, and i can use all the common controls just fine in a frame window, or any other window with a client area. i wanted to know if there was a way to use them in a dialog box. i can get a toolbar to show up but not to have any buttons on it, even though there is buttons on it in the resource editor. and i cant get a status bar to show up at all.

Share this post


Link to post
Share on other sites
Try under the tutorial section at www.winprog.org.

www.winprog.org/tutorial

Also, like S1CA said, you can just check under MSDN.

The reason why the toolbar, statusbar, menu, etc are empty is because you haven''t added anything to them yet.

Unlike visual basic, the resource editor just has a picture of buttons to make it look like a toolbar.

Here is an example of a toolbar without MFC.

  
static TBBUTTON array[3]; // the amount of buttons on a toolbar

static HWND g_hToolBar; // the toolbar handle


array[0].iBitmap=0; // the bitmap number

array[0].idCommand=ID_ONE; // the command ID

array[0].fsState=TBSTATE_ENABLED; // the button state

array[0].fsStyle= TBSTYLE_BUTTON; // the button style

array[0].dwData=0L; // application data

array[0].iString=0; // index of the button string


array[1].iBitmap=1; // the bitmap number

array[1].idCommand=ID_TWO; // the command ID

array[1].fsState=TBSTATE_ENABLED; // the button state

array[1].fsStyle= TBSTYLE_BUTTON; // the button style

array[1].dwData=0L; // application data

array[1].iString=0;

array[2].iBitmap=2; // the bitmap number

array[2].idCommand=ID_THREE; // the command ID

array[2].fsState=TBSTATE_ENABLED; // the button state

array[2].fsStyle= TBSTYLE_BUTTON; // the button style

array[2].dwData=0L; // application data

array[2].iString=0; // index of the button string


g_hToolBar = CreateToolbarEx(hWnd, // the toolbar parent handle

WS_CHILD|WS_VISIBLE, // the style

ID_TOOLBAR, // the window name

3, // the number of bitmaps

hInst, // the window instance handle

IDB_BITMAP1, // the bitmap ID

array, // the toolbar info ID

3, // the number of buttons

16, // height of the button

16, // width of the button

16, // height of the bitmap

16, // width of the bitmap

sizeof(TBBUTTON)); // size of the toolbar


// struct specifying control classes to register

INITCOMMONCONTROLSEX iccex;
/* INITIALIZE COMMON CONTROLS */
iccex.dwICC = ICC_WIN95_CLASSES;
iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCommonControlsEx(&iccex);


Remember to resize your toolbar. IE:


SendMessage(g_hToolBar,TB_AUTOSIZE,0,0); // resize the toolbar

Finally, remember to #include <commctrl.h> and commctrl.lib

Share this post


Link to post
Share on other sites