|
Victor Nijegorodov wrote: Just for a test: what will happen if you call
mCSVListCtrl.DeleteColumn(0);
from anywhere but from this MyClass::OnLvnColumnclickList(...) message handler?
It's the same. I think I'll have to go for the dummy left column idea some of you have suggested - maybe I'll use it to number the rows which might be quite nice anyway.
Thanks again for all your replies.
|
|
|
|
|
|
HI,
I have code that works fine in debug but I have already learned my lesson that it does mean It will work in Release
Anyway I got an assertion in wincore.cpp line 656 for having a window handle = NULL
After the message box came up pointing me to the location in wincore.cpp where the problem was I tried to attach the VS debugger with my solution.
Wasn't much help as the call stack was all windows code
One thing I did notice that was odd the DLL was MFC140d.DLL isn't that the debug version of MFC
I checked my property pages for release and I had /MD not /MDd shouldn't I have MFC140.DLL ??
|
|
|
|
|
Turn your warning level up .. it will give you uninitialized use warnings. The default is W3 go to W4 or WALL you might get a lot of warnings but saves you headaches
I usually start out W3 when it's getting close to release I crank the setting up and walk thru each warning.
What you are really saying is you have a bad habit of either using uninitialized variables or forgetting to initialize them which will be what your current problem is about. You need to work on getting rid of what is obviously a bad coding habbit.
/MD is the correct selection for the VC runtime library release but usually I go for /MT in release the exe gets bigger but no VC runtime install required on the target machine. Now I assume it follows thru to MFC I write so little on the MFC framework I can't say definitively. But yes usually in release /MD or /MT is the setting you would use the difference as stated, and if the blowup in size is worth not having to distribute the run-time library at all.
Now when VS debugs in release mode it's a quirky thing, as you stated you wanted no debug compilation but the VS IDE still tries to give you debug info. It seems to sort of guess at the line sometimes you will find it out by a line or 2 especially if it has optimized some of the code away. When running outside the IDE I know it only uses the correct DLL because the times I have used DLL distribution I only copy the one DLL for install.
In vino veritas
|
|
|
|
|
Thanks
I just realized I did a number of SetDlgItemText for labels in my Dialog but I never Created a window
Maybe I'll just have the appropriate CStatic's and use DDX_Control to initialize the windows handle
or better yet just use DDX_Text and put the data in a CString
Thanks
|
|
|
|
|
For some reason your release build is linked with the debug version of the MFC. You should find out why and fix that. A possible reason is linking with another DLL that depends on the MFC DLL and is a debug version itself.
With proper code, a debug build should also assert at that point (window handle NULL). However, it would not assert if the handle is not NULL but invalid (uninitialised variable). But then you usually get other runtime errors.
|
|
|
|
|
My only guess at this point that after doing various "new" to allocate heap storage to format labels for the dialog
I do AfxCheckMemory rather then assert to see if I some how over stepped my storage allocation
Thanks
|
|
|
|
|
This function works only in the Debug version of MFC. Therefore, it is common to call that within an ASSERT() .
Note also that you should check if the affected handle is on the heap. It does not help when it is on the stack.
|
|
|
|
|
I am quite sure the reason I got an assertion was because I did a SetDlgItemText without some how creating a m_hWnd
Just surprising that it worked at all under debug but then again I am beginning to understand the "debug" version covers up for a lot of mistakes
On more thing should assert only be used in "debug"
Thanks
|
|
|
|
|
Quote: I am quite sure the reason I got an assertion was because I did a SetDlgItemText without some how creating a m_hWnd That is very likely.
ForNow wrote: On more thing should assert only be used in "debug" Just read the documentation:
The assert macro is enabled in both the release and debug versions of the C run-time libraries when NDEBUG is not defined. When NDEBUG is defined, the macro is available but does not evaluate its argument and has no effect. When it is enabled, the assert macro calls _wassert for its implementation. Other assertion macros, _ASSERT, _ASSERTE and _ASSERT_EXPR, are also available, but they only evaluate the expressions passed to them when the _DEBUG macro has been defined and when they are in code linked with the debug version of the C run-time libraries. My tip: Use them often (e.g. on top of functions for parameter checking and with function return values when there is no error handling). They are simply ignored in release builds but can save you a lot of debugging time.
|
|
|
|
|
Hi,
How do I create a totally new MFC Control type? I take it that I have to create and register a new Window Class, with it's own Message Procedure, and thereafter write my own MFC/CPP around it as a Husk. Is there any way of deriving my own custom controls from CWnd directly and using the message map Macro's? As a new type of control it will need a resource to display it on screen, etc. How do I tie all this together.
Regards,
Bram van Kampen
|
|
|
|
|
Start by reading a few of the many articles at this site on custom controls. You can't expect someone to explain all of that in a few forum posts.
|
|
|
|
|
It depends what you want your class to do. Take a look at the Hierarchy Chart | Microsoft Docs[^] and see if there is an existing control that you can derive from (even if it is CWnd), since the base class will provide lots of functionality.
|
|
|
|
|
Because all MFC controls are CWnd based you should use that as base class too. Then add the painting (OnPaint , OnEraseBackground ), register the window class and add control specific message handlers as necessary.
An old but good article by Chris: Creating Custom Controls[^]
|
|
|
|
|
Hello everybody,
I'm new to MFC and after passing several hours trying to solve a problem (that might seem simple to most of you), I decided to post my question here in order to get your help and hints.
I'm developing an MFC (C++) application using Visual Studio 2017. The application contains a main CDialog to communicate with a 2D Laser sensor using TCP/IP and to plot the points detected by the sensor on screen in real time (this is done on an IDC_PICTURE element with OnPaint() as the following:
CDC* pDC = m_Picture.GetDC();
CDC memDC;
CBitmap bmp;
memDC.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC, PicW, PicH);
pDC->StretchBlt(0, 0, PicW, PicH, &memDC, 0, 0, PicW, PicH, SRCCOPY);
bmp.DeleteObject();
memDC.DeleteDC();
ReleaseDC(pDC);
This previously mentioned code is working very well without problems with the main dialog.
Long story short, my problem is the following:
On that same dialog, I created a button that opens a secondary modeless dialog that contains another IDC_PICTURE element. The main goal of the secondary dialog is to plot a delayed version (t-n) of the points seen by the Laser sensor. My main problem is that I am not being able to show anything on the secondary IDC_PICTURE. Is it wrong to do the same thing applied on the main dialog (on another IDC_PICTURE, with anothe pDC and memDC)?
The secondary dialog is defined in a separate class of which I have created an instance in the (first) main CDialog class.
I have been looking everywhere on solutions that could look similar to my problem, but I haven't found anything. What exactly am I missing?
PS. sorry if my problem description isn't clear enough. My code is getting too big to be copied/pasted.. I'd be very happy if you have any hints / questions that might make me find the solution..
Thanks in advance for your help!
|
|
|
|
|
How is the painting triggered?
I guess that you trigger it in the main dialog when new data has been received from the sensor. You have to do it similar for the second modeless dialog (e.g. by triggering a repaint after new data has been passed).
|
|
|
|
|
Thanks for your reply!
Actually the painting is triggered using the OnTimer() function as follows:
void CLMS511_interfaceDlg::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == 100)
{
DrawData();
}
CDialog::OnTimer(nIDEvent);
}
I've done the same in the secondary dialog but it didn't change anything.. :/
|
|
|
|
|
How have you done it in the second dialog?
You must pass the data to the second dialog in some way. Then just draw there aftwerwards calling InvalidateWindow() and UpdateWindow() .
Or do that from the main dialog using the member variable of the second dialog:
m_pModeLessDialog->DrawData();
Both (passing data and trigger redraw from the main dialog), requires that you have a member variable for the second dialog initialised in the button handler when the second dialog is created.
|
|
|
|
|
Are you sure that the relevant Windows messages (e.g. WM_PAINT) are being correctly dispatched to the modeless dialog?
|
|
|
|
|
I'm not sure, I actually don't know what this message is or how to handle it. I'll do the research and get back to you in case of need!
Thanks alot!
|
|
|
|
|
Bonobo8 wrote: I actually don't know what this message is or how to handle it. Then you are definitely going to have problems, especially if you are trying to paint the controls at other times. If you do not understand how Window painting works in Windows then you will continue to have problems. I suggest you look for some tutorials on how it is done.
|
|
|
|
|
Hi
I was looking to intercept a Rich Edit controls keystrokes, seems I have call CRicheditctrl::SetEventmask with ENM_KEYEVENTS> this lead me to a article about notification When a Rich Edit is resized
The Author Thales P. Carvalho has the notification method OnRequestResize in the parent window. I cannt seem to find this method in either Cdialog or CWnd maybe he was referring to OnNotify ?
|
|
|
|
|
If you have a question about an article, use the forum at the bottom of that article. That way, the author will be notified of your question, and you're not relying on them stumbling across your question in a completely different part of the site.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
See EN_REQUESTRESIZE notification code (Windows)[^]. It is a notification code send with a WM_NOTIFY message. So there must be a message map entry in the parent window class:
ON_NOTIFY(EN_REQUESTRESIZE, ID_of_the_richedit_ctrl, OnRequestResize) and a function definition in the header file:
afx_msg void OnRequestResize(NMHDR *pNMHDR, LRESULT *pResult);
|
|
|
|
|
That's what I thought thanks it wasn't clear from the article
|
|
|
|