|
I want to change the position and size of a window. In the constructor of the Doc window of a VC++ SDI I have the following code. (I'd also like to do this in any window I make.)
CSDITESTfDoc::CSDITESTfDoc()<br />
{<br />
MoveWindow(5,5,500,500,TRUE);<br />
}
The compiler says MoveWindow does not take 5 paramaters.
The format of the command is:
void MoveWindow(int x, int y, int nWidth, int nHeght, BOOL bRepaint = TRUE)
Where am I going wrong? Thanks.
|
|
|
|
|
Your doc class does not derive from CWnd so the system will try to use the MoveWindow from the Win32 API...
BOOL MoveWindow(
HWND hWnd, // handle to window
int X, // horizontal position
int Y, // vertical position
int nWidth, // width
int nHeight, // height
BOOL bRepaint // repaint flag
);
Your view class does derive from CWnd so try that tactic but from within the view class or use a reference or pointer to a view object.
|
|
|
|
|
First parameter is handle to a window(HWND).
|
|
|
|
|
Move your window from the main frame, not the document.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
========================== headers ======================
// MyTrailer.h
#if !defined(AFX_MYTRAILER_H)
#define AFX_MYTRAILER_H
#include <string>
class CMyTrailer {
public:
// Varables
CString m_csItem;
CString m_csMFG;
CString m_csID;
CMyTrailer();
~CMyTrailer();
};
#endif
// Trailer.h
#if !defined(_TRAILER_H)
#define _TRAILER_H
#include <vector>
#include "MyTrailer.h"
class CMyTrailer;
using std::vector;
using std::copy;
using std::iterator;
using std::string;
class CTrailer {
public:
CTrailer(int nIsPage=0);
~CTrailer();
// Varables:
CMyTrailer m_MyTrailer;
// Vectors:
// Setup vectors:
std::vector<CMyTrailer> m_vTlr; // Item
// Iterators:
std::vector<CMyTrailer>::iterator m_ITTrlr;
//Functions:
};
#endif
=================== end headers ==========================
CTrailer m_Trlr2(2); // create instance
================= 7th element in vector ===================
m_Trlr2.m_MyTrailer.m_csItem = "Tire";
m_Trlr2.m_MyTrailer.m_csMFG = "Goodyear";
m_Trlr2.m_MyTrailer.m_csID = "1110109";
===========================================================
How would I find the 7th element(could be anywhere but I'm using the example that it is the 7th element) in the vector when searching by
m_Trlr2.m_MyTrailer.m_csID ?
How woulod I erase only the 7th element? and would there be a blank spot in the vector after the 7th element is erased?
A C++ programming language novice, but striving to learn
|
|
|
|
|
Since vector s have random access iterators[^] something like this will do the trick:
m_vTlr.erase(m_vTlr.begin()+6)
Note this code assumes the vector contains at least 7 elements: you'll get undefined behaviour if it doesn't!
Steve
|
|
|
|
|
As for searching I'd:
1. Add an operator== for CMyTrailer :
class CMyTrailer
{
public:
CString m_csItem;
CString m_csMFG;
CString m_csID;
CMyTrailer();
~CMyTrailer();
};
inline bool operator==(const CMyTrailer &lhs, const CMyTrailer &rhs)
{
return lhs.m_csID==rhs.m_csID;
}
2. Now search as follows:
vector<CMyTrailer>::iterator i = std::find(m_vTlr.begin(), m_vTlr.end(), CString("FindMe"));
if (i!=m_vTlr.end())
{
}
The above code assumes you've included algorithm .
Steve
modified on Monday, December 03, 2007 10:06:57 PM
|
|
|
|
|
What about erase? When I find the element in the vector I want to erase it from the vector WITHOUT leaving a blank spot in the vector.
Thanks for using my code names; it sure makes it easier to understand what someone is telling me nwhen they use my code names to explain things. Thanks.
I get this error message when I included the inline function - I included it inside the class declaration - Right?
error: error C2804: binary 'operator ==' has too many parameters
#include <algorithm>
class CMyTrailer {
public:
// Varables
CString m_csItem;
CString m_csMFG;
CString m_csID;
CMyTrailer();
~CMyTrailer();
inline bool operator==(const CMyTrailer &lhs, const CMyTrailer &rhs)
{
return lhs.m_csID==rhs.m_csID;
}
};
#endif
<div class="ForumSig">A C++ programming language novice, but striving to learn</div>
<div class="ForumMod">modified on Tuesday, December 04, 2007 12:54:42 PM</div>
|
|
|
|
|
Larry Mills Sr wrote: What about erase?
if (i != m_vTlr.end())
{
m_vTlr.erase(i, i);
} Larry Mills Sr wrote: When I find the element in the vector I want to erase it from the vector WITHOUT leaving a blank spot in the vector.
Have you considered a list ?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
No I haven't. I was told a vector would be the right choice for my database. I know even less about a "list". I just know I don't want to use any of MFC's containers!
A C++ programming language novice, but striving to learn
|
|
|
|
|
You can use the CList in Simon Huges and my own article, just to see how it works (key word to search: Smart list)
But you can anyways use a list in C++ without MFC , the principies should be similar. I dont now remember if it is in the STL, stl::list
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
I'll stick with the vector for now. I still need a answer as to how to envolk the "erase" function to elimate the element I've found; and I need to resolve why the inline function supplied gives a compiler error.
<div class="ForumSig">A C++ programming language novice, but striving to learn</div>
|
|
|
|
|
I need an example with a dialog box containing a STATIC text that can be changed before showing the dialog box. Maybe the title to be also changed.
Please...
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
This changes the dialog title caption from within the dialog class:
CString windowCaption;<br />
windowCaption.Format("%s", SomeString);<br />
this->SetWindowText(windowCaption);
|
|
|
|
|
Thanks!
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Override the CDialog::OnInitDialog .
BOOL CMyDlg::OnInitDialog() <br />
{<br />
GetDlgItem(IDC_STATIC)->SetWindowText(_T("New Text"));<br />
<br />
return TRUE;<br />
}
See here[^] for more information in SetWindowText .
Regards,
Paresh.
|
|
|
|
|
Thanks! a lot
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
I need an example with a dialog box containing a STATIC text that can be changed before showing the dialog box. Maybe the title to be also changed.
Please...
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
MFC or straight Win32?
Do you have a basic understanding of how Windows UI works
or do you just need code?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
MFC
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
For change a text you can use of <code>SetWindowText</code> but I dont understand before showing the dialog box.
|
|
|
|
|
I'll try to use the other answers that I received.
Thanks!
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Very good. 
|
|
|
|
|
The Title of the DialogBox and the Static as well can be written with SetWindowText, but the thing is that in the Static, it will be better if you use a member variable to have access to it.
In case you have problems with the static. You can always use a CEdit, disabling the rand (the square around text), making it flat and activating the write-protection. The aspect will be the same as the Static and you will have it easier.
A third possibility, is just not using the Static and just use pDC->TextOut (...). To avoid the blank square behind the letters you can use pDC->SetBkMode (TRANSPARENT);
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
The question is into the title
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|