Visual Studio MFC library in 2015
I've been working on this
And it's not working for me
I don't see any item
There are many older examples
I think it doesn't work on vc2015 ?
Here is the code
void CMFCApplication67Dlg::OnTvnSelchangedTree1(NMHDR *pNMHDR, LRESULT
*pResult)
{
// TODO: Add your control notification handler code here
TVINSERTSTRUCT tvInsert;
tvInsert.hParent = NULL;
tvInsert.hInsertAfter = NULL;
tvInsert.item.mask = TVIF_TEXT;
tvInsert.item.pszText = _T("United States");
HTREEITEM hCountry = m_l.InsertItem(&tvInsert);
HTREEITEM hPA = m_l.InsertItem(TVIF_TEXT,
_T("Pennsylvania"), 0, 0, 0, 0, 0, hCountry, NULL);
HTREEITEM hWA = m_l.InsertItem(_T("Washington"),
0, 0, hCountry, hPA);
m_l.InsertItem(_T("Pittsburgh"), hPA, TVI_SORT);
m_l.InsertItem(_T("Harrisburg"), hPA, TVI_SORT);
m_l.InsertItem(_T("Altoona"), hPA, TVI_SORT);
m_l.InsertItem(_T("Seattle"), hWA, TVI_SORT);
m_l.InsertItem(_T("Kalaloch"), hWA, TVI_SORT);
m_l.InsertItem(_T("Yakima"), hWA, TVI_SORT);
The question differently.
When I drag a control from the Toolbox and wooden I copy the code examples I gave are supposed to work or what needs to be done
Set the parent item to TVI_ROOT, not null. Also, from what I can tell, your code is only called when the selection in the tree changes; you'll probably want to do the whole InsertItem stuff in CMFCApplication67Dlg::OnInitDialog.
Now I get it.
Need to boot in the "OnInitDialog" function Like here.
I looked in the "OnInitDialog" classes view
Put name and initialization code works! thanks to all who helped!
My mistake.Press double click on the tree where I rebooted. CPP no in "OnInitDialog"
I wrote that if someone will mistakenly call him might help him. Thanks again
Related
It has been 10 months since I worked on my app due to a death in the family, just started looking at it again and still not sure how to solve the problem.
The project inquires/help started here:
MFC MDI Collecting control states for the "apply" button routine
Since this is a specific focused question, I didn't want to muck up my other thread, so what I'd like to do is change the documents tab styles after the view is loaded. I know that this can be done because the master repository from Microsoft with all the code examples has a project called VCSamples-master\VCSamples-master\VC2010Samples\MFC\Visual C++ 2008 Feature Pack\TabControl which I have looked at. It dawns on me that even though I can follow its code, the calls are from within the MDI window itself where my issue is I'm trying to do this via a property page dialog using OnApply which changes things.
I was able to do part of this properly with the help of the thread above to the OutputPane successfully because I was able to get the Pane handle and execute. I was told that for the MDI tabs after creation that I need to parse the tabs, count them, and then execute. So my issue here is after I capture the tabs......how to change their styles.
Here is the code as it stands:
BOOL CSettingsUserTabs::OnApply()
{
BOOL bResult = CMFCPropertyPage::OnApply();
if (bResult)
{
// Update Output Pane Tab Styles (Works 100%)
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("UserTabStyle"), m_style_tabs); // Save value to registry
((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.RecalcLayout();
//Get the open file tabs in the MDI
for (POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition(); pos != NULL; )
{
CDocTemplate* pTempl = AfxGetApp()->GetNextDocTemplate(pos);
for (POSITION pos1 = pTempl->GetFirstDocPosition(); pos1 != NULL; )
{
CDocument* pDoc = pTempl->GetNextDoc(pos1);
for (POSITION pos2 = pDoc->GetFirstViewPosition(); pos2 != NULL; )
{
CView* pView = pDoc->GetNextView(pos2);
if (pView->IsKindOf(RUNTIME_CLASS(CTrainView)))
{
// THIS IS WHERE MY ISSUE IS, NOW THAT ALL THE TABS ARE
// CAPTURED, HOW DO I ADDRESS THEM LIKE WHAT IS SHOWN
// ABOVE:
//((CMainFrame*)AfxGetMainWnd())->xxxxxx.yyyyyy.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
}
}
}
}
}
return bResult;
}
If I can figure this last piece out, I'll be basically finished, I just can't seem to find a solution on how to do this via property sheet via OnApply.
Any suggestions or actual code examples I can see to solve my problem?
FYI: No, I haven't had any time to take additional OOP to solve this. I'm hoping someone can provide some guidance so I can move on after getting this sorted.
Thanks,
Chris
EDIT 1:
So I took a closer look at Constantine's suggestion and here is what I came up with:
BOOL CSettingsUserTabs::OnApply()
{
BOOL bResult = CMFCPropertyPage::OnApply();
if (bResult)
{
// Update Output Pane Tab Styles
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("UserTabStyle"), m_style_tabs); // Save value to registry
((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.RecalcLayout();
CMFCTabCtrl& MDI_STYLES = ((CMainFrame*)AfxGetMainWnd())->GetMDITabs();
MDI_STYLES.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
MDI_STYLES.RecalcLayout();
CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());
pMainFrame->SetFocus();
pMainFrame->RecalcLayout();
}
return bResult;
}
The m_styles_tabs is getting the index value of 0-8 when I select the radio button. The code compiles and runs and I see the index value change when I break on it, but the tabs for the MDI are still not updating. Does the edited code make sense based on the members shown here:
https://learn.microsoft.com/en-us/cpp/mfc/reference/cmfctabctrl-class?view=msvc-170#modifytabstyle
I think this the right direction, am I missing something?
Fl_Window *win = new Fl_Window(width, height, "title");
b1 = new Fl_Button(0, 0, 120, 30);
win->end();
b2 = new Fl_Button(130, 0, 120, 30);
win->show();//argc,argv);
Fl::run();
Here, second button b2 will not be shown, because after the call to end(), it is inserted into somewhere else not into win. After browsing through official docs and googling I still cannot understand the idea behind it, and how am I supposed to insert a new button into the window that is not currently selected for insertion? Is there something like win->begin() ?
By the way FLTK docs are rather a machine generated reference, very inconvenient for a learner, any good unofficial resource known?
Widgets can be added either between begin() and end() or using add.
Fl_Window *win = new Fl_Window(width, height, "title");
win->begin();
b1 = new Fl_Button(0, 0, 120, 30);
win->end();
b2 = new Fl_Button(130, 0, 120, 30);
win->add(b2)
The FLTK docs are generated by doxygen so basically they are only as good as the comments in the code (which is not bad for doxygened documentation). You'll get the same problem with code documented with javadocs and the C# autogenerated XML documentation.
Have you had a look at http://seriss.com/people/erco/fltk/ and http://seriss.com/people/erco/fltk-videos/ . They are the official "helper" web pages. I learnt a lot just by looking at the cheat sheet and examples in the distribution tarball test directory.
I'm a little new to using MFC and VC++ as such, but I'm doing this as part of a Course and i Have to stick to VC++.
http://www.cprogramming.com/tutorial/game_programming/same_game_part1.html
This is the tutorial I have been following to make a simple samegame. However when i try to display score, the score is getting displayed Underneath or outside my application window, even though I've displayed score before calling updateWindow(). I've tried various methods but I am kinda lost here.
Here is the code I'm using to Display the score:
void CSameGameView::updateScore()
{
CSameGameDoc* pDoc = GetDocument();
CRect rcClient, rcWindow;
GetClientRect(&rcClient);
GetParentFrame()->GetWindowRect(&rcWindow);
int nHeightDiff = rcWindow.Height() - rcClient.Height();
rcScore.top=rcWindow.top + pDoc->GetHeight() * pDoc->GetRows() + nHeightDiff;
rcScore.left=rcWindow.left + 50;
rcScore.right=rcWindow.left + pDoc->GetWidth() - 50;
rcScore.bottom=rcScore.top + 20;
CString str;
double points = Score::getScore();
str.Format(_T("Score: %0.2f"), points);
HDC hDC=CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);
COLORREF clr = pDoc->GetBoardSpace(-1, -1); //this return background colour
pDC->FillSolidRect(&rcScore, clr);
DrawText(hDC, (LPCTSTR) str, -1, (LPRECT) &rcScore, DT_CENTER);
}
Thank you for any help and I'm sorry if the question doesn't make sense or in ambiguous.
There are several problems with your code:
1. The hDC you are creating is going to have coordinates relative to the desktop window. To paint text in your window, use CClientDC like this: CClientDC dc(this); (see http://msdn.microsoft.com/en-US/library/s8kx4w44%28v=vs.80%29.aspx)
2. The code you have will leak a DC every time the function is called. The method in #1 will fix that.
3. Your paint code should be done in the CView::OnDraw. There you get a DC passed to you and you don't have to worry about creating one with CClientDC. Set the variables you want to draw (e.g. your points or score), store them as class members and draw them in CView::OnDraw.
Don't do the drawing in your updateScore method.
Make sense? Hang in there!
To change brightness of an image in c#.net 4 i have used the following method.
public void SetBrightness(int brightness)
{
imageHandler.RestorePrevious();
if (brightness < -255) brightness = -255;
if (brightness > 255) brightness = 255;
ColorMatrix cMatrix = new ColorMatrix(CurrentColorMatrix.Array);
cMatrix.Matrix40 = cMatrix.Matrix41 = cMatrix.Matrix42 = brightness / 255.0F;
imageHandler.ProcessBitmap(cMatrix);
}
internal void ProcessBitmap(ColorMatrix colorMatrix)
{
Bitmap bmap = new Bitmap(_currentBitmap.Width, _currentBitmap.Height)
ImageAttributes imgAttributes = new ImageAttributes();
imgAttributes.SetColorMatrix(colorMatrix);
Graphics g = Graphics.FromImage(bmap);
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.DrawImage(_currentBitmap, new Rectangle(0, 0, _currentBitmap.Width,
_currentBitmap.Height), 0, 0, _currentBitmap.Width,
_currentBitmap.Height, GraphicsUnit.Pixel, imgAttributes);
_currentBitmap = (Bitmap)bmap.Clone();
}
If brightness is changed several times then "Out of memory" exception is shown. I have tried to use "Using block" but went in vein.
Any ideas?
please see the link
http://www.codeproject.com/Articles/227016/Image-Processing-using-Matrices-in-Csharp
and suggest if any types of optimization is possible in the methods (Rotation, brightness, crop and undo).
I have downloaded the projects from CodeProject and I have fixed the memory leak. You need to dispose the Graphics object and the _currentBitmap image before you override it. Also, you need to stop using .Clone.
If you replace the contents of the ProcessBitmap function with this code, the memory leak is gone:
internal void ProcessBitmap(ColorMatrix colorMatrix)
{
Bitmap bmap = new Bitmap(_currentBitmap.Width, _currentBitmap.Height);
ImageAttributes imgAttributes = new ImageAttributes();
imgAttributes.SetColorMatrix(colorMatrix);
using (Graphics g = Graphics.FromImage(bmap))
{
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.DrawImage(_currentBitmap, new Rectangle(0, 0, _currentBitmap.Width, _currentBitmap.Height), 0, 0, _currentBitmap.Width, _currentBitmap.Height, GraphicsUnit.Pixel, imgAttributes);
}
_currentBitmap.Dispose();
_currentBitmap = bmap;
}
Also, here are some tips for further optimization:
Stop using .Clone(). I have seen the code, and it uses .Clone() everywhere. Don't clone objects unless really necessary. In image processing, you need a lot of memory to store large image files. You need to make as much processing as you can in-place.
You can pass Bitmap objects by reference between methods. You can improve performance and reduce the memory cost that way.
Always use using blocks when working with Graphics objects.
Call .Dispose() on the Bitmap objects when you're sure you don't need them anymore
I cannot figure out how to use the WebBrowser control without having it create a window in the taskbar.
I am using the IWebBrowser2 ActiveX control directly because I need to use some of the advanced features like blocking downloading JAVA/ActiveX/images etc. That apparently is not available in the WPF or winforms WebBrowser wrappers (but these wrappers do have the ability to create the control with no UI)
Here is my code for creating the control:
Type webbrowsertype = Type.GetTypeFromCLSID(Iid_Clsids.CLSID_WebBrowser, true);
m_WBWebBrowser2 = (IWebBrowser2)System.Activator.CreateInstance(webbrowsertype);
m_WBWebBrowser2.Visible = false;
m_WBOleObject = (IOleObject)m_WBWebBrowser2;
int iret = m_WBOleObject.SetClientSite(this);
iret = m_WBOleObject.SetHostNames("me", string.Empty);
tagRECT rect = new tagRECT(0, 0, 0, 0);
tagMSG nullMsg = new tagMSG();
m_WBOleInPlaceObject = (IOleInPlaceObject)m_WBWebBrowser2;
//INPLACEACTIVATE the WB
iret = m_WBOleObject.DoVerb((int)OLEDOVERB.OLEIVERB_INPLACEACTIVATE,
ref nullMsg, this, 0, IntPtr.Zero, ref rect);
IConnectionPointContainer cpCont = (IConnectionPointContainer)m_WBWebBrowser2;
Guid guid = typeof(DWebBrowserEvents2).GUID;
IConnectionPoint m_WBConnectionPoint = null;
cpCont.FindConnectionPoint(ref guid, out m_WBConnectionPoint);
m_WBConnectionPoint.Advise(this, out m_dwCookie);
This code works perfectly but it shows a window in the taskbar. If i omit the DoVerb(OLEDOVERB.OLEIVERB_INPLACEACTIVATE) call, then Navigating to a webpage is not working properly. Navigate() will not download everything on the page and it never fires the DocumentComplete event. If I add a DoVerb(OLEIVERB_HIDE) then I get the same behavior as if I omitted the DoVerb(OLEDOVERB.OLEIVERB_INPLACEACTIVATE) call.
This seems like a pretty basic question but I couldn't find any examples anywhere.
Check the wraparounds in BUG: DocumentComplete Does Not Fire When WebBrowser Is Not Visible