|
Note the other subtle change he suggested.
m_List.ClientToScreen(&point);
you used "ClientToScreen" in the context of your dialog, he's suggesting doing "ClientToScreen" in the context of the m_List control. He's changing which client's windows coordinate system to interpret the "point".
|
|
|
|
|
I got ideea, and solve the problem. Thank yyou very much !
|
|
|
|
|
Dear all, I have a problem with implementing getter and setter type class in visual C++.
Hope somebody can help me. Let me first explain the detail of my code first.
I have 3 classes separated in .cpp and .h files
- SaveClass.cpp and SaveClass.h
= stores all variable values
- Class2.cpp and Class2.h
= call Set function of "SaveClass" class to set the value
- Class1.cpp and Class1.h
= call Get function of "SaveClass" class to get the value
the codes for three class are as follows:
1. SaveClass.h
class SaveClass
{
public:
SaveClass(void);
~SaveClass(void);
int Get() const;
int Set(int var);
private:
int testVariable;
};
2. SaveClass.cpp
#include "SaveClass.h"
SaveClass::SaveClass(void){testVariable = 1;}
SaveClass::~SaveClass(void){}
int SaveClass::Get() const{return testVariable;}
int SaveClass::Set(int var){
testVariable = var;
return testVariable;
}
3. Class2.h
class Class2
{
public:
Class2(void);
~Class2(void);
int function2(void);
};
4. Class2.cpp
#include "SaveClass.h"
int Class2::function2(void)
{
SaveClass coba;
int setNumber=2;
coba.Set(setNumber);
cout << "Value for Set : " << setNumber << endl;
return 0;
}
5. Class1.h
class Class1
{
public:
Class1(void);
~Class1(void);
void function1();
};
6. Class1.cpp
void Class1::function1()
{
SaveClass coba2;
int values = coba2.Get();
cout << "Value from Get : " << values << endl;
}
when I make new class (4th class) and call function2() and function1(), command window shows:
Value for Set : 2
Value from Get : 1
It suppose to be:
Value for Set : 2
Value from Get : 2
but from the result I got 2 and 1. My question is how can I make it correct (Value for Set : 2 and Value from Get : 2)? Thanks for all your help guys.
|
|
|
|
|
The problem is that you're making the objects of class saveclass as stack variables, meaning they will be deleted when they're out of scope (i.e. at the end of the function where you called them).
You have a couple options:
0. If those two classes are controlled from a single place, you can place your saveclass object there and just pass the pointer to it to the classes that use it. This allows you to have multiple saveclass objects independent of one another.
1. You can make the saveclass storage variables be static, meaning they're independent of instance. If you do this, you can use your calls as you have them in your code, you'll just have to initialize your static variables outside of the class methods.
|
|
|
|
|
Dear Albert, Thank you so much for your help. I chose second option and its working perfectly . I just changed this part below and its working just like I want.
1. SaveClass.h
class SaveClass
{
public:
SaveClass(void);
~SaveClass(void);
int Get() const;
int Set(int var);
};
static int testVariable_static = 1;
2. SaveClass.cpp
int SaveClass::Get() const
{
return testVariable_static;
}
int SaveClass::Set(int var)
{
testVariable_static = var;
return testVariable_static;
}
|
|
|
|
|
Just to give you some follow-up advice, by declaring your static outside of your class, you've just made him a global variable. Now anyone can access him and he's polluting your global namespace.
If you want to keep him both private and keep him contained within SaveClass. Declare it inside of SaveClass and instantiate him in the cpp file.
class SaveClass
{
public:
SaveClass(void);
~SaveClass(void);
int Get() const;
int Set(int var);
private:
static int m_testVariable;
};
int SaveClass::m_testVariable = 1;
|
|
|
|
|
Hi,
would anyone know the message that is genertasted by the FrameWork for CASynsocket::OnConnect
as my connect fails with 10035 WSAEWOULDBLOCK however my OnConnect overridlable is never called
|
|
|
|
|
Internally, this is based on a callback scheme and using WM_SOCKET_NOTIFY . You shouldn't try to intercept that message though because it gets sent to an internal window in CAsyncSocket (so, yes... if you intercept the message, you'll essentially break what the framework is trying to do).
|
|
|
|
|
I have a child window showing a custom message with notification icons in it. I am showing that on the title bar of parent window and I am calling OnPaint of the child window in the OnPaint of the parent window frame class.
Issue:
How can I find the color of the parent window title bar so that I can use the same color in the child window? I want the child window to blend in with the parent window title bar.
|
|
|
|
|
If you use the MFC framework, the title bars should already be the same color (that's managed by the framework, since the OS allows you to change the theme colors). So, not sure what king of setup you have going on, maybe show some code, of importance would be how you're deriving your classes and your custom OnPaint.
|
|
|
|
|
There is a GetPixel[^] API that you can use which will give you the color value for a point on a window that belongs to a device context.
|
|
|
|
|
Hello,
from a MFC program I need to send data to an external USB Device.
System: Windows XP SP3, MS Visual Studio 2008, WinDDK (most current).
Because I don't have any valid documentation I used a sniffer showing me the used commands.
GET_DESCRIPTOR_FROM_DEVICE and BULD_OR_INTERRUPT_TRANSFER
Using CreateFile I can successfull connect to the device.
But I failed to use DeviceIoControl.
HANDLE result = CreateFile(dev_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
USBSCAN_GET_DESCRIPTOR data1;
DWORD bytesReturned;
BOOL b = DeviceIoControl(handle, IOCTL_GET_USB_DESCRIPTOR, NULL, 0, &data1, sizeof(USBSCAN_GET_DESCRIPTOR), &bytesReturned, NULL);
Error C2065 "USBSCAN_GET_DESCRIPTOR"
After including "usbscan.h" I get C2065 on METHOD_BUFFERED and FILE_ANY_ACCESS and C3861 on CTL_CODE.
When including wdm.h I get about 107 errors in driverspecs.h and kernelspecs.h.
So please, can anybody help me to get this run.
Thanks
Stefan
|
|
|
|
|
What is the USB device? It could be a USB com port, a USB network card for example. If so use the usual API to access it. COM API or sockets.
Dont forget USB is just the protocol between the system and the hardware, at the app level it really is irrelevant.
==============================
Nothing to say.
|
|
|
|
|
Hello,
its a medical device having leds. I have the commandsets to enable or disable them.
But I cannot send any commands.
Stefan
|
|
|
|
|
How does the system see the device? ie, in DeviceManager.
==============================
Nothing to say.
|
|
|
|
|
Hello,
it shows under "custom usb devices" as "[Company Name] Familiy Device".
Stefan
|
|
|
|
|
Hmm, so its not presenting itself as a well known device then. What sort of driver is sitting on the device? (ie what are the names)
Is there an inf file with a custom driver for example? If so you will need documentation on the interface to that driver. The mnuf should be able to provide it.
==============================
Nothing to say.
|
|
|
|
|
solved
http://www.codeguru.com/forum/showthread.php?p=2053720
|
|
|
|
|
I'm thinking it would be a wee more efficient if winioctl.h and usbscan.h were added to the project's stdafx.h file.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hi
I am trying to use "InvalidateRect" to paint part of screen. When I move a drawing a little faster, there will be some dirty left on screen.
How can I get rid of the screen dirty? Some code sample would be appreciated.
Best,
|
|
|
|
|
transoft wrote: there will be some dirty left on screen.
Please clarify, it is not clear where this occurs or what exactly you are referring to. You could also show some of the code you use to repaint your window.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thank you for your reply.
I just used following code:
InvalidateRect( rect, true );
Then I picked one drawing using mouse and drag it ( move it) to other place. when I move the drawing very slow (using mouse to move it slowly), it looks OK. But a little bit faster, there will be some dirty (some drawing not cleared) left on screen. Is there a way to avoid this?
Best,
|
|
|
|
|
transoft wrote: Is there a way to avoid this?
Yes, but I cannot recall the method. I think it's something to do with capturing the mouse and delaying repaint of the Window. Try a search on MSDN for what you are doing and see if you get any good hits.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
What are you invalidating? ...this may be caused by you invalidating only a small portion of a window independent of the rest of the window (causing unnecessary redraws) or by invalidating somewhere where you probably shouldn't (also causing unnecessary redraws).
You really need to share more of the code for a more definitive solution.
|
|
|
|
|
Yes, I just want to invalidate the drawing area that I am moving.
What I am doing is:
(1) while "mouse moving", I send out "InvalidateRect".
(2) do the Invalidating job
I think the problem coming from the delay "InvalidateRect" and actual paint. I also tried "RedrawWindow" without any success.
Thank you for your reply!
|
|
|
|