|
I have a Output view in my application which inherits from the MFC CScrollView. In the Output View the application displays text information. I want to provide a ability such that on clicking a button the entire content of the Output view gets cleared.
I am a MFC newbiew and do not know how to achieve this. Any help/sample code will be greatly appreciated.
Thanks,
Susmita
|
|
|
|
|
The output view is just a control isn't it ? So SetWindowText("") should clear it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
SetWindowText("") does not do it.
I saw in the code that when ever anything is displayed in that View, the view's OnDraw(CDC* pDC) Method is called.
Do I need to explicitly call it when I need to clear it?
|
|
|
|
|
Hi Susmita,
I could not give you answer still I haven't understood what you do in displaying the text in output view.
1. Is your Output view has OnDraw(...) or OnPaint() message handler to paint your document data on the output view?
2. Clear has different meanings.. Clear the View means do you want to clear the data which is stored in Document object?
3. OR you won't clear the document object content, but do you want to display some background color on the view?
For Option 3, what you can do is
1. Have one boolean variable which is funtioning like a toggle
2. When click the button to clear the view, set the bool to true (bClear = true. Now you have to Invalidate the view/window(Which will send WM_PAINT Message and call your OnDraw / OnPaint Message handler)
3. In the OnDraw/OnPaint handler check for the boolean flag (bClear)
4. if bClear is true, then do not call any paint related function
Sample Code
IMPLEMENT_DYNCREATE(CPaintTestView, CView)
BEGIN_MESSAGE_MAP(CPaintTestView, CView)
//{{AFX_MSG_MAP(CPaintTestView)
ON_COMMAND(ID_VIEW_CLEAR, OnViewClear)
ON_UPDATE_COMMAND_UI(ID_VIEW_CLEAR, OnUpdateViewClear)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
..
..
...
CPaintTestView::CPaintTestView()
{
m_bClear = false;
}
/////////////////////////////////////////////////////////////////////////////
// CPaintTestView drawing
void CPaintTestView::OnDraw(CDC* pDC)
{
CPaintTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (m_bClear)
{
}
else
{
pDC->TextOut (20,20,"I Love Bangalore");
}
}
void CPaintTestView::OnViewClear()
{
m_bClear = !m_bClear;
InvalidateRect(NULL,true);
}
void CPaintTestView::OnUpdateViewClear(CCmdUI* pCmdUI)
{
if (m_bClear)
{
pCmdUI->SetCheck ();
}
else
{
pCmdUI->SetCheck (false);
}
}
I hope this will help you..
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
Hello everyone:
I want to drag a self-customaze stuct from a edit of A dll, and Drop the struct to a edit of B dll. Please help me how to do?
Thanks.
-Freehawk
|
|
|
|
|
Playing around with some registry stuff....
I'm making a call to RegQueryValueEx() with the returnstring buffer that is 4K. I am continually getting a system error code of ERROR_MORE_DATA. When I look at the data in the dubugger, it's about 400 characters.
Could there be another problem that would give that error code?
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
Nobody has seen this or had this problem?
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
Maybe you did not fill in the buffer size on input?
You need to tell it how big your buffer is, or else you would be getting that error.
If you still have troubles, post a few lines of your code setting up your data before and during call to functiona nd we cna help you figure it out.
In other words, not in about 12 years of writing Widnows software have I EVER got that error code back from RegQueryValue unexpectedly. When I do get it bakc, it is because I am testing how large the value's data is and will then allocate a large enough buffer during a subsequent call.
From MSDN:
lpcbValue
[in, out] Pointer to a variable that specifies the size of the buffer pointed to by the lpValue parameter, in bytes. When the function returns, this variable contains the size of the data copied to lpValue, including any terminating null characters.
If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, this size includes any terminating null character or characters. For more information, see Remarks.
If the buffer specified lpValue is not large enough to hold the data, the function returns ERROR_MORE_DATA and stores the required buffer size in the variable pointed to by lpcbValue. In this case, the contents of the lpValue buffer are undefined.
|
|
|
|
|
Blake Miller wrote:
Maybe you did not fill in the buffer size on input?
Thank you. I feel so stupid.
I had this working before, but then copy/pasted the code to create a library. I left that var at 0 and was thinking that was the size of the data returned, not for "me" to fill out.
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
When the function returns, the 'size' variable will have a numeric value the size of the data stored to the buffer.
If you ever use something like this in a loop, you need to remember to reset the variable to the size of your buffer before calling RegQueryValue each time.
It is sometimes easy to overlook the [in, out] specification on a parameter
|
|
|
|
|
Good afternoon,
I am trying to use windbg to look at dump file.
Open the DMP file that created by HL.EXE in windbg
set symbols path "SRV*C:\HL\HL\Debug\HL.pdb*http://msdl.microsoft.com/download/symbol"
Set the souce file path "C:\HL\HL" (tried to set to dsp file, but got warning: Non-directory path : 'c:\HL\HL\HL.dsp)
Issue a .reload in the WINDBG command window.
Execute a 'g' command to 'go' and it came up with "No runnable debuggees error in 'g'"
is it the souce file path that I am missing? Thank you for your time!
|
|
|
|
|
Try the command .ecxr instead - assuming the dump file was generated in response to an exception, it'll display the relevant code, callstack, registers, etc.
You really can't execute a dump file, after all.
|
|
|
|
|
here is what I got from command message box:
(930.754): Wake debugger - code 80000007 (!!! second chance !!!)
eax=0012f5e8 ebx=00000000 ecx=00010101 edx=00000000 esi=005043a8 edi=00000000
eip=77e589a7 esp=0012f5d8 ebp=0012f608 iopl=0 nv up ei pl zr na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
USER32!NtUserWaitMessage+0xb:
77e589a7 c3 ret
0:000> .ecxr
eax=0012f5e8 ebx=00000000 ecx=00010101 edx=00000000 esi=005043a8 edi=00000000
eip=77e589a7 esp=0012f5d8 ebp=0012f608 iopl=0 nv up ei pl zr na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
USER32!NtUserWaitMessage+0xb:
77e589a7 c3 ret
does it mean" USER32!NtUserWaitMessage+0xb: 77e589a7 c3 ret" is there place that exe crash?
I was testing windbg, so I changed the "return CView::PreCreateWindow(cs);" to "return 0", when I debug the exe, it pops up message says "failed to create enpty document". thanks for looking!
|
|
|
|
|
Two suggestions,
1. Maybe you are looking at wrong thread? Try '~*' command to see what threads are there.
2. Try issuing 'kb' to dump call stack and see if that call stack makes sense.
|
|
|
|
|
0:000> ~
. 0 Id: 930.754 Suspend: 1 Teb: 7ffde000 Unfrozen
0:000> kb
*** Stack trace for last set context - .thread/.cxr resets it
ChildEBP RetAddr Args to Child
0012f5d4 77e33604 00000000 00000000 0000ffff USER32!NtUserWaitMessage+0xb
0012f608 77e441d4 00400348 00000000 00000001 USER32!DialogBox2+0x216
0012f62c 77e34110 77e10000 001371c0 00000000 USER32!InternalDialogBox+0xd1
0012f8e4 77e344ac 00000030 0012fa84 ffffffff USER32!SoftModalMessageBox+0x757
0012fa2c 77e3399f 00000001 00000000 00000028 USER32!MessageBoxWorker+0x247
0012fa84 77e34237 00000000 00136230 00135520 USER32!MessageBoxExW+0x77
0012fab4 77e333d0 00000000 002f419c 002f2518 USER32!MessageBoxExA+0xa0
0012fad4 5f460f22 00000000 002f419c 002f2518 USER32!MessageBoxA+0x49
0012fc14 5f460fb0 002f419c 00000030 0000f104 MFC42D!CWinApp::DoMessageBox+0x17f
0012fc2c 5f46105f 002f419c 00000000 0000f104 MFC42D!AfxMessageBox+0x2c
0012fc60 5f444e55 0000f104 00000000 0000f104 MFC42D!AfxMessageBox+0x93
0012fcbc 5f45a7c4 00000000 00000001 0012fedc MFC42D!CSingleDocTemplate::OpenDocumentFile+0x1a5
0012fd58 5f4616ea 004177d0 0012fd9c 5f43749c MFC42D!CDocManager::OnFileNew+0x121
0012fd64 5f43749c 0012fedc 00000000 7ffdf000 MFC42D!CWinApp::OnFileNew+0x2a
0012fd9c 5f437bcb 004177d0 0000e100 00000000 MFC42D!_AfxDispatchCmdMsg+0xa2
0012fdf4 5f498003 0000e100 00000000 00000000 MFC42D!CCmdTarget::OnCmdMsg+0x274
0012fe44 004015e6 0012feb0 00000000 00000000 MFC42D!CWinApp::ProcessShellCommand+0x63
0012fee8 5f4335c3 00000000 00000000 7ffdf000 HL!CHLApp::InitInstance+0xf6 [C:\HL\HL\HL.cpp @ 88]
0012ff08 00403138 00400000 00000000 00132cb0 MFC42D!AfxWinMain+0x83
0012ff20 00403043 00400000 00000000 00132cb0 HL!WinMain+0x18 [appmodul.cpp @ 30]
It kind of make sense now, because I changed the BOOL PreCreateWindow(CREATESTRUCT& cs) funtion in HLVIEW.cpp, it couldn't created the window, so it crash on HL.cpp at line 88.....the line 88 is like this "if (!ProcessShellCommand(cmdInfo))
return FALSE;"
did I get this right? Thanks a lot for your help!!!
-- modifed at 11:38 Thursday 25th August, 2005
|
|
|
|
|
It looks to me like the last thing that happened was a message box on the screen.
0012f5d4 77e33604 00000000 00000000 0000ffff USER32!NtUserWaitMessage+0xb
However, that message box was probably in response to the failed window creation, which was probably previously attempted in response to this function's internals:
0012fcbc 5f45a7c4 00000000 00000001 0012fedc MFC42D!CSingleDocTemplate::OpenDocumentFile+0x1a5
When MFC framework opens a file:
0012fd58 5f4616ea 004177d0 0012fd9c 5f43749c MFC42D!CDocManager::OnFileNew+0x121
It will attempt to create a document matching the file, and that document wants a CView-based class to display the document within. You set off a chain reaction of failures when you did not create the CView for the document.
|
|
|
|
|
this is exactly what have happened!!
but I just couldn't see it.....Thank you so much for all your help!
|
|
|
|
|
I use VC.net to create a MFC regular DLL. VC wizard generates a skeleton for me.
// CVCMFCDLL_App
BEGIN_MESSAGE_MAP(CVCMFCDLL_App, CWinApp)
END_MESSAGE_MAP()
// CVCMFCDLL_App construction
CVCMFCDLL_App::CVCMFCDLL_App()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only CVCMFCDLL_App object
CVCMFCDLL_App theApp;
// CVCMFCDLL_App initialization
BOOL CVCMFCDLL_App::InitInstance()
{
CWinApp::InitInstance();
return TRUE;
}
All these is not what I expected. I want to export my own Class. What are those for? may I delete all those stuff?
Why it contains a "theApp"? it is really confused!
|
|
|
|
|
xianwuluo wrote:
I want to export my own Class.
Sounds like you want an MFC Extension DLL then.
xianwuluo wrote:
What are those for?
Initialization, globals, whatever.
|
|
|
|
|
I don't want MFC extention DLL. regular is enough. I just found these skeleton useless.
I delete these stuff, it works!
another problem:
I don't want my class private member to be exposed to Client. I know I have to use .def file to export class. but when I do
EXPORTS
; Explicit exports can go here
CMyClass
I got compile error. CMyClass is not recongnized by compiler.
|
|
|
|
|
xianwuluo wrote:
I don't want my class private member to be exposed to Client.
Isn't that what private means ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Yes, Client can not access to it. but as the private variables or functions are listed in .h file. Client is going to include in this application. It would be nicer, that Client only see public stuff of the class.
|
|
|
|
|
Two notes:
1) C++ does name mangling to encode additional information in exported symbols. You need to list the mangled names in the .def file, or use Microsoft-specific commands in your code to make this happen. (hint: the latter is far easier than the former)
2) Because of the way C++ works, you can't expose a class without exposing private member variables. If you don't want your client to see these when reading the header file, then you'll need to go to some extra effort to make that happen - export a class that doesn't have the private member variables, but internally uses the class that does to do what it needs. Do a search for "facade pattern" if that doesn't make sense.
|
|
|
|
|
|
hi,
does anyone know how to call a program(such as mspaint, word or any other program/ executable present) from our vc++ application. i.e. on executing an application it should call another windows program.
thanks
aditya
|
|
|
|