Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems creating a class refering to hdc

Status
Not open for further replies.

markitus

Programmer
Apr 12, 2005
10
PL
hi everybody:
i'm a newbie using visual. I must create an API for drawing lines, rectangles and triangles. I need it for tomorrow :( . And I'm having problem creating a simple class called Lines into a simple .c file. When compiling, it gives back the next error :

C:\MARC\EGUI\NUEVA CARPETA\api.cpp(25) : error C2065: 'hdc' : undeclared identifier

#include <windows.h>

class Lines {

public:


public:
POINT a;
POINT b;

Lines()
{
a.x=0;
a.y=0;
b.x=0;
b.y=0;


};

void drawLine(POINT a, POINT b)
{
MoveToEx( hdc, a.x, a.y, NULL ); <-- LINE 25
LineTo( hdc, b.x, b.y );
};
};






LONG WINAPI WndProc( HWND, UINT, WPARAM, LPARAM );
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow )
{
static char szAppName[] = "MyApp";
WNDCLASS wc;
HWND hwnd;
MSG msg;
wc.style = CS_HREDRAW; //class style
wc.lpfnWndProc = (WNDPROC)WndProc; //address of event handler procedure
wc.cbClsExtra = 0; //size of class data store (in bytes)
wc.cbWndExtra = 0; //size of window data store (in bytes)
wc.hInstance = hInstance; //handle to instance registering window
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); //icon handle
wc.hCursor = LoadCursor( NULL, IDC_ARROW ); //cursor handle
// wc.hbrBackground = COLOR_WINDOW + 1; //background color
wc.lpszMenuName = NULL; //menu name
wc.lpszClassName = szAppName; //class name
RegisterClass( & wc );
hwnd = CreateWindow( szAppName, //class name
szAppName, //window name
WS_OVERLAPPEDWINDOW, //window style
CW_USEDEFAULT, //window position (x)
CW_USEDEFAULT, //window position (y)
CW_USEDEFAULT, //initial window width
CW_USEDEFAULT, //initial window height
HWND_DESKTOP, //parent window handle
NULL, //menu handle
hInstance, //application instance handle
NULL ); //data (parameter to pass)


ShowWindow( hwnd, nCmdShow );
UpdateWindow( hwnd );
//message processing loop
while( GetMessage( & msg, NULL, 0, 0 ) ) //retrieve message from queue
{
TranslateMessage( & msg ); //translate message (keyboard)
DispatchMessage( & msg ); //routing message to event handler procedure
}
return msg.wParam;
}

//window event handler procedure
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{

PAINTSTRUCT ps;
HDC hdc;
RECT rect;





switch( message )
{
case WM_PAINT:
hdc = BeginPaint( hwnd, & ps );
GetClientRect( hwnd, & rect );


DrawText( hdc, "Hello Windows!", -1, & rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER );


break;
case WM_DESTROY:
PostQuitMessage( 0 ); //sending WM_QUIT message
return 0;
}
return DefWindowProc( hwnd, message, wParam, lParam );
}


don't know what to do... How can i refer to hdc from here??? any idea ?? thank u so much.
 
Pass a hdc as parameter from WM_PAINT message processing.
Also you have no objects of class Lines, only class definition.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top