![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
|
Help me fix this code please
Hello guys, im working on this windows calculator and im having a few trouble doing stuff.
The following code will display the unfinished calculator #include <windows.h>
#include <iostream>
//define all the buttons
#define IDE_TEXT 101
#define IDB_BUTTON1 500
#define IDB_BUTTON2 501
#define IDB_BUTTON3 502
#define IDB_BUTTON4 503
#define IDB_BUTTON5 504
#define IDB_BUTTON6 505
#define IDB_BUTTON7 506
#define IDB_BUTTON8 507
#define IDB_BUTTON9 508
#define IDB_BUTTONANSWER 509
#define IDB_BUTTONADD 510
#define IDB_BUTTONMINUS 511
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
HINSTANCE g_hInst;
char szClassName[ ] = "WindowsApp";
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 */
g_hInst=hThisInstance;
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
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;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Frantz corporation", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* 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 */
);
ShowWindow (hwnd, nFunsterStil);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rc;
static HWND Button1=0;
static HWND Button2=0;
static HWND Button3=0;
static HWND Button4=0;
static HWND Button5=0;
static HWND Button6=0;
static HWND Button7=0;
static HWND Button8=0;
static HWND Button9=0;
static HWND ButtonAnswer=0;
static HWND ButtonAdd=0;
static HWND ButtonMinus=0;
static HWND ButtonWindow=0;
switch (message) /* handle the messages */
{
case WM_CREATE:
//The following codes will draw all the buttons in calculator
CreateWindow(
"Button",
"1",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
10,80,50,30,
hwnd,
(HMENU) IDB_BUTTON1,
GetModuleHandle(NULL), NULL);
CreateWindow(
"Button",
"2",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
70,80,50,30,
hwnd,
(HMENU) IDB_BUTTON2,
GetModuleHandle(NULL), NULL);
CreateWindow(
"Button",
"3",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
130,80,50,30,
hwnd,
(HMENU) IDB_BUTTON3,
GetModuleHandle(NULL), NULL);
Button4=CreateWindow(
"Button",
"4",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
10,120,50,30,
hwnd,
(HMENU) IDB_BUTTON4,
GetModuleHandle(NULL), NULL);
Button5=CreateWindow(
"Button",
"5",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
70,120,50,30,
hwnd,
(HMENU) IDB_BUTTON5,
GetModuleHandle(NULL), NULL);
Button6=CreateWindow(
"Button",
"6",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
130,120,50,30,
hwnd,
(HMENU) IDB_BUTTON6,
GetModuleHandle(NULL), NULL);
Button7=CreateWindow(
"Button",
"7",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
10,160,50,30,
hwnd,
(HMENU) IDB_BUTTON7,
GetModuleHandle(NULL), NULL);
Button8=CreateWindow(
"Button",
"8",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
70,160,50,30,
hwnd,
(HMENU) IDB_BUTTON8,
GetModuleHandle(NULL), NULL);
Button9=CreateWindow(
"Button",
"9",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
130,160,50,30,
hwnd,
(HMENU) IDB_BUTTON9,
GetModuleHandle(NULL), NULL);
ButtonAnswer=CreateWindow(
"Button",
"Answer",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
80,200,60,30,
hwnd,
(HMENU) IDB_BUTTONANSWER,
GetModuleHandle(NULL), NULL);
ButtonAdd=CreateWindow(
"Button",
"+",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
10,200,50,30,
hwnd,
(HMENU) IDB_BUTTONADD,
GetModuleHandle(NULL), NULL);
ButtonWindow=CreateWindow(
"edit",
NULL,
WS_VISIBLE | WS_CHILD,
80,300,100,20,
hwnd,
(HMENU) IDE_TEXT,
GetModuleHandle(NULL),
NULL);
break;
case WM_COMMAND:
//was a button clicked?
if( HIWORD( wParam ) == BN_CLICKED )
{
//this is where im having trouble
switch( LOWORD( wParam ) )
{
//how do i make 1 show up in text window when i click this?????
//textout does not work.
//same thing go with all the other buttons
case IDB_BUTTON1:
hdc=GetDC(hwnd);
TextOut(hdc, 80, 300, "1", 1);
break;
//how do i get the answer to show up?
case IDB_BUTTONANSWER:
break;
}
//and also, when i click a button, the window leaves!!
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
break;
}
break;
}
}Now ive got 2 problems 1: How do i make it like when i click a button, it outputs the wanted number on the screen. 2: How do i make the answer show up when i click the answer button. Please, ive been working on this for hours. Also, when i click a button, the calculator closes Oh, and the code will compile under the devc++ compiler |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|