|
always use _strtod
"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
Support CRY- Child Relief and You
|
|
|
|
|
Hi guys,
I am writing a simple program that the user would like to be able to run from the command prompt. I am wondering how I pass that infromation into the main of my program. For example, if you wish to run Windows explorer from the command line you pass the command "explorer". This will launch Windows explorer and default to showing C:\. However, you can also call explorer and have it open a specific directory "explorer C:\Test\MyTest".
My question is this:
Is the second part of that simply passed as the argument to main? For example if I wanted my program to specify a string, could I have my main function accept a const char *?
I.E. void main(const char *inputString) ?
where inputString would be whatever it is that I have passed immediately after my *.exe name?
so the total call would be something like:
C:\> stringParser This Is My Test
which would hopefully pass a pointer to "This is My Test" into my main argument.
Thanks,
Joe
|
|
|
|
|
In Visual C++, you can use the version of _tmain that has command line argument parameters:
int _tmain(int argc, _TCHAR* argv[])
See main: Program Startup[^]
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark Salsbery wrote: int _tmain(int argc, _TCHAR* argv[])
strange from microsoft that argv is not an array of const TCHAR*
|
|
|
|
|
toxcct wrote: strange from microsoft that argv is not an array of const TCHAR*
Yeah. I guess it stays consistent with the old days of C
There's no const in any of the prototype variations.
Beats me!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
if you somehow graduate to windows programming you can use GetCommandline api to reterive the command line
"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
Support CRY- Child Relief and You
|
|
|
|
|
Hi all,
Can any one convert this simple piece of code from C#.NET to C++(general). I am getting error while performing this. I guess i am going wrong somewhere.
private String GetFileName(String filter){
OpenFileDialog dlg = new OpenFileDialog();
dlg.Multiselect = false;
if(filter.Length > 0){ dlg.Filter = filter; }
if( dlg.ShowDialog(this) != DialogResult.Cancel){
return dlg.FileName;
}else{
return null;
}
}
private void btnImageFile_Click(object sender, System.EventArgs e) {
String fileName = GetFileName("Bitmaps (*.bmp)|*.bmp|Tagged Image File Format(*.tif)|*.tif|PNG-24(*.png)|*.png");
if(fileName != null){
txtImageFile.Text = fileName;
SetImage(fileName);
}
Thanks a lot
|
|
|
|
|
Do you want to show a dialog to user for select an image file(not multiselect because its false on your code) and draw it? You can write this code with CFileDialog
|
|
|
|
|
okay
well i can open a dialog box and select file by
OpenPictureDialog1->Title= "Open File: ";
if (OpenPictureDialog1->Execute())
bmpFileEdit->Text=OpenPictureDialog1->FileName;
return;
But i want that it should not select any file other than .bmp, .tif and .png.
So you mean i can do this via CFileDialog. Okay ill look for it, if i get any clue how to do it with this.
Thanks
|
|
|
|
|
I dont have any compiler now(but I have 3dmax program now ) but try to compile this code and see what happens?(it shows only txt files
CFileDialog m_Open_Dialog(1,0,0,OFN_EXPLORER ,"Text Files (*.txt)|*.txt||",0);
and also instead use of
use of
if(m_Open_Dialog.DoModal() == IDOK)
-----------------------------------------------
It seems previous code show a dialog to user to select image files and show filename on the a labeltext maybe and send filename to a function.
|
|
|
|
|
Something like this maybe (I've used no MFC and no STL/MFC/ATL string classes)...
bool GetFileName(LPTSTR pszBuffer, DWORD dwBufferSize, LPCTSTR pszFilter)
{
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.lpstrFilter = pszFilter;
ofn.lpstrFile = pszBuffer;
ofn.nMaxFile = dwBufferSize;
ofn.Flags = OFN_EXPLORER;
return 0 != ::GetOpenFileName(&ofn);
}
...
TCHAR szFileName[MAX_PATH] = _T("");
if (GetFileName(szFileName, MAX_PATH, _T("Bitmaps (*.bmp)\0*.bmp\0Tagged Image File Format(*.tif)\0*.tif\0PNG-24(*.png)\0*.png\0\0")))
{
}
else
{
}
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi thanks a lot
But i think simple use of filter could solve this out. Well what i did now is
<br />
OpenPictureDialog1->Title= "Open File: ";<br />
OpenPictureDialog1->Filter = "Bitmap files (*.bmp)|*.BMP";<br />
if (OpenPictureDialog1->Execute())<br />
bmpFileEdit->Text=OpenPictureDialog1->FileName;<br />
return;
So this gives me only bitmap file to select. So its fine the only thing now left is function
SetImage(fileName) function i.e.
<br />
private void SetImage(String fileName){<br />
picImage.Image = new Bitmap(fileName);<br />
<br />
btnHide.Enabled = btnExtract.Enabled = true;<br />
btnSaveBitmap.Enabled = false;<br />
<br />
int index = fileName.LastIndexOf("\\")+1;<br />
if(index > 0){ fileName = fileName.Substring(index); }<br />
grpPicture.Text = "Carrier Bitmap ("+fileName+")";<br />
}
Ill try to convert this aswell. Well and yeh i said General C++ i meant no VC++. As i am using Borland. So it doesnt support the option you gave.
Can any one give me any tips as i have got this VC++ pure win32 application and C#.net application n i want to convert it to General Borland C++. I know i have to do it manually but still any good pts i should follow.
Thanks a lot for your time...
SS
|
|
|
|
|
What part didn't compile on Borland? You should be able to use Windows APIs - that's what .NET
is using under the hood. You may need to include the appropriate header files and link libraries.
For non-Unicode builds you can eliminate the "_T()" macros I used. Replace "LPCTSTR" with "const
char *", "LPSTR" with "char *", "TCHAR" with "char".
For the second part, what needs to happen? Do you load the image as a GDI+ Bitmap object?
Then format the file name into a string?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
hi i have to cancel(close) the dilaog from a user defined function. how to do this?
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
Simply call OnCancel from your function.
|
|
|
|
|
hmm i tried that but got crash sinc hwnd is null
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
Where and how are you calling OnCancel() ?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can you show code snippet?
|
|
|
|
|
You could manually send a WM_CLOSE message to your dialog handle.
For instance if the handle to your dialog is:
HWND MyDialog;
SendMessage(MyDialog, WM_CLOSE, 0, 0);
KR
|
|
|
|
|
I have a CDialog on which I have a extension CToolbar ctrl. I have extended the CTOolbar so that I can use OnKickIdle from my CDialog to get the ON_UPDATE_COMMAND_UI for my CToolbar buttons.
My question is this: How can I capture the tab key to also tab through the CToolbar buttons and also tab through the CDialog menu's?
|
|
|
|
|
What does your OnKickIdle() look like? I have used this kind of code:
LRESULT CMyDTestDlg::OnKickIdle(WPARAM wParam, LPARAM lParam)
{
UpdateDialogControls(this, FALSE);
AfxCallWndProc(this, m_hWnd, WM_IDLEUPDATECMDUI, TRUE, 0);
SendMessageToDescendants(WM_IDLEUPDATECMDUI, TRUE, 0, TRUE, TRUE);
return 0;
}
Best wishes,
Hans
|
|
|
|
|
My code looks like this:
LRESULT CCTSubmiterDlg::OnKickIdle( WPARAM wParam, LPARAM lParam )<br />
{<br />
SendMessageToDescendants( WM_IDLEUPDATECMDUI, wParam, lParam, TRUE, TRUE );<br />
<br />
CMenu* pMainMenu = GetMenu();<br />
CCmdUI cmdUI;<br />
<br />
for (UINT n = 0; n < pMainMenu->GetMenuItemCount(); ++n)<br />
{<br />
CMenu* pSubMenu = pMainMenu->GetSubMenu(n);<br />
cmdUI.m_nIndexMax = pSubMenu->GetMenuItemCount();<br />
<br />
for (UINT i = 0; i < cmdUI.m_nIndexMax;++i)<br />
{<br />
cmdUI.m_nIndex = i;<br />
cmdUI.m_nID = pSubMenu->GetMenuItemID(i);<br />
cmdUI.m_pMenu = pSubMenu;<br />
cmdUI.DoUpdate( this, FALSE );<br />
}<br />
}<br />
<br />
return 0;<br />
}
|
|
|
|
|
Andy H wrote: My question is this: How can I capture the tab key to also tab through the CToolbar buttons and also tab through the CDialog menu's?
AFAIK, there's no tab-through-buttons functionality in a toolbar (or am I wrong?).
Do you have a way to implement that functionality?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
You could just do it manually in whatever your message loop is (GetMessage, PeekMessage etc), by checking the MSG wParam to see if it's the tab key, then check to see if the message occurred in your Toolbar ctrl or your CDialog, and if so, tab to whatever you want.
KR
|
|
|
|
|
I have a MDI application which has a muliple dialog windows. One of these dialog windows needs to be update on regular basis. I am assume the best way to accomplish this is to add/create a OnTimer function and in it add code to refresh the window. What is the syntex for accomplish this.
<br />
void Lenze8200_Dlg::OnUpdate(CView* , LPARAM , CObject* )<br />
{<br />
Red_ON = AfxGetApp()->LoadIcon(IDI_RED_ON_LED); <br />
Red_OFF = AfxGetApp()->LoadIcon(IDI_RED_OFF_LED); <br />
Green_ON = AfxGetApp()->LoadIcon(IDI_GREEN_ON_LED); <br />
Green_OFF = AfxGetApp()->LoadIcon(IDI_GREEN_OFF_LED); <br />
Led_OFF = AfxGetApp()->LoadIcon(IDI_OFF_LED); <br />
<br />
if( G2MainApp.pitch_is_connected() == false ) <br />
{<br />
m_iconPitchConnected.SetIcon( Red_ON );<br />
}else{<br />
m_iconPitchConnected.SetIcon( Green_ON );<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
void Lenze8200_Dlg::OnTimer(UINT nIDEvent)<br />
{<br />
<br />
CFormView::OnTimer(nIDEvent);<br />
}<br />
<br />
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|