Click here to Skip to main content
15,904,023 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Does it take much time to do such a user interface? Pin
toxcct21-Nov-07 21:15
toxcct21-Nov-07 21:15 
GeneralRe: Does it take much time to do such a user interface? Pin
Cedric Moonen21-Nov-07 4:45
Cedric Moonen21-Nov-07 4:45 
GeneralRe: Does it take much time to do such a user interface? Pin
followait21-Nov-07 15:41
followait21-Nov-07 15:41 
GeneralRe: Does it take much time to do such a user interface? Pin
Nelek21-Nov-07 20:39
protectorNelek21-Nov-07 20:39 
QuestionRe: Does it take much time to do such a user interface? Pin
Hamid_RT21-Nov-07 19:11
Hamid_RT21-Nov-07 19:11 
Questionoft used derived class(VC6/MFC) Pin
Tara1421-Nov-07 4:21
Tara1421-Nov-07 4:21 
AnswerRe: oft used derived class(VC6/MFC) Pin
Nelek21-Nov-07 20:36
protectorNelek21-Nov-07 20:36 
QuestionHelp with C++ Win32 GDI Program Pin
Jason Daniel Cohn21-Nov-07 3:52
Jason Daniel Cohn21-Nov-07 3:52 
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

AnswerRe: Help with C++ Win32 GDI Program Pin
KarstenK21-Nov-07 4:00
mveKarstenK21-Nov-07 4:00 
AnswerRe: Help with C++ Win32 GDI Program Pin
CPallini21-Nov-07 4:06
mveCPallini21-Nov-07 4:06 
AnswerRe: Help with C++ Win32 GDI Program Pin
Cedric Moonen21-Nov-07 4:08
Cedric Moonen21-Nov-07 4:08 
QuestionExtracting formatted text from Excel [modified] Pin
martinds4421-Nov-07 3:50
martinds4421-Nov-07 3:50 
QuestionActiveX Pin
ashok_toknow21-Nov-07 2:29
ashok_toknow21-Nov-07 2:29 
QuestionWizard for derivated classes Pin
Dirso21-Nov-07 2:12
Dirso21-Nov-07 2:12 
QuestionHelp regarding DeleteFile(..) Pin
chandu00421-Nov-07 1:55
chandu00421-Nov-07 1:55 
QuestionRe: Help regarding DeleteFile(..) Pin
Nelek21-Nov-07 2:00
protectorNelek21-Nov-07 2:00 
AnswerRe: Help regarding DeleteFile(..) Pin
chandu00421-Nov-07 2:16
chandu00421-Nov-07 2:16 
GeneralRe: Help regarding DeleteFile(..) Pin
Nelek21-Nov-07 3:48
protectorNelek21-Nov-07 3:48 
GeneralRe: Help regarding DeleteFile(..) Pin
chandu00421-Nov-07 4:51
chandu00421-Nov-07 4:51 
AnswerRe: Help regarding DeleteFile(..) Pin
chandu00421-Nov-07 2:21
chandu00421-Nov-07 2:21 
GeneralRe: Help regarding DeleteFile(..) Pin
Nelek21-Nov-07 3:19
protectorNelek21-Nov-07 3:19 
GeneralRe: Help regarding DeleteFile(..) Pin
chandu00421-Nov-07 4:49
chandu00421-Nov-07 4:49 
GeneralRe: Help regarding DeleteFile(..) Pin
Nelek21-Nov-07 20:32
protectorNelek21-Nov-07 20:32 
AnswerRe: Help regarding DeleteFile(..) Pin
Malli_S21-Nov-07 2:02
Malli_S21-Nov-07 2:02 
GeneralRe: Help regarding DeleteFile(..) Pin
chandu00421-Nov-07 2:22
chandu00421-Nov-07 2:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.