|
Check:
rename, _wrename
Mazy
Don't Marry a Person You Can Live With...
Marry Someone You Can Not Live Without
|
|
|
|
|
You can use the MoveFile API call.
Nish
Nish was here, now Nish has gone;
He left his soul, to turn you on;
Those who knew Nish, knew him well;
Those who didn't, can go to hell.
I like to on the Code Project
Sonork ID 100.9786 voidmain
www.busterboy.org
|
|
|
|
|
I have a requirement by which my application should run in two modes
1) As a back ground process taking inputs as a command line arguments
2) As a stand alone GUI application with dialogs etc stuff.
So how to go about it?
It should be developed in VC++ on NT
1) Is it wise to develop the product as two applications? One application will be providing only GUI functionality and
the other doing the core job?
or
2) Develop a single application which runs with GUI if there is no command line argument and works in
background if data is fed as command line arguments.
Can any one share some experiences?
|
|
|
|
|
I would suggest parsing the commandline in a single application. Well designed classes would allow code reuse, minus the GUI code.
I've never written an app that required console/plus windows if thats your desired effect. However I have developed an app that parsed the Cmdline and decided whether to show windows or just go abouts doing it business.
I'd go with one module, not two...just my opinion though.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I recently had to do something like this.
I wrote a console app that would take command line options and could be run on its own.
I then made a dialog app that would generate the command line string and use a call to CreateProcess to run the console application.
Doing it this way simplified the process cuz I only had to write the guts of the program once for the console app. The GUI was just a front-end app to convert user input to a command line string yet would produce the same output.
Josh Knox
that-guy.net
"Before you criticize someone, walk a mile in their shoes. That way, when you criticize them, you're a mile away, and you have their shoes." - author unknown
|
|
|
|
|
Hi folks!
I just start to go crazy. I had to convert an Word-Document in an AFP-Document for an HOST-System. I can´t use the MFC and I also had to use an IBM Printer Driver for the convertion .doc to .afp.
I wanna use the OpenPrinter()- and SetPrinter()-methods because the user should not see an printing dialog and the IBM printing driver is not the standard printer.
My OpenPrinter()-Call always fails, the return value is zero. When I check the LastError-Code it´s 87 (The parameter is incorrect.).
Is there anybody out there who can help me? What is my mistake? Thanks a lot for any help or suggestion!
cu,
Lars
|
|
|
|
|
- What name are you passing in?
- Where did you get the name? Did you hard code it or enum installed printers?
- Does this work when you do it manually; i.e. open the document in word, select print from the file menu, select the printer, print?
farewell goodnight last one out turn out the lights Smashing Pumpkins, Tales of a Scorched Earth
|
|
|
|
|
Hi, Shog9!
I tried every printer name I could find ("friendly" name, shared name, etc). For testing I coded the printer name hard, maybe I should try EnumPrinters() (got this tip just a few minutes before...).
Can´t proof it manually ´cause the printer driver is "installed" at the "FILE"-port, ´cause I don´t wanna print "real". I just wanna use this driver to convert a .doc-File to an .afp-File. After convertion, I´ll transport the afp-File to a HOST system.
Thanks for trying helping me!!!
cu,
Lars
|
|
|
|
|
I have made a smart edit control class called CStringEdit that is subclassed off the CEdit class. This control works very nicely for me when I include it as a member variable control in a Dialog class. The purpose of this control is to let me have a lot more run time control over a users data entry in a dialog edit box.
The CStringEdit class has interfaces to perform these functions:
void SetFixedLen(BOOL bFixedLen) ... used to set the string to fixed length padded if necessary to the right at the call to GetText(). Defaults to FALSE.
void SetMaxLength(int nMax) ... used to set the maximum string length. The default value of zero means no length restriction and FixedWidth feature is ignored.
void SetLegal(LPCSTR lpszLegal) ... used to enter a string of characters that are legal in the edit box. Defaults to NULL string which means that all characters are legal.
void SetIllegal(LPCSTR lpszIllegal) ... used to put in a string of characters that are specifically illegal in the editbox. Defaults a NULL string such that there are no illegal characters.
void SetText(LPCSTR lpszText) ... used to send intial text to the edit box.
void GetText(CString& strText) ... used to get back out the edited text string.
This control class uses a connection that I setup with the ClassWizard on the OnUpdate() message to validate the edit box contents at each instance that the control thinks there has been a change to the text content and it thinks it is time to re-display the control contents. In this event routine I do the validation to limit the string length and verify if the string contents are valid. It works just dandy!!!
NOW FOR MY PROBLEM.......
I have a particular instance of this control in a dialog where there needs to be some additional real time validation of the edit box content that is dependent upon other things on that same dialog. I have tried to connect the specific instance of this edit control member variable to its own OnUpdate() procedure in the dialog class. Once again this cinnection was mapped using the Class Wizard. My problem is that the event procedure is never being invoked.
Can anyone help me figure out why this does not work?? I can send the whole class source code plugged into a simple demo app if my write-up here is not complete enough....
Thanks from a new VC++ 6 user.
Mike
|
|
|
|
|
I sort of lost you in the last paragraph where you have defined your problem. Are you trying to call a message handler function through direct function call ? If this being the problem then rather than calling the function directly - you must use PostMessage() (see MSDN help on PostMessage() ) to invoke the event handler. PostMessage() a parameter that contains the MESSAGE_ID, LPARAM, and WPARAM
If i incorrectly understood the problem then can you please elaborate it further
-cheers
-kashif manzoor
peace to all
|
|
|
|
|
Your problem is that you have two OnUpdate s, one in CStringEdit and one in the parent dialog, and the latter handler is not being called, right?
If so, then the solution goes as follows:- In
StringEdit.h , change
afx_msg void OnUpdate(); to
afx_msg BOOL OnUpdate(); Do the necessary modifications on the .cpp as well, and have this handler return FALSE .
- In
StringEdit.cpp , replace
ON_CONTROL_REFLECT(EN_UPDATE, OnUpdate) with
ON_CONTROL_REFLECT_EX(EN_UPDATE, OnUpdate) That should do it. The changes indicate the framework that the reflection handler of CStringEdit allows further processing by the parent (by returning FALSE instead of TRUE as the code for ON_CONTROL_REFLECT does internally).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I made the changes you suggested, (you were right on track of understanding
what was not working for me). Now when I compile the program and try to
run it there always is a run time error that happens. I get a box that pops
up a with "Unhandled Exception". Hitting OK to this dumps me into the
debugger with the current code pointer positioned at the BEGIN_MESSAGE_MAP(CStringEdit, CEdit)
line of the CStringEdit class code. I have no idea of what casues this
or what to do about it.
Take a look at what I now have and tell me if you can see anything wrong
with it. Here is what I have:
In the customized edit control called CStringEdit header file StringEdit.h there is:
class CStringEdit : public CEdit
{
....
....
protected:
// Generated message map functions
//{{AFX_MSG(CStringEdit)
afx_msg BOOL OnUpdate();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
...
...
}
Then in the implementation, StringEdit.cpp, file I have the following code following
your suggestion.
//////////////////////////////////////////////////
//
// BEGIN_MESSAGE_MAP and END_MESSAGE_MAP macros
//
BEGIN_MESSAGE_MAP(CStringEdit, CEdit)
//{{AFX_MSG_MAP(CStringEdit)
ON_CONTROL_REFLECT_EX(EN_UPDATE, OnUpdate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
And for the actual update routine itself in the same file there is the
member function as shown below. This function is supposed to validate
the edit box content per the definitions of my CStringEdit class but
the parent dialog may want to further validate the edit box content.
BOOL CStringEdit::OnUpdate()
{
// local code in here to validate edit contents and possibly
// modify and or reject the most recent changes by replacing
// edit content with last know valid content.
...
...
return(FALSE);
}
Now in the parent dialog class the code that I have now in place
to attempt to provide the further validation of the looks as follows.
In the dialog header file there is this code...
class CEditCounters : public CDialog
{
...
...
// Dialog Data
//{{AFX_DATA(CEditCounters)
enum { IDD = IDD_EDIT_COUNTERS };
...
CStringEdit m_CntFormat_Edit;
...
//}}AFX_DATA
...
// Generated message map functions
//{{AFX_MSG(CEditCounters)
...
afx_msg void OnUpdateCntFormatEdit();
...
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
...
...
// function to check a counter format string
BOOL CEditCounters::FormatCheck(CString *pCntFormat);
};
And for completeness (please bear with here) the dialog implementation file
(.cpp file) has the code snippetts as shown below.
...
...
BEGIN_MESSAGE_MAP(CEditCounters, CDialog)
//{{AFX_MSG_MAP(CEditCounters)
...
ON_EN_UPDATE(IDC_CNT_FORMAT_EDIT, OnUpdateCntFormatEdit)
...
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
...
...
void CEditCounters::OnUpdateCntFormatEdit()
{
CString strBuffer;
m_CntFormat_Edit.GetText(strBuffer);
if(FormatCheck(&strBuffer) == FALSE) // validate the string
{
m_CntFormat_Edit.SetText(strBuffer); // replace if changed by validate
}
}
...
...
BOOL CEditCounters::FormatCheck(CString *pCntFormat)
{
// validate string and if ok return TRUE else
// suggest a change in string and return FALSE
...
...
}
|
|
|
|
|
Seems to me everything's fine. Have you tried with "Rebuild All"? Sometimes it helps.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for looking at all my code!! I tried the ReBuild All again (I had done this before anyway out of normal practice) but it does not help the problem. I have now done some debug investigation. I set two breakpoints. One at the UpDate function in the CStringEdit class and one at the Update handler code in the parent dialog code. What seems to be happening is that the two breakpoints are being hit alternately first the edit control update and then the parent update routine in a never ending loop. I see the ESP register steadily going downard in addresses at each breakpoint. I am guessing that there is an interlock in here that some how that makes the stack grow till it reaches its lower bound and tries to reference memory outside my programs stack area. DOes this seem like this could happen?? And if so how does one fixup to prevent a deadly loop like this from happening?
|
|
|
|
|
Actually I found that my check code in the dialog was never happy with the edit
text and was changing the edit box content...This apparently cases the edit control
to get another update message and so the process went on till some 12 megabytes of
stack get used up!!!!
Thanks again,,,I think I am on track now of how to correct the problem. Your
help with ON_CONTROL_REFLECT_EX is more than appreciated !!
Mike Karas
|
|
|
|
|
In case it is of any help, I suggest you follow the following policy when implement OnUpdate : Have a boolean flag, say m_bInOnUpdate to prevent reentrancy, and do not call SetWindowText till you've parsed the whole string. Sort of like this:
BOOL CStringEdit::OnUpdate()
{
if(m_bInOnUpDate)return TRUE;
m_bInOnUpDate=TRUE;
CString str;
GetWindowText(str);
SetWindowText(str);
m_bInOnUpDate=FALSE;
} (Actually, either of these two techniques would suffice alone.)
As a quality of implementation issue, you can also treat the selection (the highlithed portion) of the edit box and make it consistent with your "purged" string. Use GetSel /SetSel for this.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi ,
I have a window ,which it has got lot of images.
If the user clicks anywhere in the window,i need to update some things.If the user keeps on clicking for about 2-3 minutes.Then the dc i receive in the OnPaint() or OnEraseBkGnd() will be null.
Is there any way to solve this problem..
Thanks
Neha
|
|
|
|
|
well.. this sounds for me like a resource leak...
maybe this article helps you any further:
http://www.codeproject.com/gdi/csavedc.asp
hope this helps
bernhard
Sometimes I think the surest sign for intelligent life elsewhere in
the universe is that none of them ever tried to contact us.
|
|
|
|
|
But when i run through Boundscheker.there was no resource or memory leaks..
Thanks
Neha
|
|
|
|
|
well.. i didn't know that..
i've never used boundschecker.. so i don't know anyhting bout i neither..
if you could post some pseudocode here.. maybe this would help.. (just to show the context how're you using your dc functions)
bernhard
Sometimes I think the surest sign for intelligent life elsewhere in
the universe is that none of them ever tried to contact us.
|
|
|
|
|
I have a doubht,Like in my code some parts i had used
HDC hDC=::GetDC(this->m_hWnd);
After my work is done i will say DeleteDC(hDC);
Will that be fine?
Thanks
Neha
|
|
|
|
|
First off:
An application must not delete a device context whose handle was obtained by calling the GetDC function. Instead, it must call the ReleaseDC function to free the device context.
Secondly
You have to restore the HDC when using SDK type DC's
With MFC i don't think you have this problem.
Yes it's a GDI leak, use VC++ stress utility and watch the GDI values drop like mad. I don't think BoundsChecker checks for these kind of memory leaks...I don't have and never used it, only know what i've read.
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
If i do ReleaseDC() also , i have the problem.
I have VC++ 6.0.But in tools i didn't find any stress utility.
Thanks
Neha
|
|
|
|
|
Visual C++ tools menu and you didn't find stress...?
Which version of C++ are you using...
Anyways...Windows 98 comes with (if you install it) resource meter, this should do the same trick.
Even if you call Release it'll still leak, yes...I only pointed that out cuz...well MSDN says so...so do it!
You have to restore your original HDC object
I'm tired and i dunno if i can remember correctly, it's been a while since i programmed SDK...
HDC hdc = ::GetDC(this->m_hWnd);
HGDIOBJ oldBrush = SelectObject(hdc, color);
SelectObject(hdc, oldBrush);
DeleteObject(color);
Sorry I had to refer to some old code, you MUST restore the old object back to original state or you will leak.
If this doesn't work...Then i'm gonna need to know more...
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Correction this leakage will ocurr in MFC...so always restore your objects.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|