|
Wish I had a £1 for every time I've done something similar
MVP 2010 - are they mad?
|
|
|
|
|
Hello everyone,
I am extremly new to vc++ 6.0 programming and i need to create a drag drop control that would draw an image or say a shape into my window.Can you people please tell me how should i start and where to start from.Name of class or may be library should help.
Thank you in advance.
|
|
|
|
|
hi ,I'm a freshman ,and newer to study c !this is my program!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define STOP 0
#define TRUE 1
#define OK 1
#define FILE_NAME ("my.text")
typedef struct List
{
long lNum;
char cpsName[30];
long lCScore;
long lMathScore;
long atol(long i);
struct List *next;
}Stu;
Stu stuList[3] =
{
{1, "asd", 32, 44, 0},
{2, "ffg", 66, 66, 0},
{3, "dgd", 55, 44, 0},
};
Stu *CreateList()
{
Stu *head = NULL;
Stu *NewNode = NULL;
int i = 0;
for (i=0; i<3; i++)
{
NewNode = (Stu*)malloc(sizeof(Stu));
NewNode->lNum = stuList[i].atol(stuList[i].lNum);
strncpy(NewNode->cpsName, stuList[i].cpsName, 30);
NewNode->lCScore = stuList[i].atol(stuList[i].lCScore);
NewNode->lMathScore = stuList[i].atol(stuList[i].lMathScore);
NewNode->next = NULL;
if (NULL == head)
{
head = NewNode;
}
else
{
head->next = NewNode;
head = NewNode;
}
}
return head;
}
int SaveToFiles(Stu *head)
{
Stu *p = head;
FILE *fp;
char cFileName[1024] = {0};
//strcpy(cFileName, FILE_NAME);
if ((fp = fopen(FILE_NAME, "wb")) == NULL)
{
printf( "Open file error!\n" );
exit (1);
}
while (p != NULL)
{
if (fwrite(p, sizeof(Stu), 1, fp) == 1)
{
p = p->next;
}
else
{
printf("Write file error!\n");
exit(1);
}
}
//fputs(p, cFileName);
fclose(fp);
printf( "Save file succeed!\n" );
return OK;
}
int OpenFiles()
{
char cFileName[256] = {0};
FILE *fp;
if (0 == (fp = fopen(FILE_NAME, "r")))
{
printf("Open file error!\n");
exit(0);
}
fgets(cFileName, 250, fp);
printf("%s", cFileName);
fclose(fp);
return OK;
}
int main()
{
Stu *head = NULL;
head = CreateList();
SaveToFiles(head);
OpenFiles();
//Print(head);
return 0;
}
|
|
|
|
|
Please read the posting guidelines[^]. For instance, format your code properly using the code tag (otherwise, it is not readable).
Furthermore, you didn't ask any question and you didn't provide any description of the problem you encounter.
|
|
|
|
|
In addition to Cedric's good advice, you should review the CreateList() function, to see what it actually returns.
MVP 2010 - are they mad?
|
|
|
|
|
Hello!
In my MFC programm on Visual C++ 2008 i have the following problem with opening a file for reading:
-------------------------------------------
1) First step i do is to unzip a existing file (sSourceFile) containing my data with CZipArchive
Here to simplify matters without exception handling:
CZipArchive ZipArchive;
ZipArchive.Open(sSourceFile, CZipArchive::zipOpenReadOnly);
for (int i = 0; i < ZipArchive.GetCount(); i++)
{
ZipArchive.SetPassword(key);
ZipArchive.ExtractFile(i, GetProgramPath()); // GetProgramPath() is a own method which returns the current path
}
ZipArchive.Close();
-------------------------------------------
2) After that i rename the unzipped file:
DeleteFile(sTargetFile);
CFile::Rename( sSourceFile, sTargetFile ); // both, sSourceFile and sTargetFile, with full qualified path
So far it works without problems. The sTargetFile exists (reviewed by debugging).
-------------------------------------------
3) Now i want to open the renamed file for reading
CFile file;
file.Open(sTargetFile, CFile::modeRead);
-------------------------------------------
After that on some machines (with Windows 7) i get an CFileException::sharingViolation exception.
But on the most machines it works without an exception.
What is the matter for this exception?
Does the CFile::Rename still block the file?
How i can wait until the file is definitively closed?
Please help me!
modified on Sunday, January 31, 2010 5:51 AM
|
|
|
|
|
|
good idea, but the problem is a time-critical affair. This means as soon as i have for example a built-in debug message after CFile:Rename and CFile:Open, the problem disappears. So i can not look which process has the file between CFile:Rename and CFile:Open.
Any other help there?
|
|
|
|
|
Quick question - I'm wondering how I can detect when the user presses the enter key on the edit control in my dialogBox(), ie what messages do i need to handle in the dialog procedure?
|
|
|
|
|
WM_COMMAND with LOWORD(wParam) == IDOK and (HWND)lParam == your edit control HWND.
cheers,
AR
|
|
|
|
|
thanks for that! Works beautifully
|
|
|
|
|
You're welcome
|
|
|
|
|
You may also want to investigate whether the ES_WANTRETURN setting is appropriate to your control.
MVP 2010 - are they mad?
|
|
|
|
|
my control is a single-line edit box, so ES_WANTRETURN won't be needed
|
|
|
|
|
Hi all,
i m using this to set background color of menu.
To change the background color of MenuBar, simply add below's line of code, beginning of mainframe OnCreate
CBrush* NewBrush;
NewBrush = new CBrush;
NewBrush->CreateSolidBrush(RGB(139,137,137));
MENUINFO MenuInfo = {0};
MenuInfo.cbSize = sizeof(MenuInfo);
MenuInfo.hbrBack = *NewBrush; // Brush you want to draw
MenuInfo.fMask = MIM_BACKGROUND;
MenuInfo.dwStyle = MNS_AUTODISMISS;
CMenu* pMenu = this->GetMenu();
if(IsMenu(pMenu->m_hMenu))
{
SetMenuInfo(pMenu->m_hMenu, &MenuInfo);
}
after using this,color of menu bar is changed but the color of menu items not changed.
please tell me how can i change the menu items color.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Use owner-drawn menus. There are plenty of samples - just search the C++ articles for 'owner-drawn menu'.
L u n a t i c F r i n g e
|
|
|
|
|
Hi,
In my application i have funtion like
char* CTagController :: SendInitialPoints()
{
union UController CON;
memset(CON.Buffer,0,CONSIZE);
CON.S.AlarmPriority =AlarmPriority;
CON.S.AlarmEnable =AlarmEnable;
CON.S.TagIndex =TagIndex;
.
.
.
.
return CON.Buffer;
}
In another function,im using this
char *pConInitData = 0 ;
pConInitData = pTagController->SendInitialPoints();
My problrem is,When i set Common Language Runtime Support (/clr) option in CLR support,
the pConInitData shows some garbage value.
If i set No Common Language Runtime support,then pConInitData returns correct value.
Whats the problem in setting /clr option.
Actually i convert VC6 to VS2008.Actually i want to set that /clr option,because im using some WPF controls in my applcaiton.
Pls help me
Anu
|
|
|
|
|
It looks like you are returning a pointer to an area of memory that is part of a stack variable. Thus, when SendInitialPoints() returns CON is eligible for garbage collection and may disappear. You should allocate your buffer using new to ensure it does not disappear before you have finished with it.
MVP 2010 - are they mad?
|
|
|
|
|
You can either allocate memory for the union on the heap as Richard said or you can create it on the stack from the caller function and pass it into the SendIntialPoints function.
char* CTagController::SendInitialPoints(UController& CON)
{
memset(CON.Buffer,0,CONSIZE);
CON.S.AlarmPriority =AlarmPriority;
CON.S.AlarmEnable =AlarmEnable;
CON.S.TagIndex =TagIndex;
.
.
.
.
return CON.Buffer;
}
This can be called as follows -
char *pConInitData = 0 ;
union UController CON;
pConInitData = pTagController->SendInitialPoints(CON);
In this case you do not need the function to return anything.
So the calling can be as follows -
union UController CON;
pTagController->SendInitialPoints(CON);
|
|
|
|
|
Hi Guys,
I got a txt file which contains html codes in it.
<td class="ticker_name"><a href="http://finance.yahoo.com/q;_ylt=Al7he7j4xkWAM99.PPB7UVFO7sMF;_ylu=X3oDMTE5cnE2OWVuBHBvcwMzBHNlYwNtYXJrZXRTdW1tYXJ5SW5kaWNlcwRzbGsDbmFzZGFx?s=%5EIXIC" >Nasdaq</a></td><td><span class="streaming-datum" id="yfs_l10_^ixic">2,147.35</span></td><td class="ticker_down"><span class="streaming-datum" id="yfs_c10_^ixic">-31.65</span></td><td class="right_cell ticker_down"><span class="streaming-datum" id="yfs_pp0_^ixic">-1.45%</span>
how do i extract the value example 2,147.35 and -31.65 of NASDAQ
|
|
|
|
|
You could write your own parser or adapt from this article[^].
MVP 2010 - are they mad?
|
|
|
|
|
My immediate approach would be to:
(a) Scan for and replace all comas with nothing. I.e "," --> ""
(b) Scan for the text ixic">
(c) if string not found, then exit loop - jump to (g)
(d) Advance the returned pointer by the length of the search string (6 bytes)
(e) Do a scanf, asking for a float
(f) Return to (b)
(g) ...
Perhaps a little something like this?
#include <stdlib.h>
#include<stdio.h>
#include<string.h>
#include <string>
using namespace std;
string& str_replace(const string &search, const string &replace, string &subject)
{
string buffer;
int sealeng = search.length();
int strleng = subject.length();
if (sealeng==0)
return subject;
for(int i=0, j=0; i<strleng; j=0 )
{
while (i+j<strleng && j<sealeng && subject[i+j]==search[j])
j++;
if (j==sealeng)
{
buffer.append(replace);
i+=sealeng;
}
else
{
buffer.append( &subject[i++], 1);
}
}
subject = buffer;
return subject;
}
int main()
{
FILE *fp;
char *htmlStr, *tmp, *filename="infile.html";
char *pos1, *pos2, *pos3;
float retrievedNum;
long fileSize;
string findMe = "ixic\">";
fp = fopen(filename, "r+b");
fseek(fp, 0, SEEK_END);
fileSize = ftell(fp);
fseek(fp, 0, SEEK_SET);
htmlStr = new char[fileSize+1];
htmlStr[fileSize] = 0;
fread(htmlStr, sizeof(char), fileSize, fp);
string tmpS = htmlStr;
string find = ",";
string replace = "";
tmpS = str_replace(find, replace, tmpS);
printf("%s\n\n", tmpS.c_str() );
fclose(fp);
strcpy(htmlStr, tmpS.c_str() );
pos1 = htmlStr;
while (pos1 = strstr(pos1, findMe.c_str()))
{
pos1 += strlen(findMe.c_str());
sscanf(pos1, "%f", &retrievedNum);
printf("Retrieved: %f\n", retrievedNum);
}
delete htmlStr;
}
Yeah, the code's not winning any beauty pageants.
|
|
|
|
|
benjamin yap wrote: how do i extract the value example 2,147.35 and -31.65 of NASDAQ
Have a look at regular expressions (RE). There are various libraries for C++, see Boost or CodeProject articles about it. You could scan line by line trough your HTML-input and with a regular expression test/extract the wanted information.
Hope this helps,
M
|
|
|
|
|
Hi,
I am writing an Installer for Software Upgrades. The final step is to Delete the existing Bin Directory, and renaming the Temp One to the Old Dir Name. This will ofcourse fail if the existing Bin Dir contains Files that are in Use.
The First part of the question is, How can I force Terminate running Apps.(and then finalise the installation, and restart what was running. No problem with doing that last step)
The Second part is, When the above fails, I would like to Shut down the computer, restart it, Block everything while I finalise the initial Installation, before the 'Start' list executes, and then resume Normal Startup.
The third part is, 'Can that be done remotely on a Networked Computer.'
BTW We Don't use '.COM' or 'ActiveX'. The preferred solution would entail the 'Kernel' API functions.
Regards,
Bram van Kampen
|
|
|
|
|
Hi all,
I have been using the following method to allow multiple instances of a class CInd1 to be generated using a base class pointer with various virtual functions in the base class. The problem I have is that I now would like to access variables in the class CInd1 generated by new. I can't figure out how to do this. The pointer m_pIndicator points to the desired class but it's a CIndicator class pointer (necessary to use virtual functions). Is there any way to re-cast the pointer or similar to gain access to CInd1 variables?
Thanks
class CInd1 : public CIndicator
{
Public:
virtual void CInd1::Draw(..) const;
CInd1(..);
CInd1 () {}
};
class CIndicator : public CObject
{
public:
virtual void Draw(CDC* pDC) const {}
public:
CIndicator() {};
};
CIndicator* m_pIndicator;
m_pIndicator = new CInd1(..);
m_pIndicator-> ??
|
|
|
|
|