|
Are you using MFC?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
Normally you cannot do this. The easiest way is to declare the DlgProc as a static member, but that will give you problems accessing other class members. You can also store the this pointer in a static member, and again add a static DlgProc then cast the pointer to access the class members, but this method causes problems when using more than one instance of the class. By far, the best method is to use a thunk.
|
|
|
|
|
I believe you are trying to make a wrapper class for handling dialog without using MFC ? If this is the case, there is a trick to do that. If not, then ignore my post
Ok, so member functions and global functions don't have the same parameters (the this parameter is passed to a member function). That's why you are getting this error. However there is a trick to do what you are looking for. I'm a little bit lazy to explain all in detail so I made a search on google, and I found this[^] piece of code that solve your problem. If you don't understand some parts, just ask.
Basically the idea is that you save the pointer to your class instance with SetWindowLong as user data and you get it back in your dialog procedure, so that you can cast it back to your class (and so, call a member function that will manage the messages).
Hope this helps
|
|
|
|
|
Thanks for your reply,
I tried that code. But now I get another error. "error C3861: 'Dialog': identifier not found, even with argument-dependent lookup" at at line "Dialog* pthis = (Dialog *)GetWindowLong( hWnd, GWL_USERDATA );"
maybe because that code is in MFC while I am using win32. Can I know how can I use the same with win32?
Priyank
|
|
|
|
|
Of course, I gave you the link so you have an example to understand how it work. If you copy paste it, it's normal that it won't work .
Dialog is the name of the class they use. Replace it by the name of your class (and isntead of copy/pasting the code, try to understand it, it is much more useful).
priyank_ldce wrote: maybe because that code is in MFC while I am using win32
Not at all, this code is pure Win32.
|
|
|
|
|
Oh sorry, Dialog is looking more like windows class or variable type not user class and I didn't check it. But it is working now . Thanks again.
Priyank
|
|
|
|
|
When using that method make sure that you only create one instance of the class. Because the this pointer is stored in a static member, all class instances will share the same value of that pointer. When dereferencing that pointer in your DlgProc, it will always be the same. I'm guessing that your code only needs one instance, but keep this in mind next time you try using this method (ie for a TimerProc).
|
|
|
|
|
Did you look at the link ??
It has nothing to do with storing the pointer as a static member. It stores the pointer using SetWindowLong and associate it with a windows handle. Thus, each time you have a new instance of your dialog, you also have another windows handle. So, you can perfectly have several instances of this class without any problem.
|
|
|
|
|
I do appologise, I had a quick glance at the article, perhaps a little too quick, and incorrectly thought it was an implementation of another method.
|
|
|
|
|
I know I should know the answer to this...
I want to round a number *down* to an integer multiple of another number.
% doesn't work on doubles / floats.
fmod does, but it has the same problem.
Using % or fmod, I can round a number towards 0. I want to round it towards negative infinity.
So,
rounddown(82,40) becomes 80.
rounddown(0,40) becomes 0;
rounddown(-39,40) becomes 0 as well, but I want -40!
I hope that explains things well enough.
Yours in need-of-more-caffeine-or-the-weekend,
Iain.
|
|
|
|
|
Mmmhh, maybe using floor()[^] ? You could divide the first number by the second (82/40=2.05 and -39/40=-0.975), then use floor, that will give you 2 and -1 (respectively) and finally multiply back by your second number: 2*40=80 and -1*40=40.
Hope this helps
|
|
|
|
|
#define ROUNDDOWN(number,base) ( base * floor (double(number) / double(base)) )
does the job perfectly, thanks Cedric. I didn't have the double()s in to start with, and I did get odd results when using integers....
Iain.
|
|
|
|
|
If you know that your first number was negative, and you actually rounded up, then just substract the second number from the result and you have rounded down.
Hope that helps.
|
|
|
|
|
My initial version did have (number < ) ? (....) : (...), but my adding / subtracting numbers messed it up further when I was on a number "boundary".
Cedric (38mins ago) gave me the clue (ie 99% of the work) I needed.
Thanks,
Iain.
|
|
|
|
|
I have created somewhat of a window wrapper class in non MFC. Within this class I have added the ablity for a user to attach their own window procedure. So basically I am dealing with two procedures. That of the class will either call the new attached procedure or call DefWindowProc(). This itself is not the problem. The problem is which messages should be handled within the class, which should be passed to the new procedure (bearing in mind the new procedure will call DefWindowProc). I read somewhere about a few messages that MUST be handled though now I am unable to find which messages, so could somebody please jog my memory.
|
|
|
|
|
nothing is so clear anywhere
it is recommended to call DefWindowProc after every
message you handle. But some times it is not a good idea.
suppose we want to override the look of a control in this case if we update the look ourself and then call DefWindowProc it will overwrite over operation.
so calling the default here not a good idea.
just remember that window functionality must not suffer.
otherwise Windows will get angry.
|
|
|
|
|
Hi.
I'm writing an application that it connects with a SQL database using ADO, and in many places it execute store procedures, but there is a routine that it doesn't work. This is the portion of code with the bug.
<br />
<br />
...<br />
Cmd->PutRefActiveConnection(pAdoCone);<br />
<br />
Cmd->CommandText = "ProductsInOrders";<br />
Cmd->CommandType = adCmdStoredProc;<br />
<br />
vtidProduct.vt = VT_I4;<br />
vtidProduct.intVal = (int)idProduct; <br />
<br />
paramID = Cmd->CreateParameter ("ProdID",adInteger,adParamInput,sizeof(int),vtidProduct);<br />
<br />
paramID->Value = vtidProduct;<br />
<br />
Cmd->Parameters->Append(paramID);<br />
<br />
Rs = Cmd->Execute(&vtMissing, &vtMissing, adCmdStoredProc); <br />
<br />
m_lstOrders.ResetContent();<br />
<br />
while (!Rs->adoEOF)<br />
{<br />
idOrder = Rs->GetFields()->GetItem("OrderID")->Value.iVal;<br />
<br />
data.Empty();<br />
<br />
data.Format("%i", idOrden); <br />
<br />
m_lstOrders.AddString (data);<br />
<br />
<br />
Rs->MoveNext(); <br />
}<br />
...<br />
Well, it looks like the store procedure return 0 records, that's why the flow never enter the while, but I test the SP in SQL, (SQL 2000), and it works, and there is more, I wrote a little VB 6.0 application to test the SP and it works too!!. So, there's something wrong, (maybe is something stupid but I can't see it now, I'm blind!). Debugging, I can see right values for the parameter idProduct, I think the Execute method is wrong, because everything goes well until that line, then I get an empty recordset.
If someone see what is wrong, I will really appreciate any suggestion.
Thanks.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
Hi,
I hawe a problem writing registry keys and values in registry under current user that has not administrator rights. We have an application that must work under common user priveleges but must install it under adin rights because we must register some activeX components. Is there a Way to write registry entries from one user to another. In some instalations I saw some options that say "use settings for all users"... if those settings are writen in the registry how can I access them and where are they stored.
I'm working in VS.NET 2002 in MFC.
Thanks in advance.
|
|
|
|
|
Just doing a quick peek, and you could use LogonUser , ImpersonateLoggedOnUser , etc.
Or CreateProcessWithLogonW...
You'd need the adminish name & password. But unless you knew them, you shouldn't be fiddling with HKLM anyway. That's the whole point of user security...
Iain.
|
|
|
|
|
Raul Simcic wrote: I saw some options that say "use settings for all users"... if those settings are writen in the registry how can I access them and where are they stored.
The area for common user data is [driveletter]:\Documents and Settings\All Users folder.
This doc explains in detail where you "should" store configuration stuff.
See section 3.0 Data and Settings Management
Designed for Windows XP Application Specification[^]
Maybe this will help you, maybe not
Mark
|
|
|
|
|
Typical practice with the registry is to store per-user settings under HKEY_CURRENT_USER\Software\<Company Name>\<Application Name> , and per-application (or 'all users') settings under HKEY_LOCAL_MACHINE\SOFTWARE\<Company Name>\<Application Name> .
The one difficulty with using the HKEY_LOCAL_MACHINE subkey is that normally, non-privileged users do not have write access to that part of the registry. You can have your installation modify the access control list to allow it, however.
Raul Simcic wrote: Is there a Way to write registry entries from one user to another
This is not something you want to do. What happens when users are added to or removed from a machine?
Software Zen: delete this;
|
|
|
|
|
Hi All,
I came across to a problem with the new Windows Vista - RC2, while using RegCreateKeyEx. I have a small function that sets a DWORD value to the Registry. It works fine on XP, but recently I used the Vista OS and I get an "Access Denied" Error (5).
Looking around the net I read about having to set the "access descriptor" within the SECURITY_ATTRIBUTES before passing to RegCreateKeyEx. But I haven't been able to find an example of doing that, or any other solution to my problem.
Forgot to mention: The error occurs when I try to set the ClearPageFileAtShutdown key to 1 within the HKEY_LOCAL_MACHINE, SYSTEM\CurrentControlSet\Session Manager\Memory Management.
#####################################################################
Here is the function that Im using:
LONG WriteRegDWORD( HKEY hKey, _TCHAR* sSubKey, _TCHAR* sKeyValueName, DWORD dwKeyValue )
{
DWORD dwDisp = 0;
SECURITY_ATTRIBUTES saSecAttr = {0};
HKEY hKeyHandle = NULL;
LONG Res = 0;
Res = RegCreateKeyEx( hKey, sSubKey, 0, _T(""), 0, KEY_ALL_ACCESS, &saSecAttr,
&hKeyHandle, &dwDisp );
if( Res == ERROR_SUCCESS )
{
Res = RegSetValueEx( hKeyHandle, sKeyValueName, 0, REG_DWORD, (LPBYTE)&dwKeyValue,
(DWORD)sizeof(DWORD) );
if( Res != ERROR_SUCCESS )
{
_tprintf(_T("ERROR: %d \n"), Res );
}
RegCloseKey(hKeyHandle);
}
else
{
_tprintf( _T("ERROR: %d \n"), Res );
}
return Res;
}
#####################################################################
If anyone has a suggestion or solution to my problem I will highly appreciated.
Thank you,
Nick
-- modified at 7:38 Friday 20th October, 2006
|
|
|
|
|
This should help.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thank you DavidCrow,
But unfortunately this example didn't help.
To be more precise to the particular example, the call to RegOpenKeyEx returns "access denied" under Windows Vista RC2 when trying to open key HKEY_LOCAL_MACHINE, System\CurrentControlSet\Control\Session Manager\Memory Management.
Thank you,
Nick
|
|
|
|
|