|
Rajesh R Subramanian wrote: CFileDialog?! So, you're using MFC. Then you must use CStdioFile class to read file (you said line by line) instead of ReadFile() and that will make things simpler for you
no no,
i was not the one who posted the thread and asked the question of reading line be line.
my question is, normally, without specifying the path, the files in the curdir can be accessed by default.
but in the same app, if we had used CFileDialog::DoModal(); after that, the above condition would not be applicable.
i wanted to understand from you, if there is any way to overcome this.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
chandu004 wrote: i was not the one who posted the thread and asked the question of reading line be line.
Sorry about the confusion. Clearly, I need some rest.
Like I said, you can retrieve the full path of the file selected by the user by calling CFileDialog::GetPathName() if the user clicked OK. Something like this:
CFileDialog cfd(true);
if(cfd.DoModal() == IDOK)
{
CString szSelectedFile = cfd.GetPathName();
}
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hi Rajesh,
If Possible please try to help me regading the thread increase the DialogBox size during Runtime which was posted by me....
|
|
|
|
|
Rajesh R Subramanian wrote: Like I said, you can retrieve the full path of the file selected by the user by calling CFileDialog::GetPathName() if the user clicked OK.
iam aware of these operations sir, i think iam unable to put my qn into proper words. now i think i also need some rest.
any way here is my last attempt to explain my doubt.
1.in some of my screens/modules, i used file operations simply by using the filename with out path.
assume my application and the files are in "E:\\project" folder.
2.these modules were working perfectly.
3.say there is one more module in the same application, where, user has to browse for a file and he selects a file from desktop(obviously he clicks ok). now, the application will read some data from the selected file and do some thing else.
4.from this point onwards, the modules as discussed in point no 1 shows abnormalities coz, the default filenames are not available on desktop.
i mean, default folder is reset from the application folder to desktop.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Why does changing one thing affects the other?! Sounds like a design issue to me.
If you are dealing with say 3 different files, you can have string member variables in your class that will hold the path of each file used and initialize them once (and update them if the user browses for a different file)?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: If you are dealing with say 3 different files
not 3 files. the file count is variable and dynamic.
any way, take it easy.
thank you.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
You mean there are different files, can be on any location and must be kept track of by your application? You could use an array of strings as a data member in your class? If you could explain your scenario more appropriately and explain your current approach, people over here can propose something better. Perhaps you should start a new thread.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
actually this problem i faced in a projhect i executed ~2 yrs ago.
i solved it by some other techniques, like using some function which gets the application path.
i posted my query to enquire if there was any other straight forward method.
any way leave it my friend, iam still failing to explain my problem correctly.
i feel we are getting carried away.
thank you once again.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Hi,
There is a flag for CFileDialog, named OFN_NOCHANGEDIR to keep current directory unchanged after file selection. It is used to form dwFlags which is 4th parameter of CFileDialog constructor. It can be used with flags member of OPENFILENAME structure for Win32 API, of course.
However, you might also keep track of current directory by yourself using GetCurrentDirectory() and SetCurrentDirectory() functions.
|
|
|
|
|
no, i am doing WIN32 programming in vc++.
|
|
|
|
|
hope your problems are solved.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
readfile() is still not solved.
|
|
|
|
|
I've read through this whole thread, and here's the problem...
If you open a file with just the filename, the system looks for that file in the "current directory". The problem is that the current directory when you first start the app (from windows explorer) will be the directory containing the app. However, if you browse to a different folder (with CFileDialog for example), that changes the "current directory".
To resolve this, you can find the directory that your app is in by using
GetModuleFileName and then you can use
PathRemoveFileSpec to remove the app name. Next use
PathAppend to add the name of the file you want. Now you have the complete path to your file in your app directory, regardless of what the "current directory" is.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
thanks.
i try to write some code with readfile() for line by line read, it is working but the problem is that it does not print the very last character before the end of file ---
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#define BUFFER_SIZE 82
void main(int argc, TCHAR *argv[])
{
HANDLE hFile;
DWORD dwBytesRead = 0;
char ReadBuffer[BUFFER_SIZE] = {0}, ss[16] = {0};
printf("\n");
hFile = CreateFileA("c:\\ip.txt",
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
printf("Could not open file (error %d)\n", GetLastError());
return;
}
if( FALSE == ReadFile(hFile, ReadBuffer, BUFFER_SIZE-2, &dwBytesRead, NULL) )
{
printf("Could not read from file (error %d)\n", GetLastError());
CloseHandle(hFile);
return;
}
ReadBuffer[dwBytesRead+1]='\0';
int i ,j;
i = -1;
while(ReadBuffer[i+1] != '\0')
{
j = -1;
do
{
i++;
j++;
ss[j] = ReadBuffer[i];
}while((ReadBuffer[i+1] != '\n')&&(ReadBuffer[i+1] != '\0'));
ss[j] = '\0';
printf("%s\n", ss);
i++;
}
CloseHandle(hFile);
return;
}
the file, i want to read, has maximum of 16 characters in a line.
|
|
|
|
|
I think your problem is here:
do
{
i++;
j++;
ss[j] = ReadBuffer[i];
}while((ReadBuffer[i+1] != '\n')&&(ReadBuffer[i+1] != '\0'));
ss[j] = '\0';
You didn't say if the GetModuleFileName solved your other problem or not, but I'm guessing it did.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
i try to get the ip address from a file and then make socket and send info, i want to send same info to same ip twice so i put ip "127.0.0.1" twice in the text file, but it sends info only once. here is the code ----
#include <windows.h>
#include <winsock.h>
#include <stdio.h>
#include <lm.h>
#include <tchar.h>
#include <wchar.h>
#include <iostream>
#define NETWORK_ERROR -1
#define NETWORK_OK 0
short int c = 1;
void ReportError(int, const char *);
void printServ();
int sockpro();
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
{
while(1)
{
printServ();
Sleep(1000);
}
return 0;
}
void ReportError(int errorCode, const char *whichFunc)
{
char errorMsg[92];
ZeroMemory(errorMsg, 92);
sprintf_s(errorMsg, "Call to %s returned error %d!", (char *)whichFunc, errorCode);
MessageBoxA(NULL, errorMsg, "socketIndication", MB_OK);
}
void printServ()
{
SC_HANDLE hSCM;
SERVICE_STATUS ss;
short int j, x;
x = 1;
wchar_t* prName[] = {
_T("W3SVC"),
};
for(j=0; j<x ; j++)
{
hSCM = OpenSCManager
(
NULL,
SERVICES_ACTIVE_DATABASE,
SC_MANAGER_CONNECT
);
if (hSCM != NULL)
{
SC_HANDLE hService = OpenService
(
hSCM,
prName[j],
SERVICE_QUERY_STATUS
);
if (hService != NULL)
{
if (QueryServiceStatus(hService, &ss) != FALSE)
{
if ((ss.dwCurrentState == SERVICE_RUNNING)
||(ss.dwCurrentState == SERVICE_START_PENDING))
{
c = 0;
}
else if (((ss.dwCurrentState == SERVICE_STOPPED)
||(ss.dwCurrentState == SERVICE_STOP_PENDING))&& (c == 0))
{
sockpro();
MessageBoxA(NULL, "Iis is stopped", "Service Stopped", MB_OK);
c = 1;
}
}
}
else
MessageBoxA(NULL, "Iis not found", "Service Stopped", MB_OK);
CloseServiceHandle(hService);
}
CloseServiceHandle(hSCM);
}
}
int sockpro()
{
HANDLE fSor;
char fBuffer[1024] = {0}, sss[1024] = {0};
DWORD dwRead = 0;
WORD sockVersion;
WSADATA wsaData;
int nret, byteSend;
struct in_addr addr;
LPHOSTENT hostEntry;
SOCKET theSocket;
SOCKADDR_IN serverInfo;
for(int i=0; i<1024; i++)
fBuffer[i] = NULL;
fSor = CreateFileA("c:\\ip.txt",
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
ReadFile(fSor, fBuffer, 1024, &dwRead, NULL);
fBuffer[dwRead+1] = '\0';
unsigned int y,j;
y=0;
do
{
strcpy_s(sss, fBuffer + y);
j = strlen(sss);
y = y + j + 1;
printf("%s", sss);
char st[100] = "IIS is stopped on Server";
addr.s_addr = inet_addr((const char*)sss);
sockVersion = MAKEWORD(1, 1);
WSAStartup(sockVersion, &wsaData);
hostEntry = gethostbyaddr((char *) &addr, 4, AF_INET);
if (!hostEntry)
{
nret = WSAGetLastError();
ReportError(nret, "gethostbyaddr()");
WSACleanup();
return NETWORK_ERROR;
}
theSocket = socket(AF_INET,
SOCK_STREAM,
IPPROTO_TCP);
if (theSocket == INVALID_SOCKET)
{
nret = WSAGetLastError();
ReportError(nret, "socket()");
WSACleanup();
return NETWORK_ERROR;
}
SOCKADDR_IN serverInfo;
serverInfo.sin_family = AF_INET;
serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);
serverInfo.sin_port = htons(23571);
nret = connect(theSocket, (LPSOCKADDR)&serverInfo, sizeof(struct sockaddr));
if (nret == SOCKET_ERROR)
{
nret = WSAGetLastError();
ReportError(nret, "connect()");
WSACleanup();
return NETWORK_ERROR;
}
byteSend = send(theSocket, st, strlen(st), 0);
if (byteSend == SOCKET_ERROR)
{
nret = WSAGetLastError();
ReportError(nret, "send()");
WSACleanup();
return NETWORK_ERROR;
}
Sleep(5000);
}while(y <= dwRead);
closesocket(theSocket);
WSACleanup();
CloseHandle(fSor);
return NETWORK_OK;
}
|
|
|
|
|
Hi,
im using the below code to increase the size of the DialogBox along with the controls inside it during Runtime...ie im overriding DoModal()function...
CTestDlgDlg is my application name....
INT_PTR CTestDlgDlg::DoModal()
{
CDialogTemplate dlt;
int nResult;
// load dialog template
//CTestDlg::IDD is the ID of my resoource...
if (!dlt.Load(MAKEINTRESOURCE(CTestDlg::IDD))) return -1;
// set your own font, for example "Arial", 10 pts.
dlt.SetFont(L"Arial", 12);
// get pointer to the modified dialog template
LPSTR pdata = (LPSTR)GlobalLock(dlt.m_hTemplate);
// let MFC know that you are using your own template
m_lpszTemplateName = NULL;
InitModalIndirect(pdata);
// display dialog box
nResult = CDialog::DoModal();
// unlock memory object
GlobalUnlock(dlt.m_hTemplate);
return nResult;
}
The issue every control in the DialogBox is getting increased except checkbox,Radio button..please let me know can i increase the size of the checkbox,RadioButton in this case....
|
|
|
|
|
|
Thanks for ur Reply....
Font is getting increased with the piece of code which i posted but the control size is not getting increased....
|
|
|
|
|
Anybody please let me know regarding the same....
|
|
|
|
|
I have tested your DoModal() function in my system especially. I think, it works well. That is, all controls including check boxes and radio buttons resized proportionally as expected. I added some same-sized controls (e.g check box, radio buttton, combo box, push button, edit box, static) to my dialog at design time, all of them were still in same size when I run this dilaog with your DoModal().
As I said before, I think that the problem with your controls or any other place there of your project. If you find some more clue, we can help you better.
Please try to set static edge style (WS_EX_STATICEDGE) of the problematic controls to see their boundaries exactly.
|
|
|
|
|
Hello,
The last time I wanted to have dynamically resizable controls on my dialog, I used CResizableDialog[^]. I don't see why you need checkboxes and radio buttons to be enlarged along with the dialog. That sounds more like magnification/shrinking of the controls rather than dynamically resizing them.
I don't see why you need to resize a checkbox though. But whatever floats your boat.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
because in our application dialogBox along with controls should resize based on the Resolution of the system... so that user will be able to have a clear view...
|
|
|
|
|
I have created an MDI application. In that I am creating new window.
I want functionality as after left clicking of mouse on view that window should be closed.
My problem is, how can I close the window after left click on that created window.
Thanks in advance
Nikesh
|
|
|
|
|
Post a WM_CLOSE message to your window?
PS: Do not re-post your queries.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|