|
Hehe, never mind, I found it.
|
|
|
|
|
<br />
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run<br />
I can add a value to this programatically under Windows 98, but when I give my program to my friend on XP, CRegKey::Create() fails. Am I not being told something?
-Jason
nirgle.bitdevil.com
|
|
|
|
|
|
Michael Dunn wrote:
What is the return value from Create()?
Seems to be 161.
#define ERROR_BAD_PATHNAME 161L
Perhaps Software needs to be capitalized? Is the Windows XP Registry case sensitive?
BTW here is the code:
CRegKey autoRunKey;
long ret;
if ((ret = autoRunKey.Create(HKEY_CURRENT_USER, "\\Software\\Microsoft\\Windows\\CurrentVersion\\Run")) != ERROR_SUCCESS)
{
CString f;
f.Format("Couldn't open key.. return code is %ld", ret);
AfxMessageBox(f);
}
-Jason
nirgle.bitdevil.com
|
|
|
|
|
hmm, two things to change. 1, remove the backslash before "software". (Case doesn't matter with registry names). 2, never use KEY_ALL_ACCESS with registry functions because they will fail if the user is not an administrator. The default access for the ATL functions I've encountered is KEY_ALL_ACCESS, which in hindsight was a bad design decision. Anyway, don't take the default access, specify exactly the access you need (KEY_WRITE or whatever). You didn't say if the XP user is running as admin, but if they're not, then the access problem is definitely making the call fail.
--Mike--
My really out-of-date homepage
Buffy's on. Gotta go, bye!
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
Thanks for the quick response. I tried removing the \\ on a hunch, and it ended up working. Good idea. I'll look into the permissions thing too.
Thanks!
-Jason
nirgle.bitdevil.com
|
|
|
|
|
I haven't yet used XP, but it is supposed to be Win2K warmed over. This may be a permissions issue. Does your friend run the program under a user account that has permission to alter the Registry?
|
|
|
|
|
I'm working on a trace utility, mainly to extend my knowledge of IOStreams and STL. I have a map to keep track of a number of edit windows, which all take the same position and are sown based on a tab control.
map<cstring, ctracewnd*=""> m_TraceMap;
Now, I hide all my windows before showing the one selected, like this:
void HideWindow(std::pair<cstring, ctracewnd="" *=""> p)
{
CTraceWnd * pWnd = p.second;
pWnd->ShowWindow(SW_HIDE);
}
void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)
{
std::for_each(m_TraceMap.begin(), m_TraceMap.end(), HideWindow);
// etc, etc.
Now I have two questions.
1. How can I make HideWindow a member function of CTabView ? I've tried mem_funxxx stuff, to no avail, and spent a good amount of time reading 'Generic Programming and the STL', also without any success.
2. Better yet, is there a way I can call ShowWindow(SW_HIDE) directly, OR add a HideWindow function that does this to CTraceWnd, and call that ?
Thanks to anyone who answers.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
class MyClass : public CTabView
{
public:
MyClass() {}
void HideWindow() { CTabView::ShowWindow(SW_SHOW); };
};
// this seems like it should be a template of some kind
void HideWindow(const std::pair<int, MyClass>& v)
{
MyClass& blah = const_cast<MyClass&>(v.second);
blah.HideWindow();
}
void main()
{
std::map<int, MyClass> blah;
std::for_each(blah.begin(), blah.end(), HideWindow);
}
|
|
|
|
|
Thanks, I'm sure this will work, and the way I'm doing it now works, too, but I want to get rid of the global function altogether and replace it with a member function, either of the class held in the second part of the pair, or in the class calling the function.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
void CTabView::HideWindow(std::pair<cstring, ctracewnd="" *=""> p)
{
CTraceWnd * pWnd = p.second;
pWnd->ShowWindow(SW_HIDE);
}
void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)
{
std::for_each(m_TraceMap.begin(), m_TraceMap.end(), std::mem_fun_ref(&CTabView::HideWindow));
but I get this error:
error C2784: 'class std::mem_fun_ref_t<_R,_Ty> __cdecl std::mem_fun_ref(_R (__thiscall _Ty::*)(void))' : could not deduce template argument for '<unknown>' from 'void (__thiscall CTabView::*)(struct std::p
air<class cstring,class="" ctracewnd="" *="">)'
I thought maybe mem_fun1_ref, but things just got worse. I tried adding the function to CTraceWnd, but that was worse again....
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Try making a "void HideWindow ()" method in CTraceWnd. Then "std::mem_fun_ref (CTraceWnd::HideWindow)" should work.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
I had done that previously, and I get this:
void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)
{
std::for_each(m_TraceMap.begin(), m_TraceMap.end(), std::mem_fun_ref(CTraceWnd::HideWindow));
void CTraceWnd::HideWindow(std::pair<cstring, ctracewnd*=""> p)
{
p.second->ShowWindow(SW_HIDE);
}
error C2784: 'class std::mem_fun_ref_t<_R,_Ty> __cdecl std::mem_fun_ref(_R (__thiscall _Ty::*)(void))' : could not deduce template argument for '<unknown>' from 'void (__thiscall CTraceWnd::*)(struct std::
pair<class cstring,class="" ctracewnd="" *="">)'
Tried mem_fun1_ref as well. I don't think this can work as I need to pull second out of the pair first, which requires some non-standard stuff found in STLPort, etc. I will install STLPort tonight.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Create a from std::unary_function derived helper class then it should work. For map for_each functors, it should look like this, remember the first pair argument must be const (i think). I assume your maps' pairs' first argument is an int.
class hidewindow_functor : public std::unary_function< std::pair<int const,CWnd*>, void>
{
public:
void operator() (std::pair<int const,CWnd*>& target) const
{
target.second->ShowWindow(SW_HIDE);
}
};
Cheers,
Alexander Berthold
|
|
|
|
|
Thanks - although not quite what I was after, I'm now convinced I need some non standard STL stuff from STLPort to make it work the way I want. However, it only works if I make CWnd above CTraceWnd, can you tell me why STL cannot do the cast ?
Thanks.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
I have a CListCtrl derived class and I want to recieve notification when a user resizes the columns so I can make sure they dynamically resize and never have a scrolling portion. But none of my attempts to catch this message are working. I found an article that subclasses the CHeaderCtrl - is this the only way, or does anyone know of another way ? I just want tis one stupid message....
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
|
I know about the messages, but overriding them using class wizard does *nothing*. Or have I got something else wrong and am just blaming this ? I went into class wizard, chose HDN_TRACK, put an AfxMessageBox in there and started sliding the things about to try and get a response. I'm using a splitter SDI app.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
hmm... I just tried it with an Explorer-style app, handling the HDN_* messages in the list view, and it looks like ClassWizard has a bug. It makes ON_NOTIFY_REFLECT macros for the header messages, which is totally wrong. For example, change:
ON_NOTIFY_REFLECT(HDN_DIVIDERDBLCLICK, OnDividerdblclick) to
ON_NOTIFY(HDN_DIVIDERDBLCLICK, 0, OnDividerdblclick) The header control always has ID 0, that's the reason for the 0 above.
--Mike--
My really out-of-date homepage
Buffy's on. Gotta go, bye!
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
Thanks Mike, but I did this, handling the message in my CListCtrl derived class and changing the macro to ON_NOTIFY, inserting a 0 between the other two arguments. It is never called.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
I did something like this about 6 months ago, so my memory is a bit rusty.
This worked for me anyway, but with some flickering of the scrollbars (I never could figure out how to get a shot at resizing the headers before the listctrl tried to draw them)
Here's a skeleton of the code I used.
BOOL CNumbersListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
NMHDR* pNMHDR = (NMHDR*)lParam;
HD_NOTIFY *phdn = (HD_NOTIFY *)lParam;
switch(phdn->hdr.code)
{
case HDN_BEGINTRACK:
{
TRACE(_T("CNumbersListCtrl::OnNotify -- HDN_BEGINTRACK Trapped\n"));
return(FALSE);
break;
}
case HDN_ENDTRACK:
{
TRACE(_T("CNumbersListCtrl::OnNotify -- HDN_ENDTRACK Trapped\n"));
if (phdn->iItem == 0)
{
TRACE(_T("CNumbersListCtrl::OnNotify -- Resising right to fit\n"));
}
else if (phdn->iItem == 1)
{
TRACE(_T("CNumbersListCtrl::OnNotify -- Resising left to fit\n"));
}
break;
}
}
return CListCtrl::OnNotify(wParam, lParam, pResult);
}
|
|
|
|
|
Thanks, but this did not work. Right now I am doing this in OnNotify:
GetAsyncKeyState(VK_LBUTTON);
if (GetAsyncKeyState(VK_LBUTTON) && 4294967284 == pnmh->code)
{
CRect rc;
GetClientRect(&rc);
SetColumnWidth(1, rc.Width() - GetColumnWidth(0));
}
if I change that big number to HDM_ITEMCHANGINGA, HDM_ITEMCHANGEDA, or the W equivelants ( or drop the A or W ) it either does nothing or crashes. I am certain the two messages I get are ITEMCHANGED and ITEMCHANGING. The HDM_TRACK message is a phantom - it is NEVER sent ASAIK.
I've tried several things and in the end I've concluded that CListCtrl is rubbish. It works for me as it stands, although it flickers and jumps when the mouse button is raised. I'm interested if you have any comments.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Christian Graus wrote:
Thanks, but this did not work. Right now I am doing this in OnNotify:
Ok. I remeber that I had alot of trouble catching the HDN_BEGINTRACK, not to mention the HDN_TRACK (AFAIR I never got it). I know I got the above code to work and Ive glanced through the rest of the code to see if I did anything special somewhere else, but I cant find anything suspicious. Also, that project was for WinCE, but the page that explained how to catch the header notification was for the desktop so I assumed it would work there too. I wish I still had that link, but it was like 6 months ago so it probably went in the trashbin some time ago. Ill do a bit of research after work today and post here if I find anything usefull.
Christian Graus wrote:
and in the end I've concluded that CListCtrl is rubbish.
So true.
|
|
|
|
|
I did some testing yesterday. I create a subclassed CListCtrl in a childview and the only extra stuff I have is this in OnNotify (see below). It keeps the total column width to 240 the whole time and doesnt flicker at all (as opposed to the CE version of CListCtrl, which decides to draw the bottom scrollbar each time before I get a chance to resize the columns)
The only diffrence with this and the earlier version is that I look for HDN_xxxA and HDN_xxxW instead of just HDN_xxx.
Let me know if you still cant get it to work.
BOOL CNumbersListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
HD_NOTIFY *phdn = (HD_NOTIFY *)lParam;
switch(phdn->hdr.code)
{
case HDN_BEGINTRACKA:
case HDN_BEGINTRACKW:
{
TRACE(_T("CNumbersListCtrl::OnNotify -- HDN_BEGINTRACK Trapped\n"));
SetRedraw(false);
return(FALSE);
break;
}
case HDN_ENDTRACKA:
case HDN_ENDTRACKW:
{
int windowsize = 225;
TRACE(_T("CNumbersListCtrl::OnNotify -- HDN_ENDTRACK Trapped\n"));
SCROLLINFO si;
if (GetScrollInfo(SB_VERT, &si))
{
if ((int) si.nPage <= (si.nMax-si.nMin))
windowsize = 225;
else
windowsize = 240;
}
else
windowsize = 240;
if (phdn->iItem == 0)
{
int left = phdn->pitem->cxy;
TRACE(_T("CNumbersListCtrl::OnNotify -- Resize right to fit\n"));
SetColumnWidth(1, windowsize - left);
}
else if (phdn->iItem == 1)
{
int right = phdn->pitem->cxy;
TRACE(_T("CNumbersListCtrl::OnNotify -- Resize left to fit\n"));
SetColumnWidth(0, windowsize - right);
}
SetRedraw(true);
Invalidate();
break;
}
}
return CListCtrl::OnNotify(wParam, lParam, pResult);
}
|
|
|
|
|
Thanks - I had tried this but it just bombed out when I handled these messages. I'll have a look at this code to see what I was doing wrong.
I was actually trying to catch TRACKA and TRACKW though, I'm starting to think these are never sent.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|