|
|
Hi, friends,
I used to integrate the simulink package to my project, that is, I opened a
Simulink window and moved the window to the related view, assumed to be the CMHCSimPlatformView, the codes are referred to as follows:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CMHCSimPlatformView::OnStartMatlabEngine()
{
...
m_hSimulink = ::FindWindow(NULL,"Project_1 ");
if(::IsWindow(m_hSimulink))
{
//Set the CMHCSimPlatformView is the parent window for the simulink one
::SetParent(m_hSimulink,this->GetSafeHwnd());
CWnd * pWnd = NULL;
pWnd = FromHandle(m_hSimulink);
CRect rect;
GetClientRect(&rect);
//move the simulink window to the related area, that is to the
//client area of the CMHCSimPlatformView.
pWnd->MoveWindow(&rect,false);
//delete the catpion of the simulink interface
pWnd->ModifyStyle(WS_CAPTION|WS_BORDER,0);
//delte the system menu of the simulink interface
pWnd->SetMenu(NULL);
//delete the system toolbar of the simulink interface
HWND handToolbar = ::FindWindowEx(m_hSimulink,NULL,_T ToolbarWindow32"),NULL);
CWnd* pToolWnd;
pToolWnd = FromHandle(handToolbar);
pToolWnd->ShowWindow(FALSE);
CFrameWnd * pFrame=(CFrameWnd *)AfxGetMainWnd();
pFrame->GetActiveFrame()->UpdateWindow ();
UpdateData(true);
}
...
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
where, Project_1 is the name of a simulink file opened before, and m_hSimulink is a variable of HWND.
Surely, the simulink window was moved to the CMHCSimPlatformView client area when the above codes are executed. However, after later opertions, the simulink window was often covered with the CMHCSimPlatformView window.
How to ensure that the simulink window always stays on the top ?and how to
change the simulink window according to the CMHCSimPlatformView area?
Regards.
zhou_rusheng
|
|
|
|
|
Please give me some ideas.
|
|
|
|
|
I want to add ZoomIn/ZoomOut in my MFC Application, works on text and image, just like MSWORD, how can I get this??
thanks for your response
-- modified at 22:50 Monday 17th April, 2006
|
|
|
|
|
MM_ISOTROPIC will get you zoom with minimal effort. You'll have to work a little though to get an app like MSWORD. I can't help you there.
|
|
|
|
|
Here's a little to get you started. Start a new MFC/SDI app and plop this stuff in the appropriate locations. Set up menu/toolbar buttons for the zoomin/zoomout. Add some drawing code to your OnDraw and you should find that the drawing is fit_to_width in the view and it should be fit to width when printing. The rest is up to you. have fun...
(Let me know if I missed something)
///////////////////////////////////////////////
//Constants
const int MAX_SCALE = 20; // The maximum scale factor
//CDocument members...
protected:
CSize m_DocSize;
CSize CYourDoc::GetDocSize() const
{
return m_DocSize;
}
CYourDoc::CYourDoc()
{
// TODO: add one-time construction code here
m_DocSize=CSize(2000,2800);
}
//CScrollView members...
protected:
int m_Scale;
CYourView::CYourView()
{
// TODO: add construction code here
m_Scale=1; // Set scale factor 1:1
SetScrollSizes(MM_TEXT,CSize(0,0)); // Set arbitrary values
}
void CYourView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CScrollView::OnPrepareDC(pDC);
// TODO: Add your specialized code here and/or call the base class
// Set up the DC for the current scale factor
int nExtentX;
int nExtentY;
CSize sizeDoc;
CRect rectClient;
// Allows the rectangle to include the bottom and rightmost logical unit
// SetGraphicsMode(pDC->m_hDC,GM_ADVANCED);
pDC->SetMapMode(MM_ISOTROPIC); // Allow scaling with aspect ratio preserved
// Get pertinent rectangle data
GetClientRect(&rectClient);
sizeDoc=GetDocument()->GetDocSize();
sizeDoc.cy=(-sizeDoc.cy); // Y goes down as it increments
pDC->SetWindowExt(sizeDoc); // Window extent is size of document
// Calculate viewport extent
nExtentX=(int)(GetScale()*rectClient.Width());
nExtentY=(int)((GetScale()*((nExtentX*sizeDoc.cy)/(sizeDoc.cx))));
// What kind of device context do we have?
if (pDC->IsPrinting()==TRUE) {
// Printer Context. Allow printing to edge of context. No scaling. Margins?
pDC->SetViewportExt(pDC->GetDeviceCaps(HORZRES),-pDC->GetDeviceCaps(VERTRES));
} else {
// Context is for screen
pDC->SetViewportExt(nExtentX,nExtentY);
}
}
int CYourView::GetScale()
{
return m_Scale;
}
void CYourView::SetScale(int nScaleFactor)
{
m_Scale=nScaleFactor;
ResetScrollBars(); // Adjust scrollbars to new scale
}
void CYourView::OnUpdateViewZoomout(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (GetScale()>=2) pCmdUI->Enable(TRUE);
else pCmdUI->Enable(FALSE);
}
void CYourView::OnUpdateViewZoomin(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (GetScale()<MAX_SCALE) pCmdUI->Enable(TRUE);
else pCmdUI->Enable(FALSE);
}
void CYourView::ResetScrollBars()
{
CSize sizeDoc;
CClientDC dc(this);
this->OnPrepareDC(&dc); // Update the device context
sizeDoc=GetDocument()->GetDocSize();
dc.LPtoDP(&sizeDoc); // Logical to device
this->SetScrollSizes(MM_TEXT,sizeDoc); // Update scrollbars
}
void CYourView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
// TODO: calculate the total size of this view
ResetScrollBars();
}
void CYourView::OnSize(UINT nType, int cx, int cy)
{
CScrollView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
ResetScrollBars();
}
// Toolbar/menu button handler
void CYourView::OnViewZoomin()
{
// TODO: Add your command handler code here
if (GetScale()<MAX_SCALE) SetScale(GetScale()+1);
Invalidate();
}
// Toolbar/menu button handler
void CYourView::OnViewZoomout()
{
// TODO: Add your command handler code here
if (GetScale()>=2) SetScale(GetScale()-1);
Invalidate();
}
-- modified at 23:44 Monday 17th April, 2006
|
|
|
|
|
really appreciate for your answer.
I add function TextOut in CMyView::OnDraw(), when I clicked ZoomIn, the view extended it's size, but the text in view still keeped it's size.
should I add some other code?
|
|
|
|
|
I get it!
firt time I failed because I used Textout function without creating a CFont.
bob16972,thank you very much!!
|
|
|
|
|
I'm glad it's working.
Take care.
|
|
|
|
|
google offers a set of commands, such as link, pagerank, which can be used on google web-page.
my question is:
how to develop a VC program which uses google commands to retrieve google info of these commands?
any links, sample or comments?
thx
A special image tool for C++ programmers, don't miss it!
The world unique Software Label Maker is here for you and me ...
A nice hyper tool for optimizing your MS html-help contents.
|
|
|
|
|
includeh10 wrote: how to develop a VC program which uses google commands to retrieve google info of these commands?
Google provide apis for same!, you can get that from google itself
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hi all,
Can Windows Media Player play from a buffer instead of a file?
Thanks!
Harshita
|
|
|
|
|
I suspect it can render from an IStream interface. If this is the case all you have to do is implement an IStream that gets its data from a buffer. CreateStreamOnHGlobal and friends may be of interest.
Steve
|
|
|
|
|
Thanks for your reply!
I have implemented an IStream that gets data from a buffer but I do not understand to which Media Player API should I feed this input?
I had gone through ReadFromStream sample of WMF 9 SDK. But, this sample takes an input from a file instead of IStream!
It would be great if you could provide some guideline. Thank again!
Harshita
|
|
|
|
|
I was only guessing when I suggested using an IStream interface (as I indicated in the post). I would search the SDK for IStream , IStorage and IMoniker . If you do say and send my the results perhaps I can help.
Steve
|
|
|
|
|
Thanks Steve!
Actually I even wanted to know that if I implement WMP to read from an IStream, is it important to have the knowledge of COM?
Regards,
Harshita
|
|
|
|
|
IStream is a COM interface, so if you implement it yourself, yes. In my opinion knowledge of COM is essential knowledge for Windows developers. Especially if you write unmanaged code. In this instance you may be able to get away with using the CreateStreamOnHGlobal API and use a system supplied implementation however.
Steve
|
|
|
|
|
Thanks again for your kind suggestion!
Can you suggest me some good URL for learning COM?
Regards,
Harshita
|
|
|
|
|
Hello,
Visual Studio 2005
From the help on: Compiler Warning (level 2) C4356
If I modify that example like:
#include <iostream>
template <class T>
class C {
static int n;
};
class D : C<int> {};
int C<int>::n = 0;
if I take this code and put it in a DLL
like this:
# if defined(MYLIB_EXPORTS)
# define MYLIB_API __declspec(dllexport)
# else
# define MYLIB_API __declspec(dllimport)
# endif
template <class T>
class C {
static int n;
static void show() {
std::cout << "C:show()" << std::endl;
std::cout << n << std::endl;
}
};
class MYLIB_API D : C<int> {};
int C<int>::n = 3;
#include "mydll.h"
int main() {
int k1 = D::n;
int k2 = C<int>::n;
D::show();
}
The error I get, if I uncomment (a) or (b), is always:
1>myapp.obj : error LNK2001: unresolved external symbol "public: static int C<int>::n" (?n@?$C@H@@2HA)
This makes sense because I am not exporting C.
So the question is:
1.1) Why then method show() gets exported ?
1.2) In other words: Why the method gets exported and the data member not ?
2) Is there any way to export directly the data ?
( of course I could workaround the problem and access the static data member through a static method )
3) A last question, a little different, but maybe related:
If I try to export some data from a DLL, like:
// file mydll.h :
static MYLIB_API int mydata; // error C2201: 'mydata' : must have external linkage in order to be exported/imported
MYLIB_API static int mydata2; // error C2201: 'mydata' : must have external linkage in order to be exported/imported
I think that with vc70, if I remember well, I was not gettting any error message while compiling the DLL, but the LNK2001 error when linking the application.
In other words I am always forced to export data as static data member of a class, ( which is in some cases very unconvenient), like:
class MYLIB_API MyDataClass {
static int data;
};
int MyDataClass::data = 5;
Is there a way to do it without using a class ?
Thank you very much for any answer.
Marcello
|
|
|
|
|
static tokens are only seen in the scope of that specific compilation unit.
Maxwell Chen
|
|
|
|
|
This is not the case when the static keyword is used on a class member: in this case it means that the member is shared across all instances of the class and can be accessed without a this pointer.
Just for interests sake, the use of static to make a global variable or function private to a compilation unit is deprecated in C++. The recommended way to achieve this effect is to use an anonymous namespace. i.e.
namespace
{
int g_Var;
}
Steve
|
|
|
|
|
I was talking about this line.
static MYLIB_API int mydata; // error C2201: 'mydata' : must have external linkage in order to be exported/imported
Maxwell Chen
|
|
|
|
|
A data member of a class can be declared static; be it in the public or private part of the class definition. Such a data member is created and initialized only once, in contrast to non-static data members, which are created again and again, for each separate object of the class. A static data member is created once: when the program starts executing. Nonetheless, it is still part of the class.
Static data members which are declared public are like `normal' global variables: they can be reached by all code of the program using their name, together with their class name and the scope resolution operator. This is illustrated in the following code fragment:
#include <iostream>
template <class t="">
class C {
public:
static int n;
};
The data member n is a private static variable. During the execution of the program, only one C::n exists, even though more than one object of the class C may exist. This data member could be inspected or altered by the constructor, destructor or by any other member function of the class C.
|
|
|
|
|
Thank you for the all answers.
But the question I made is not a beginner's question.
It is about exporting a static variable and if there is any reason why it is made so difficult to export it.
We know that it is possible to export a static member from a template class specialization,
We know that it is not possible to use the __declspec(dllexport) keyword with a template.
But in the example I gave I was able to get a static methods of a template exported even if the __declspec(dllexport) was not used. But this is not happening with a static data member.
The reason I am trying to do this is that I need to export and use a class created by using the Curiously Recurring Template Pattern (CRTP). In my case the template base class needs to have a static member.
About the third question, I am pretty sure that it is possible by using an export file (.def) and using a special keyword in it [ unfortunately I don't remember exactly how ].
Cheers,
Marcello
|
|
|
|
|
"Windows requires all public symbols to be explicitly exported from a DLL via the __declspec(dllexport) syntax (and correspondingly dllimported when referenced in some other DLL).
I guess it works pretty well on C libraries. But it doesn't work so well on C++ libraries, particularly with template classes--the template itself, of course, doesn't have a link-time presence, so it doesn't make sense to dllexport a template. What you really mean to export is the template instantatiation. But template instantiations are implicit, according to the language, so where do you put the dllexport syntax?
Microsoft came up with a place to put the dllexport syntax, which is to explicitly put a line like this in the DLL that exports a particular template instance:
Code:
template class __declspec(dllexport) my_template_class<my_instance>;
And also put a line like this in a DLL that imports that template instance:
Code:
extern template class __declspec(dllimport) my_template_class<my_instance>;
These lines must be the first instantiation of the template instance, which means they must be seen by the compiler before any other reference to my_template_class<my_instance>.
Of course, this is a Microsoft extension to C++ syntax; the language itself does not require this sort of declaration (and non-Microsoft compilers won't understand it).
The problem with this declaration is that it explicitly expands and exports all methods and components of the template class, whether they are actually used or not; and it requires that nested template classes be explicitly exported before their containing classes are exported.
That's not too bad, but it turns out that the standard STL implementation of list, map, set, multiset, multimap--basically everything other than vector--use nested template classes that are mutually recursive. That is, the nested class includes references to the containing class, and vice-versa. This makes it impossible to export the nested classes first, since expanding them requires expanding the containing class--which has not been exported yet, violating the rule that the export syntax must appear before the first instance is encountered. Similarly, you can't export the containing class first, which would expand the nested class before its export syntax. This means that none of the STL classes except for vector can be exported from a DLL.
But do you really need to export a template instance from a DLL? Isn't each instance of a template technically a completely new copy of the class? If you don't even try to export the class, you should end up with a new copy of the template code in each DLL, but since all of the copies are essentially the same, they should be compatible with each other. So what happens if you don't try to export the class?
It turns out this works, mostly, but the standard implementation of STL relies on some static members of the template class, which the language specifies that the linker should resolve to the same pointer value by runtime. The Microsoft DLL linker doesn't do this (because, without having explicitly exported the template classes, the linker sees them as unrelated classes). The net result is that any class that tries to expose iterators to its internal STL object, even via an inline method, will crash if those iterators are accessed by code in another DLL.
We spent a long time trying to figure out why our code, which worked fine on Unix, was crashing when we ported it to Windows. We finally tracked it down to this, and the only solution we could find--short of making everything non-inline and paying the corresponding run-time performance penalty--was to compile everything into one big DLL. Now, within the one DLL, all the iterators are valid and can be accessed by code in different modules.
This was back on VC6. Beginning with VC7.0, Microsoft started shipping with a third-party reimplementation of STL, that supposedly works around the DLL linker issue by not requiring static members to be unified. So presumably the issue is now a moot point on VC7.0 and above--you should be able to use STL iterators across DLL's now, although you still pay the cost of code bloat--although we haven't tested this."
/////////////////////////////////////////////////////////////////
// header file DLL
#ifdef MYDLL_EXPORTS<br />
#define MYDLL_API __declspec(dllexport)<br />
#else<br />
#define MYDLL_API __declspec(dllimport)<br />
#endif<br />
<br />
class MYDLL_API CMyDLL {<br />
public:<br />
CMyDLL(void);<br />
static void SetN(int x);<br />
static int GetN();<br />
static void show();<br />
static int n;<br />
};<br />
MYDLL_API int CMyDLL::n;
// CPP file DLL
CMyDLL::CMyDLL() { return; }<br />
<br />
void CMyDLL::show() {<br />
std::cout << "CMyDLL:show()" << std::endl;<br />
std::cout << n << std::endl;<br />
}<br />
<br />
void CMyDLL::SetN(int x) { n = x; }<br />
<br />
int CMyDLL::GetN() { return n; }
// main file
#include "stdafx.h"<br />
#include <iostream><br />
#include "myDLL.h"<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
CMyDLL::n = 2;<br />
CMyDLL::SetN(9);<br />
int k1 = CMyDLL::n;<br />
std::cout << k1 << std::endl;<br />
CMyDLL::show();
return 0;<br />
}<br />
Result: // ???
2 // direct call n
CMyDLL:show()
9 // calling via function
|
|
|
|
|