|
In your view class, implement the virtual OnDraw() method. Put all your drawing code within this method either directly or indirectly by calling other functions to draw your views client area content.
// .h
virtual void OnDraw(CDC* pDC);
// .cpp
void CYourView::OnDraw(CDC* pDC)
{
/*
Draw your graphics primitives here. This includes anything
that is displayed within your client area. Whenever a portion
of your client area gets invalidated, this method will get
called to redraw the area affected.
*/
pDC->MoveTo(10,10);
pDC->LineTo(100,100);
}
|
|
|
|
|
Also, If you want to explicitly force a redraw of your client area like when you change the text that will get output on the next draw, you can call CWnd::Invalidate() to invalidate the entire client area or CWnd::InvalidateRect() if only a portion needs to be redrawn.
Note that this only invalidates it. The OnDraw() method will not get called until the message loop processes the next draw request. Normally this is soon enough not to notice any delay. However, if you need it to force an immediate refresh, you can call CWnd::UpdateWindow() to redraw the invalidated rectangle or CWnd::RedrawWindow() whose actions depend on the flags passed in.
NOTE: CWnd::UpdateWindow and CWnd::RedrawWindow are not normally used unless you have special needs. Most drawing code should simply allow the message loop to call your OnDraw() when it can to prevent delays in processing other messages.
|
|
|
|
|
|
When I am calling a thread from main dialog to get data from server and show it in the child dialog
i.e setting the values of the controls with the values from the server It is giving erroe when i update. Please tell what is the error My code is as follows:
void CVisitorDtlsDlg::FillDetails(VisitorDetails stVisitorDetails)
{
m_stVisitorDetails = stVisitorDetails;
m_strBrowser = stVisitorDetails.strBrowser;
m_strCity = stVisitorDetails.strCity;
m_strCountry = stVisitorDetails.strCountry;
m_strJava = stVisitorDetails.strJava;
m_strLanguage = stVisitorDetails.strLanguage;
m_strOS = stVisitorDetails.strOS;
m_strRefere = stVisitorDetails.strRefere;
m_strRegion = stVisitorDetails.strRegion;
m_strScreen = stVisitorDetails.strScreenColors;
m_strTime = stVisitorDetails.strUserTime;
m_strScreen = stVisitorDetails.strScreenColors;
m_strURL = stVisitorDetails.strURL;
m_strIPHost = stVisitorDetails.strIPHost;
m_strSysBrowser = stVisitorDetails.strSysBrowser;
m_strVisitorName= stVisitorDetails.strVisitorName;
m_strVisitorEmail= stVisitorDetails.strVisitorEmail; m_strCustomInformation=stVisitorDetails.strCustomInformation;
m_strCountryLanguage= stVisitorDetails.strCountryLanguage;
m_strCurrency= stVisitorDetails.strCurrency;
m_strPopulation= stVisitorDetails.strPopulation;
this->UpdateData(false);
m_staticURL.SetLinkText(m_strURL);
m_staticVisitorEmail.SetLinkMail(m_strVisitorEmail);
m_staticRefere.SetLinkMail(m_strRefere);
this->UpdateData(false);
CRect rect1;
m_staticURL.GetWindowRect(&rect1);
ScreenToClient(&rect1);
InvalidateRect(&rect1);
CRect rect2;
m_staticRefere.GetWindowRect(&rect2);
ScreenToClient(&rect2);
InvalidateRect(&rect2);
CRect rect3;
m_staticVisitorEmail.GetWindowRect(&rect3);
ScreenToClient(&rect3);
InvalidateRect(&rect3);
}
I am calling the above function in a thread from CMainDlg which is the Parent Dialog
Thanks in Advance
|
|
|
|
|
MFC window objects (like your CDialog -derived class) can only be used from the original GUI thread that created them.
If you want a worker thread to update data in a dialog, the best method is to use a user-defined message and call PostMessage to tell the dialog to update itself.
|
|
|
|
|
Can u tell me how to define a user method and how to call PostMessage()
I am new to VC++
|
|
|
|
|
This[^] article should help.
|
|
|
|
|
Still i am having error i have used the following code for posting message from worker thread
AfxGetMainWnd()->PostMessageW(WM_GET_DATA, 0, 0);
and the message handler used is
|
|
|
|
|
Dhiraj kumar Saini wrote: Still i am having error...
What error? We're not mind readers. This is akin to taking your car to the local mechanic, dropping it at his door and saying, "Fix this."
See here.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Dude, when will you learn to use the "code block" tag ?
For your question: UpdateData is considered UI stuff, so you can't call it from a thread. The easiest option that you have here is to have a VisitorDetails structure member of your dialog class that you will fill from within your thread. Once this is done, the thread will need to send a user defined message to the main window signaling that this is done. In the function that handle that message, set your class member as you did here and call UpdateData.
|
|
|
|
|
while porting application code from VC++6 to VS2008 the call of CreateEx function is returning the false with the same parameters in VS2008 while with same parameter the call of CreateEx function is working fine in the VC++6.
The code flow is like this:
Called MFC's API CreateEx with the following prameter's
if ( !CreateEx( 0, AFX_WNDMDIFRAME, NULL, dwCreateStyle, 0, 0, 0, 0, pParentWnd->m_hWnd,
( HMENU)uID, NULL ) )
{
return FALSE;
}
Earlier in VC++6.0 this API was internally using the function ::CreateWindowEx then this function was returning the proper handle of the splitter window.
But now in VS2008 this API internally calls the function ::AfxCtxCreateWindowEx instead of ::CreateWindowEx. and this new function is returning the handle as NULL.
This code works properly for the main window but in case of splitter window it is failing.
In the application i have used a dynamic splitter window which is fully customized and derived from CWnd class.
If i changed the second parameter as STATIC of CreateEx functionn then it works fine but resizing of splitter window is not working and application is crashing.
Below is the function from where CreateEx is called............
BOOL CSplitterWndX::CreateCommon( const CWnd* const pParentWnd, const SIZE sizeMin, const DWORD dwStyle, const UINT uID )
{
ASSERT( pParentWnd != NULL );
ASSERT( ( sizeMin.cx >= 0 ) && ( sizeMin.cy >= 0 ) );
ASSERT( ( dwStyle & WS_CHILD ) );
ASSERT( uID != 0 );
ASSERT( ( m_pColInfo == NULL ) && ( m_pRowInfo == NULL ) );
ASSERT( ( m_nMaxCols > 0 ) && ( m_nMaxRows > 0 ) );
DWORD dwCreateStyle = dwStyle & ~( WS_HSCROLL | WS_VSCROLL );
if ( afxData.bWin4 )
{
dwCreateStyle &= ~WS_BORDER;
}
VERIFY( AfxEndDeferRegisterClass( AFX_WNDMDIFRAME_REG ) );
if ( !CreateEx( 0, AFX_WNDMDIFRAME, NULL, dwCreateStyle, 0, 0, 0, 0, pParentWnd->m_hWnd, ( HMENU )uID, NULL ) )
{
return FALSE;
}
TRY
{
m_pColInfo = new CRowColInfo[m_nMaxCols];
for ( int nCol = 0 ; nCol < m_nMaxCols ; nCol++ )
{
m_pColInfo[nCol].nMinSize = sizeMin.cx;
m_pColInfo[nCol].nIdealSize = 0;
m_pColInfo[nCol].nCurSize = -1;
m_pColInfo[nCol].bFixedSize = FALSE;
m_pColInfo[nCol].bAlwaysVisible = FALSE;
}
m_pRowInfo = new CRowColInfo[m_nMaxRows];
for ( int nRow = 0 ; nRow < m_nMaxRows ; nRow++ )
{
m_pRowInfo[nRow].nMinSize = sizeMin.cy;
m_pRowInfo[nRow].nIdealSize = 0;
m_pRowInfo[nRow].nCurSize = -1;
m_pRowInfo[nRow].bFixedSize = FALSE;
m_pRowInfo[nRow].bAlwaysVisible = FALSE;
}
m_pOldColInfo = new CRowColInfo[m_nMaxCols];
for ( int nCol = 0 ; nCol < m_nMaxCols ; nCol++ ) // Windows Vista Support 0.1
{
m_pOldColInfo[nCol].nMinSize = sizeMin.cx;
m_pOldColInfo[nCol].nIdealSize = 0;
m_pOldColInfo[nCol].nCurSize = -1;
m_pOldColInfo[nCol].bFixedSize = FALSE;
m_pOldColInfo[nCol].bAlwaysVisible = FALSE;
}
m_pOldRowInfo = new CRowColInfo[m_nMaxRows];
for ( int nRow = 0 ; nRow < m_nMaxRows ; nRow++ ) // Windows Vista Support 0.1
{
m_pOldRowInfo[nRow].nMinSize = sizeMin.cy;
m_pOldRowInfo[nRow].nIdealSize = 0;
m_pOldRowInfo[nRow].nCurSize = -1;
m_pOldRowInfo[nRow].bFixedSize = FALSE;
m_pOldRowInfo[nRow].bAlwaysVisible = FALSE;
}
SetScrollStyle( dwStyle );
}
CATCH_ALL( pE )
{
DestroyWindow();
return FALSE;
}
END_CATCH_ALL
return TRUE;
}
waiting for early response.....
Sachindra
modified on Sunday, September 7, 2008 6:15 AM
|
|
|
|
|
Hi all,
I'm still beginner in MFC .
My question is how I can copy a file.
For example,
I want to copy from C:\pic.jpg to D:\pic.jpg using MFC.
Thanks all.
|
|
|
|
|
|
Use CopyFile() or CopyFileEx(), dependent on whether you want notification of the copy progress through a callback function (the docs will explain it in more detail).
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Actually on the button click of the Parent dialog i want to fetch data fom the server and show it on a child dialog and at the same time i am using an animation control to show the status of loading or processing.
Earlier I was doing it as a single process so the animation control was not working while data was coming and being painted on the child window rather it was working after the data was already fetched and painted.
For that reason i have created a new thread and paled the code for animation in it but i dont knowhot to ruun a thread. I have used the following code.
void CMainDlg::OnDetails()
{
running = TRUE;
CWinThread * myWorkerThread;
myWorkerThread=AfxBeginThread(run, this);
if(IsGetDlg_created==true && m_dlgGetFootPrint.IsWindowEnabled()==true)
{
UpdateSelectedVisitorDetails();
m_dlgVisitorDetails.ShowWindow(SW_SHOW);
m_dlgGetFootPrint.ShowWindow(SW_HIDE);//added by dhiraj on 27-08-08
//m_dlgGetFootPrint.DestroyWindow();//added by dhiraj on 28-08-08
}
else
{
UpdateSelectedVisitorDetails();
}
}
//added on 6-09-08
UINT CMainDlg::run(LPVOID p)
{
CMainDlg * me = (CMainDlg *)p;
me->run();
return 0;
}
void CMainDlg::run()
{
m_avi.Open(IDR_AVI1);
m_avi.Play(0,-1,-1);
running = FALSE;
}
Whats wrong in it.
|
|
|
|
|
One remark: please read the posting guidelines before posting a new message. Format your code properly so that it is easier to read (didn't some people already tell you that ?)
For your question: you are doing the opposite as you should: your thread should be used to fetch the data from the server, not to do some UI stuff. All the UI stuff (e.g. playing the animation) should be done in the main thread. So, in your thread function you should put all the code that is trying to fetch data from the server, and send messages to the main thread to inform the UI about the status of the operation.
|
|
|
|
|
If I use the dc returned by CPrintDialog::GetPrinterDC to do print, will there be problems(eg. print pool)?
system
|
|
|
|
|
I don't see any issues in using the Printer DC returned by GetPrinterDC Method.
Regards,
Rane
|
|
|
|
|
I was wondering if anyone knew of a straight forward way of calling (non-exported) functions in an executable from a DLL. We are building a, for lack of a better name, private plug-in system that will grant the plug-in access to all of a processes internals, without having to export the hundreds of methods and classes we have.
cheers,
-B
|
|
|
|
|
oohhh .. thats a hard one. Unless your executable exposes some sort of API I think you'd have to resort to using injection/hooking from the dll (which I presume is in another process) to access the functions in the executable, even then ...
Usually as Im sure you're painfully aware, a plugin system involves the executable 'discovering' its plugins, then possibly calling something within the plugin to say 'what do you expose/do', or has a narrowly defined interface, not the other way around ..
If it were me (and Ive been here before, and are about to venture in this space again), I would would have the exe expose its functions through an IPC or TCP/IP interface, presenting commands to a command interpreter built into the exe, but its hard to do that unless you build it from the ground up. My next app is going to have an inbuild mini-webserver in it for both input/output and control ..
Maybe you can research injection/hooking, the microsoft library 'detours' for example to see if that can help ... the danger with these (well, one of the dangers), is that the usage is tightly bound to your internals/classes ...
sorry, good luck
[edit] .. if it were just a matter of exposing global variables for instance, I'd be using a shared memory implementation [/edit]
'g'
|
|
|
|
|
Thanks, I figured it'd be a tough one... just thought I'd ask
One option I was already looking at was generating a map of all the function addresses and giving plug-in builders a stub to link with that would find the location of the function in the loaded executable, properly construct the stack for its calling convention, and then call it. Very harry.
As for the API idea: we were planning on exporting a simple and well defined API for public plug-ins, but we would like to have private plug-ins have first-class access to all the symbols in the running process, which is the problem area. As for shared memory, I'd love to do that too, but it would require some time to track down all the globals we export, and I'm not sure I'm up to spending the next few days (years?) tolling though 20+ years of code to find all the interdependencies. So, although it's a great suggestion, I think this part needs to be automated, to be done at build time, such that any new globals will automatically be exported/shared. Also, I've little faith that the Linux/UNIX developers would appreciate me making them add extra dressing to their globals (and even if they loved the idea, if someone forgets once just before a release, then our users are out of luck if they want to access that object).
I think we'll just scrap the idea of "private" plug-ins for now, and just define a basic public API. We already support SOAP, among other network based communications channels, so we may just expand the SOAP interface to allow for a greater range of hackery.
Thanks for the input.
cheers,
-B
|
|
|
|
|
Hi.
I am creating a MFC DLL using MFC as statically linked. It is basically a dialog based app, except I'm creating it as a DLL.
I am doing this in Studio 2005.
It has one dialog, with Ok,Cancel buttons and one CEdit box.
When I try to use AfxMessageBox( ),
AfxMessageBox("I am about to create/instantiate MyLilDllDlg dialog", MB_ICONWARNING, NULL);
I get compiler error as follows:
1>c:\temp\dll\mylildll\mylildll\mylildlldlg.cpp(40) : error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types
1> c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5031): could be 'int AfxMessageBox(LPCTSTR,UINT,UINT)'
1> c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5033): or 'int AfxMessageBox(UINT,UINT,UINT)'
1> while trying to match the argument list '(const char [52], long, int)'
Is there something I need to include or configure in my project settings to allow me to use Afx... ?
Thank you.
|
|
|
|
|
The third argument must be 0, not NULL, to make it a UINT value. The compiler error returned means that none of the two overloaded argument types (either LPCTSTR, UINT, UINT or UINT, UINT, UINT ) were found in your execution of the AfxMessageBox() function as NULL is not a legal UINT value.
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
First off, thanks! Embarrasedly I should have looked closer at what the suggestion in the compiler was saying.
I settled on the following:
AfxMessageBox(LPCTSTR("I am about to create/instantiate MyLilDllDlg dialog"), MB_ICONWARNING, 0);
It needs the casting to LPCTSTR. I got by with last arg being NULL.
Thanks for telling me what I was doing wrong. Without that, I would have not tried to find out more about it on my own.
Johnny
|
|
|
|
|
hi,
I'm just a beginner at programming(c++) and I wanted to create a program to do binomial expansions easily,
I have created the program and it works well. But because i'm a beginner at programming i'm using a win32 console for the program and i want to show powers, squares and cubes, which in the output of my program look like this:
2^3
0r
4^2
is there any way to show them as you would write them, like in superscript or something cos at the moment it looks a mess.
Hope you understand my problem.
Any answers appreciated
ps if you have any recomendations on C++ books which include how to use windows forms to create a program they would be appreciated
|
|
|
|
|