|
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.
|
|
|
|
|
Hey folks..
I have a dialog based application who's background is a DARK_CYAN color. I have two TabControls on this dialog, each of which need to have a different background brush.
When I call:
SetClassLong ( hwndFirstTab, GCL_HBRBACKGROUND, (LONG) hDarkCyanBrush );
It sets the background of both tab-controls to be DarkCyan, and understandably so, "class" = controls of type in Win32.
Anyone have any tips that would give me what I want, without getting my hands into CustomDrawing?
I've looked at SetWindowLong() for an option to change the background brush, but no luck.
Thanks!
Mike
doner@obtain.com
|
|
|
|
|
Mike Doner wrote:
Anyone have any tips that would give me what I want, without getting my hands into CustomDrawing?
Sorry, but i think drawing it yourself is going to be the way you have to go. Shouldn't be too hard i think, handling WM_ERASEBKGND should do it.
If you need something fancier, there are two nice articles on owner drawn tabs here on CP.
---Shog5---
From now on we can call C# and MC++ "The square wheel languages" -- Jack Handy, The Lounge
|
|
|
|
|
I've converted my source code to work with the new Standard C++ library headers. i.e. iostream, fstream, etc. But, I can't seem to open files in binary mode for read/write cuz my data is all screwed up. The documentation says setmode() no longer can be used for the new iostream library.
I'm using...
open(fileSpecPassed, ios::in | ios::out | ios::binary);
Does the iostream library not work with files in a binary mode?
|
|
|
|
|
Well, the new iostream s library supports the binary mode. I've done it in the past, so your problem is hopefully solvable Could you post a little code showing how you use the library?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I keep running into the same ol' crap again. I'm converting some code that works in Borland C++ 5.01 to VC++ 6.0. Anyways, code that worked in Borland obviously doesn't in MSVC. You were right, it does work in binary. It turns out that the sizeof operator does not work the same between versions so I was off in reading contents of objects.
Previous programmer had statements like:
stream.Read(&site.peArray, sizeof(site.peArray));
where peArray was defined as:
#define MAX_PE_PER_SITE 4
TPerEcho peArray[MAX_PE_PER_SITE];
The object is 6 bytes long, a float + a short but it kept coming up with 8 bytes from the sizeof() operator (actually 32 instead of 24).
|
|
|
|
|
sizeof always works the same, it's the way the compiler packs structures in memory that changes. see "pragma pack".
-c
The ants are my friends. They're blowing in the wind.
|
|
|
|