|
The "LPSTR lpCmdLine" parameter in the WinMain function holds the parameters.
|
|
|
|
|
could you please tell me how should I do this? I am not very familiar with VC++?
thanks.
|
|
|
|
|
try searching in the articles or in MSDN there should be some examples.
|
|
|
|
|
In your WinMain function, the third parameter is a LPTSTR (char*) called lpstrCmdLine. This is where your command line parameters will come in. You can simply process the string data in this field just line you would for the argv parameters of the main function for a console application.
If you want to run your program in the debugger and send command line parameters to your app, you can go to the menu Project | Settings, then select the debug tab, and set the program arguments field.
If you are using MFC (which is a little different) or you need more help just ask.
Good Luck.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
I am a little confused, kilowatt.
What I would like to do is:
when the external program calls my win application, it passes (let's assume) 1 parameter, which is a string. Then in my win application, I would like to display this parameter. How could I implement this? Could you possible specify it in details? I am using Visual C++ 6.0.
Thanks a lot.
|
|
|
|
|
you could store this string, for example:
char str[32];
WinMain(...)
{
strcpy(str, lpCmdLine);
}
and in some function display it in a messagebox like this:
MessageBox(hWnd, str, "", MB_OK);
|
|
|
|
|
where can i find the winmain() function?
|
|
|
|
|
For MFC applications, use CWinApp::lpCmdLine. Example:
<br />
CString str;<br />
str = AfxGetApp()->lpCmdLine;<br />
MessageBox(str);<br />
Above code will popup a message box which displays whatever parameter you passed to your application exe.
|
|
|
|
|
what about multiple parameters? how can I separate them? one character by one character?
|
|
|
|
|
No matter how many parameters you have entered, that's always a command "line", for example, if your app exe named "abc.exe" and you typed the following line to launch your program:
<br />
abc.exe -s -a -p -nodemo -window<br />
that line consists of 5 parameters, the contents of lpCmdLine will be:
<br />
"-s -a -p -nodemo -window"<br />
It's YOUR responsiblity to parse the command line into individual parameters, and that's pretty easy if you ask me. By the way, you will need to tell the users how to specify command line parameters when you ship your application, thus you should know the rule of parsing.
|
|
|
|
|
When i use this function, the path to each subfolder doesen't get added to the listview, what gets added is the path to the desktop folder and then the subfolder name of the folder the user selected in the SHBrowseForFOlder dialog, for example: C:\Documents and Settings\Administrator\Dekstop\<subfolder name>
here's the code:
void OnOpenFolder()
{
BROWSEINFO bi = {0};
IShellFolder *pSf;
LPMALLOC pMalloc;
LPENUMIDLIST pFolder = NULL;
DWORD pActual = 0;
LVITEM Lvi = {0};
char szFolderPath[MAX_PATH+1];
bi.hwndOwner = ghWnd;
bi.pidlRoot = NULL;
bi.lpszTitle = "Locate MP3 Folder";
bi.ulFlags = BIF_DONTGOBELOWDOMAIN;
bi.lpfn = NULL;
SHGetDesktopFolder (&pSf);
if (pSf)
{
LPITEMIDLIST pIdl;
pIdl = SHBrowseForFolder(&bi);
SHGetPathFromIDList(pIdl, szFolderPath);
Lvi.mask = LVIF_TEXT;
Lvi.pszText = szFolderPath;
Lvi.iItem = SendMessage(DlgItems[7], LVM_GETITEMCOUNT, 0, 0);
ListView_InsertItem(DlgItems[7], &Lvi);
if (pIdl)
{
IShellFolder *pBrowse = NULL;
SHGetMalloc(&pMalloc);
pSf->BindToObject(pIdl, NULL, IID_IEnumIDList, (LPVOID*)&pBrowse);
pSf->Release();
pBrowse->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &pFolder);
if (pBrowse)
{
while (pFolder->Next(1, &pIdl, &pActual) == S_OK)
{
SHGetPathFromIDList(pIdl, szFolderPath);
Lvi.pszText = szFolderPath;
Lvi.iItem = SendMessage(DlgItems[7], LVM_GETITEMCOUNT, 0, 0);
ListView_InsertItem(DlgItems[7], &Lvi);
}
}
pBrowse->Release();
}
pMalloc->Free(pIdl);
pMalloc->Release();
}
pSf->Release();
}
Anyone know what's wrong?
|
|
|
|
|
I just dug up some old code that was calling SHBrowseForFolder and I noticed that I used:
BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT
for the bi.ulFlags member. Try that and see if it makes a difference.
Regards,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
It doesen't make any difference if i call the BindToObject like this:
pSf->BindToObject(pIdl, NULL, IID_IShellFolder, (LPVOID*)&pBrowse);
but maby it's there the bug is because when i run it like this
pSf->BindToObject(pIdl, NULL, IID_IEnumIDList, (LPVOID*)&pBrowse);
which should be the correct way, it comes with an unhandled exception error when it gets to the EnumObjects function.
You know what could be wrong?
Unhandled exception in app.exe: 0xC0000005: Access Violation.
Thanks
|
|
|
|
|
Your reply does not go with the original question, but I've taken some time to look into your problem. I changed BindToObject to pass IID_IShellFolder instead of IID_IEnumIDList and it seems to work fine.
According to the docs, IID_IEnumIDList is NOT a "directly exposed interface" so you can't pass it directly into BindToObject. If you do, you'll get an error and pBrowse will be NULL, so you'll then get an access violation when you try to use it (to call EnumObjects).
Regards,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
Chaning the uiFlags didn't work. It works fine with me too when i use IID_IShellFolder, it's the IID_IEnumIDList it can't handle. I just got an advice from someone saying it should be IEnumIDList instead. But it's strange that it returns the desktop folder path + the subfolder name, bcause according to MSDN you normally initialize the IShellFolder pointer with SHGetDesktopFolder...
|
|
|
|
|
Replace
SHGetPathFromIDList(pIdl, szFolderPath); in while loop by
TCHAR pszDisplayName[MAX_PATH];
TCHAR szRes[MAX_PATH];
STRRET strDispName;
pBrowse->GetDisplayNameOf(pIdl, SHGDN_INFOLDER, &strDispName);
StrRetToBuf(&strDispName, pIdl, pszDisplayName, MAX_PATH);
PathCombine(szRes,szFolderPath,pszDisplayName);
result path is szRes
P.S. must inlcude "shlwapi.h" (shlwapi.lib for linker)
soptest
|
|
|
|
|
Hello
I have problems with adding a property page in a new thread. The problem is CPropertyPage::AddPage() always produces debug assertion failure, when running from a thread.
it looks like this:
UINT SomeThread(LPVOID p)
{
...
CMyPropertyPage* newpage;
newpage=new CMyPropertyPage;
pdlg->m_PropertySheet.AddPage(newpage); //debug asertion failed
...
}
pdlg in this example was restored from the FromHandle function. I know that this error is caused by the fact that AddPage() is run in separate thread. Anyone knows how to do it properly ?
I will appreciate any suggestions... thanks
|
|
|
|
|
Post a message to the original thread to add the page. (PostThreadMessage)
Good Luck,
Bill
|
|
|
|
|
Thanks for the reply...
..but the thread in which CPropertySheet was created is the main user interface thread... and I don't know how to send it a ThreadMessage...
Is there any other solution ?
|
|
|
|
|
Ok,
Problem : Cannot get window handle to CPropertySheet
Solution : No problem, all we need is the thread handle and
we can post a msg to it.
Analysis : Ok, every MFC project contains the global CWinApp derived object.
Use that to get the handle of the main thread, and do a PostThreadMessage.
MFC takes care of the routing, so dont worry.
Just make sure that the id of the msg is unique and
there is a handle in the CProp(Page)(Sheet) you want to handle
the message.
|
|
|
|
|
hi all,
there is something not very important, but annoying :
* how can i include images into a project ? i know it's possible to do so within the ressource editor but only for .GIF, .ICO and what about .JPG ?
thanx
|
|
|
|
|
Just Import it into the resources, with a custom resource type string, like "JPG".
-c
The ants are my friends. They're blowing in the wind.
|
|
|
|
|
I have MDI type app.. with in CMainFrm I have a worker thread that needs to access one of the views to update the data.. The thread works fine as long as I dont pass it a pointer to the view.. how can I access the view from with in the thread? This is how I am trying to access the view..
CListView* pList = (CListView*)(MDIGetActive()->GetActiveView());
This view will allways be the active view when the thread is started.
Any ideas?
Rob
|
|
|
|
|
It may be better to have the main thread access the view. Have the worker thread post a message to the mainthread (PostThreadMessage).
Good Luck,
Bill
|
|
|
|
|
When you use the window in the worker thread,
they will not execute since windows depend on the
message loop to dispatch mesgs.
And obviously your worker thread does not have a mesg loop.
So the next best solution is to have a function in the
view and have the worker thread post a mesg which will
be handled and acted upon by the main ui thread with
the PostThreadMessage.
Use a user defined message which will map to the said fn.
|
|
|
|