|
thats what im trying to do
RegSetValueEx(hKey, "Background", 0, REG_SZ, (const unsigned char *)"0 78 152", dwvalue);
that works fine but when i get the color from the dialog is when it kicks me in the head
COLORREF color;<br />
CString c;<br />
DWORD r, g, b;<br />
if (m_check3.GetCheck() == 1)<br />
{<br />
CColorDialog dlg;<br />
if(dlg.DoModal()== IDOK)<br />
{<br />
color = dlg.GetColor();<br />
r = GetRValue(color);<br />
g = GetGValue(color);<br />
b = GetBValue(color);<br />
}<br />
c.Format("%d %d %d", r, g, b);<br />
hKey = HKEY_USERS;<br />
path = ".DEFAULT\\Control Panel\\Colors";<br />
DWORD value = color;<br />
MessageBox(c);<br />
DWORD dwvalue = sizeof(DWORD);<br />
RegOpenKeyEx(hKey, path, 0, KEY_ALL_ACCESS, &hKey);<br />
RegSetValueEx(<br />
hKey,<br />
"Background",<br />
0,<br />
REG_SZ,<br />
(const unsigned char *)&value, <--- here<br />
dwvalue<br />
);<br />
}
|
|
|
|
|
<br />
CString c;<br />
DWORD r, g, b;<br />
CColorDialog dlg;<br />
COLORREF color;<br />
if(dlg.DoModal()== IDOK)<br />
{<br />
color = dlg.GetColor();<br />
r = GetRValue(color);<br />
g = GetGValue(color);<br />
b = GetBValue(color);<br />
}<br />
c.Format("%d %d %d", r, g, b);<br />
MessageBox(c);<br />
HKEY hKey = HKEY_USERS;<br />
CString path = ".DEFAULT\\Control Panel\\Colors";<br />
DWORD value = color;<br />
DWORD dwvalue = sizeof(unsigned char) * c.GetLength();<br />
RegOpenKeyEx(hKey, path.GetBuffer(0), 0, KEY_ALL_ACCESS, &hKey);<br />
RegSetValueEx(<br />
hKey,<br />
"Background",<br />
0,<br />
REG_SZ,<br />
(const unsigned char *)c.GetBuffer(0), <br />
dwvalue<br />
);<br />
The code on top will work.
the problem is that you are sending in a DWORD as a string.
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?
|
|
|
|
|
|
My pleasure.
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?
|
|
|
|
|
You should save the null terminator too (according to the docs)
DWORD dwvalue = sizeof(unsigned char) * c.GetLength();
should be
DWORD dwvalue = sizeof(unsigned char) * (c.GetLength() + 1);
|
|
|
|
|
Here's a tip, for what it's worth.
With CString objects, unless you need to change the buffer directly, it's safer to use
the const accessor methods (the LPCSTR cast or the GetString() method.
CString::GetBuffer() is over-used (when not necessary) IMO
(const unsigned char *)c.GetString(),
instead of
(const unsigned char *)c.GetBuffer(0),
Mark
|
|
|
|
|
Hi everyone. i hope someone can help me with my problem.
I need to create a GUI that will send commands to a command line program. I am doing this under Linux.
I need to be able to start the GUI and then the GUI needs to start the Command Line program.
Im basically creating a front end for the command line program. i need to have the GUI displayed and the command line program running in the background, either hidden or not.
How do i send commands from the GUI to the command line ???
How do i get the output from the command line so that it can be displayed in the GUI ???
All of the above needs to be done in C++.
I would be greatfull for any help.
G
|
|
|
|
|
ANSI C has spawn functions for spawning processes. Some of them allow you to hook the Standard IO of the spawned process. Windows has OS API's for doing the same thing so perhaps Linux does as well. The OS API's are generally preferable however the spawn functions should work if you need them.
led mike
|
|
|
|
|
How do I clear the screen when using a menu
|
|
|
|
|
clrscr();
What screen, what menu ?
if it's an MFC application, your menu handle should set some internal values that will be used in the WM_PAINT handler of the view; if you clear the screen, you will only draw the background, if not, you will draw the background and whatever else you draw.
|
|
|
|
|
sorry, I should have been more clear. I am only using the command screen and a text menu. After a selection is chosen, I want the screen to clear and either show some result or the menu again. I have the menu in a while loop, but I don't know how to make the screen blank after a selection.
|
|
|
|
|
Check out FillConsoleOutputCharacter() and FillConsoleOutputAttribute() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I would like to serialize the following CObArray class:
<br />
class CNode : public CSubNode <br />
{<br />
DECLARE_SERIAL (CNode)<br />
public:<br />
void Serialize(CArchive &ar);<br />
CNode();<br />
virtual ~CNode();<br />
CObArray * GetSubNodesP() {return &m_oaSubNodes;}<br />
void SetNodePath(CString inPath) {m_strNodDescr = inPath;}<br />
CString GetNodePath() {return m_strNodDescr;}<br />
<br />
private:<br />
int m_iCurPosition;<br />
CString m_strNodDescr;<br />
CObArray m_oaSubNodes;<br />
};<br />
Here is the serialization function in the document class....
<br />
void CFTreeBrowserDoc::Serialize(CArchive& ar)<br />
{<br />
<br />
m_oaNodes.Serialize(ar);<br />
<br />
}<br />
<br />
...and in CNode...
<br />
<br />
void CNode::Serialize(CArchive &ar)<br />
{<br />
<br />
m_oaSubNodes.Serialize(ar);<br />
<br />
if (ar.IsStoring())<br />
ar << m_iCurPosition << m_strNodDescr;
<br />
else<br />
ar >> m_iCurPosition >> m_strNodDescr;
<br />
}<br />
<br />
<br />
...and so far (because I haven't got around to implementing what I want to do with it yet) in the CSubNode class...
<br />
<br />
void CSubNode::Serialize(CArchive &ar)<br />
{<br />
CObject::Serialize(ar);<br />
<br />
}<br />
Now because I haven't yet got very far at all with this, I have only tried writing and reading values to and from 'm_strNodDescr' in the CNode objects. The program writes these values to a file which it saves. I know this has worked, because I can see the values when I open the file in a generic editor. However, when I load the file back into my application, the array of CNode objects, as far as I can tell, doesn't get re-populated.
Your help and opinions here are much appreciated,
Ben.
|
|
|
|
|
Ben Aldhouse wrote: void CNode::Serialize(CArchive &ar)
{
Did you forget to call base class member here ? CObject::Serialize(ar) in this case .
|
|
|
|
|
Thanks for your answer,I will go away and have a look...
|
|
|
|
|
Ok , so I have checked. I had been calling the ancestor function in the CSubNode class, but not in the CNode class serialization function. Both serialization functions now call the ancestor function. The result is the same. I can save (at least, to some extent), but not reload the data back into the array.
|
|
|
|
|
I've got this sorted out now. The full solution to the problem is written up here. Looking at the above message, it seems to me that, at the time, my mistake was in the CNode::Serialize function where I had simply tried to serialize the CObArray object (of sub nodes) with the insertion and extraction operators along with the other node object members. The way to get this to work, it turns out, is to not treat the collection of sub nodes like the other node object members but instead call its CObArray serialization function. Hence the node object serialization function looks like this:
void CNode::Serialize(CArchive &ar)
{
CSubNode::Serialize(ar);
int iNoSubNodes = 0;
if (ar.IsStoring())
{
iNoSubNodes = m_oaSubNodes.GetSize();
ar << m_iSubNodePosition << m_strString << iNoSubNodes;
}
else
ar >> m_iSubNodePosition >> m_strString >> iNoSubNodes;
m_oaSubNodes.Serialize(ar);
}
|
|
|
|
|
Hi,
I have a custom file format i would automatically assign to an application.
How do i do this? Is there any sample code out there or does the Windows API / MFC support some helpers for that?
I already implemented a class to store and read registry items. If there are no helper functions out there can you tell me where and what i have to write into the registry to assign a file format to an application?
Hope to hear from anyone soon . Thanks a lot for your help in advance!!!
- Ben
|
|
|
|
|
The easiest way, IMO, is to create an SDI application, and look at the .reg file that gets created as a result. That will show you the minimum registry keys/values that need to be created.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Directly from MSDN:
REGEDIT
HKEY_CLASSES_ROOT\.riy = FMA000_File_assoc
HKEY_CLASSES_ROOT\FMA000_File_assoc = File_assoc
HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\command = fileasso.EXE
HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec = [Open(%1)]
HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec\application
= Myserver
HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec\topic = system
HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\command = fileasso.EXE
HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\ddeexec = [Open(%1)]
HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\ddeexec\application
= MYServer
HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\ddeexec\topic = System
HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\ddeexec\ifexec =
[Test(%1)]
Peace!
-=- James 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! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Have a look also on IQueryAssociations (retrieve using AssocCreate). This won't work for rewrite, but for query will do it.
|
|
|
|
|
In my MFC project, I declare a struct Stru_A,
struct Stru_A{
char Name[30];
int Age;
}
I would like to initialize the member variable Name with sth like a constructor used for a class. Does this make sense?
|
|
|
|
|
Yes.
Peace!
-=- James 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! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
it depends if you allocate your struct with new or with malloc .
if it's with new , then, yeah, add a constructor.
If it's with malloc , even if you have a constructor, it will not be called, juste create a wrapper function to allocate and initialize the structure.
something like :
Stru_A* MallocStru_A( char* name, int age )
{
}
|
|
|
|
|
Thanks, Maximilien
Would you please more specific about how to create a constructor for the struct
struct Stru_A{
char Name[30];
int Age;
};
And, how to use
<br />
Stru_A* MallocStru_A( char* name, int age )<br />
{ <br />
}<br />
<br />
to initialize a struct for later use.
|
|
|
|