|
To All,
Thanks for your help and advice. I got this working the way I intended, and everything works fine.
Aaron
|
|
|
|
|
CTreeCtrl uses SetItemData() to associate a pointer to an object. In my tree ctrl every object stands for a string. Is there any way to associate a string with an item using SetItemData() without creating a new string and pointer to it then adding passing that through SetItemData()?
hope that makes some sort of sence
basicly i have a loop which adds all of my items and i want it to call SetItemData() after adding it, and associate the item just added with a string
thanks for any insight!
-dz
|
|
|
|
|
You can store pointers to strigns (or whatever thing, for that matter), but it is your responsibility to keep track of the lifespan of these objects: in other words, these objects must be stored somewhere else, as what you're passing to the CTreeCtrl are just pointers.
If you're familiar with list s and string s, this pseudocode shows the general idea:
class CMyDlg
{
...
std:list<std::string> m_item_strings;
void populate_tree()
{
for(...){
HITEM hItem=m_tree.InsertItem(...);
std::string item_string=...;
m_item_strings.push_back(item_string);
m_tree.SetItemData(hItem,(DWORD)&m_item_strings.back());
}
}
};
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
i m using winsock control in MFC application.its Connect method is
Connect(const VARIANT& RemoteHost, const VARIANT& RemotePort).
i dont now how to pass these parameters.infact i dont know much about VARIANTS.plz send me piece of code to use this fuction.
|
|
|
|
|
This is not a funny a answer but use CAsyncSocket class or CSocket. Those are very easy to use!
Sorry to disappoint ya!
Rickard Andersson@Suza Computing
ICQ#: 50302279 (Add me!)
E-mail: nikado@pc.nu
I'm from the winter country SWEDEN!
|
|
|
|
|
This is good coding:
// Prototype
LRESULT CALLBACK SubClassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
.
.
.
LRESULT CALLBACK SubClassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
.
.
.
// Somewhere in the code...
wpOldProc = (WNDPROC)SetWindowLongPtr(this->hControl, GWL_WNDPROC, (LONG)SubClassProc);
.
.
.
Why isn't this good coding???
class SomeClass
{
.
.
.
LRESULT CALLBACK SubClassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
.
.
.
};
.
.
.
LRESULT CALLBACK SomeClass::SubClassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
.
.
.
//Further in some function:
wpOldProc = (WNDPROC)SetWindowLongPtr(this->hControl, GWL_WNDPROC, (LONG)SubClassProc);
.
.
.
I contantly get a type cast error. WHY???
I really want to work object oriented, so please give an object oriented example of this.
LPCSTR Dutch = "Double Dutch "
|
|
|
|
|
This problem is explained in some detail in Mike Dunn's C++ FAQ.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, everyone
I am developing a Windows Application using Visual C++ 6.0. This application is going to be called by another program. When that program calls my windows application, it will pass several parameters to my win application. Could anyone tell me how to make my windows application take parameters?
|
|
|
|
|
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
|
|
|
|
|