|
I have an MDI project, that obvioulsy can open more then one document open ... but the request is to could be open only one ... how can I do that ?
Let say that we have open a first document file, and if the user want to create a new document or open an existing document file, should close all documents and let the user to create or open another document ...
I override OnFileNew() and OnFileOpen() from CMyDocument class, but I can't create or open documents then ... there is another solution ?
Thank you.
|
|
|
|
|
Flaviu2 wrote: another solution ?
Please check the behavior of notepad.exe .
It is concepted as SDI application
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
Though, I need a MDI application that should open a single document at time ...
|
|
|
|
|
Then please post your overwritings here
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
Well, if I map OnFileOpen like this (trying to close all documents first) :
protected:
afx_msg void OnFileOpen();
DECLARE_MESSAGE_MAP()
and
BEGIN_MESSAGE_MAP(CMyDoc, CDocument)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
END_MESSAGE_MAP()
void CMyDoc::OnFileOpen()
{
theApp.CloseAllDocuments(TRUE);
}
I can not open any files ...
|
|
|
|
|
Try it now :
void CMyDoc::OnFileOpen()
{
theApp.CloseAllDocuments(TRUE);
CDocument::OnFileOpen();
}
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
I try this too but I get follow error :
void CMyDoc::OnFileOpen()
{
theApp.CloseAllDocuments(TRUE);
CDocument::OnFileOpen();
}
...
|
|
|
|
|
... and so ? :
void CMyDoc::OnFileOpen()
{
theApp.CloseAllDocuments(TRUE);
theApp.OnCmdMsg(ID_FILE_OPEN, 0, NULL, NULL);
}
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
All I try to do is to close all documents open on file new and file open handler ... and after that, of course, let user to create or open an existing document ...
|
|
|
|
|
If you never want to open more than one document then why are you using an MDI application? The logical (and sensible) answer is to change your app to be SDI. Alternatively you can make it more complex than necessary by adding some global flags to prevent opening more than one document at a time.
|
|
|
|
|
Because the application must have more then one kind of document ...
|
|
|
|
|
Hi,
Since I knew The Code Project, it has been helpful a lot.
Now I think I have a small misunderstanding about pointer to member function in a struct and I need your help, which will be priceless to me.
I am simply trying to see how pointer to member function works and it seems a little tricky.
The code I am having a problem with is below.
#include <iostream>
#include <conio.h>
#define KEY_ESC 27
using std::cout;
using std::endl;
class CAccount;
struct StateMap
{
int input;
void (CAccount::*mfp)();
};
class CAccount
{
public:
enum
{
STATE_IDLE,
STATE_INPUT,
STATE_WAIT_ACK
};
public:
StateMap map[3];
int m_iState;
CAccount();
void OnIdle();
void OnInput();
void OnWaitAck();
};//class CAccount
CAccount::CAccount(){
map[0].input = 1;
map[0].mfp = &CAccount::OnIdle;
map[1].input = 2;
map[1].mfp = &CAccount::OnInput;
map[2].input = 3;
map[2].mfp = &CAccount::OnWaitAck;
m_iState = STATE_IDLE;
}
void CAccount::OnIdle()
{
cout << "OnIdle()" << endl;
}
void CAccount::OnInput()
{
cout << "OnInput()" << endl;
}
void CAccount::OnWaitAck()
{
cout << "OnWaitAck()" << endl;
}
int main()
{
int ch = 0;
int i;
CAccount account;
while ( ch != KEY_ESC )
{
ch = _getch();
i = 0;
while ( account.map[i].input != 0 )
{
if ( ch == account.map[i].input )
{
(account.(map[i].*mfp))(); // compile error
}//if
i++;
}//while
}//while
return 0;
}//main()
I just don't know the right syntax for that part.
How should I change that error line to make it work?
Thanks in advance.
|
|
|
|
|
Try the following :
typedef void (*LPSTATEPROC) (void);
struct StateMap
{
int input;
LPSTATEPROC mfp;
};
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
Thanks.
Eugen Podsypalnikov wrote: typedef void (*LPSTATEPROC) (void);
You meant this, right?
typedef void (CAccount::*LPSTATEPROC) (void);
But it seems like it doesn't still work and the error occurs at the same line.
#include
#include
#define KEY_ESC 27
using std::cout;
using std::endl;
class CAccount;
typedef void (CAccount::*LPSTATEPROC) (void);
struct StateMap
{
int input;
LPSTATEPROC mfp;
};
class CAccount
{
public:
enum
{
STATE_IDLE,
STATE_INPUT,
STATE_WAIT_ACK
};
public:
StateMap map[3];
int m_iState;
CAccount();
void OnIdle();
void OnInput();
void OnWaitAck();
};//class CAccount
CAccount::CAccount(){
map[0].input = 1;
map[0].mfp = &CAccount::OnIdle;
map[1].input = 2;
map[1].mfp = &CAccount::OnInput;
map[2].input = 3;
map[2].mfp = &CAccount::OnWaitAck;
m_iState = STATE_IDLE;
}
void CAccount::OnIdle()
{
cout << "OnIdle()" << endl;
}
void CAccount::OnInput()
{
cout << "OnInput()" << endl;
}
void CAccount::OnWaitAck()
{
cout << "OnWaitAck()" << endl;
}
int main()
{
int ch = 0;
int i;
CAccount account;
while ( ch != KEY_ESC )
{
ch = _getch();
i = 0;
while ( account.map[i].input != 0 )
{
if ( ch == account.map[i].input )
{
(account.(map[i].*mfp))(); // compile error
}//if
i++;
}//while
}//while
return 0;
}//main()
How can I change that error line to make it work?
Thanks!
|
|
|
|
|
I think the line:
(account.(map[i].*mfp))();
should not use indirection, and should read:
(account.(map[i].mfp))();
|
|
|
|
|
|
|
Hi, I just figured it out myself. But your reply helped me a lot to figure out to make it work!
Thank you so much.
|
|
|
|
|
Hi i am from mexico sorry my english is very bad.
i want to start programming to C++ but i dont know what IDE use.... in the university i use Borland but i dont know here start.
Can you tell me?
|
|
|
|
|
|
There's a lot of options...
Visual Studio
CodeBlocks
NetBeans
Eclipse (with CDT)
CodeLite
Dev-C++
KDevelop
It all depends on what you're looking for, obviously Visual Studio is most popular for Windows based development. Some of the cross platform IDEs (such as Eclipse or NetBeans, or others) are good if you're targeting non-windows systems, since you can take the IDE with you to your target machine for debugging.
|
|
|
|
|
Thanks Holguin....
I install Dev-C++ i think is the best IDE for me.
Thanks all for yours answers.
|
|
|
|
|
Hi,
I'm using windows 7 pc, and trying to write a Bluetooth server app.
My requirement is to pair my Mobile (Nokia -N8) with my server app, and then exchange data using a service class.
ISSUE:
The issue I'm facing is, on running server on my PC, the server waits for connection request from phone.
But phone is asking me to enter a pass code, But i don't know how to handle this passcode issue at server side. and establish the connection.
The connection always fails with a message that no response from server.
Here is my server code, which I'm running on my win 7 PC.
// Bluetooth.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <winsock2.h>
#include <ws2bth.h>
#include <bthsdpdef.h>
#include <bluetoothapis.h>
#pragma comment(lib, "Ws2_32.lib")
int _tmain(int argc, _TCHAR* argv[])
{
//----------------------
// Initialize Winsock.
WSADATA wsaData;
int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != NO_ERROR)
{
wprintf(L"WSAStartup failed with error: %ld\n", iResult);
return 1;
}
//----------------------
// Create a SOCKET for listening for
// incoming connection requests.
SOCKET ListenSocket;
ListenSocket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
if (ListenSocket == INVALID_SOCKET) {
wprintf(L"socket failed with error: %ld\n", WSAGetLastError());
WSACleanup();
return 1;
}
//----------------------
// The sockaddr_in structure specifies the address family,
// IP address, and port for the socket that is being bound.
SOCKADDR_BTH blthsocket;
memset(&blthsocket,0,sizeof(SOCKADDR_BTH));
blthsocket.addressFamily = AF_BTH;
blthsocket.btAddr = 0;
blthsocket.serviceClassId = GUID_NULL;
blthsocket.port = BT_PORT_ANY ;
wprintf(L"============ Before Bind =============\n");
wprintf(L"blthsocket.btAddr = %d \n",blthsocket.btAddr);
wprintf(L"blthsocket.port = %d \n",blthsocket.port);
if (bind(ListenSocket,(SOCKADDR *) & blthsocket, sizeof (blthsocket)) == SOCKET_ERROR)
{
wprintf(L"bind failed with error: %ld\n", WSAGetLastError());
closesocket(ListenSocket);
WSACleanup();
return 1;
}
wprintf(L"Binding is complete\n");
wprintf(L"\n\n============ After Bind =============\n");
int len = sizeof(blthsocket);
if (0 == getsockname (ListenSocket, (sockaddr*)&blthsocket, &len))
{
wprintf (L"Local Bluetooth device is %04x%08x \nServer channel = %d\n",
GET_NAP(blthsocket.btAddr), GET_SAP(blthsocket.btAddr), blthsocket.port);
}
//----------------------------------------------------------------------------
wprintf(L"Waiting for client to connect...\n");
listen (ListenSocket, 5);
for ( ; ; ) {
SOCKADDR_BTH sab2;
int ilen = sizeof(sab2);
SOCKET s2 = accept (ListenSocket,(sockaddr*)&sab2, &ilen);
if (s2 == INVALID_SOCKET) {
wprintf (L"Socket bind, error %d\n", WSAGetLastError ());
break;
}
wprintf (L"Connection came from %04x%08x to channel %d\n",
GET_NAP(sab2.btAddr), GET_SAP(sab2.btAddr), sab2.port);
wprintf (L"Hello");
SpinConnectionThreadsOnSocket (s2);
}
closesocket (ListenSocket);
WSACleanup();
return 0;
}
Kindly help resolving this issue, Thanks in advance.
Regards,
Vijay.
|
|
|
|
|
Windows has several bluetooth APIs that you can use.
BluetoothAuthenticateDevice is the API to send authentication code to the bluetooth device.
|
|
|
|
|
I have written an MFC application, with an embedded WebBrowser Control, using Visual Studio 6 C++
It follows an example on MSDN entitled "Using MFC to Host a WebBrowser Control".
The application creates an html script and navigates to it using code similar to ...
m_browser.Navigate(filenamestring, NULL,NULL,NULL,NULL); for example.
If the connection fails, I get the "Internet Explorer Script Error" debug popup.
Is it possible to detect / trap this error within my program so the popup is not generated ??
modified on Monday, August 22, 2011 12:50 PM
|
|
|
|