|
LiYS wrote: I'm always wondering what happens when something is casted
Don't wonder. Study the subject, get or find materials (like this for example[^] ) and read it until you understand.
|
|
|
|
|
LiYS wrote: Why the reference '&' is needed here?
Where?
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
jhwurmbach wrote: SPREADSHEET& g_ss = * (PSPREADSHEET) m_pArray ;
|
|
|
|
|
:-OOk. Well....
I second the question of the original poster: Why are we taking a reference from that pointer?
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
That little snippet of code makes my head hurt.
A C++ spreadsheet class implementing a multidimension array of CELL structs
is SO much cleaner to use, encapsulated, typesafe, etc., etc...
Hapy Thanksgiving man!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: That little snippet of code makes my head hurt.
Yeah, I thought about trying to explain that the wrong question was being asked but figured what the heck, they're all gone fishin
|
|
|
|
|
CELL* m_pArray = (CELL*) VirtualAlloc(NULL, g_nNumRows * g_nNumCols, <font color="Red"><-- shouldn't that be g_nNumRows * g_nNumCols * sizeof(CELL)</font>
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The easiest way to understand typedef is that it works the same way as if you were declaring a variable. If you were declaring a 2d array of cells, you could use CELL array[g_nNumRows][g_nNumCols]; . If you put a typedef in front of the declaration, it gives a name to the type that such a variable would be.
The & is used to create a reference to the SPREADSHEET that will act like a value. In many cases, this is a good way to avoid using * for all your variable references, and to make sure you don't accidentally change the value of the pointer it hides. In this case, the effects are complicated by the way pointers act like arrays, so this might not be good code to start learning from.
The more appropriate way to write the last line might make more sense:
SPREADSHEET& g_ss = *reinterpret_cast<PSPREADSHEET>(m_pArray)
In this case, the C array/pointer equivalence is used again. Casting to and from void * is more common, and it is used for code that works on pointers without regard to the type pointed to.
I can see a couple problems in the code you have posted. The names of the array dimensions look like variable names, but array sizes declared that way have to be compile time constants. Also, there seems to be a sizeof(CELL) missing in the VirtualAlloc statement.
Nathan
|
|
|
|
|
Thanks Nathan,
Nathan Holt at EMOM wrote: The & is used to create a reference to the SPREADSHEET that will act like a value. In many cases, this is a good way to avoid using * for all your variable references, and to make sure you don't accidentally change the value of the pointer it hides. In this case, the effects are complicated by the way pointers act like arrays, so this might not be good code to start learning from.
This & references to array's address?
To me cast into user defined type in this scenario is just like stuff the memory into the target type's structure in byte.
|
|
|
|
|
|
A user interface? All I see is an image.
|
|
|
|
|
|
done. where do i send it now ?
|
|
|
|
|
Simply upload an image, that'll be fine
|
|
|
|
|
Really?
followait@163.com
or
followait@hotmail.com
|
|
|
|
|
ohhh, no no no, it took me time to do it ! i want to be payed !
you can use my paypal account for that (same Id as my nickname)
|
|
|
|
|
Check your link. I suppose it is a warning telling us that there is no image available but there is only chinese characters.
|
|
|
|
|
Sorry.
But the image is there.
|
|
|
|
|
I have some chinese letters and a "prohibited" symbol.
BTW, a GUI can be done in a few minutes or in days. It directly depends on what you want to do. Just asking "How much time need a GUI?" is no sense sorry.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
|
Hi,
There are certain sub-classes that I use often in many projects. For example CMyDialog, CMyFormView... Each time I have to use CMyDialog instead of CDialog I have to rename CDialog to CMyDialog in the .cpp and .h files.
Is there any way to add CMyDialog, CMyFormView to the list of base classes so that this derivation is done automatically while creating a new dialog/formView class?
Thanks.
Tara
Fortitudine Vincimus!
|
|
|
|
|
I don't know if there is a way, but I guess is not a good idea to go into the core of the MFC and modify things.
I personally find the CTRL+H (search and replace all) very usefull for that moment, and is just a few seconds.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Hi, I need help with a C++ Win32 GDI project I am working on in both Bloodshed Dev C++ and Visual C++ 6.0 and Up in Windows XP SP2.
What my program does is moves a ball (circle) arround the screen corresponding to arrow keys, and a fixed cross that reappears as the ball passes over it. The problem is that when I do the BitBlt, it draws a square instead of a circle, so a square is overwriting the cross (basically, a circle with a white square region around it. Is there a way to do this BitBlt with just the circle and not the square because this is annoying. In other words, I don't want a square region overwriting the cross - just the circle.
Here is what I have so far:
----------------------------
#include <windows.h>
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
static HANDLE hBitmap;
static HBRUSH hBrush;
static HDC hdc;
static HDC hdcMem;
static int cxClient;
static int cyClient;
static int xCenter = 100;
static int yCenter = 100;
static int objSize = 100;
static int cxTotal;
static int cyTotal;
static int cxRadius;
static int cyRadius;
static int cxMove;
static int cyMove;
static int xPixel;
static int yPixel;
static int nScale;
static bool flag = false;
static int crossx = 100;
static int crossy = 100;
double MAX (double a, double b)
{
if (a > b)
{
return a;
}
return b;
}
double MIN (double a, double b)
{
if (a < b)
{
return a;
}
return b;
}
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by
windows */
wincl.style = CS_HREDRAW | CS_VREDRAW; /* Catch
double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the
window class */
wincl.cbWndExtra = 0; /* structure or the window
instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
800, /* The programs width */
600, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave
*/
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
if (hBitmap)
{
DeleteObject(hBitmap);
}
PostQuitMessage (0); /* send a WM_QUIT to the message queue
*/
break;
case WM_CREATE:
hdc = GetDC(hwnd);
xPixel = GetDeviceCaps(hdc,ASPECTX);
yPixel = GetDeviceCaps(hdc,ASPECTY);
ReleaseDC(hwnd,hdc);
return 0;
case WM_PAINT:
hdc = GetDC(hwnd);
hdcMem = CreateCompatibleDC(hdc);
if(flag)
{
RECT rc;
rc.left = 0;
rc.top = 0;
rc.right = 800;
rc.bottom = 600;
FillRect(hdc, &rc, (HBRUSH)RGB(0,0,0));
MoveToEx(hdc, crossx, crossy, NULL);
LineTo(hdc, crossx+50, crossy);
LineTo(hdc, crossx+50, crossy-50);
LineTo(hdc, crossx+75, crossy-50);
LineTo(hdc, crossx+75, crossy);
LineTo(hdc, crossx+125, crossy);
LineTo(hdc, crossx+125, crossy+25);
LineTo(hdc, crossx+75, crossy+25);
LineTo(hdc, crossx+75, crossy+75);
LineTo(hdc, crossx+50, crossy+75);
LineTo(hdc, crossx+50, crossy+25);
LineTo(hdc, crossx, crossy+25);
LineTo(hdc, crossx, crossy);
}
SelectObject(hdcMem,hBitmap);
BitBlt(hdc,xCenter-cxTotal/2,yCenter-cyTotal/2,cxTotal,cyTotal,hdcMem,0,0,SRCC
OPY);
ReleaseDC(hwnd,hdc);
DeleteDC(hdcMem);
flag = false;
return 0;
case WM_MOVE:
hdc = GetDC(hwnd);
MoveToEx(hdc, crossx, crossy, NULL);
LineTo(hdc, crossx+50, crossy);
LineTo(hdc, crossx+50, crossy-50);
LineTo(hdc, crossx+75, crossy-50);
LineTo(hdc, crossx+75, crossy);
LineTo(hdc, crossx+125, crossy);
LineTo(hdc, crossx+125, crossy+25);
LineTo(hdc, crossx+75, crossy+25);
LineTo(hdc, crossx+75, crossy+75);
LineTo(hdc, crossx+50, crossy+75);
LineTo(hdc, crossx+50, crossy+25);
LineTo(hdc, crossx, crossy+25);
LineTo(hdc, crossx, crossy);
ReleaseDC(hwnd,hdc);
return 0;
case WM_SIZE:
xCenter = (cxClient=LOWORD(lParam))/2;
yCenter = (cyClient=HIWORD(lParam))/2;
nScale = (int)MIN(cxClient*xPixel,cyClient*yPixel)/16;
cxRadius = nScale/xPixel;
cyRadius = nScale/yPixel;
cxTotal = 2*(cxRadius+cxMove);
cyTotal = 2*(cyRadius+cyMove);
if (hBitmap)
{
DeleteObject(hBitmap);
}
hdc = GetDC(hwnd);
hdcMem = CreateCompatibleDC(hdc);
// hdcCross = CreateCompatibleDC(hdc);
MoveToEx(hdc, crossx, crossy, NULL);
LineTo(hdc, crossx+50, crossy);
LineTo(hdc, crossx+50, crossy-50);
LineTo(hdc, crossx+75, crossy-50);
LineTo(hdc, crossx+75, crossy);
LineTo(hdc, crossx+125, crossy);
LineTo(hdc, crossx+125, crossy+25);
LineTo(hdc, crossx+75, crossy+25);
LineTo(hdc, crossx+75, crossy+75);
LineTo(hdc, crossx+50, crossy+75);
LineTo(hdc, crossx+50, crossy+25);
LineTo(hdc, crossx, crossy+25);
LineTo(hdc, crossx, crossy);
hBitmap = CreateCompatibleBitmap(hdc,cxTotal,cyTotal);
ReleaseDC(hwnd,hdc);
SelectObject(hdcMem,hBitmap);
Rectangle(hdcMem,-1,-1,cxTotal+1,cyTotal+1);
hBrush = CreateHatchBrush(HS_DIAGCROSS,0);
SelectObject(hdcMem,hBrush);
SetBkColor(hdcMem,RGB(0,127,255));
Ellipse(hdcMem,cxMove,cyMove,cxTotal-cxMove,cyTotal-cyMove);
DeleteDC(hdcMem);
DeleteObject(hBrush);
return 0;
case WM_KEYDOWN:
switch(wParam)
{
case VK_LEFT:
xCenter -= 10;
flag = true;
break;
case VK_RIGHT:
xCenter += 10;
flag = true;
break;
case VK_UP:
yCenter -= 10;
flag = true;
break;
case VK_DOWN:
yCenter += 10;
flag = true;
break;
}
SendMessage(hwnd, WM_PAINT, 0, 0);
return 0;
default: /* for messages that we don't deal with
*/
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
Jason Cohn
|
|
|
|
|
Did you try it with a CRgn or HREGION ?
Greetings from Germany
|
|
|
|
|
usually a well chosen raster operation (such us SRCPAINT, instead of SRCCOPY) does the trick (of course you have to choose bitmap colors accordingly)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|