|
Dear James,
Thanks for the help.
I've looked up the RegCreateKeyEx function on MSDN, as you have suggested. I have tried to copy the code present in the second coloured box at (http://msdn2.microsoft.com/en-us/library/aa363634.aspx) into my c++ code, but I am sure I am either missing something crucial or inserting it in the wrong location, since it is returning a thousand errors when I try to compile it!
Not sure what I am doing wrong. Consider that I am a real beginner. My code is all written in c++ using VS2005 and Win32 application.
My code looks like that:
<code>#include "stdafx.h"
#include <ctime>
#include <math.h>
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
#include <iomanip>
using std::setprecision;
int _tmain(int argc, _TCHAR* argv[])
{
// my code
return 0;
}</code>
Thank you!
J_E_D_I
|
|
|
|
|
One problem you might be having is that you are not linking with the correct libraries to support the new functions you have added.
The RegCreateKeyEx() function requires that your program be linked with Advapi32.lib. Have you added this library to you project's linker input settings?
You would add the name "Advapi32.lib" to where it says "Additional Dependencies" in the Project Settings dialog box.
--------------------------------
"All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
|
|
|
|
|
Many thanks for the advice.
I have added the Advapi32.lib to the Additional Dependencies and tried to compile it (code below) but it results in many errors.
I would be very grateful for any advice.
#include "stdafx.h"
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
#include <iomanip>
using std::setprecision;
int _tmain(int argc, _TCHAR* argv[])
{
CString default_server;
CString default_root_dir;
CStringArray servers;
CStringArray rootdirs;
default_server = "";
default_root_dir = "";
servers.RemoveAll();
rootdirs.RemoveAll();
/* Read FTP server name and root directories from registry. GetRegistryList reads all the key values and fill in
the CString array */
HKEY hKey = GetRegistryKey( "Server" );
GetRegistryList( hKey, default_server, servers);
/* Now read it from array and add to a combo box */
for(int i=0; i<servers.getsize(); i++="" )
{
cstring="" str="servers[i].Left(" servers[i].find("#")="" );
combo-="">AddString( str );
}
Now, here is how to add one registry entry to the registry.
AddRegValue("Server", m_szftpServerName , m_szWebRootDir );
Now, here is how to delete a key and its corresponding value from the registry:
AddRegValue("Server", m_szftpServerName , m_szWebRootDir );
/* ************************************************************
Registry functions STARTS
************************************************************/
HKEY GetRegistryKey( CString str )
{
HKEY hViewerKey = NULL;
HKEY hSoftDirKey = NULL;
HKEY hCompanyKey = NULL;
HKEY hCompanyDirKey = NULL;
CString m_pszRegistryKey = "MIS Inc.";
CString m_pszProfileName;
m_pszProfileName = "Settings";
CString section = str;
//read from the registry...for default viewer
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSoftware, 0, KEY_WRITE|KEY_READ, &hSoftDirKey)
== ERROR_SUCCESS)
{
DWORD dw;
if (RegCreateKeyEx(hSoftDirKey, (LPCTSTR)m_pszRegistryKey, 0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_WRITE|KEY_READ, NULL, &hCompanyKey, &dw) == ERROR_SUCCESS)
{
if(RegCreateKeyEx(hCompanyKey, (LPCTSTR)m_pszProfileName, 0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_WRITE|KEY_READ, NULL, &hCompanyDirKey, &dw) == ERROR_SUCCESS)
{
RegCreateKeyEx(hCompanyDirKey, (LPCTSTR)section, 0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_WRITE|KEY_READ, NULL, &hViewerKey, &dw);
}
}
}
if (hCompanyKey != NULL)
RegCloseKey(hCompanyKey);
if (hSoftDirKey != NULL)
RegCloseKey(hSoftDirKey);
if (hCompanyDirKey != NULL)
RegCloseKey(hCompanyDirKey);
return hViewerKey;
}
BOOL GetRegistryList(HKEY hKey, CString &strValue, CStringArray &keyValue)
{
// HKEY hKey = GetConversionKey( "Data" );
DWORD dwType, dwCount;
long index = 0;
LONG lResult = 0;
CHAR ValueName[max_value];
DWORD dwcValueName = max_value;
CString data;
ValueName[0] = '\0';
dwCount = max_value;
lResult = RegEnumValue(hKey,index,ValueName,//regenumvalue return the key value names.
&dwcValueName, NULL, &dwType, NULL, &dwCount);
while(lResult != ERROR_NO_MORE_ITEMS)
{
RegQueryValueEx(hKey, ValueName, NULL, &dwType, (LPBYTE)data.GetBuffer(dwCount/sizeof(TCHAR)),
&dwCount);
data.ReleaseBuffer();
CString str = (CString)ValueName;
if(!(str.IsEmpty())) //neglecting the default value.
{
str = (CString)ValueName + "#" + data;
//concatenating the key value and its data
//separating with #
keyValue.Add((LPCTSTR)str);
}
++index;
dwcValueName = max_value;
lResult = RegEnumValue(hKey,index,ValueName, &dwcValueName,NULL,&dwType,NULL, &dwCount);
}
//this call is for default viewer.
lResult = RegQueryValueEx(hKey, NULL, NULL, &dwType, NULL, &dwCount);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_SZ);
lResult = RegQueryValueEx(hKey, NULL, NULL, &dwType, (LPBYTE)strValue.GetBuffer(dwCount/sizeof(TCHAR)),
&dwCount);
strValue.ReleaseBuffer();
}
RegCloseKey(hKey);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_SZ);
return TRUE;
}
return FALSE;
}
BOOL GetLeftRegistryList(HKEY hKey, CString &strValue, CStringArray &keyValue)
{
// HKEY hKey = GetConversionKey( "Data" );
DWORD dwType, dwCount;
long index = 0;
LONG lResult = 0;
CHAR ValueName[max_value];
DWORD dwcValueName = max_value;
CString data;
ValueName[0] = '\0';
dwCount = max_value;
lResult = RegEnumValue(hKey,index,ValueName,//regenumvalue return the key value names.
&dwcValueName, NULL, &dwType, NULL, &dwCount);
while(lResult != ERROR_NO_MORE_ITEMS)
{
RegQueryValueEx(hKey, ValueName, NULL, &dwType, (LPBYTE)data.GetBuffer(dwCount/sizeof(TCHAR)),
&dwCount);
data.ReleaseBuffer();
CString str = (CString)ValueName;
if(!(str.IsEmpty())) //neglecting the default value.
{
str = (CString)ValueName;
//concatenating the key value and its data
//separating with #
keyValue.Add((LPCTSTR)str);
}
++index;
dwcValueName = max_value;
lResult = RegEnumValue(hKey,index,ValueName, &dwcValueName, NULL, &dwType, NULL, &dwCount);
}
//this call is for default viewer.
lResult = RegQueryValueEx(hKey, NULL, NULL, &dwType, NULL, &dwCount);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_SZ);
lResult = RegQueryValueEx(hKey, NULL, NULL, &dwType, (LPBYTE)strValue.GetBuffer(dwCount/sizeof(TCHAR)),
&dwCount);
strValue.ReleaseBuffer();
}
RegCloseKey(hKey);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_SZ);
return TRUE;
}
return FALSE;
}
BOOL AddRegValue(const CString& key, const CString& value, const CString& data)
{
HKEY hKey = GetRegistryKey(key);
LPCTSTR lpszEntry = value;
LPCTSTR lpszValue = data;
if (hKey == NULL)
return FALSE;
LONG lResult = RegSetValueEx(hKey, lpszEntry, NULL, REG_SZ, (LPBYTE)lpszValue, (lstrlen(lpszValue)+1)*sizeof
TCHAR));
RegCloseKey(hKey);
//adding in the registry so that number of extensions can be retrieved
//for which the viewers are added.
SetKruseExtension(value, data);
if(lResult == ERROR_SUCCESS)
return TRUE;
else
return FALSE;
}
BOOL DeleteRegValue(const CString& key, const CString& value, const CString& data)
{
HKEY hKey = GetRegistryKey(key);
LPCTSTR lpszEntry = value;
LPCTSTR lpszValue = data;
if (hKey == NULL)
return FALSE;
LONG lResult = RegSetValueEx(hKey, lpszEntry, NULL, REG_SZ, (LPBYTE)lpszValue, (lstrlen(lpszValue)+1)*sizeof
TCHAR));
RegCloseKey(hKey);
//adding in the registry so that number of extensions can be retrieved
//for which the viewers are added.
SetKruseExtension(value , data);
if(lResult == ERROR_SUCCESS)
return TRUE;
else
return FALSE;
}
/* ************************************************************
Registry functions ENDS
************************************************************/
return 0;
}
|
|
|
|
|
try using CRegKey!
"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
|
|
|
|
|
I have a table filled in from reading a text file and I load that into a multi column CListCtrl, which is fine, I can also append to columns in there.
Is there an easy way to delete a specific column on a specific row?
What I'm doing right now:
a dialog button "Clear Entry" calls GetSelectionMark() on the table, and uses that to set the columns to "" in a rather heavy handed way
LVITEM lvi;
CString item = "";
lvi.mask = LVIF_IMAGE | LVIF_TEXT;
lvi.iItem = sel;
lvi.iSubItem = 3;
lvi.pszText = (LPTSTR)(LPCTSTR)(item);
m_Table.SetItem(&lvi);
lvi.iSubItem = 5;
lvi.pszText = (LPTSTR)(LPCTSTR)(item);
m_Table.SetItem(&lvi);
this seems to work fine, though there are issues
1) if the table hasnt been clicked there is no selection mark.
2) you can only click on the 1st column in a particular row - this is fine, but if I then click "Clear Entry" button, it works OK but the blue highlight disappears like that row is no longer selected but if I add data there and click "Clear Entry" it seems to remember what was last selected and deletes those items - a bit messy
I see DeleteAllItems and DeleteColumn, but how can I delete just one item on one particular row in an elegant way?
tia
L
|
|
|
|
|
ldsdbomber wrote: 1) if the table hasnt been clicked there is no selection mark.
So just disable the "clear" button until a selection is made.
"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
|
|
|
|
|
ldsdbomber wrote: Is there an easy way to delete a specific column on a specific row?
For a row subitem to be considered "deleted", that means its text is empty, correct?
If so, the only way I see to "delete" the subitem is to set its text to "" like you are doing.
I personally prefer to use LPSTR_TEXTCALLBACK instead of storing the text in the control.
Then when a LVN_GETDISPINFO notification is received, I can supply the text for all the items
and subitems.
This allows me to store objects of any type (representing the listview items) in any container
I prefer to use (array, etc).
Then, to "delete" an item, I can set a flag indicating the item is "deleted" or actually change
the text in my list object and refresh/repaint the control. Then the updated text is changed
the next time the LVN_GETDISPINFO is received for the item/subitem. (if that makes sense )
ldsdbomber wrote: 1) if the table hasnt been clicked there is no selection mark.
If you aren't relying on the user to select items then you'll have to keep track of what items
are in the list yourself. Another advantage of storing the data separately as I described above.
ldsdbomber wrote: 2) you can only click on the 1st column in a particular row
Even with the LVS_EX_FULLROWSELECT extended style?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark,
where do I put this LVS_EX_FULLROWSELECT. I don't see that style in the dialog resource view, and have tried programmatically setting it via SetExtendedStyle, but maybe I am doing it wrong, I've created a control member variable for my dialog of type listview, which has the LVS_REPORT style via the dialog resource editor checkboxes.
I've tried m_Table.SetExtendedStyle(LVS_EX_FULLROWSELECT);
but maybe I'm doing it in the wrong place or wrong way?
|
|
|
|
|
OK I have found that and it now works, I had it in the wrong block of code
All I need now is which message I need to handle so that if the user clicks an item in the row, I can then use the SetExtendedStyle call, or can that be done in the InitDialog?
Also, I am still having problems selecting anything other than the 1st column item - I thought the FULLROWSELECT allowed you to select a row by clicking any of the items?
|
|
|
|
|
oh!
putting it in OnInitDialog seems to have done the trick!
many thanks
|
|
|
|
|
Cool! Yeah, OnInitDialog should be a good place to set the style
Glad you got it working!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks Mark.
Now, if only I could programmatically set the selected state - so that if data is added to the table in a particular row, it's highlighted as though the user clicked that row, it would be perfect. Have tried the SetSelectionMark but that doesn't seem to be it! Do you know how that's done~?
|
|
|
|
|
LVIS_SELECTED (SetItemState()) should be the message you want to use.
state, stateMask LVIS_SELECTED | LVIS_FOCUSED
You may need to remove the slected/focused state from the previously selected item(s)...
LVM_GETNEXTITEM (GetFirstSelectedItemPosition()/GetNextSelectedItem()) will help find those.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hello,
If I have vector of int and vector of strings
vector<int>IntVector
vector<string>StringVector
and now I want to compare an int a within IntVector
and string s within StringVector
which comparison or search within these vectors will take more time.
I expect the size of vectors to be 100000.
so will it make a significant difference.
Prithaa
|
|
|
|
|
prithaa wrote: which comparison or search within these vectors will take more time.
Why don't you implement both and time them, then tell us?
led mike
|
|
|
|
|
prithaa wrote: which comparison or search within these vectors will take more time.
Without actually testing it myself, I'd say comparing strings would be slower.
"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
|
|
|
|
|
Hello,
Thanks
Even I thought strings would take more time.
Pritha
|
|
|
|
|
Hi,
Why don't you try to compare ASCII code? It can be the easiest way, as long numbers and letters are there and are different, and you can use higher than, lower than, equal... as well.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Hi, in my application I'm setting the fonts of some controls through WM_SETFONT by creating a LOGFONT and then calling CreateFontIndirect to create an HFONT from the LOGFONT.
For some reason the fonts don't look the same in debug and release mode. Also they look different on different computers. Is there a better way I can set the fonts, a more "standard" way that would look the same on all systems/modes?
For instance I wish I could just say, make the font 10 point FixedSys font. But with LOGFONT I have to give it lfHeight and lfWidth which seems somewhat arbitrary.
Thanks for help!
KR
|
|
|
|
|
KellyR wrote: But with LOGFONT I have to give it lfHeight and lfWidth which seems somewhat arbitrary.
Probably not much help, but...
I get consistent results across machines by setting only the lfHeight, lfWeight,
lfPitchAndFamily, and lfFaceName members of the LOGFONT struct. The rest of the members are set
to 0. I use a negative height and let the system pick the appropriate width.
The only inconsistency I've experienced is when using a specific font that does not come pre-
installed on all systems (so the font gets mapped to the closest match, not always good).
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I didn't realize I could use negative height to have the system auto-set width; this seems to make everything work correctly in my program. Thanks much!!
KR
|
|
|
|
|
Use (or lookup the implementation of) CFont::CreatePointFont(...) - it is great for creating fonts of specific point sizes. For example:
CFont fMyFont;
fMyFont.CreatePointFont( 100, _T( "FixedSys" ) );
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
hello, I have an project which generate boxes(bin packing) and I want to save the results on the disk(in the memory) so I can use this results in matlab or to save this results in xml so i can use xml for further reaserch please..if you know how can i do this help me ........if you can give me some clues... thanks
lavi
|
|
|
|
|
you have to know the structure of the files matlab is waiting for...
is this basic text, or binary one ?
|
|
|
|
|
if is basic test how can I save my results ...please help me... I realy need help
|
|
|
|
|