|
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
|
|
|
|
|
I am using Microsoft Visual Studio 6.00.
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.
So how can I sort out this problem?
Thanks in advance
Nikesh
|
|
|
|
|
1. Call frame window's DestroyWindow function
2. Send WM_CLOSE message to your frame window handle
3. DestroyWindow with frame window handle
4. PostQuitMessage with exit code.
You may need to take care about the data in the child window.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
I created a combo box using the fllowing createwindowex() function.
m_hWnd = CreateWindowEx(
NULL,
L"ComboBox",
L"Appliance Name",
WS_CHILD |
WS_VISIBLE |
CBS_HASSTRINGS |
CBS_DROPDOWNLIST ,
10, 0, 200, 30,
hwndParent,
(HMENU) IDC_MAIN_COMBOBOX,
GetModuleHandle(NULL),
NULL);
And added two strings using the CB_ADDSTRING message. Still when i click the dropdownbox. it is not opening the list box.just a thik line only appears below that Combobox.
Can any one detect what wrong I am doing?
birajendu
CyberG India
Delhi
India
|
|
|
|
|
Can you try with CB_SETMINVISIBLE [^]macro? This message sets the minimum number of visible items in the drop-down list of a combo box.
Instead of using SendMesssage you can call ComboBox_SetMinVisible [^]macro and pass the number of elements required.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
My issue was different. The problem was it required more clint area while drop down.
case CBN_DROPDOWN:
{
RECT rcClient;
// Get the coordinates of the parent window's client area.
GetClientRect((HWND) lParam, &rcClient);
MoveWindow((HWND)lParam,rcClient.left,rcClient.top ,rcClient.right,rcClient.bottom+300,true);
}
I added this above code. which fixed my issue.
birajendu
SonicWALL
Bangalore
India
|
|
|
|
|
I have been using WinExec to launch IE with a URL containing a PHP file and some parameters to send quick updates to a web based MySql database. However the browser widow that opens is becoming annoying. Can someone suggest a simple way or point me to a tutorial that would explain how to run a web based php file from our MFC application. How do I just kick off such an online process ? Thanks
|
|
|
|
|
|
I need to scroll the CFormView derived view to the top of the form. When I use OnScroll with SB_TOP the form scrolls only one line up after each ESC key press. However, using SendMessage function works just fine.
Am I doing something wrong? (VC 6.0)
Yes, I was not reading "fine print"!
As always please ignore the dereferencing symbol, it is actually "->".
Any constructive comments are appreciated.
Cheers Vaclav
if(pMsg->message == WM_KEYDOWN)
{
if(pMsg->wParam==VK_F2)
{
TRACE("\nBOOL CFD2008View::PreTranslateMessage(MSG* pMsg) VK_F2");
m_edit.SetFocus();
}
if(pMsg->wParam==VK_ESCAPE)
{
TRACE("\nBOOL CFD2008View::PreTranslateMessage(MSG* pMsg) VK_ESCAPE");
ShowWindow(SW_HIDE);
int iPos = 0 ;
SetDlgItemText(IDC_EDIT1,"");
C_ResetCompletionFlags();
SendMessage(WM_VSCROLL, SB_TOP,0); // works OK
OnScroll(SB_TOP,iPos,TRUE); // scrolls one line up only
ShowWindow(SW_SHOWMAXIMIZED);
m_edit.SetFocus();
}
modified on Friday, June 19, 2009 9:44 PM
|
|
|
|
|
The first parameter of OnScroll() is composed of two parts; a low-order byte for horizontal scrolling, and high-order byte for vertical scrolling.
For vertical scrolling to top, you should use like that.
OnScroll(MAKEWORD(0, SB_TOP), 0, TRUE);
But. if the form has horizontal scrollbar, you will have another problem because of design of that function. SB_LINEUP or SB_LINELEFT is defined as 0. And the function runs in both direction at one whack. That means 0 in high-order byte will be interpreted horizontal line left at the same time. So, you will have unwanted left scroll with above call.
You may have to call again to keep the horizontal position unchanged.
OnScroll(MAKEWORD(SB_LINEDOWN, 0), 0, TRUE);
However, top for both direction will work well.
OnScroll(MAKEWORD(SB_TOP, SB_TOP), 0, TRUE);
Or if there is no horizontal, there won't be any problem.
Otherwise, IMHO, SendMessage(...) way is more appropiate.
|
|
|
|
|
Thanks for your clarification. Appreciate that very much
|
|
|
|
|
Please help.
Thank you in advance.
Easy Profiler : a compile-time profiler for C++
www.potatosoftware.com
|
|
|
|
|