Click to See Complete Forum and Search --> : Set the color,font,and size of edit on toolbar


Cooker
August 22nd, 2004, 08:01 AM
Hi,All:

HWND CreateAToolBar(HWND hwndParent)
{
HWND hwndTB;
TBADDBITMAP tbab;
TBBUTTON tbb[NUM_BUTTONS];
INITCOMMONCONTROLSEX icex;
char szBuf[MAX_LEN] ;
int cch;
int iNew, iOpen, iSaveas;

// Ensure that the common control DLL is loaded.
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx(&icex);
tbab.hInst = GetModuleHandle(NULL);
tbab.nID = IDR_TOOLBAR1;

// Create a toolbar.
hwndTB = CreateWindowEx(0, TOOLBARCLASSNAME, (LPSTR) NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | TBSTYLE_LIST, 0, 0, 0, 0, hwndParent,
(HMENU) IDR_TOOLBAR1, GetModuleHandle(NULL), NULL);

// Send the TB_BUTTONSTRUCTSIZE message, which is required for
// backward compatibility.
SendMessage(hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);

tbab.hInst = HINST_COMMCTRL;
tbab.nID = IDB_STD_SMALL_COLOR;
SendMessage(hwndTB, TB_ADDBITMAP, 0, (LPARAM)&tbab);


LoadString(GetModuleHandle(NULL), IDS_NEW, szBuf, MAX_LEN-1);
cch = strlen(szBuf);
szBuf[cch+1] = '\0';
iNew = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) szBuf);

LoadString(GetModuleHandle(NULL), IDS_OPEN, szBuf, MAX_LEN-1);
cch = strlen(szBuf);
szBuf[cch+1] = '\0';
iOpen = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) szBuf);


LoadString(GetModuleHandle(NULL), IDS_SAVEAS, szBuf, MAX_LEN-1);
cch = strlen(szBuf);
szBuf[cch+1] = '\0';
iSaveas = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) szBuf);

ZeroMemory(tbb, sizeof(tbb));

tbb[0].iBitmap = 53;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_SEP;
tbb[0].idCommand = 0 ;
tbb[0].iString = 0;

tbb[1].iBitmap = STD_FILENEW;
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON;
tbb[1].idCommand = IDM_NEW;
tbb[1].iString = (int)iNew;

tbb[2].iBitmap = STD_FILEOPEN;
tbb[2].fsState = TBSTATE_ENABLED;
tbb[2].fsStyle = TBSTYLE_BUTTON;
tbb[2].idCommand = IDM_OPEN;
tbb[2].iString = (int)iOpen;

tbb[3].iBitmap = STD_FILESAVE;
tbb[3].fsState = TBSTATE_ENABLED;
tbb[3].fsStyle = TBSTYLE_BUTTON;
tbb[3].idCommand = IDM_SAVE;
tbb[3].iString = (int)iSaveas;

SendMessage(hwndTB, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);

// Create the edit control child window.
hwndTB= CreateWindowEx(0L, "Edit", NULL, WS_CHILD | WS_BORDER
| WS_VISIBLE | ES_LEFT | ES_AUTOVSCROLL | ES_MULTILINE,
1, 2, 50, 22, hwndTB, (HMENU) IDM_EDIT, GetModuleHandle(NULL), 0 );
return hwndTB;

}

How do I set the color,font,size of the Edit's text???
Thanks!

Bond
August 23rd, 2004, 07:22 AM
Why are you using your hwndTB handle when creating your Edit box? Your "CreateToolbar" function is now returning a handle to your edit control, not your toolbar.

In any event, you just need to send the edit control a WM_SETFONT message. If you want to use the same font as your parent dialog or window, use WM_GETFONT to retrieve the handle, which you can pass to WM_SETFONT.