|
You have been at this for two weeks now. You should be posting information about what you have tried along with how and why it did not work as expected.
Off by one thread error Last modified: Friday, June 30, 2006 10:22:50 AM -- posting error by user - led mike
|
|
|
|
|
The short answer is: You can pass it any way you want to.
The long answer is: There are some good ways, and some bad ways of doing this depending on what you are trying to do.
If you can be more specific about the architecture (e.g. are the forms/dialogs that need access to this object going to be writing to it, or just reading from it? are they only going to need part of the information for each dialog? etc), more details can be given about how you might want to implement it.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I basically used the standard Windows forms project to start off. The .cpp, with the main(), that Visual Studio automatically creates is used to run the thread that launches my main form. The main form allows me to modify and view the status of my object, which interacts with various hardware cards and other. From that form, I have one sub-layer of forms that allow me to modify specific aspects of the object. Each form, except the main one, typically modifies or views information about one portion of the object, such as a card it interacts with. So I need to both write and read from the object within both layers of forms.
To answer the post of the next person, I have already separated my application based on the Model-View-Controller pattern. I simply do not know how to give access to the object to each form, since each form is a class.
I hope this helps you in answering me. I am hoping you will be able to suggest one of the good ways to give access.
Thanks in advance.
kialmur
|
|
|
|
|
kialmur wrote: To answer the post of the next person, I have already separated my application based on the Model-View-Controller pattern. I simply do not know how to give access to the object to each form, since each form is a class.
So each form is a "view" in the design and uses the "controler" to send messages into the other isolated objects in the design.
kialmur wrote: So I need to both write and read from the object within both layers of forms.
Well not directly that is why you have the MVC design. The forms don't know about the object just the controller and events. So the forms call methods of the controller which results in the "write" operations. Some other object(s) should be performing the "read" operations which then results in an "event" that the forms can subscribe to. The event can contain the data directly or the data can be sent into the "model" in the design at "read" time and then when the form event handler fires it can access the data through the "model" object.
Does that help?
|
|
|
|
|
I understand what you are saying about the controller. However, how do I access the controller functions from the forms. If I wrap them in a class, they become hard to access from the forms because I have to pass a pointer to the class object or use some other method. I can make the functions public, but I would prefer not to, naturally. How do I make my controller functions available to my forms in Visual Studio or any other software?
kialmur
|
|
|
|
|
That depends on your use model. In some use models controllers can just be instantiated whenever needed by the "view", other use models might require a Singleton design. With most good designs passing pointers about is rarely necessary.
|
|
|
|
|
Thanks. I cannot simply reinstantiate a new controller each time, but the Singleton design works for me.
kialmur
|
|
|
|
|
One way to to this is to create a set of abstract classes (aka interfaces), have your object class implement the methods for those interfaces, and pass a pointer to the proper interface to the respective dialog (either at construction, or via a member function).
For example:
class IPersonalInfo
{
public:
void setName(const std::string& name) = 0;
void setAddress(const std::string& addr) = 0;
const std::string& getName() const = 0;
const std::string& getAddress() const = 0;
};
class IFavoriteMovie
{
public:
void setMovie(const std::string& movie) = 0;
const std::string& getMovie() const = 0;
};
class MyData : public IPersonalInfo, public IFavoriteMovie
{
public:
MyData() : _Name(""), _Address(""), _FavMovie("")
{}
void setName(const std::string& name) { _Name = name; }
void setAddress(const std::string& addr) { _Address = addr; }
const std::string& getName() const { return _Name; }
const std::string& getAddress() const { return _Address; }
void setMovie(const std::string& movie) { _FavMovie = movie; }
const std::string& getMovie() const { return _FavMovie; }
private:
std::string _Name;
std::string _Address;
std::string _FavMovie;
};
class CMainDialog : public CDialog
{
...
private:
MyData _MyData;
};
class CPersonalInfoDialog : public CDialog
{
public:
CPersonalInfoDialog(IPersonalInfo* pInfo);
...
};
class CFavoriteMovieDialog : public CDialog
{
public:
CFavoriteMovieDialog(IFavoriteMovie* pInfo);
...
};
The dialogs would operate on your data via the interfaces.
There are other ways of doing it, and all have their pro's and con's.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
|
Lets say, i have this simple dialog box, with a "load picture" button (which i've got it working), with a few clicks, the picture is able to be displayed in the frame. Afterwhich, -=Here Comes My questions=- how do i encrypt the picture and displaying it with the original image side by side?? (The frames are there side by side just that i do not know how to encrypt and display it ) Afterwhich, how to i save it? so That i can load it for decryption?? Please help me thanks
Thanks
|
|
|
|
|
You have been at this for two weeks now. You should be posting information about what you have tried along with how and why it did not work as expected.
|
|
|
|
|
If you encrypt the image as a whole, it will no longer be identifiable as an image. The results of attempting to display it would be, for lack of a better term, undefined. If you want to still view the image after it is encrypted, then you will need to access the bits and encrypt them. The result will be somewhat unpleasant to look at but that sounds more like what you are after.
In GDI+, the bitmap object supports accessing the raw bits with "LockBits()". The scan lines can have dead space at the ends to properly align. This depends on the color depth. However, since your encrypting, this deadspace will only add to the distortion when viewing so you probably don't need to account for it when processing as long as it is preserved when you decrypt.
I think you will need to resist any temptation to change the PixelFormat since you will be leaving the rest of the image file structure intact.
Good luck!
|
|
|
|
|
Does anyone know a callback or hook for this? I am basically interested in a very specific network adapter, and need to know when it has been plugged in, or removed.
I can poll for this, but would rather just wait for an event.
|
|
|
|
|
Can you not use the ISensNetwork interface for this?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Receiving Connection Notifications[^]
Applications interested in receiving advance and after-the-fact notification of connection events must supply a DLL that exports two functions, AddConnectNotify and CancelConnectNotify.
Registering to Receive Connection Notifications [^]
After you have created a DLL to receive connection notifications, you must register it with the system. You do this by adding a REG_EXPAND_SZ value under the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\Notifyees key. This value specifies the path to the DLL that implements the Connection Notification API.
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Exactly how would AddConnectNotify() or CancelConnectNotify() help in detecting when a network cable has been un/plugged?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Apparently you missed the CancelConnectNotify portion of the previous post.
|
|
|
|
|
Nope, didn't miss it at all. Neither function seems to go with what the OP requested.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow,
Thanks for the vote of 1, I have returned the favor.
Actually, you should not answer questions if you do not know the answer. In fact, by registering for MPR notifications you can detect connections and disconnections of network resources, including type RESOURCEDISPLAYTYPE_NETWORK which equates to a cat-5 cable being plugged and thus connecting to a network resource.
Here is some sample code:
Enjoy.
<br />
#define UNICODE<br />
#define _UNICODE<br />
<br />
#include <windows.h><br />
#include "npapi.h"<br />
<br />
BOOL FormatAddFlags(DWORD, LPTSTR);<br />
BOOL FormatNetResource(LPNETRESOURCE, LPTSTR);<br />
<br />
DWORD dwCounter = 0;<br />
<br />
BOOL APIENTRY DllMain(HANDLE hModule, DWORD reason, LPVOID lpResv)<br />
{<br />
return TRUE;<br />
<br />
}<br />
<br />
DWORD APIENTRY AddConnectNotify(LPNOTIFYINFO lpNotifyInfo,<br />
LPNOTIFYADD lpAddInfo)<br />
{<br />
<br />
TCHAR sz[1024], sz1[1024];<br />
<br />
<br />
if (lpNotifyInfo->dwNotifyStatus == NOTIFY_PRE) {<br />
lstrcpy(sz, TEXT("Pre-Add:"));<br />
dwCounter++;<br />
lpNotifyInfo->lpContext = (VOID *)dwCounter;<br />
} else if (lpNotifyInfo->dwNotifyStatus == NOTIFY_POST) {<br />
wsprintf(sz, TEXT("Post-Add (%x):"), <br />
lpNotifyInfo->dwOperationStatus);<br />
} else {<br />
lstrcpy(sz, TEXT("Other-Add:"));<br />
}<br />
<br />
wsprintf(sz1, TEXT("Context=%x"), <br />
(DWORD)lpNotifyInfo->lpContext);<br />
lstrcat(sz, sz1);<br />
<br />
if (FormatAddFlags(lpAddInfo->dwAddFlags, sz1)) {<br />
lstrcat(sz, sz1);<br />
}<br />
<br />
<br />
if (FormatNetResource(&(lpAddInfo->NetResource), sz1)) {<br />
lstrcat(sz, sz1);<br />
}<br />
<br />
MessageBox(lpAddInfo->hwndOwner, sz, TEXT("Connect"), MB_OK);<br />
<br />
return WN_SUCCESS;<br />
<br />
}<br />
<br />
DWORD APIENTRY CancelConnectNotify(LPNOTIFYINFO lpNotifyInfo,<br />
LPNOTIFYCANCEL lpCancelInfo)<br />
{<br />
<br />
TCHAR sz[1024], sz1[1024];<br />
<br />
<br />
if (lpNotifyInfo->dwNotifyStatus == NOTIFY_PRE) {<br />
lstrcpy(sz, TEXT("Pre-Cancel:"));<br />
dwCounter++;<br />
lpNotifyInfo->lpContext = (VOID *)dwCounter;<br />
} else if (lpNotifyInfo->dwNotifyStatus == NOTIFY_POST) {<br />
wsprintf(sz, TEXT("Post-Cancel (%x):"), <br />
lpNotifyInfo->dwOperationStatus);<br />
} else {<br />
lstrcpy(sz, TEXT("Other-Cancel:"));<br />
}<br />
<br />
wsprintf(sz1, TEXT("Context=%x"), <br />
(DWORD)lpNotifyInfo->lpContext);<br />
lstrcat(sz, sz1);<br />
<br />
if (lpCancelInfo->lpName != NULL) {<br />
lstrcat(sz, TEXT(", Name="));<br />
lstrcat(sz, lpCancelInfo->lpName);<br />
}<br />
<br />
if (lpCancelInfo->lpProvider != NULL) {<br />
lstrcat(sz, TEXT(", Provider="));<br />
lstrcat(sz, lpCancelInfo->lpProvider);<br />
}<br />
<br />
if (lpCancelInfo->dwFlags & CONNECT_UPDATE_PROFILE) {<br />
lstrcat(sz, TEXT(", Flags=PersistentCancel"));<br />
} else {<br />
wsprintf(sz1, TEXT(", Flags=(%x)"), lpCancelInfo->dwFlags);<br />
lstrcat(sz, sz1);<br />
}<br />
<br />
if (lpCancelInfo->fForce) {<br />
lstrcat(sz, TEXT(", Force=TRUE"));<br />
} else {<br />
lstrcat(sz, TEXT(", Force=FALSE"));<br />
}<br />
<br />
MessageBox(NULL, sz, TEXT("Connect"), MB_OK);<br />
<br />
return WN_SUCCESS;<br />
<br />
}<br />
<br />
<br />
BOOL FormatAddFlags(DWORD dwAddFlags, LPTSTR psz)<br />
{<br />
TCHAR szTemp[MAX_PATH];<br />
<br />
lstrcpy(psz, TEXT(", AddFlags="));<br />
<br />
if (dwAddFlags & CONNECT_TEMPORARY) {<br />
lstrcat(psz, TEXT("Temporary "));<br />
}<br />
if (dwAddFlags & CONNECT_INTERACTIVE) {<br />
lstrcat(psz, TEXT("Interactive "));<br />
}<br />
if (dwAddFlags & CONNECT_PROMPT) {<br />
lstrcat(psz, TEXT("Prompt "));<br />
}<br />
if (dwAddFlags & CONNECT_UPDATE_PROFILE) {<br />
lstrcat(psz, TEXT("UpdateProfile "));<br />
} <br />
if (dwAddFlags & CONNECT_UPDATE_RECENT) {<br />
lstrcat(psz, TEXT("UpdateRecent "));<br />
}<br />
<br />
wsprintf(szTemp, TEXT("(%x)"), dwAddFlags);<br />
lstrcat(psz, szTemp);<br />
<br />
<br />
return TRUE;<br />
<br />
}<br />
<br />
BOOL FormatNetResource(LPNETRESOURCE lpNetResource, LPTSTR psz)<br />
{<br />
<br />
TCHAR szTemp[MAX_PATH];<br />
<br />
*psz = 0;<br />
<br />
<br />
switch(lpNetResource->dwScope) {<br />
case RESOURCE_CONNECTED:<br />
lstrcpy(psz, TEXT(", Scope=Connected"));<br />
break;<br />
<br />
case RESOURCE_GLOBALNET:<br />
lstrcpy(psz, TEXT(", Scope=GlobalNet"));<br />
break;<br />
<br />
case RESOURCE_CONTEXT:<br />
lstrcpy(psz, TEXT(", Scope=Context"));<br />
break;<br />
<br />
default:<br />
wsprintf(szTemp, TEXT(", Scope=%x"), lpNetResource->dwScope);<br />
lstrcpy(psz, szTemp);<br />
break;<br />
}<br />
<br />
<br />
switch(lpNetResource->dwType) {<br />
case RESOURCETYPE_DISK:<br />
lstrcat(psz, TEXT(", Type=Disk"));<br />
break;<br />
<br />
case RESOURCETYPE_PRINT:<br />
lstrcat(psz, TEXT(", Type=Printer"));<br />
break;<br />
<br />
case RESOURCETYPE_ANY:<br />
lstrcat(psz, TEXT(", Type=Any"));<br />
break;<br />
<br />
default:<br />
wsprintf(szTemp, TEXT(", Type=%x"), lpNetResource->dwType);<br />
lstrcat(psz, szTemp);<br />
break;<br />
}<br />
<br />
<br />
switch(lpNetResource->dwDisplayType) {<br />
case RESOURCEDISPLAYTYPE_NETWORK:<br />
lstrcat(psz, TEXT(", DisplayType=Network"));<br />
break;<br />
<br />
case RESOURCEDISPLAYTYPE_DOMAIN:<br />
lstrcat(psz, TEXT(", DisplayType=Domain"));<br />
break;<br />
<br />
case RESOURCEDISPLAYTYPE_SERVER:<br />
lstrcat(psz, TEXT(", DisplayType=Server"));<br />
break;<br />
<br />
case RESOURCEDISPLAYTYPE_SHARE:<br />
lstrcat(psz, TEXT(", DisplayType=Share"));<br />
break;<br />
<br />
case RESOURCEDISPLAYTYPE_DIRECTORY:<br />
lstrcat(psz, TEXT(", DisplayType=Directory"));<br />
break;<br />
<br />
case RESOURCEDISPLAYTYPE_GENERIC:<br />
lstrcat(psz, TEXT(", DisplayType=Generic"));<br />
break;<br />
<br />
default:<br />
wsprintf(szTemp, TEXT(", DisplayType=%x"), <br />
lpNetResource->dwDisplayType);<br />
lstrcat(psz, szTemp);<br />
break;<br />
}<br />
<br />
<br />
lstrcat(psz, TEXT(", Usage="));<br />
<br />
if (lpNetResource->dwUsage & RESOURCEUSAGE_CONNECTABLE) {<br />
lstrcat(psz, TEXT("Connectable "));<br />
}<br />
if (lpNetResource->dwUsage & RESOURCEUSAGE_CONTAINER) {<br />
lstrcat(psz, TEXT("Container "));<br />
}<br />
if (lpNetResource->dwUsage & RESOURCEUSAGE_NOLOCALDEVICE) {<br />
lstrcat(psz, TEXT("NoLocalDevice "));<br />
}<br />
if (lpNetResource->dwUsage & RESOURCEUSAGE_SIBLING) {<br />
lstrcat(psz, TEXT("Sibling "));<br />
}<br />
if (lpNetResource->dwUsage & RESOURCEUSAGE_ATTACHED) {<br />
lstrcat(psz, TEXT("Attached "));<br />
}<br />
<br />
wsprintf(szTemp, TEXT("(%x)"), lpNetResource->dwUsage);<br />
lstrcat(psz, szTemp);<br />
<br />
<br />
if (lpNetResource->lpLocalName != NULL) {<br />
lstrcat(psz, TEXT(", LocalName="));<br />
lstrcat(psz, lpNetResource->lpLocalName);<br />
}<br />
<br />
if (lpNetResource->lpRemoteName != NULL) {<br />
lstrcat(psz, TEXT(", RemoteName="));<br />
lstrcat(psz, lpNetResource->lpRemoteName);<br />
}<br />
<br />
if (lpNetResource->lpComment != NULL) {<br />
lstrcat(psz, TEXT(", Comment="));<br />
lstrcat(psz, lpNetResource->lpComment);<br />
}<br />
<br />
if (lpNetResource->lpProvider != NULL) {<br />
lstrcat(psz, TEXT(", Provider="));<br />
lstrcat(psz, lpNetResource->lpProvider);<br />
}<br />
<br />
return TRUE;<br />
}<br />
<br />
|
|
|
|
|
Randor wrote:
Thanks for the vote of 1, I have returned the favor.
You have made an erroneous assumption. I do not vote on posts, nor do I care how posts are voted upon. So your vote of 1 has "fallen on deaf ears."
In any case, the documentation indicates that AddConnectNotify() is only called when one of WNetAddConnection() , WNetAddConnection2() , and WNetAddConnection3() is used to add a connection. How would un/connecting a cable simulate the calling of one of those functions?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Exactly how would AddConnectNotify() or CancelConnectNotify() help in detecting when a network cable has been un/plugged?
I've never actually used this stuff...so I'm sure you know much more about it than I do. But, the documentation says:
CancelConnectNotify
The CancelConnectNotify function is implemented by applications that need to receive notification from the MPR when a network resource is connected or disconnected.
Also, I believe that ISensNetwork::ConnectionMade and ISensNetwork::ConnectionLost are only for TCP/IP connections.
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
EricDV wrote: But, the documentation says:
CancelConnectNotify
The CancelConnectNotify function is implemented by applications that need to receive notification from the MPR when a network resource is connected or disconnected.
That same documentation states that it is called before and after each cancel connection operation (WNetCancelConnection() or WNetCancelConnection2() ). I just don't see how the un/plugging of a cable is going to mimic that.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
David,
It appears that you are correct. AddConnectNotify and CancelConnectNotify are not called when a network cable is plugged in or unplugged. I tried them out, and notification is only received when an application creates a network connection or disconnects an existing network connection - which has nothing to do with the network cable.
My misunderstanding...I'm stupid.
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
|
Hi,
I am creating a program in Visual Studio 6.0. I am using MFC and Document/View architecture. I add the "Microsoft Web Browser" ActiveX control to the document window. Then I open an HTML document in this window. This HTML document has an embedded ActiveX control object e.g. CExampleActiveXCtl in it. I want to send and receive data to this embedded object from my program. How do I get the pointer to the embedded ActiveX control object?
Any help will be greatly appreciated.
Thank you in advance,
Regards,
RS
|
|
|
|
|