How to display data in a cell structure



Hi,


In a Visual Studio C++ console program I get data (it is updated every 10 seconds) that are structured in the way shown below to the function

void ProcessCDUData(PMDG_NGX_CDU_Screen *pS)
{
// code for displaying to window ????
}


How do I code in the most efficient way to display the data as text to a window

Any tips/examples are welcomed.

----------------------------------------------------------------------------------------------------

// Screen Cell Structure
//
// The Symbol is the ASCII code of the character to be drawn plus the following special symbols:
// \xA1: left arrow
// \xA2: right arrow


struct CDU_Cell
{
unsigned char Symbol;
unsigned char Color; // any of CDU_COLOR_ defines
unsigned char Flags; // a combination of CDU_FLAG_ bits
};

// CDU Screen Data Structure

#define CDU_COLUMNS 24
#define CDU_ROWS 14

struct CDU_Screen
{
CDU_Cell Cells[CDU_COLUMNS][CDU_ROWS];
bool Powered; // true if the CDU is powered
};

// CDU Screen Cell Colors
#define CDU_COLOR_WHITE 0
#define CDU_COLOR_CYAN 1
#define CDU_COLOR_GREEN 2
#define CDU_COLOR_MAGENTA 3
#define CDU_COLOR_AMBER 4
#define CDU_COLOR_RED 5

// CDU Screen Cell flags
#define CDU_FLAG_SMALL_FONT 0x01 // small font, including that used for line headers
#define CDU_FLAG_REVERSE 0x02 // character background is highlighted in reverse video
#define CDU_FLAG_UNUSED 0x04 // dimmed character color indicating inop/unused entries
Hi, found the solution

for (int i = 0; i < 14; i++) {
for (int j = 0; j < 24; j++) {
printf("%c ", (((pS)->Cells)[j])[i]);
}
printf("\n");
}

Now I just need to make screen refresh between the data interval
Hi

in my concole program

this function works OK

void ProcessCDUData(PMDG_NGX_CDU_Screen *pS)
{

for (int i = 0; i < 14; i++) {
for (int j = 0; j < 24; j++) {
printf("%c ", (((pS)->Cells)[j])[i]);
}
printf("\n");
}
}


But, now I want to make a Win32 program

How do I output the same data to a window

by WM_PAINT or another way?


In WM_PAINT you use DrawText or TextOut instead of printf. However it's not that easy - you need to learn a bit more about the Win Api.

http://www.functionx.com/win32/Lesson01.htm
http://www.catch22.net/tuts
http://zetcode.com/gui/winapi/
I have been struggling with this the whole day.

I have tried both DrawText and TextOut, but with no succees so far.


I have the other code OK, it is just the DrawText or TextOut I can't manage.

I will look into the links

Thomas1965: Thanks
Last edited on
This problem is driving me crazy.

There must be a simple solution to this.

Anyone?
There must be a simple solution to this.


WHY ?

A relative simple way is to use C++/CLI or VB.NET or C#. There you can create simple UI without much background knowledge.
Can you post your code? Do you have MFC or is it a standard Platform SDK application?
@kbw

he is using
In a Visual Studio C++ console program
As I understand it, the sample console program works. And now he want's to apply it to a GUI app. Hence my question. Of course, I could be completely wrong.

I have been struggling with this the whole day.


A famous author on Windows programming books once wrote a book on how to write GUI apps. The intended audience for his book was professional C programmers, i.e., folks who were professionals and had been doing it for years. His words to them were that it was difficult material and to expect about six months or 180 days before they would begin to 'get it'. So take heart, you only have 179 days of struggle left!
I need to solve it now, can't wait for 179 more days):

More info here.

In my console app I have this code:
void ProcessCDUData(PMDG_NGX_CDU_Screen *pS)
{

for (int i = 0; i < 14; i++) {
for (int j = 0; j < 24; j++) {
printf("%d ", (((pS)->Cells)[j])[i]);
}
printf("\n");
}
}

This is printing the correct text to the screen.

But, I need to change from printing to a console screen to a Window.

The problem is that the rather complex 2 dimentional structure ( see top of this thread)

make it difficult for me to find a way to store the data so I can send it to some Direct2D code

I have the correct Direct2D code. I have the correct code to get the data in the structure, but
I can't find a method to temporary store it before sending it to the Direct2D code.

I get this error

( " no suitable conversion function from "PMDG_NGX_CDU_Cell" to "unsigned char" exists)

when I change the

printf("%d ", (((pS)->Cells)[j])[i]);
}
printf("\n");
}

to

1
2
3
4
5
6
7
8
9
10
unsigned char cdu0[3];

void ProcessCDUData(PMDG_NGX_CDU_Screen *pS)
{

for (int i = 0; i < 14; i++) {
	for (int j = 0; j < 24; j++) {


	cdu0[3] =	(((pS)->Cells)[j])[i]);


Here is a link that better visualy describe the complexity of the structures:

https://onedrive.live.com/redir?resid=C6D71753A7446334!102437&authkey=!AMwtgvFjQk16raM&v=3&ithint=photo%2cpng





You can't store a whole struct in a char.
cdu0[3] = (((pS)->Cells)[j])[i]);

Try this
1
2
3
4
  
cdu0[0] =	pS->Cells[j][i].Color;
cdu0[1] =	pS->Cells[j][i].Flags;
cdu0[2] =	pS->Cells[j][i].Symbol;
Thoms1965: I think you are close to be my hero of day

But, I get

Error C2440 '=' : cannot convert from 'unsigned char' to 'int [14]'

even if I have unsigned char type on both side of expression
Last edited on
Maybe you need brackets around. (pS->Cells[j][i]).Color;
Hi,

I had another int cdu0 definition that caused the error above.

Now it works.

Thomas1965: I owe you a BIG THANK
Topic archived. No new replies allowed.