|
|
Hi there,
I have a class called CChecklist that derives from CFormview and a checkmark image that I made invisible until the user finishes entry of another view called CFruits. How can I access IDC_CHECKMARK from CFruits class? I tried creating a object of class CChecklist to access its member function in order to change the visibility property of the control, but it gave me a run-time error. Please see below. How can I accomplish this?
void CCheckList::makeVisible()
{
GetDlgItem(IDC_CHECKMARK)->ShowWindow(TRUE);
}
void CFruits::OnOK()
{
CChecklist cl;
cl.makeVisible(); //run-time error
PostMessage(WM_COMMAND,ID_FILE_CLOSE);
}
|
|
|
|
|
makeVisible will try to find a child-control of CCheckList with the id IDC_CHECKMARK . Furthermore, you are creating an instance of CChecklist out of the blue - this instance has nothing to do with your other view/control.
You should not try to access controls between views, this makes it impossible to move one view to another application, and is considered Real Bad Programming. If you have two views, I assume that you have a single document holding both of them? In that case, the proper way to go about this is via the CDocument update-mechanism. You do this by calling CDocument::OnUpdateAllViews when you want to change stuff across view-boundaries, in (pseudo)code:
void CFirstView::SomeFunction()
{
CSomeDoc* pDoc = GetDocument();
pDoc->UpdateAllViews( this, HINT_SOME_VALUE_YOU_DEFINE );
}
and in the recipient view, you add an update handler, so:
void CSecondView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
if( lHint == HINT_SOME_VALUE_YOU_DEFINE )
{
}
}
You should also get a basic textbook on C++, you'll have to learn the difference between a class and an instance of a class, for example. Lots of grief lies ahead if you don't know this
|
|
|
|
|
I did just as you suggested but I might have missed something. Here are my code samples just in case you can pinpoint the problem.
//Main application class
BOOL CMPSApp::InitInstance()
{
/* additional code present */
CMultiDocTemplate* pFirstView = new CMultiDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMyDoc), RUNTIME_CLASS(CMDIChildWnd),
RUNTIME_CLASS(CFirstView));
AddDocTemplate(pMHCEditDocTemplate);
CMultiDocTemplate* pFirstView = new CMultiDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMyDoc), RUNTIME_CLASS(CMDIChildWnd),
RUNTIME_CLASS(CSecondView));
AddDocTemplate(pMHCEditDocTemplate);
}
void CFirstView::OnOK()
{
if (g_selected == TRUE)
{
CDocument* pDoc = GetDocument();
pDoc->UpdateAllViews(NULL);
}
PostMessage(WM_COMMAND, ID_FILE_CLOSE);
}
void CSecondView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
If (g_list->items.selected == 0)
{
GetDlgItem(IDC_APPLE)->ShowWindow(TRUE);
}
}
When UpdateAllViews() is called, there is only one view in the list and that is CFirstView, the calling view. Why does it not recognize the other views? Am I missing something? Thanks!
|
|
|
|
|
You are not only trying to send data between two views, they reside in different documents as well.
First, you have to get the doc templates from, the app, loop them and get the documents from each doc template. Well, it's easier to explain in code
POSITION templatePosition = AfxGetApp()->GetFirstDocTemplatePosition();
while( templatePosition != NULL )
{
CDocTemplate* documentTemplate = AfxGetApp()->GetNextDocTemplate( templatePosition );
if( documentTemplate )
{
POSITION documentPosition = documentTemplate->GetFirstDocPosition();
while( documentPosition != NULL )
{
CDocument* document = documentTemplate->GetNextDoc( documentPosition );
if( document )
document->UpdateAllViews( NULL );
}
}
}
Now, OnUpdate will be called for all views.
|
|
|
|
|
It works beautifully! Thanks Johan!
|
|
|
|
|
My pleasure
|
|
|
|
|
The CChecklist object you create in the CFruits::OnOK() isn't the same you have subclassed somewhere else in your code. That object isn't subclassed at all and I suppose that this is why you get that runtime error.
You could try to do something like this (ain't that pretty though and I'm not sure does this work):
void CFruits::OnOK()
{
HWND hCheckMark =
::GetDlgItem( ::GetDlgItem(handle_to_checklists_parent, IDC_CHECKLIST), IDC_CHECKMARK );
::ShowWindow( hCheckMark, SW_SHOW );
PostMessage(WM_COMMAND,ID_FILE_CLOSE);
}
Cohen
|
|
|
|
|
Hi
I made a project of Dialog box using MFC.My Project name is Dialog1.All Operations I have done.Finally I Select the ClassView tab from the project workspace pane.CDialog1Dlg
class is not appeared in calss veiw tab.
I would like to know that "how to get CDialog1Dlg class " in class view tab.
rajesh
|
|
|
|
|
Go to the Dlg class header file.Make some change there..
( Just give a blank line after class declaration )
Check the class view.
|
|
|
|
|
Hian buddy close your project and now sercah for your projectname.ncb file and delete the file
now reopen yiour dsw file you Class CDialog1Dlg visible in class view
I Think It will Work
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Hello,
I want to send a packet of data to a web server on port 80. How exactly would I go about doing this.
|
|
|
|
|
Take a look at the InternetXXXXXX() and HttpXXXXXX() functions in MSDN such as:
InternetOpen, InternetConnect, HttpOpenRequest, HttpSendRequest etc.
Bikram Singh
|
|
|
|
|
thank you. But how exactly would i implement this into code. Could you give me some source for a program that sends a packet of data to a web server
|
|
|
|
|
Hi,
Is there any way to convert a HKEY value to it's corresponding registry key name?i.e how do you convert (HKEY) 0x80000000 to HKEY_CLASSES_ROOT ?
|
|
|
|
|
HKEY_CLASSES_ROOT is a macro, defined as
#define HKEY_CLASSES_ROOT ((HKEY)0x80000000)
Do you need to "convert" it to a string?
Instead of using the long-drawn-out switch() statement approach, do it this way:
<br />
#define MAKE_SZ(something) #something <br />
<br />
const char *szHKCR = MAKE_SZ(HKEY_CLASSES_ROOT);<br />
<br />
printf("\n%s",szHKCR);<br />
The 'something' in the macro parameter can be 'anything'. It need not be a pre-defined macro like HKEY_CLASSES_ROOT is. For example, the following will also work:
<br />
const char *Dummy = MAKE_SZ(uioiasdhfkjasdhf);<br />
<br />
printf("\n%s",Dummy);<br />
HTH
Bikram Singh
|
|
|
|
|
Dear Vikram ,
Your method works fine for predefined keys like HKEY_LOCAL_MACHINE etc.But what about HKEY values returned by functions like RegOpenKey,RegCreateKey ? Eg:
RegOpenKey(HKEY_CURRENT_CONFIG,TEXT("Software\\Fonts"),&hKey) returns an integer value in hKey.I want to somehow get the keyname "HKEY_CURRENT_CONFIG\Software\Fonts" from the value in HKEY .
Any suggestions????????????
|
|
|
|
|
My name is BIKRAM, dude.
While I can, possibly, with difficulty, attempt to find out the keypath from a handle-value, its not worth the trouble.
It seems you have either a design problem or are attempting to intercept a function call from a process. In either case, you will need to re-think your strategy. I could help you in this, but i do knot know exactly what you want to accomplish and why.
Bikram Singh
|
|
|
|
|
Hi friends,
I am trying to devlop a Single Document (Document/View Architecture) MFC application, which has Three frames. Left frame has a Hierarchy tree and on selection of any leaf node, number (not fixed) of images be displayed on the right upper frame (four picture per row) dynamically as shown below.
---------------------------------------
| | |
| | |
| Tree | Images |
| | |
| | |
| |-----------------------------
| | |
| | Discription |
| | |
--------- -----------------------------
On click of an image its description should be displayed in right lower frame
My first priority is to display images dynamically.
Example: when there are 10 images, it should display 4 in first row, 4 in second row and last 2 in third row.
If any material/example/sample code/suggestion, Please reply me.
I need it very argently. Please help me.
Thanx
|
|
|
|
|
You might want to search for thumbnail in the MFC/C++-articles, I got 4 hits. You will most probably get a few good ideas there.
|
|
|
|
|
Thanx Johan.
I got some usefull info from the search.
In deed I was looking for similar which I got in search.
Thanx again
|
|
|
|
|
Hi,
In .NET the class view , resource view etc can be docked on the left hand side of the screen and then
when the mouse hovers over them they jut out and can be viewed. Does anyone have an example of how this could be implemented ?
Thankyou,
flip
|
|
|
|
|
1. I have a class that, due to some restrictions, can be instantiated only once at any one time. I was thinking of doing that by using a global variable (I know it's bad...), the code might look like this:
A::A()
{
if(GLOBAL_A_INSTANTIATED > 0)
{
delete this;
return;
}
GLOBAL_A_INSTANTIATED = 1;
.....
.....
}
A::~A()
{
GLOBAL_A_INSTANTIATED = 0;
}
my concern is, how about auto-variables that are instantiated without the new operator? Will this work?
Or are there any better solutions other than using a global variable?
2. Should I declare my member variables that will be updated by a callback function as volatile?
Thanks!
|
|
|
|
|
Indrawati wrote:
my concern is, how about auto-variables that are instantiated without the new operator? Will this work?
Yes, it would work the same as for instanced instantiated using the new operator.
Indrawati wrote:
Or are there any better solutions other than using a global variable?
You could use a static data member in the class. Or use some Windows-specific technique like creating a mutex with a unique name.
Indrawati wrote:
2. Should I declare my member variables that will be updated by a callback function as volatile?
You dont really need to use the volatile keyword unless you are using multiple threads..
Bikram Singh
|
|
|
|
|
Hi
Thanks for the reply.
I have searched the net for some more information, but according to C++ FAQ Lite, delete this must not be invoked on local objects which are allocated on the stack (http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.14), so I guess that means I can't do that on auto-variable, can I?
And regarding the 2nd question, if the callback function is called by another thread, I have to declare the variable as volatile, right?
Thanks!
|
|
|
|