Can someone give me an example for adding a CMFCPropertyGridCtrl to a Dialog. I tried to create a dialog and add a CMFCPropertyGridCtrl. But it gives me errors. A tutorial or a working code is highly appreciated.
Thanks.
Finally I learned to add a CMFCPropertyGridCtrl. Here is the code..
CMFCPropertyGridCtrl m_wndPropList1;
m_wndPropList1.Create( WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, rectPropList1, this, MY_GRID_CTRL_ID);
m_wndPropList1.EnableHeaderCtrl();
//m_wndPropList.EnableDescriptionArea();
m_wndPropList1.SetVSDotNetLook(TRUE);
m_wndPropList1.MarkModifiedProperties(TRUE);
m_wndPropList1.SetAlphabeticMode(!TRUE);
m_wndPropList1.SetShowDragContext(TRUE);
CMFCPropertyGridProperty* pGroupFont = new CMFCPropertyGridProperty(_T("Theme Header Text Properties"));
LOGFONT lf;
CFont* font = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
font->GetLogFont(&lf);
lstrcpy(lf.lfFaceName, _T("Arial"));
COLORREF col = RGB(0 , 0 ,0);
pGroupFont->AddSubItem(new CMFCPropertyGridFontProperty(_T("Header Font"), lf,
CF_EFFECTS | CF_SCREENFONTS, _T("Specifies the default font for the dialog") , IDC_PROPERTY_GRID1_FONT , col) );
CMFCPropertyGridColorProperty* pColorProp = new CMFCPropertyGridColorProperty(_T("Header Font Color"),
RGB(0, 0, 0), NULL, _T("Specifies the default dialog font color") , IDC_PROPERTY_GRID1_FONT_COLOR);
pColorProp->EnableOtherButton(_T("Other..."));
pColorProp->EnableAutomaticButton(_T("Default"), ::GetSysColor(COLOR_3DFACE));
pGroupFont->AddSubItem(pColorProp);
CMFCPropertyGridColorProperty* pColorProp2 = new CMFCPropertyGridColorProperty(_T("Header Back Color"),
RGB(255, 255, 255), NULL, _T("Specifies the default dialog background color") , IDC_PROPERTY_GRID1_BACK_COLOR);
pColorProp2->EnableOtherButton(_T("Other..."));
pColorProp2->EnableAutomaticButton(_T("Default"), ::GetSysColor(COLOR_3DFACE));
pGroupFont->AddSubItem(pColorProp2);
m_wndPropList1.AddProperty(pGroupFont);
Related
I am making dialog based programs with MFC.
How do I change the text of the edit control to bold or change the size?
Where and what kind of code should I write?
Please tell me specifically.
In your OnInitDialog, create a CFont object (declared in your dialog)
m_pFont=new CFont;
int lfHeight;
lfHeight = (int) -(dSize* 90 / 72.);
int nWeight=FW_NORMAL;
if ( isBold )
nWeight=FW_BOLD;
pFont->CreateFont( lfHeight , 0, 0, 0, nWeight, (BYTE)isItalic, (BYTE)isUnderline, 0, (BYTE)nCharSet, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T("Arial") );
And then call SetFont(m_pFont) for your edit control - delete it in your destructor.
How do you add Images to a ClistCtrl in MFC? I have tried and found that it's quite difficult.
I used CImageList to add images and then passed it to the CListCtrl. Can you provide some samples?
m_sentToCListCtrl.InsertColumn(0, _T("Item Name"), LVCFMT_LEFT,nColInterval*3);
m_sentToCListCtrl.InsertColumn(1, _T("Value"),LVCFMT_LEFT, nColInterval);
m_sentToCListCtrl.InsertColumn(2, _T("Time"), LVCFMT_LEFT, rect.Width()-4*nColInterval);
ListView_SetExtendedListViewStyle(m_sentToCListCtrl.m_hWnd,LVS_EX_CHECKBOXES );
// Create 256 color image lists
HIMAGELIST hSentToList =ImageList_Create(84,71, ILC_COLOR8 |ILC_MASK , 8, 1);
m_sentToImageList.Attach(hSentToList);
You need to add some bitmaps to your CImageList after you have created it. Something like this:
m_myImageList.Create(84,71, ILC_COLOR8 |ILC_MASK , 8, 1);
CBitmap bm;
bm.LoadBitmap(IDB_BITMAP1);
m_myImageList.Add(&bm, RGB(0, 0, 0));
bm.LoadBitmap(IDB_BITMAP2);
m_myImageList.Add(&bm, RGB(0, 0, 0));
Then, attach it to the CListCtrl:
m_sentToCListCtrl.SetImageList(&m_imageList, LVSIL_SMALL);
Finally, you add items to your CListCtrl by using the InsertItem method:
LVITEM lvItem;
lvItem.iItem = 0;
lvItem.iImage = 0; // image index that refers to your image list
lvItem.pszText = L"Item 1";
lvItem.mask = LVIF_TEXT;
m_sentToCListCtrl.InsertItem(&lvItem);
For more info refer to CListCtrl documentation. There are examples too.
I wanna make a large toolbar with support of icons with more colors depth than default in Visual Studio. I am using Visual Studio 2005 and the Toolbar is on a CDialog.
I used the Code found : here
but did not work.
int CSalariesForm::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDR_MAINFRAME1), IMAGE_BITMAP,
0,0, LR_CREATEDIBSECTION | LR_LOADMAP3DCOLORS);
CBitmap bm;
bm.Attach(hBitmap);
CImageList m_imagelist;
m_imagelist.Create(20, 20, ILC_COLOR8, 4, 4);
m_imagelist.Add(&bm, (CBitmap*) NULL);
cToolBar.Create(this);
cToolBar.GetToolBarCtrl().SetImageList(&m_imagelist);
cToolBar.ShowWindow(SW_SHOW);
cToolBar.SetBarStyle(CBRS_TOOLTIPS | CBRS_FLOATING | CBRS_ALIGN_TOP | CBRS_FLYBY);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
return 0;
}
And when I call the dialog there is no Toolbar shown. What is wong with the code?
Thank You
Assigning an image list to a toolbar does not create any toolbar buttons. Also your image list should be a class member, not a local variable.
// header file
private:
CImageList m_imagelist;
CToolBar m_toolbar;
// source file
enum { width = 20, height = 20 }; // width and height of one button image
m_toolbar.Create(this);
// create the image list
m_imagelist.Attach(
ImageList_LoadImage(
AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1), width, 4,
CLR_DEFAULT, IMAGE_BITMAP, LR_CREATEDIBSECTION | LR_LOADTRANSPARENT )
);
// set button and image sizes (copied from CToolBar::LoadToolBar)
m_toolbar.SetSizes(CSize(width+7,height+7), CSize(width,height));
// set image list
m_toolbar.GetToolBarCtrl().SetImageList(&m_imagelist);
// define command ids for each button
const UINT cmdIds[] = {
IDOK,
0, // separator
IDCANCEL,
};
// assign ids to the toolbar
m_toolbar.SetButtons(cmdIds, sizeof(cmdIds)/sizeof(UINT));
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
IDB_BITMAP1 is a 40x20 24bit color bitmap (two 20x20 buttons). If you need more control over the creation of the buttons, you can use CToolBarCtrl::SetButtons() instead. Refer to ImageList_LoadImage for more details on loading the image list.
Normally to change the characteristics (Font, color) of a Section in Plain mode we have to create an entire view from scratch.
In cases where a simple change is needed in color/size, is there an easier way to do this?
Here's what I tend to do:
var header = new UILabel(new RectangleF(0, 0, 320, 25)){
Font = UIFont.BoldSystemFontOfSize (22),
TextColor = UIColor.White,
BackgroundColor = SomethingPretty,
Text = "Something"
};
Section secGroup = new Section(header);
This appears to be the simplest way:
var header = new UILabel(new RectangleF(0, 0, 320, 25)){
Font = UIFont.BoldSystemFontOfSize (22),
TextColor = UIColor.White,
BackgroundColor = SomethingPretty,
Text = "Something"
};
Section secGroup = new Section(header);
I created programmatically a multi view iphone application.
when adding objects to a view, like a button for example. in position x = 0, y = 0
this results to x = 0, y = 20 in the iphone simulator.
this is the used code :
UIButton *btnGoToStartView = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnGoToStartView.frame = CGRectMake(0, 0, 240, 30);
[btnGoToStartView setTitle:#"Btn Name" forState:UIControlStateNormal];
[btnGoToStartView addTarget:self action:#selector(myBtnAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnGoToStartView];
In the other hand, when I'm placing a button using Interface Builder in position x = 0, y = 0 the result is good.
Till now I didn't found the real reason for this vertical shifting.
Thanks in advance for your hints.
Regards.
It's Ok, I found the solution.
It's a problem of the UIView not the control.
in Interface builder, I opened the MainWindow.xib then I modified the attribute Layout in the inspector window.
I checked [wants full screen].
That's all.