I'm new here and this is my first post.I'm now learning C++ from scratch in school,and yesterday I completed a task using VC++ 6.0 in school,which showed a GUI with a red line "I love BLEACH".However,when I compiled it in codeblocks at home,.obj file was available while linking failed.What's more,it showed many strange words(what you see here is what I saw in my PC):
#include<windows.h>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="Hello";
char lpszTitle[]="I love BLEACH";
wndclass.style=0;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszClassName;
if(!RegisterClass(& wndclass))
{
MessageBeep(0);
return FALSE;
}
hwnd=CreateWindow(
lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW ,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(& Msg,NULL,0,0))
{
TranslateMessage(& Msg);
DispatchMessage(& Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
HFONT hF_black;
PAINTSTRUCT ps;
TEXTMETRIC tm;
char lpsz_1[]="I love BLEACH";
int X=0,Y=0;
int i;
switch(message)
{case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SetTextColor(hdc,RGB(255,0,0));
GetTextMetrics(hdc,&tm);
Y=Y+tm.tmHeight+tm.tmExternalLeading;
hF_black=CreateFont(
0,
0,
0,
0,
FW_HEAVY,
0,
0,
0,
GB2312_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE, "gerry");
for(i=0;i<200;i++)
{Sleep(5);
TextOut(hdc,X+i,Y,lpsz_1,13);
InvalidateRect(hwnd,NULL,1);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
P.S.:I use windows xp sp2.