![]() |
| | #1 |
| Back! ^.^ Join Date: Oct 2001
Posts: 568
| Quack! It doesn't work! >.< Code: /*
Olympic Symbol Program
*/
#include <lvp\gui_top.h>
class GuiClass
{
public:
GuiClass();
void GuiMouseClick(int x, int y);
void GuiPaint();
String Title();
private:
};
GuiClass::GuiClass()
{
}
String GuiClass::Title()
{
return ("The Olympic Symbol!");
}
void GuiClass::GuiMouseClick (int x, int y)
{
}
void GuiClass::GuiPaint()
{
Circle(180,200,50);
Circle(250,200,50);
Circle(320,200,50);
Circle(215,270,50);
Circle(285,270,50);
}
#include <lvp\gui_bot.h>
C:\DEV-C_~1\INCLUDE\lvp\gui_bot.h: In function `int WinMain(HINSTANCE__ *, HINSTANCE__ *, CHAR *, int)': and this (2 times): 474 c:\dev-c_~1\include\lvp\gui_bot.h warning: converting NULL to non-pointer type Can anyone help me fix this? o.O |
| *Michelle* is offline | |
| | #2 |
| Banned Join Date: Feb 2003 Location: Australia
Posts: 986
| Well both your problems seem to be in gui_bot.h, maybe it might be easier to post some of the code from this (unless it is some sort of a standard header, which I have not heard of before). ~ Paul |
| nickname_changed is offline | |
| | #3 |
| Back! ^.^ Join Date: Oct 2001
Posts: 568
| Ya, it's actually a header file. I didn't make that... Anyway, here's the entire gui_bot.h ![]() Code: // gui_bot.h: implements the Windows function, and starts the
// Windows To support event driven programming
// Lawrenceville Press September 1998
#include <windows.h>
#include <stdio.h>
// Standard prototype for window procedure.
//LRESULT FAR PASCAL _export WndProc(HWND hWnd, UINT message,
// WPARAM wParam, LPARAM lParam);
LONG PASCAL WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
// Class which acts as wrapper for GUI functions
class MyGuiWindow {
public:
friend void Circle(int xc,int yc,int r);
friend void Line(int x1, int y1, int x2, int y2);
friend int MessageBox(String Text, String Title);
friend int MessageBoxYN(String Text, String Title);
// friend int SetTimer(UINT TimerID, UINT Time); // Not implemented
friend void SetColor(int R, int G, int B);
friend void SetFillColor(int R, int G, int B);
friend void SetColor(COLORREF NewColor);
friend void SetFillColor(COLORREF NewColor);
friend void SetThickness(int PixelWidth);
friend void FloodFill(int x, int y);
friend void SetPixel(int x, int y);
friend int GetPixel(int x, int y);
friend void DrawText(String S);
friend void DrawText(int N);
friend void DrawText(long N);
friend void DrawText(double D);
friend void DrawCenteredText(String S);
friend void DrawCenteredText(int N);
friend void DrawCenteredText(long N);
friend void DrawCenteredText(double D);
friend void SetTextColor(COLORREF NewColor);
friend void SetTextSize(int NewFontSize);
friend void SetTextFont(String FontName);
friend void gotoxy(int x, int y);
friend int wherex();
friend int wherey();
friend void FilledCircle(int xc,int yc,int r);
friend void Rectangle(int x1, int y1, int x2, int y2);
friend void FilledRectangle(int x1, int y1, int x2, int y2);
MyGuiWindow();
private:
void open(HWND hwnd, HDC win_hdc);
HDC _hdc;
HWND _hwnd;
int _disp_xmax; // the physical window dimension (in pixels)
int _disp_ymax;
int RedVal, GreenVal, BlueVal, ThickVal;
int RedFillVal, GreenFillVal, BlueFillVal;
int RedTextVal, GreenTextVal, BlueTextVal;
int FontSize;
String FontName;
int FontFamily;
// The core function should have access to my wrapper data: friend
// friend LRESULT FAR PASCAL _export WndProc(HWND hWnd, UINT message,
// WPARAM wParam, LPARAM lParam);
friend LRESULT FAR PASCAL WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
};
//-------------------------------------------------------
// Global objects
GuiClass GUI; // "User" defined
MyGuiWindow gui_out; // The actual Window object
HINSTANCE GlobalhInstance; // Global instance handle
//-------------------------------------------------------
MyGuiWindow::MyGuiWindow():
RedVal(0),GreenVal(0), BlueVal(0), ThickVal(1),
RedFillVal(0),GreenFillVal(0), BlueFillVal(0),
RedTextVal(0),GreenTextVal(0), BlueTextVal(0), FontSize(22),
FontName("System"), FontFamily(FF_SWISS)
{}
//-------------------------------------------------------
void MyGuiWindow::open(HWND hwnd, HDC win_hdc)
{
RECT rect;
GetClientRect(hwnd, &rect);
_disp_xmax = rect.right - 1;
_disp_ymax = rect.bottom - 1;
_hdc = win_hdc;
_hwnd = hwnd;
SelectObject(_hdc, GetStockObject(NULL_BRUSH));
SelectObject(_hdc, GetStockObject(BLACK_PEN));
SelectObject(_hdc, GetStockObject(SYSTEM_FONT));
}
//-------------------------------------------------------
int GetMaxX()
{
return GetSystemMetrics(SM_CXSCREEN);
}
//-------------------------------------------------------
int GetMaxY()
{
return GetSystemMetrics(SM_CYSCREEN);
}
//-------------------------------------------------------
void Line(int x1, int y1, int x2, int y2)
{
HPEN hpen = CreatePen(PS_SOLID, gui_out.ThickVal,
RGB(gui_out.RedVal, gui_out.GreenVal, gui_out.BlueVal));
HPEN hpenOld = HPEN(SelectObject(gui_out._hdc, hpen));
//MoveTo(gui_out._hdc, x1, y1);
MoveToEx(gui_out._hdc, x1, y1, NULL);
LineTo(gui_out._hdc, x2, y2);
SelectObject(gui_out._hdc, hpenOld);
DeleteObject(hpen);
}
//---------------------------------------------------
void Circle(int xc,int yc,int r)
{
HPEN hpen = CreatePen(PS_INSIDEFRAME, gui_out.ThickVal,
RGB(gui_out.RedVal, gui_out.GreenVal, gui_out.BlueVal));
HPEN hpenOld = HPEN(SelectObject(gui_out._hdc, hpen));
Ellipse(gui_out._hdc,xc-r, yc-r, xc+r, yc+r);
SelectObject(gui_out._hdc, hpenOld);
DeleteObject(hpen);
}
//---------------------------------------------------
void Rectangle(int x1, int y1, int x2, int y2)
{
HPEN hpen = CreatePen(PS_INSIDEFRAME, gui_out.ThickVal,
RGB(gui_out.RedVal, gui_out.GreenVal, gui_out.BlueVal));
HPEN hpenOld = HPEN(SelectObject(gui_out._hdc, hpen));
Rectangle(gui_out._hdc,x1, y1, x2, y2);
SelectObject(gui_out._hdc, hpenOld);
DeleteObject(hpen);
}
//---------------------------------------------------
void DrawText(String S)
{
SetTextColor(gui_out._hdc, RGB(gui_out.RedTextVal, gui_out.GreenTextVal, gui_out.BlueTextVal));
HFONT hFont = CreateFont(gui_out.FontSize,0,0,0,FW_NORMAL,0,0,0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
PROOF_QUALITY, gui_out.FontFamily | VARIABLE_PITCH, gui_out.FontName.c_str());
HFONT hOldFont = HFONT(SelectObject(gui_out._hdc, hFont));
// Below for Visual C++
POINT P;
GetCurrentPositionEx(gui_out._hdc, &P);
SetTextAlign(gui_out._hdc,TA_BASELINE | TA_LEFT | TA_UPDATECP);
TextOut(gui_out._hdc,P.x,P.x,S.c_str(),S.length());
// Above for Visual C++
//*/
/* This for Borland C++
DWORD P = GetCurrentPosition(gui_out._hdc);
SetTextAlign(gui_out._hdc,TA_BASELINE | TA_LEFT | TA_UPDATECP);
TextOut(gui_out._hdc,LOWORD(P),HIWORD(P),S.c_str(),S.length());
//*/
SelectObject(gui_out._hdc, hOldFont);
DeleteObject(hFont);
}
//---------------------------------------------------
void DrawCenteredText(String S)
{
SetTextColor(gui_out._hdc, RGB(gui_out.RedTextVal, gui_out.GreenTextVal, gui_out.BlueTextVal));
HFONT hFont = CreateFont(gui_out.FontSize,0,0,0,FW_NORMAL,0,0,0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
PROOF_QUALITY, gui_out.FontFamily | VARIABLE_PITCH, gui_out.FontName.c_str());
HFONT hOldFont = HFONT(SelectObject(gui_out._hdc, hFont));
// Below for Visual C++
POINT P;
GetCurrentPositionEx(gui_out._hdc, &P);
SetTextAlign(gui_out._hdc,TA_BASELINE | TA_CENTER | TA_UPDATECP);
TextOut(gui_out._hdc,P.x,P.x,S.c_str(),S.length());
// Above for Visual C++
/* This for Borland
DWORD P = GetCurrentPosition(gui_out._hdc);
SetTextAlign(gui_out._hdc,TA_BASELINE | TA_CENTER | TA_UPDATECP);
TextOut(gui_out._hdc,LOWORD(P),HIWORD(P),S.c_str(),S.length());
*/
SelectObject(gui_out._hdc, hOldFont);
DeleteObject(hFont);
}
//---------------------------------------------------
void DrawText(int N)
{
char buf[80];
wsprintf(buf,"%i",N);
String S = buf;
DrawText(S);
}
//-------------------------------------------------------
void DrawText(long N)
{
char buf[80];
wsprintf(buf,"%li",N);
String S = buf;
DrawText(S);
}
//---------------------------------------------------
void DrawText(double D)
// Print double in XXX.XX form, with exactly two decimals
{
char buf[80];
int whole = int(D);
int fraction = int((D-whole)*100);
if (fraction < 0)
fraction = -fraction;
wsprintf(buf,"%i.%i",whole,fraction);
String S = buf;
DrawText(S);
}
//---------------------------------------------------
void DrawCenteredText(int N)
{
char buf[80];
wsprintf(buf,"%i",N);
String S = buf;
DrawCenteredText(S);
}
//-------------------------------------------------------
void DrawCenteredText(long N)
{
char buf[80];
wsprintf(buf,"%li",N);
String S = buf;
DrawCenteredText(S);
}
//---------------------------------------------------
void DrawCenteredText(double D)
// Print double in XXX.XX form, with exactly two decimals
{
char buf[80];
int whole = int(D);
int fraction = int((D-whole)*100);
if (fraction < 0)
fraction = -fraction;
wsprintf(buf,"%i.%i",whole,fraction);
String S = buf;
DrawCenteredText(S);
}
//---------------------------------------------------
void SetTextColor(COLORREF NewColor)
{
gui_out.RedTextVal = GetRValue(NewColor);
gui_out.GreenTextVal = GetGValue(NewColor);
gui_out.BlueTextVal = GetBValue(NewColor);
}
//---------------------------------------------------
void SetTextSize(int NewFontSize)
{
gui_out.FontSize = NewFontSize;
}
//---------------------------------------------------
void SetTextFont(String NewFontName)
{
if (NewFontName == "Arial"
|| NewFontName == "System"
|| NewFontName == "Times New Roman"){
gui_out.FontName = NewFontName;
if (NewFontName == "Times New Roman")
gui_out.FontFamily = FF_ROMAN;
else
gui_out.FontFamily = FF_SWISS;
}
}
//---------------------------------------------------
void SetPixel(int x, int y)
{
SetPixel(gui_out._hdc, x, y,
RGB(gui_out.RedVal, gui_out.GreenVal, gui_out.BlueVal));
RECT rect;
rect.left = x;
rect.top = y;
rect.right = x;
rect.bottom = y;
InvalidateRect(gui_out._hwnd, &rect, TRUE);
}
//---------------------------------------------------
int GetPixel(int x, int y)
/* Returns true iff pixel is not white */
{
return (GetPixel(gui_out._hdc,x,y)!=RGB(255,255,255));
}
//---------------------------------------------------
int wherex()
{
// Below for Visual
POINT P;
GetCurrentPositionEx(gui_out._hdc, &P);
return P.x;
// Above for Visual */
/* Below for Borland:
DWORD P = GetCurrentPosition(gui_out._hdc);
return LOWORD(P);
// Above for Borland */
}
//---------------------------------------------------
int wherey()
{
// Below for Visual
POINT P;
GetCurrentPositionEx(gui_out._hdc, &P);
return P.y;
// Above for Visual */
/* Below for Borland
DWORD P = GetCurrentPosition(gui_out._hdc);
return HIWORD(P);
// Above for Borland */
}
//---------------------------------------------------
void gotoxy(int x, int y)
{
// Borland: MoveTo(gui_out._hdc, x, y);
MoveToEx(gui_out._hdc, x, y, NULL); // Visual
}
//---------------------------------------------------
int MessageBox(String Text, String Title)
{
return MessageBox(gui_out._hwnd, Text.c_str(), Title.c_str(),
MB_OK | MB_ICONINFORMATION);
}
//---------------------------------------------------
int MessageBoxYN(String Text, String Title)
{
return MessageBox(gui_out._hwnd, Text.c_str(), Title.c_str(),
MB_YESNO | MB_ICONQUESTION)==IDYES;
}
//---------------------------------------------------
void SetColor(COLORREF NewColor)
{
gui_out.RedVal = GetRValue(NewColor);
gui_out.GreenVal = GetGValue(NewColor);
gui_out.BlueVal = GetBValue(NewColor);
}
//---------------------------------------------------
void SetFillColor(COLORREF NewColor)
{
gui_out.RedFillVal = GetRValue(NewColor);
gui_out.GreenFillVal = GetGValue(NewColor);
gui_out.BlueFillVal = GetBValue(NewColor);
}
//---------------------------------------------------
void SetColor(int R, int G, int B)
{
gui_out.RedVal = R;
gui_out.GreenVal = G;
gui_out.BlueVal = B;
}
//---------------------------------------------------
void FloodFill(int x, int y)
{
HBRUSH hbr = CreateSolidBrush(
RGB(gui_out.RedFillVal,
gui_out.GreenFillVal,
gui_out.BlueFillVal));
HBRUSH hbrOld = HBRUSH(SelectObject(gui_out._hdc, hbr));
ExtFloodFill(gui_out._hdc, x, y,
GetPixel(gui_out._hdc,x,y), FLOODFILLSURFACE);
SelectObject(gui_out._hdc, hbrOld);
DeleteObject(hbr);
}
//---------------------------------------------------
void SetFillColor(int R, int G, int B)
{
gui_out.RedFillVal = R;
gui_out.GreenFillVal = G;
gui_out.BlueFillVal = B;
}
//---------------------------------------------------
void SetThickness(int PixelWidth)
{
gui_out.ThickVal = PixelWidth;
}
//---------------------------------------------------
void FilledCircle(int xc,int yc,int r)
{
HPEN hpen = CreatePen(PS_INSIDEFRAME, gui_out.ThickVal,
RGB(gui_out.RedVal, gui_out.GreenVal, gui_out.BlueVal));
HPEN hpenOld = HPEN(SelectObject(gui_out._hdc, hpen));
HBRUSH hbr = CreateSolidBrush(
RGB(gui_out.RedFillVal,
gui_out.GreenFillVal,
gui_out.BlueFillVal));
HBRUSH hbrOld = HBRUSH(SelectObject(gui_out._hdc, hbr));
Ellipse(gui_out._hdc,xc-r, yc-r, xc+r, yc+r);
SelectObject(gui_out._hdc, hbrOld);
DeleteObject(hbr);
SelectObject(gui_out._hdc, hpenOld);
DeleteObject(hpen);
}
//---------------------------------------------------
void FilledRectangle(int x1, int y1, int x2, int y2)
{
HPEN hpen = CreatePen(PS_INSIDEFRAME, gui_out.ThickVal,
RGB(gui_out.RedVal, gui_out.GreenVal, gui_out.BlueVal));
HPEN hpenOld = HPEN(SelectObject(gui_out._hdc, hpen));
HBRUSH hbr = CreateSolidBrush(
RGB(gui_out.RedFillVal,
gui_out.GreenFillVal,
gui_out.BlueFillVal));
HBRUSH hbrOld = HBRUSH(SelectObject(gui_out._hdc, hbr));
Rectangle(gui_out._hdc, x1,y1,x2,y2);
SelectObject(gui_out._hdc, hbrOld);
DeleteObject(hbr);
SelectObject(gui_out._hdc, hpenOld);
DeleteObject(hpen);
}
///////////////////////////////////////////////////////////
// WinMain
///////////////////////////////////////////////////////////
//int PASCAL WinMain(HINSTANCE hCurrentInst,
int WINAPI WinMain(HINSTANCE hCurrentInst,
HINSTANCE hPreviousInst, LPSTR /*lpszCmdLine */,
int nCmdShow)
{
WNDCLASS wndClass;
HWND hWnd;
MSG msg;
// If there's no previous instance of this application,
// define and register the window class.
if (hPreviousInst == NULL)
{
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hCurrentInst;
wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = HBRUSH(GetStockObject(WHITE_BRUSH));
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = "MyGui";
RegisterClass(&wndClass);
}
// The following line will open a console window also
// _InitEasyWin(); cout << "Hello" << endl;
// Get the size of the screen.
UINT width = GetSystemMetrics(SM_CXSCREEN);
UINT height = GetSystemMetrics(SM_CYSCREEN);
GlobalhInstance = hCurrentInst;
// Create a window of the previously defined class.
hWnd = CreateWindow(
"MyGui", // Window class's name.
GUI.Title().c_str(), // Title bar text.
WS_OVERLAPPEDWINDOW, // The window's style.
0, // X position.
0, // Y position.
width, // Width.
height, // Height.
NULL, // Parent window's handle.
NULL, // Menu handle.
hCurrentInst, // Instance handle.
NULL); // No additional data.
// Display the window on the screen.
ShowWindow(hWnd, nCmdShow);
// Force the window to repaint itself.
UpdateWindow(hWnd);
// Start the message loop.
while (GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
///////////////////////////////////////////////////////////
// WndProc()
//
// This is the main window procedure, which is called by
// Windows.
///////////////////////////////////////////////////////////
//LRESULT FAR PASCAL _export WndProc(HWND hWnd, UINT message,
LONG PASCAL WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT paintStruct;
// UINT width = GetSystemMetrics(SM_CXSCREEN);
// UINT height = GetSystemMetrics(SM_CYSCREEN);
// Handle message
switch(message)
{
case WM_PAINT:
hDC = BeginPaint(hWnd, &paintStruct);
gui_out.open(hWnd, hDC);
GUI.GuiPaint();
EndPaint(hWnd, &paintStruct);
return 0;
case WM_LBUTTONUP:
// Following lines not needed since use default for Invalidate
// RECT rect;
// rect.left = 1;
// rect.top = 1;
// rect.right = width;
// rect.bottom = height;
GUI.GuiMouseClick(LOWORD(lParam),HIWORD(lParam));
// InvalidateRect(hWnd, &rect, TRUE);
// GUI.GuiPaint();
// The following line causes a repaint of the entire window if the
// on a mouse-click. This causes flicker, but makes it easier for the
// client programmer.
InvalidateRect(hWnd, NULL, TRUE);
return 0;
/* Dialog boxes require a resource file, which we avoid
case WM_RBUTTONUP:
FARPROC lpfnAboutDialogProc;
lpfnAboutDialogProc = MakeProcInstance(
(FARPROC)AboutDialogProc, GlobalhInstance);
DialogBox(GlobalhInstance, MAKEINTRESOURCE(DIALOG_1),
hWnd, lpfnAboutDialogProc);
FreeProcInstance(lpfnAboutDialogProc);
//if (x == -1)
// MessageBox("error creating dbox","error");
return 0;
*/
// Timer not yet implemented
// case WM_TIMER:
// GUI.EvTimer(wParam);
// InvalidateRect(hWnd, &rect, TRUE);
// return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
// Make sure all unhandled messages get returned to Windows.
return DefWindowProc(hWnd, message, wParam, lParam);
}
|
| *Michelle* is offline | |
| | #4 |
| samurai warrior Join Date: Nov 2001
Posts: 196
| lawrenceville press..yuck...are you using visual c++...because it doesnt work for us too...that book was made for borland c++......if you want GUI you have two options..WIN32 API or Visual Basic... your choice |
| nextus is offline | |
| | #5 |
| Back! ^.^ Join Date: Oct 2001
Posts: 568
| No... I use dev C++... So GUI doesn't work in that? Darn it! :| Now I have to get another program *sigh* |
| *Michelle* is offline | |
| | #6 |
| Back! ^.^ Join Date: Oct 2001
Posts: 568
| Wow, heh, that's way beyond my level Sorry, I didn't understand that. But anyway, I tried commenting out the Visual C++ version and uncommenting the borland one, it didn't work. In fact, it gave me two errors instead of one XD Ya. And how exactly do you fix the NULL problem again? |
| *Michelle* is offline | |
| | #7 |
| Back! ^.^ Join Date: Oct 2001
Posts: 568
| I tried it with Visual C++ but this is what I got: --------------------Configuration: GUi2 - Win32 Debug-------------------- Compiling... GUI2.cpp Linking... LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/GUi2.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. GUi2.exe - 2 error(s), 0 warning(s) |
| *Michelle* is offline | |
| | #8 | |
| I lurk Join Date: Aug 2002
Posts: 1,361
| Quote:
#pragma comment(linker, "/subsystem:windows") | |
| Eibro is offline | |
| | #9 |
| Back! ^.^ Join Date: Oct 2001
Posts: 568
| Eibro!!!!!!!!!!!!!!!!!!!!!!! *MUAH* IT works now! yeeeaaah! Thank you soo much! |
| *Michelle* is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| getline() don't want to work anymore... | mikahell | C++ Programming | 7 | 07-31-2006 10:50 AM |
| Why don't the tutorials on this site work on my computer? | jsrig88 | C++ Programming | 3 | 05-15-2006 10:39 PM |
| Problems in getting OpenGL to work | zonf | C Programming | 5 | 02-13-2006 04:48 AM |
| fopen(); | GanglyLamb | C Programming | 8 | 11-03-2002 12:39 PM |
| DLL __cdecl doesnt seem to work? | Xei | C++ Programming | 6 | 08-21-2002 04:36 PM |