|
li zhiyuan wrote: how to solve the following problem ... psofile.cpp(150) : error C2109: subscript requires array or pointer type
by modifying whatever is in line 150 until it is correct.
my guess is whatever is to the left of an open square bracket should be but isn't an array or a pointer.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
li zhiyuan wrote: how to solve the following problem: after compilation:
psofile.cpp(150) : error C2109: subscript requires array or pointer type
This deserves a place in the Top 5 list of idiotic posts.
|
|
|
|
|
I am trying to print (text) fields onto a form. so I need to specify to my print fumction the exact x and y coordinates. The following code shows what I tried to do. I specify the coordinates but it prints a bit off not falling into the boxes of the from. I tried accounting for printer margins and still cannot get it to properly print. What am doing wrong ? For that matter is there a better way ?
Here are parts of relevant code.
omap = pDC->SetMapMode (MM_TEXT);
sx = pDC->GetDeviceCaps (LOGPIXELSX); // x axis pixels per inch
yx = pDC->GetDeviceCaps (LOGPIXELSY); // y axis pixels per inch
xmargin = pDC->GetDeviceCaps (112); // Left margin
ymargin = pDC->GetDeviceCaps (113); // Top margin
r_font.CreateFont (-Size, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, 0,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Courier New");
SelectFont (&r_font);
// to move half inch in and half inch down xpos would be sx/2
// and yx/2 (not accounting for printing margins). If accounting
// then factor in xmargin and ymargin.
TextOut (xpos, ypos, str, sz);
Thanks
I am using Visual C++ 5.0
|
|
|
|
|
Is it a matter of text alignment when using the TextOut() function?
See GetTextAlign()/SetTextAlign()[^].
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Henri,
I think the problem is with calculating the xpos and ypos.if u want to print the text inside a box u have to find the RECT of that box. Then add xpos and ypos to RECT.left and RECT.top to get the exact position.
eg:
Assuming RECT rect = {20,20,100,100} ;
TexOut(rect.left + xpos, rect.top + ypos , str, sz);
this is a guess and if this is not the thing then plz avoid this post.
|
|
|
|
|
I looked at SetTextAlign/GetTextAlign.
I did pDC->SetTextAlign ((TA_LEFT | TA_TOP | TA_NOUPDATECP));
from OnBeginPrinting.
Still prints off. I dont not know if I need to account for printer margins and if so how to do so.
I tried with accounting and without, as follows
void CMyFormView::MyOutStr (CDC *pDC, int x, int y, char *str)
{
int xpos, ypos, sz;
if (!(sz = strlen(str)))
return;
//xpos = x - r_xmargin; //account for margin
//xpos = x; //do not account
if (xpos < 0)
xpos = 0;
//ypos = y - r_ymargin;
//ypos = y;
r_xlast = xpos;
r_ylast = ypos;
pDC->TextOut (xpos, ypos, str, sz);
}
could not print to location I specified. Any clues, suggestions would be appreciated. Thanks.
Henri
|
|
|
|
|
this is my code for a simple hangman game:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void main()
{
string response;
int w=0;
const int WORDS=4;
do
{
const char body[] = "o/|\\|/\\";
string words[WORDS] = {"MACAW", "SADDLE", "TOASTER", "XENOCIDE"};
string xword(words[w].length(), '?');
string::iterator i;
string::iterator ix = xword.begin();
char letters[26] = {'\0'};
int n=0;
int xcount = xword.length();
bool found = false;
bool solved = false;
bool hung = false;
int offset = 0;
int bodycount = -1;
cout << "guess the word:";
for(unsigned loop = 0; loop < words[w].length(); loop++)
cout << "X";
do
{
cout << "\n\nGuess a letter (case does not matter): " << xword << "\n? ";
char temp;
cin >> temp;
if (!isalpha(temp))
{
cout << "\n LETTERS ONLY PLEASE\n";
continue;
}
letters[n] = toupper(temp);
i = words[w].begin();
found = false;
offset = 0;
while (i != words[w].end())
{
if (*i == letters[n])
{
*(ix + offset) = *i;
found = true;
if (--xcount == 0)
solved = true;
}
i++;
offset++;
}
if (!found)
bodycount++;
bool newline = false;
for(int q = 0; q <= bodycount; q++)
{
switch (q)
{
case 0:
cout << " ";
break;
case 1:
case 4:
case 5:
newline = true;
break;
case 6:
cout << " ";
newline = false;
break;
case 7:
newline = true;
cout << " ";
break;
default:
newline = false;
}
if (newline)
cout << "\n";
if (q == 4)
cout << " ";
cout << body[q];
}
if (bodycount == 7)
{
cout << "\n\n...GAMEOVER...\n";
hung = true;
break;
}
cout << "\nyour guesses\n";
for (int k = 0; k <= n; k++)
cout << setw(2) << letters[k];
n++;
}while(!solved);
cout << "\n\nword: " << words[w] << "\n\n ";
if (!hung)
cout << "\ncongradulations!! you guessed my word " << "my word:\n";
if (w++ >= WORDS)
break;
cout << "play again (yes | no)? ";
cin >> response;
}while(!response.compare("yes"));
cout << "\nThank You for Playing Hangman" << endl;
}
i am haveing a prob when guessing a letter if u guess a letter correctly and then guess the same letter again then it runs it as if u guessed a diff letter correctly so a user could just guess the same letter for the length of the word and wind up winning with out even guessing ne other letter and i was wondering how to fix this
One love
modified on Sunday, January 27, 2008 8:54:54 PM
|
|
|
|
|
1/ I'm not going to read through all that lot!
2/ Don't fix it. It's a legitimate mistake for someone to make. I never let my brothers off from re-guessing a letter, and they never showed mercy to me.
3/ You could have an array of bools 26 long to represent whether a particular letter had been guessed or not. Set it all to false and the beginning, and each to true when a letter was guessed.
Iain.
|
|
|
|
|
Hi,
How can I prevent the list box of the combo box appear when catching the CBN_DROPDOWN message? I've tried calling to ShowDropDown(FALSE) without success. I need to validate a user when dropping down the combo box and if the user doen't validate, I must show a message error and don't let the combo box to show its list box.
Kind regards,
Jose
|
|
|
|
|
i think you need to subclass the ComboBox with your own WndProc
|
|
|
|
|
Do you want to have listbox of combobox always?
|
|
|
|
|
Yes I want. Sometimes I need to show an error message to the user when he pushes the button to drop down the list before the list is shown and stop showing the list.
Regards,
fjsen
|
|
|
|
|
If you want to show message error why you dont use of Statusbar
|
|
|
|
|
Hello
I want to write a simple application which converts a video file to a vcd\dvd file,
so my VCD Player or DVD Player must play it directly ,after burning a disc with converted file.
How can I convert videos to VCD\DVD formats ?
Thank you very much.
|
|
|
|
|
Hi,
Couldnt find a better place to post this question it includes C and Assembly both.
Basically, I am looking for some code which could let me read a file using Assembly and then use C to manipulate the file and then save it back using Assembly. even if i can read the file using assembly and c will work for me for now.
Thanks,
Umer
|
|
|
|
|
I assume your system has a regular operating system, with a file system and such. So:
Why would you read a file using Assembly if you plan on handling the data in C anyway???
If there is no compelling reason to use Assembly, then don't. If there is, use it where you
have to, file I/O would not be the first area that comes to mind.
BTW If you need to support a special device, write a device driver for it; and do that in
C or C++ too, not Assembly.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
well what i am trying to do is write a mini os... so using assembly or c to implement the i/o is the only solution to the problem and the main reason for this os something else so i am not going on to write these features myself.
what i am actually trying to do is read the bitmap file and display it.
if there is a pure c solution to it... its going to work i wont mind... as long as it works
thanks for the reply.
Umer
|
|
|
|
|
Member 1950781 wrote: what i am trying to do is write a mini os
At the OS level you'll need to manipulate the hardware directly.
A good place to start is the specs for the hardware your OS will run on.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
i m running it in the virtual pc
i am able to get it to print text on the screen but i cant figure out a way to do these io functions
|
|
|
|
|
i figured i will have to go through a hell lot of trouble of implementing an ide driver to do the file system io
anyways thanks a lot guys
|
|
|
|
|
Hi,
you can write most of an operating system in a high-level language (C, C++, Pascal, whatever).
Having pointers and not relying on a virtual machine (as in Java and .NET) makes it easier.
I did a couple of OSses in C, for different microprocessors.
The only thing you will need assembly code for, is the actual task switch code, where
you unload the CPU state for one task/process and load the next.
you can read an image file in any language you choose; all it takes is reading the file
as binary data, and interpreting its content. I wrote C# image viewers for most of the popular
image file formats.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hello,
I'm writing an MFC application that produces printed documents. I am using MFC's native printing support to draw to a CScrollView, through my own implementation of OnDraw(CDC* pDC) .
This works nicely. I can see what I've drawn in the ScrollView, and can scroll by compensating for the offset in co-ordinates in my OnDraw ( I haven't forgotten to *not* compensate when printing; pDC->IsPrinting() is called).
However, I cannot figure out why (through inference from an example app, and reading the documentation available) my "drawing" won't print or appear in print preview.
void CReportView::OnPrint(CDC *pDC, CPrintInfo *pInfo)
{
UNREFERENCED_PARAMETER(pInfo);
CReportView::OnDraw(pDC); // my own implementation of OnDraw
CScrollView::OnPrint(pDC,pInfo);
}
I would have thought that by passing the device context that the framework provides to OnPrint to OnDraw, that the printing device context would have been drawn to, but this doesn't work.
What should I do?
Thanks,
Sternocera
|
|
|
|
|
Here's a quick sample to plop into a new CScrollView doc/view app to see if the results are consistent using print preview. It's more of a WYSIWYG approach and simplifies printing because it uses the same drawing code to print that is used for the screen. Try this out in a new project then adapt what you need to your application.
NOTE: This was previous post of mine describing the print paging mechanism to someone but it demonstrates general printing. I hope it helps.
//CDocument members...
// Header file .h
protected:
CSize m_DocSize;
// Implementation file .cpp
CSize CYourDoc::GetDocSize() const
{
return m_DocSize;
}
CYourDoc::CYourDoc()
{
// TODO: add one-time construction code here
m_DocSize=CSize(2000,2800);
}
//CScrollView members...
// Header file .h
private:
int m_nPage;
// Implementation file .cpp
CYourView::CYourView()
{
// TODO: add construction code here
SetScrollSizes(MM_TEXT,CSize(0,0)); // Set arbitrary values
m_nPage=1;
}
/***************************************
NOTE: The pInfo parameter is uncommented
****************************************/
void CYourView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* pInfo)
{
// TODO: add extra initialization before printing
pInfo->SetMaxPage(3);
}
void CYourView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
m_nPage=pInfo->m_nCurPage;
CScrollView::OnPrint(pDC, pInfo);
}
void CYourView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CScrollView::OnPrepareDC(pDC);
// TODO: Add your specialized code here and/or call the base class
// Set up the DC for the current scale factor
int nExtentX;
int nExtentY;
CSize sizeDoc;
CRect rectClient;
pDC->SetMapMode(MM_ISOTROPIC);
// Get pertinent rectangle data
GetClientRect(&rectClient);
sizeDoc=GetDocument()->GetDocSize();
sizeDoc.cy=(-sizeDoc.cy); // Y goes down as it increments
pDC->SetWindowExt(sizeDoc); // Window extent is size of document
// Calculate viewport extent
nExtentX=rectClient.Width();
nExtentY=(int)((nExtentX*sizeDoc.cy)/(sizeDoc.cx));
// What kind of device context do we have?
if (pDC->IsPrinting()==TRUE) {
pDC->SetViewportExt(pDC->GetDeviceCaps(HORZRES),-pDC->GetDeviceCaps(VERTRES));
} else {
// Context is for screen
pDC->SetViewportExt(nExtentX,nExtentY);
}
}
void CYourView::ResetScrollBars()
{
CSize sizeDoc;
CClientDC dc(this);
this->OnPrepareDC(&dc); // Update the device context
sizeDoc=GetDocument()->GetDocSize();
dc.LPtoDP(&sizeDoc); // Logical to device
this->SetScrollSizes(MM_TEXT,sizeDoc); // Update scrollbars
}
void CYourView::OnSize(UINT nType, int cx, int cy)
{
CScrollView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
ResetScrollBars();
}
void CYourView::OnDraw(CDC* pDC)
{
CYourDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CSize sizeDoc=pDoc->GetDocSize();
CRect rectOutline(0,0,sizeDoc.cx,sizeDoc.cy);
rectOutline.DeflateRect(10,10); // Ensure we can see it
LOGFONT logFont={0};
memcpy(logFont.lfFaceName,"Arial",6);
logFont.lfHeight=300;
CFont font;
font.CreateFontIndirect(&logFont);
CFont* pOldFont=pDC->SelectObject(&font);
CBrush* pOldBrush=(CBrush*)pDC->SelectStockObject(NULL_BRUSH);
CString sMessage;
sMessage.Format("You can add code to center the printout later\nPage %d",m_nPage);
pDC->DrawText(sMessage,&rectOutline,DT_CENTER|DT_WORDBREAK);
pDC->Rectangle(&rectOutline);
pDC->SelectObject(pOldFont);
pDC->SelectObject(pOldBrush);
}
|
|
|
|
|
Holle,
I would like to implement a system using Browser/Server architecture.
Server end will run Linux whereas clinet end will run Windows.
What computer programing language will be suitable for this application development.
Thanks
|
|
|
|
|
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|