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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help linking OFWIN

Status
Not open for further replies.

trose178

Programmer
Nov 26, 2002
26
US
Help im a newb and dont know how to do much C++ but im learning. I need help compiling OFWIN using Listing OFWIN1 and OFWIN2 for a simple windows program. heres my code:

// OFWIN.CPP Native windows program to display text in a window
#include <windows.h>

long CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam);

// Listing OFWIN_1
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS WindowClass; // Structure to hold windows attributes

static char szAppName[] = &quot;OFWIN&quot;; // Define window class name
HWND hWnd; // Window Handle
MSG msg; // Windows message structure

// Redraw the window if the size changes
WindowClass.style = CS_HREDRAW | CS_VREDRAW;

// Define our procedure for message handling
WindowClass.lpfnWndProc = WindowProc;

WindowClass.cbClsExtra = 0; // No extra bytes after window class
WindowClass.cbWndExtra = 0; // structure or the window instance

WindowClass.hInstance = hInstance; // Application instance handle

// Set default application icon
WindowClass.hIcon = LoadIcon(0, IDI_APPLICATION);

// Set window cursor to be the standar arrow
WindowClass.hCursor = LoadCursor(0, IDC_ARROW);

// Set gray brush for background color
WindowClass.hbrBackground = static_cast<HBRUSH>(GetStockObject(GRAY_BRUSH));

WindowClass.lpszMenuName = 0; // No menu, so no resource name

WindowClass.lpszClassName = szAppName; // Set class name

// Now register our window class
RegisterClass(&WindowClass);

// Now we can create the window
hWnd = CreateWindow(
szAppName, // Window class name
&quot;A Basic Window the Hard Way&quot;, // Window Title
WS_OVERLAPPEDWINDOW, // Window style as overlapped
CW_USEDEFAULT, // Default screen position of upper left
CW_USEDEFAULT, // corner of our window as x,y....
CW_USEDEFAULT, // Default Window size
CW_USEDEFAULT, // ...
0, // No parent window
0, // No menu
hInstance, // Program Instance handle
0 // No window creation data
);

ShowWindow(hWnd, nCmdShow); // Display the window
UpdateWindow(hWnd); // Cause window client area to be drawn

// The message loop
while(GetMessage(&msg, 0, 0, 0) == TRUE) // Get any messages
{
TranslateMessage(&msg); // Translate the message
DispatchMessage(&msg); // Dispatch the message
}

return msg.wParam; // End, so return to windows
}


// Listing OFWIN_2
long CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
HDC hDC; // Display context handle
PAINTSTRUCT PaintSt; // Structure efining area to be drawn
RECT aRect; // A working rectangle

switch(message) // Process selected messages
{
case WM_PAINT: // Message is to redraw this window
hDC = BeginPaint(hWnd, &PaintSt); // Prepare to draw the window

// Get upper left and lower right of client area
GetClientRect(hWnd, &aRect);

SetBkMode(hDC, TRANSPARENT); // Set test background mode

// Now draw the text in the window client area
DrawText(
hDC, // Device context handle
&quot;But, soft! What light through yonder window breaks?&quot;,
-1, // Indicate null terminated string
&aRect, // Rectangle in which text is to be drawn
DT_SINGLELINE| // Text format - single line
DT_CENTER| // - centered in the line
DT_VCENTER); // - line centered in aRect

EndPaint(hWnd, &PaintSt); // Terminate window redraw operation
return 0;
}
return 0;
}

I added the last return 0; because for some reason it said there was on end of file so i just tried improvising with that but maybe thats why it didn't work.

Heres the error I get:

Linking...
LINK : fatal error LNK1168: cannot open Debug/OFWIN2.exe for writing
Error executing link.exe.

Thanks in advance for all of your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top