Is the given code correct? I am wondering about the return instruction, in which a CString object is created: return CString( szHomeDirBuf ); In my opinion this object will be already destroyed while the function returns. When accessing from caller, the object is already invalid. CString res = GetUserHomeDir(); Am I wrong?
Member 8534035
Posts
-
Is there any Win32 API to get users home directory -
Controls in CPaneDialog (MFC) not Workingsorry for the late reply...I was absent a while! in the meantime I lost my first trail project and did it again, somehow differently ;) but it is still not working! My steps in detail: 1. Using the original source code from VS Gesture Demo 2. Adding a ListControl to the IDD_OPTIONS Dialog resource (report style) ID: IDC_LIST_INPANE 3. doing the same what the framework would do automatically for a standard dialog: - in OptionPane.h I added
CListCtrl m_ListCtrl;
- in OptionPane.cpp in DoDataExchange
DDX_Control(pDX, IDC_LIST_INPANE, m_ListCtrl);
4. Added a Handler for WM_INITDIALOG
LRESULT COptionsPane::HandleInitDialog(WPARAM wParam,LPARAM lParam)
{
UNREFERENCED_PARAMETER(wParam);
UNREFERENCED_PARAMETER(lParam);m_ListCtrl.InsertColumn(0,_T("Col1"),LVCFMT_LEFT,50);
m_ListCtrl.InsertColumn(1,_T("Col2"),LVCFMT_LEFT,50);int nItem;
nItem = m_ListCtrl.InsertItem(MAXINT,_T("Item1"));that's quite all! Now, when I am starting the program, I will get an assertion in HandleInitDialog at the first access of m_ListCtrl. It seems m_hWnd is not valid at this moment. What I need to do additionally in comparison to CDialog (where I initialize the control in OnInitDialog()) Is CPaneDialog::HandleInitDialog the wrong place for initialization of controls?
-
Controls in CPaneDialog (MFC) not WorkingHello, I am tryint to use CPaneDialog for implementing dockable Dialogs, based on a Dialog resource. I started with the GestureDemo from Microsoft's MFC samples. There is an option dialog bases on CPaneDialog. The demo works as it is. I added to the dialog resource a ListControl. Here is my problem. The Control is not displaying any content! I tested the same dialog inside a standard CDialog. So actually my control works fine! Is there anything additionally, I need to do in a CPaneDialog to interact with dialog controls? Unfortunately I cannot find further source code samples. Seems, nobody is using CPaneDialog. Any hints? Thanks a lot!
-
embed WxWidgets in MFC applications?Hi Everyone, is it possible to embed WxWidgets Controls in a MFC based application? In detail, is there a way to use wxWidget Controls inside a MFC Control? specially CView, CFormView or CDockablePane? My problem: I have a huge MFC appication with rich GUI features. I need to extend this application with a feature, that user will be able to display application data by creating his own views. I could start this task with an approach like this: XUIFramework: A GUI Framework based on XML and MFC[^] Actually it would work with some simple MFC controls, but there will be a lot of work to make it more functional. So my basic idea is, to use wxWidgets because of its rich functionality. But I cannot rewrite the complete application to base it on wxWidgets instead of MFC. An further advantage of wxWidget would be, that it should be very easy to create a runtime for other systems like linux to run the user's GUI! I have found in internet a few comments about such an approach. some says, it could be possible. But I have not found anything concrete. If I would have a very basic sample, I could start such a project. Any ideas?
-
How to Mix MFC Controls and OpenGL?Hello, is it anyhow possible to mix or overlay MFC Controls in OpenGL controlled screen area? My aim is as follows: I have 3D animation (like industrial robot visualisation). Nearby 3D objects I want to display object related information (e.g. with a CListBox Control). I have already a lot of Controls, based on MFC Controls with enhanced functionality. I want to reuse this at top of a 3D scene? Any ideas, if it is possible or how I should start? Many Thanks Richard
-
MFC CListCtrl how to Display SubItem text with tabulator ?sorry, I was talking about '\t', the ASCII sign for tabulator. If I assign a text with SetItemText() to a CListCtrl item, the tabulator is ignored completely. e.g. "label:\tsome text which should begin at next tabulator position" The CListCtrl is not viewing any spacing for the tabulator.
-
MFC CListCtrl how to Display SubItem text with tabulator ?hmm, maybe I do not understand this approach completely! I could calculate the text size and tab position. but when replacing the tab character with a number of blanks, I will not get an accurate tab position. it will looks quite crude over several lines. further I will have additional issues with the blanks, when I want do make in place edititing. Is there any possibility to draw the text of an subitem by myself? e.g. if I would catch a notification message that an subitem needs to be drawn, that I call a function like CDC::TabbedTextOut() ? Thanks again!
-
MFC CListCtrl how to Display SubItem text with tabulator ?you propose to replace with number of tabs? it's much effort, because I need to loop over the text and replace by different number of tabs (depending on position). further this works only for fix size fonts.
-
MFC CListCtrl how to Display SubItem text with tabulator ?Hi all, I am inserting text to CListCtrl Items with function SetItemText(). The text contains '\t'. I would need to display the text of the subitems with expanded tabulators. Is there a way? I cannot find any hints about this issue. Many Thanks
-
access violation with std::map (VS2015)I need a sorted list of strings with some additional information for each entry, so I thought about to use std::map I am doing just simple things: Definition:
typedef std::map tTABMNEMO;
tTABMNEMO TabMnemo;and in constructor of using class I am calling firstly:
TabMnemo.clear();
already this first access (in constructor of using class) causes an access violation. any idea, what could be wrong? Do I need to initialize anyhow? maybe it is because of my program structure? this map is defined globally outside of the class and all the member functions of the using class are static functions!
-
C++ lambda callbacks, how to initialize with NULL pointer ?oh....you are right! with
nullptr
it works!!! never, never used it before! Many Thanks Richard -
C++ lambda callbacks, how to initialize with NULL pointer ?Hi all, I need callback functions between different classes. I had already a solution based on stl, which was compilable with VS2010. Unfortunately I was not able to find a way to compile it with VS2015. I got weird error messages. Now I found a solution with lamda C++11 lambda function pointers. Actually it works, but I have one open issue. For having a save source code, I want to initialize the function pointer with NULL. But compiler is producing weird error messages again! My Code:
typedef std::function _tcedit_cb_;
class MyClass
{
public:
MyClass ()
{
m_cbGetItemData = NULL; // <--- compile error because of the NULL pointer
}
_tcedit_cb_ m_cbGetItemData;...
}How I can initialize the function callback pointer? I need to initialize in order to avoid running into illegal code! e.g. I tried to cast ... = (_tcedit_cb_) NULL; error messages:
c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : error C2893 : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : note : With the following template arguments :
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : note : '_Callable=_Decayed &'
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : note : '_Types={int, int, ATL::CStringT>> }'
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\functional(210) : note : see reference to function template instantiation '_Rx std::_Invoke_ret<_Rx,_Callable&,_Ty,_Ty,ATL::CStringT>>>(std::_Forced<_Rx,false>,_Callable &,_Ty &&,_Ty &&,ATL::CStringT>> &&)' being compiled
1> with
1>[
1> _Rx = bool,
1> _Callable = _Decayed,
1> _Ty = int
1>] -
Draw and re-pos CStatic controls in CDockablePaneSolved by myself! In OnPaint() I changed the positions of the CStaticControls. Of course this is causing "recursive" WM_PAINT calls. I moved this code to other functions (OnSize, OnTimer,...), now it works!
-
Draw and re-pos CStatic controls in CDockablePaneHi all, I have spend already many hours to find the reason of my current problem. I have a CDockablePane, in which I am placing a lot of CStatic controls. The CStatic controls I am using to display bitmaps. A dockable pane is designed for resizing at any time. Therefore I try to recalculate the positions of each CStatic after OnSize is called. With some CStatic controls it is running well. But when I am adding an additional control, I am getting strange problems: The pane is not repainted properly and OnPaint is recalled cyclically. My code (partially): Header:
class CPaneCtrlPLC : public CDockablePane
{
DECLARE_DYNAMIC(CPaneCtrlPLC)public:
CPaneCtrlPLC();
virtual ~CPaneCtrlPLC();protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);private:
CStatic m_Ctrl_PLCLED[6];
CStatic m_SwitchCtrl;
CStatic m_Ctrl_test;C-File:
int CPaneCtrlPLC::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
return -1;m\_ColorSieGreen = RGB(0, 153, 153); m\_ColorSieWhite = RGB(251, 253, 253); m\_ColorText = RGB(230, 228, 193); m\_ColorBgnd = RGB(119, 117, 127); m\_BrushSieGreen.CreateSolidBrush(m\_ColorSieGreen); m\_BrushBgnd.CreateSolidBrush(m\_ColorBgnd); m\_BitmapSWITCHSTOP.LoadBitmapW(IDB\_SWITCH\_STOP); m\_bitmapLEDOFF.LoadBitmapW(IDB\_LEDOFF); m\_bitmapLEDRED.LoadBitmapW(IDB\_LEDRED); m\_bitmapLEDGREEN.LoadBitmapW(IDB\_LEDGREEN); m\_bitmapTest.LoadBitmapW(IDB\_LEDGREEN); // TODO: Add your specialized creation code here DWORD dwStyle = WS\_CHILD | WS\_VISIBLE | TVS\_SHOWSELALWAYS | SS\_BITMAP; m\_SwitchCtrl.Create(NULL, dwStyle, CRect(0, 0,0,0),this); m\_SwitchCtrl.SetBitmap(m\_BitmapSWITCHSTOP); int iLed; for (iLed = 0; iLed < MaxNumPLCLeds; ++iLed) { DWORD dwStyle = WS\_CHILD | WS\_VISIBLE | TVS\_SHOWSELALWAYS | SS\_BITMAP; m\_Ctrl\_PLCLED\[iLed\].Create(NULL, dwStyle, CRect(xPosPLCLEDS,(yPosPLCLEDS + (26\* iLed)), 0, 0), this); m\_Ctrl\_PLCLED\[iLed\].SetBitmap(m\_bitmapLEDOFF); } { DWORD dwStyle = WS\_CHILD | WS\_VISIBLE | TVS\_SHOWSELALWAYS | SS\_BITMAP; m\_Ctrl\_test.Create(NULL, dwStyle, CRect(xPosPLCLEDS + (17 \* iLed), yPosPAELEDS + 20, 0, 0), this); m\_Ctrl\_test.SetBitmap(m\_bitmapTest); }
...
I was able to strip the OnPaint(0) function to a minumum to reprocude the problem. If I comment out the re-positioning of the m_Ctrl_test, everything works fine, but with this statement I have
-
problems with std::bind in VS2015Hi all, I have a weird problem with stl ! I need to work with callback functions between different classes. With VS2010 I have done this already different times without any problem. With VS2015 I cannot compile such code! Example:
in Header in Class Declaration:
#include <functional>
...
bool ProvideItemData(int nItem, int nSubItem);in .cpp:
{ //using namespace std::placeholders; // for \`\_1\` m\_ListCtrl.SetOwnerData(std::bind(&CBlockEditView::ProvideItemData, this, std::placeholders::\_1)); }
declaration in called class:
bool SetOwnerData(std::function <bool(int nItem,int nSubItem)> callback);
When compiling in VS2010, I get weird error messages:
c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(1501): error C2440: 'return': cannot convert from 'std::_Unforced' to 'bool'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(1501): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\functional(210): note: see reference to function template instantiation '_Rx std::_Invoke_ret<_Rx,_Callable&,_Ty,_Ty>(std::_Forced<_Rx,false>,_Callable &,_Ty &&,_Ty &&)' being compiled
1> with
1> [
1> _Rx=bool,
1> _Callable=_Decayed,
1> _Ty=int
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\functional(208): note: while compiling class template member function 'bool std::_Func_impl<_Decayed,_Alloc,_Ret,int,int>::_Do_call(int &&,int &&)'
1> with
1> [
1> _Alloc=std::allocator,
1> _Ret=bool
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\functional(136): note: see reference to class template instantiation 'std::_Func_impl<_Decayed,_Alloc,_Ret,int,int>' being compiled
1> with
1> [
1> _Alloc=std::allocator,
1> _Ret=bool
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\functional(339): note: see reference to class template instantiation 'std::_Is_large<_Myimpl>' being compiled
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\functional(318): note: see reference to function template instantiation 'void std::_Func_class<_Ret,int,int>::_Reset_alloc<_Ty,std::allocator>(_Fx &&,const _Alloc & -
Floating view in Visual Studio Style ProjectI want to create an IDE which should have similar look and feel like Visual Studio itself. For this I created a "Visual Studio Style" Project by usage of AppWizard. Now I am wondering, how to implement "Windows Float" functionality? What I mean exactely? e.g. when you look at Visual Studio's Solution Explorer window, there is a small down arrow in the title bar. When you click on it, a menue opens and you can change the window style to "float". This feature I want to use instead of a non modal dialog, becaue this would be much more flexible. Has anybody an idea, how to implement. Maybe it is also implement in the IDE Framework of the MFC, but I do not know how to activate?? Any ideas? Many thanks
-
MDI Application How to change Views Titleoh...many thanks for the link! finally it works now! according to the link I override:
void CMainFrame::OnUpdateFrameTitle( BOOL bAddToTitle )
but this is affecting the application main title. but overriding
void CChildFrame::OnUpdateFrameTitle( BOOL bAddToTitle )
does exactely what I need! many thanks for your help! I searched already at least 2 hours for a solution!
-
MDI Application How to change Views Titleuups...sorry...the source code I have written manually on the post, because my development environment is on another computer. but in principal it is according to what I have programmed
-
MDI Application How to change Views TitleHi, step by step I am creating a Visual Studio Style IDE Project, but I am running in a bunch of problems. My application is MDI based, created in Visual Studio Style with Project Wizard. Further I added functionality for viewing different views for each document. For this views I need to set an application specific Windows title. Actually I found hints how to solve:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style &= ~(LONG) FWS_ADDTOTITLE;
return CFrameWnd::PreCreateWindow(cs);
...CMyView::OnInitialUpdate()
{
CView::OnInitialUpdate();
GetParent()->SetWindowsText(_T("myText"));But it works only partially. The default view's title disappears, but my own one is not displayed. The title in the tab header is empty after the changes. Maybe it is because my view is a splitter view or the ChildFrame is with a Tab Control. I have no idea, how to solve. Anybody, who has an idea? Many Thanks!
-
MFC Visual Studio Style Project cannot change title of FileViewHi all, I have started a project for an IDE using MFC Visual Studio Style Project. I want to change the standar title of the FileView pane. for this I changed the IDS_FILE_VIEW text. But the result is not like expected. On initial startup at top of the pane the new title is displayed correctly, but at button tabs there is still the old name "File View". And if I switch between the tabs, the old name is displayed on pane's top too. In the whole project I cannot find other locations of the "File View" string, therefore I do not have any idea, how to change the behaviour! Any ideas?