|
Bob Stanneveld wrote:
is there already a function call, message, notification or whatever that retreives the previous selected item for me or do I have to add this little simple feature myself?
Yes and yes.
Bob Stanneveld wrote:
Ofcouse I can implement this simple thing, but it would make my code more clean and elagent if I was using an existing feature (if there is one) than reinveting the wheel...
It's a simple matter of handling the LBN_SELCHANGE notification.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
DavidCrow wrote:
It's a simple matter of handling the LBN_SELCHANGE notification.
If it was that simple, why do I get the index of the newly selected item instead of the item that is deselected (the previous selection)?
My current solutions is as follows: I keep 2 variables: the first (nPrevSel) is the previous selection (or -1 if there is none) and the second (nCurSel) for the current selection. In the OnSelChange() handler, I set nPrevSel to nCurSel and nCurSel becomes equal to CListBox::GetCurSel() .
I do not find this and elegent solution, but I don't think that there is a solution like as elegant as CListBox::GetCurSel() .
I also got the blogging virus..[^]
|
|
|
|
|
Bob Stanneveld wrote:
My current solutions is as follows: I keep 2 variables: the first (nPrevSel) is the previous selection (or -1 if there is none) and the second (nCurSel) for the current selection. In the OnSelChange() handler, I set nPrevSel to nCurSel and nCurSel becomes equal to CListBox::GetCurSel().
This is exactly how it is done. I don't find it inelegant at all.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Bob Stanneveld wrote:
I have a listbox in my dialog. I added a handler for the CBN_SELCHANGE notification
Did you mean LBN_SELCHANGE ?
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hello,
I have a listbox control and I was catching the CBN_SELCHANGE notification (which actually worked ). No I catch the LBN_SELCHANGE, which also workes. This lets me believe that they are the same..
Now I'm using that notification.
I also got the blogging virus..[^]
|
|
|
|
|
I have used Visual Studio 6 for a long time and I like the multiple, non maximized windows. For one thing I can put one window next to another and compare them. Also I can use a dual monitor system and have different windows on different monitors.
Visual Studio 7.0 has nice Property pages etc, which fold away into the edge of the screen, but I can see only one window of source code which is maximized to fill all the rest of the space.
What I would REALLY like is the best of both worlds, with Property pages which fold away AND multiple source windows which don't fill the whole area.
If I can't get my wish list, I'd settle for the vs6.0 look, where I can at least see multiple windows.
Any suggestions?
Thanks,
Ilan
|
|
|
|
|
|
This one is really driving me nuts! I am creating a dialog using the following code:
<br />
if (!::IsWindow(pPS->pDlg->m_hWnd)){<br />
pPS->pDlg->Create(IDD_CFG_DLG, this); <br />
}<br />
HWND hwndParent = ::GetParent(pPS->pDlg->m_hWnd); <br />
The creation happens after the OnInitDialog() of the main application window (a dialog) and everything seems to return success except for the GetParent() call which I am expecting to return my main dialog's m_hWnd. The IDD_CFG_DLG does have the "CHILD" style set and no border if that matters (I don't think it does).
I have also tried forcing the parent by calling SetParent() but even though it returns no error, the result is the same - the parent of the created dialog is still NULL!
What am I doing wrong here?
Thanks,
Dave
|
|
|
|
|
Hi all !
I would like to protect a standard C struct with a CRC in order to check if the structure contains valid information.
A wrote a small demo program with a standard C structure as member. If I read any element of the structure the checksum should be checked for correctness. If I write any element of the structure the checksum has to be recalculated. I would like to do that by overloading the -> operator.
In the demo program the call of the -> operator function works fine. However I have the problem to check if there is a Read- or Writeaccess. How can I check if an expression like
x->deviceData.HW_Version is used within a write or a read context ?
sincerly
Manfred
#include "stdafx.h"
#include <stdio.h>
// --- standard C structure ------------------------------
typedef
struct
{
int SW_Version ;
int HW_Version ;
unsigned long SerialNumber ;
} DeviceData ;
// --- class with CRC functionality ------------------------
class CCrc
{
public:
unsigned short crc ;
} ;
class CrcClass : public CCrc
{
public:
DeviceData deviceData ;
void CheckCrc() ;
CrcClass * operator->() ;
};
CrcClass * CrcClass::operator->()
{
CheckCrc() ;
return this;
};
void CrcClass::CheckCrc()
{
if( 1 ) // throw Exception for test
{
throw "Invalid Checksum !!!!\r\n" ;
}
};
int main(int argc, char * argv[])
{
CrcClass x ;
try
{
x->deviceData.HW_Version = 111 ;
x->deviceData.SW_Version = 222 ;
x->deviceData.SerialNumber = 333 ;
printf("%d", x->deviceData.HW_Version );
printf("%d", x->deviceData.SW_Version );
printf("%d", x->deviceData.SerialNumber );
}
catch( char * exMessage )
{
printf("%s", exMessage ) ;
}
return 0;
}
|
|
|
|
|
You should really use Get/Set methods and put your member variables as private.
In each Getter and Setter you can check the CRC.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Honnestly I found that overriding the -> in this case is not really appropriate. It breaks the 'natural law' for objects and pointers. Here, you have an object (that is not a pointer !) and you will access it's member variable as if it was a pointer ! So that's really strange...
This operator is sometimes overriden in some very specific cases like for example when it must be 'seen' as a pointer (a class that wraps a pointer for example). The best example is the 'smart pointers'. It's a class that wraps a pointer and handle all the memory management for this pointer (ok, I won't describe the functionality of the smart pointers...). So there is here a purpose for overloading this operator: give the class the same 'feel' as it was a real pointer !
In your case, it has nothing to do with pointers at all so your code look like you access your member variable as if the object was a pointer...
Otherwise, I don't see why you want to use so complicated things: why don't you just write a function that will check this ?? And there is no way to know if the operator is read for reading or writing as far as I know (I might be wrong...).
|
|
|
|
|
i want to make program for start service or stop services from source code
|
|
|
|
|
|
i want to make on function in vc++ so its always give
me random number between 0 and 100 .plz give me complete solution
|
|
|
|
|
Good luck. The best you can do is to use rand() to get a pseudo-random number. Something like:
int x = rand() % 101;
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Here is an example for you :
#include <stdlib.h>
#include <time.h>
int main( void )
{
int i;
// Seed the random-number generator with current time so that numbers will be different every time we run.
srand( (unsigned)time( NULL ) );
// Now generate random number 0-100
i = rand()%101;
// Write out
printf("%d",i);
}
m0n0
|
|
|
|
|
if you don't care the numerical distribution within the function, use the rand()%101 as others have recommended. Pay attention to inclusive verses exclusive. rand()%101 will give you results 0..100 inclusive. rand()%99+1 will give you 1-99 range (or 0..100 exclusive).
There are no "perfect" random number generators, there is only the best for your needs. For 99.9% of random number needs, a rand()%n distribution for 0..(n-1) range is sufficient. If you have need of better attempts at uniform and non-uniform distribution random generators, you can google on the subject, or visit the boost library set.
http://www.boost.org/libs/random/index.html[^]
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
Hi all,
I'm implementing a COM Server (using attributed ATL 7) running as a windows service. During the build process VC (Visual C++ .NET 2003) generates the necessary IDL code and when done it registers the service.
The service registration (which I assume is carried out by running "myserver /RegServer") fails however, and a messagebox appears stating that "The program can not be started because the some_dll.dll could not be found...".
My app uses two custom dll's and I am sure that they are in my "path" variable since it is no problem to start the application in debug mode from within VC.
If I put the dll's in my working directory though, the server registration succeeds.
Does anyone know why the registration fails if the dll's are not put in my working directory? Why does it seem as the service registration process is not searching my "path" for dlls?
/Rillbert
|
|
|
|
|
This would be my first guess: There are two paths. One for the user and one for the system. A NT service typically runs under LOCALSYSTEM account, in which case it might not have access to the 'user' path variable but it does to the 'system' path variable. Check your 'path' variable and make sure the place you want to put the DLL is in the 'path' assigned to the system.
|
|
|
|
|
hi
please tell me how can i convert hex value to normal charactor string programatically
e.g.
44,00,3a,00,5c,00,44,00,6f,00,63,00,75,00,6d,00,65,00,6e,00, 74,00,73,00,20,00,61,00,6e,00,64,00,20,00,53,00,65,00,74,00, 74,00,69,00,6e,00,67,00,73,00,5c,00,41,00,6d,00,6f,00,6c,00, 2e,00,41,00,4d,00,4f,00,4c,00,5c,00,4c,00,6f,00,63,00,61,00, 6c,00,20,00,53,00,65,00,74,00,74,00,69,00,6e,00,67,00,73,00, 5c,00,41,00,70,00,70,00,6c,00,69,00,63,00,61,00,74,00,69,00, 6f,00,6e,00,20,00,44,00,61,00,74,00,61,00,5c,00,4d,00,69,00, 63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,5c,00,4f,00,75,00, 74,00,6c,00,6f,00,6f,00,6b,00,5c,00,4f,00,75,00,74,00,6c,00, 6f,00,6f,00,6b,00,2e,00,70,00,73,00,74,00,00,00
want to convert in normal string pls send me pcs of code in c++
Thanking you
Manoj Jangid
|
|
|
|
|
|
Jangid wrote:
please tell me how can i convert hex value to normal charactor string programatically
e.g.
44,00,3a,00,5c,00,44,00,6f,00,63,00,75,00,6d,00,65,00,6e,00, ...
What do you mean by "normal charactor string"?
|
|
|
|
|
That looks like a UNICODE string. Notice the 3 sets of NUL bytes at the end... I suspect if he loaded the entire data set into a buffer and called WideCharToMultiByte, he would end up with a 'normal 'string.
|
|
|
|
|
Try this approach,It will definitely work.I have tried in my code
char _hex_buf[4] = "12A";
int _hexdata;
sscanf(_hex_buf,"%x",&_hexdata);
Regards
Pankaj
|
|
|
|
|
I have solved the 1010 compiler error unexpected EOF by deleting dependencies with *.pch files.Now I have linker error LNK2001 unresolved external symbol _winmain@16.Please help.This is my code:
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmd,int nCmdShow )
{
int brojevi[9];
brojevi[0]=3;
int s;
s=1;
brojevi[s] = brojevi[0];
while(s<9)
{
brojevi[s]=brojevi[s]*3+8;
s++;
}
s=0;
while(s<9)
printf("\nbrojevi[%d] = %d",s,brojevi[s]);
return 0
};)
|
|
|
|
|