|
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
|
|
|
|
|
this code correct or no? thank you in advance.
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include<iostream>
#include<math.h>
using namespace std;
using namespace cv;
float soft_tresholding(Mat src, float threshold)
{
int height=src.rows;
int width=src.cols;
for(int y=0; y < height; y++)
{
for(int x=0; x < width; x++)
{
if (src(y*width+x) > threshold)
src(y*width+x) = src(y*width+x) - threshold;
else if (src(y*width+x) < -threshold)
src(y*width+x) = src(y*width+x) + threshold;
else
src(y*width+x) = 0;
}
}
}
int main()
{
system("clear");
Mat src=imread("/home/jamal/Bureau/lena.jpg",0);
Mat dst;
float threshold;
dst=soft_thresholding(src,threshold);
namedWindow("Picture", CV_WINDOW_AUTOSIZE);
imshow("Picture", src);
namedWindow("picf", CV_WINDOW_AUTOSIZE);
imshow("Picf", dst);
waitKey();
return 0;
}
modified 13-Aug-17 9:15am.
|
|
|
|
|
saidinsan000000000 wrote: this code correct or no?
But didn't you test it?
Does it compile?
Does it work as expected?
|
|
|
|
|
saidinsan000000000 wrote: this code correct or no? It all depends on what you mean by "correct." Are you asking if it is syntactically correct, logically correct, or some other measurement?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I read a program, a function definition like:
void A( int channel)
{
}
While the caller like:
A();
I know it's OK. can't find a explanation.
|
|
|
|
|
why do you say it's OK ?
it's not.
void A( int channel)
{
}
int _tmain(int argc, _TCHAR* argv[])
{
A();
return 0;
}
1>c:\temp\fargs.cpp(11) : error C2660: 'A' : function does not take 0 arguments
|
|
|
|
|
But in the program,
our system.
It works.
I tested it. just the caller.h:
extern void A(void);
I debugged the code, it stepped into the A(i);
in fact, only one A() function in the program.
|
|
|
|
|
what compiler are you using?
at best, i would think the behavior is undefined. the function is going to try to find a parameter, somewhere. maybe it pulls some random garbage off the stack where it expects a parameter to be, or maybe your compiler puts variables into certain registers (and so the function will just grab random garbage out of a register).
|
|
|
|
|
It's a GHS compiler.
An embedded project.
|
|
|
|
|
It's possible that the compiler patches the call with a default argument.
What is the value in channel? I'm guessing it is 0.
Anyway this is not valid in standard C and will surely not compile in GCC or Microsoft C compilers.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|