|
I am looking for a way to override the maximize button for the main window in an MDI application. I have found several articles telling me how to override the maximize button for the child window, but not the main window. What I need is when the User clicks on the maximize button the application maximizes itself to two monitors instead of just one monitor. I hope that somebody can help me.
|
|
|
|
|
You need to handle the WM_SYSCOMMAND message.
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
switch(nID)
{
case SC_MAXIMIZE:
break;
case SC_MINIMIZE:
break;
case SC_CLOSE:
break;
}
CFrameWnd::OnSysCommand(nID, lParam);
}
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you that was extremely helpful
|
|
|
|
|
I need someone to please help me figure out how to get a TCHAR into a CString; when I will NOT know in advance what the TCHAR will be. Here's my code:
// SysData.h : header file
//
#pragma once
// CSysData
// Class that contains the System File Data
class CSysData
{
public:
// Functions:
CSysData(); // Default Constructor
~CSysData(); // Default Destructor
void CreateDirectoryName(CSysData cData);
void CleanUp(void);
// Copy Constructor:
CSysData(const CSysData& cSource);
// Assignment operator:
CSysData& operator= (const CSysData& cSource);
CString SetPathName(CString str);
//Varables:
CString m_csOperatorName;
CString m_csWellName;
CString m_csPath;
CString m_IsFileName;
CString m_csDirections;
CString m_csTanks;
};
Here's how I obtain the path:
CString CSystemDB::SetPath(CSysData cSysData)
{
CString str, str1, str2, str3;
str1 = _T("c:\\Wells\\Program\\DataBases\\Operators\\");
// Make path for SystemDB.bku file for each Operator:
str3 = "c:\\Wells\\Program\\DataBases\\SystemDB\\SystemDB.bku";
m_csSystemDB_BKU = str3;
// Make path for SystemDB.sdb file for each Operator:
str2 = "c:\\Wells\\Program\\DataBases\\Operator\\";
str2 += cSysData.m_csOperatorName;
str2 += _T("\\");
str2 += "SystemDB.sdb";
m_csSysNameTMP = str2;
str = str1;
str += cSysData.m_csOperatorName + _T("\\");
str += cSysData.m_csWellName;
str += _T("\\");
m_vSys.m_cSysData.m_csPath = str;
DoDirectory(m_vSys.m_cSysData);
// Now get the file filename:
cSysData.m_IsFileName = cSysData.m_csWellName;
cSysData.m_IsFileName += ".wdb";
m_csFileName = str;
}
The cSysData data was collected from dialog editbox input from the User.
now I must open a CStdioFile using a TCHAR filename. m_csFileName has that filename at this point, BUT it is not a TCHAR. How do I make it into a TCHAR? I simply don't know how. Mark showed me how to do it using the CString Constructor, but this is not possible after the CString has already been constructed.
Can someone please help me?
A C++ programming language novice, but striving to learn
|
|
|
|
|
sorry, i don't really get your question.
if you want to get a char (TCHAR) at a certain position, use CString::operator[]() or CString::GetAt()
if you want to retrieve a certain character (TCHAR), use CString::Find()
and please, please, PLEASE, format your code samples using <pre></pre> tags
|
|
|
|
|
Probably you need a const TCHAR * : just pass the CString itself.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Larry Mills Sr wrote: now I must open a CStdioFile using a TCHAR filename.
Why? What's wrong with:
CStdioFile file(m_csFileName, CFile::modeRead);
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Larry Mills Sr wrote: BUT it is not a TCHAR. How do I make it into a TCHAR?
Hello Larry,
You seem to reiterate the same questions regarding TCHAR which implies that you may be confused about the subject. First thing you should know is that technically there is no such thing as a TCHAR. TCHAR simply means "Template Character" and is simply a wrapper definition for both wchar_t and char based on whether or not UNICODE is defined. In other words if UNICODE is defined then TCHAR=wchar_t otherwise its a char.
All you need to do is enable unicode support in your project and CString will default to CStringW and TCHAR will default to wchar_t. Thats all you need to do. There are some functions which may require you to convert the wchar_t to multi-byte and if you run into these types of functions you can use my previous answer to convert the wchar_t to char[^].
Best Wishes,
-David Delaune
|
|
|
|
|
More here...[^]
Larry Mills Sr wrote: m_csFileName has that filename at this point, BUT it is not a TCHAR. How do I make it into a TCHAR?
Actually the character type of the string IS the same as TCHAR.
As David mentioned, a TCHAR is just a conditional macro whose resulting type is based
on whether the _UNICODE macro is defined or not. CString is the same - its
internal string character type is determined by the same Unicode macro being defined
or not defined.
I'm still not sure where in your code you think you need this "TCHAR"...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark,
You showed me yesturday to get a CString set for TChar you have to do so in it's constructor. Naturally all members of a class(ie, CSysData cSysData in my case) are iniatized upon insanitation therefore I would not be able to do as you did in your example using my class. So naturally I am confused and have no way of knowing what to do next, which is why I included the class header and the function(SetPath(....)) to show you and everyone else what I was doing.
This operation has to be done correctly because throughout the program I'm writing most functions will need some data from the file this class (CSysData) establishes.(ie, SystemDB.sdb).
I'm not sure what David means by setting CString to UNICODE. How, exactly? and How will that setting effect SetWindowTextW(IDC_NAME,str);(where str is CString str) or GetWindowText(str); Do you use a CString or do you have to use something else? to get the data?
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: are iniatized upon insanitation
Yes sometimes it happens that way.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Larry Mills Sr wrote: You showed me yesturday to get a CString set for TChar you have to do so in it's constructor.
That was yesterday, and only to specifically get the file to open,
which I thought was the problem. That was a code example which hard-coded
a valid pathname so you could check your file handling code.
This string issue is entirely separate, and I'm not sure what problem you're
having at this point Compiler errors? Runtime errors? Step through with
the debugger (it's only a handful of lines of code) and watch the value of your
strings. If they're not doing what you want, then fix the code.
Larry Mills Sr wrote: I'm not sure what David means by setting CString to UNICODE. How, exactly?
With visual studio projects, typically you just use the project/general/character set setting.
If you set this to use Unicode character set, then VS adds "/D "_UNICODE" /D "UNICODE"" to the compiler
command line. This defines two macros: _UNICODE and UNICODE. Now if you look at the header files
for CString(T) and TCHAR, you'll see that the definition of _UNICODE affects the character type
of those generic string types.
Larry Mills Sr wrote: How will that setting effect SetWindowTextW(IDC_NAME,str);(where str is CString str) or GetWindowText(str);
You use a CString and that's it. Any method that takes a CString is already coded
to take generic strings into consideration. All you have to be concerned with is passing
the appropriate type. If a method expects a CString, then pass it a CString.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote:
With visual studio projects, typically you just use the project/general/character set setting.
If you set this to use Unicode character set, then VS adds "/D "_UNICODE" /D "UNICODE"" to the compiler
command line. This defines two macros: _UNICODE and UNICODE. Now if you look at the header files
for CString(T) and TCHAR, you'll see that the definition of _UNICODE affects the character type
of those generic string types.
Please be patient; I don't want to mess anything up in the compiler. Are you saying I need to go into the compiler settings and ADD a "/D" to it's settings in order for my CStrings to work as correct filenames? for "CStdioFile". Or did I missunderstand you?
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: Are you saying I need to go into the compiler settings and ADD a "/D"
No. That's what the Visual Studio does for you when you change the character set setting.
I still don't know what problem(s) you're having...
Compiler errors? Linker errors? Runtime errors? Not doing what you expect it too when it runs?
Larry Mills Sr wrote: in order for my CStrings to work as correct filenames? for "CStdioFile".
You don't have to do anything.
CStdioFile::Open(), for example, takes a LPCTSTR as an argument.
Since CString has a LPCTSTR casting operator, you can use a CString anywhere a LPCTSTR
is expected:
CStdioFile file;
file.Open(SomeCString, ...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The error I was getting was a runtime error saying among other things "Disk Full" when I have over 65GB remaining. I checked each time and the path was exactly right. When I changed it using the CString constructor method of loading the CString(like you did) I didn't get any errors and the file was written to.
Mark, it's simply confusing. You say that you can use CString anywhere it wants a LPCTSTR (is that true only if you have the "/D" setting in the compiler? It sure doesn't work correctly if you ASSIGN another CString's data into the one you want to use for a CStdioFile filename!. That's what I'm trying to solve. You've seen my code; I've got to be able to save the filename in my class (CSysData::m_csPath and the newly created CSysData::m_IsFileName). m_IsFileName will be the file that I will hopefully find at the path represented by CSysData::m_csPath. But I can't get CStdioFile::Open(filename,....,) to accept my CString::m_csPath + CSysData::m_IsFileName combination.
I can hardcode the paths for the file but I cannot hardcode the CSysData::m_IsFileName CString, because part of the name for the CSysData::m_IsFileName will be determined later adding date and time to it to make it a unqinue(ms) filename.
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: You say that you can use CString anywhere it wants a LPCTSTR (is that true only if you have the "/D" setting in the compiler? It sure doesn't work correctly if you ASSIGN another CString's data into the one you want to use for a CStdioFile filename!.
Yes, you can pass a CString object anywhere a LPCTSTR is the argument type. That means you can pass
a CString to CStdioFile::Open() NO PROBLEM. This has nothing to do with compiler settings. CString
is a string of a generic character type. The 'T' in LPCTSTR indicates it is a pointer to a generic
character type string. CString has a LPCTSTR operator. That makes a CString usable in place of a LPCTSTR,
regardless of whether you're building with _UNICODE defined or not.
If it doesn't work at runtime, then the contents of your string are WRONG.
It seems you need to focus on your string building. Have you stepped through with the debugger?
It doesn't matter what logic you go through to get a pathname for a file....however you build that
pathname, it needs to be valid for the file to open. If the file is not opening then your pathname is bad!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Larry Mills Sr wrote: now I must open a CStdioFile using a TCHAR filename
Where do you get that from? TCHAR is not mentioned anywhere in the CStdioFile/CFile docs.
CFile::Open() takes a LPCTSTR type argument for the pathname.
Larry Mills Sr wrote: m_csFileName has that filename at this point
Then all you need to do is use m_csFileName (I'm assuming m_csFileName is a CString):
CStdioFile myfile;
myfile.Open(m_csFileName, ...);
Seriously - step through this SetPath() method in the debugger. Look at the values of the
strings after each line is executed.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have walked through SetPath and I have stepped through FileSaveys. The values are exactly the same. I don't know what's going on; I just know that it is not doing as it is supposed to. I believe everything you are telling me Mark. Believe me that the error message is telling me my path is wrong when I KNOW it is the same. Or the debugger is lying to me. It's there and it's correct!. I took the same path and created a different CString varable, placed it into that CString's constructor and there was no problems. If you woul, use my class and create a file-path by adding CStrings together and see it that works on your machine. Again I've checked SetPath, and at the very point that I transfer what str has in it, to the public CString varable m_csFileName is correct. m_csFileName shows in the debug as to have received the correct path. in SetPath. it also shows the correct path in FileSaveSys right up to the Open STATEMENT. I can hardcode this path. But what worries me is the actual filename I will be lokking for in the future may not be there. m_csIsFileName will be unique and I won't know it's name because the program created that name by adding the date and time to the end of the m_csWellName. "SystemDB.sdb" is only a practice/proveable file for testing the ability of the program to work correctly to that point. If the well name was Murphy13 and the date was Jan 12, 2008 the time the User called for the file is: 11:02am, the filename would be "Murphy13011220081102.ddb". But I won't know anything about that! That's why this part must work correctly, and I can't get my CStrings to coopporate.
A C++ programming language novice, but striving to learn
|
|
|
|
|
Hi,
I've added a toolbar in a dialog based project following
what's written in this page:
http://www.codeproject.com/KB/dialog/dialog_tips.aspx[^]
The project already has a menu bar so in the toolbar I've set
the same ID for buttons having a corresponding menu item.
Now the situation is the following:
when I push toolbar buttons the application calls automatically
the callback associated to the right menu item but...
I don't know how to let the toolbar buttons be enabled or disabled
according to menu items (ON_UPDATE_COMMAND_UI).
How can I solve this problem?
Thanks a lot.
|
|
|
|
|
|
Currently, I am working on a GUI for video surveillance-object detection using MFC and is rather unfamiliar in using the MFC. I wonder if anyone here would able to give me some advice for source code for the following:
1) Using a dialog-based application in C++6.0, how do I capture live video from the webcam to the dialog box itself (i.e. picture control) using OpenCv (without using directshow)? I should be able to click on buttons created and the livevideo will start/pause/stop on the dialog box(i.e. picture control).
For now, I am thinking of this method whereby I follow the below link to create the picture control and let it draw the bmp file.
http://www.codeguru.com/cpp/g-m/bit...icle.php/c4939/
This implies that I need to convert the opencv's ipl file to mfc's bmp file and deal with multiple images so as to provide realtime images. Thinking of using a 'for' loop to perform the capturing of multiple images, but would like to ask if you have any better suggestions?
2)As I will need to store the bmp files to be processed for object recognition when I press the "InitializeDetector" button created, I would like to ask if anyone knows how to create a framegrabber? How do I store the files for image processing?
Please advise.
Thanks in advance!
|
|
|
|
|
|
I have this existing MFC application. I'd like some external C#/Silverlight application to communicate with it. Does anyone know how to add code so it can act as web service? Any pointer to articles / sample is welcome!
Thanks in advance!
|
|
|
|
|
|
ohhh you are being harsh ... I know roughly a web service is. But true not that much. I know it's stateless and that you can pass it some SOAP command...
What I want to do is provide an API to my MFC application... some way of communicating between a web app and my app... A web service seemed a good idea - do say if I am wrong!
|
|
|
|