#include<windows.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
int nMode;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="映射模式";
char lpszTitle[]="P103";
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=lpszClassName;
wndclass.lpszMenuName=NULL;
wndclass.style=0; 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;
PAINTSTRUCT ps;
HBRUSH hB1,hB2,hB3,hB4,hB5;
HPEN hP;
switch(message)
{
case WM_CREATE:
hP = CreatePen(PS_DASHDOT,25,RGB(50,125,40));
break; case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SetMapMode(hdc,nMode);
SelectObject(hdc,hP);
MoveToEx(hdc,0,10,NULL);
LineTo(hdc,700,600);
hB1=(HBRUSH)GetStockObject(WHITE_BRUSH);
SelectObject(hdc,hB1);
Rectangle(hdc,0,0,360,900); hB2=(HBRUSH)GetStockObject(BLACK_BRUSH);
SelectObject(hdc,hB2);
Rectangle(hdc,360,0,720,900); hB3=(HBRUSH)GetStockObject(GRAY_BRUSH);
SelectObject(hdc,hB3);
Rectangle(hdc,720,0,1080,900); hB4=(HBRUSH)GetStockObject(BLACK_BRUSH);
SelectObject(hdc,hB4);
Rectangle(hdc,1080,0,1440,900); hB5=(HBRUSH)GetStockObject(BLACK_BRUSH);
SelectObject(hdc,hB5);
Pie(hdc,0,0,300,200,50,50,300,50); EndPaint(hwnd,&ps);
return 0;
break;
case WM_DESTROY:
DeleteObject(hB1);
DeleteObject(hB2);
DeleteObject(hB3);
DeleteObject(hB4);
DeleteObject(hB5);
DeleteObject(hP); PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
int nMode;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="映射模式";
char lpszTitle[]="P103";
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=lpszClassName;
wndclass.lpszMenuName=NULL;
wndclass.style=0; 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;
PAINTSTRUCT ps;
HBRUSH hB1,hB2,hB3,hB4,hB5;
HPEN hP;
switch(message)
{
case WM_CREATE:
hP = CreatePen(PS_DASHDOT,25,RGB(50,125,40));
break; case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SetMapMode(hdc,nMode);
SelectObject(hdc,hP);
MoveToEx(hdc,0,10,NULL);
LineTo(hdc,700,600);
hB1=(HBRUSH)GetStockObject(WHITE_BRUSH);
SelectObject(hdc,hB1);
Rectangle(hdc,0,0,360,900); hB2=(HBRUSH)GetStockObject(BLACK_BRUSH);
SelectObject(hdc,hB2);
Rectangle(hdc,360,0,720,900); hB3=(HBRUSH)GetStockObject(GRAY_BRUSH);
SelectObject(hdc,hB3);
Rectangle(hdc,720,0,1080,900); hB4=(HBRUSH)GetStockObject(BLACK_BRUSH);
SelectObject(hdc,hB4);
Rectangle(hdc,1080,0,1440,900); hB5=(HBRUSH)GetStockObject(BLACK_BRUSH);
SelectObject(hdc,hB5);
Pie(hdc,0,0,300,200,50,50,300,50); EndPaint(hwnd,&ps);
return 0;
break;
case WM_DESTROY:
DeleteObject(hB1);
DeleteObject(hB2);
DeleteObject(hB3);
DeleteObject(hB4);
DeleteObject(hB5);
DeleteObject(hP); PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
解决方案 »
- TRACE()语句靠得住吗?
- 请问在对话框里画图和在View里画图有什么区别?
- 在CEdit控件中用SendMessage发WM_CHAR消息模拟输入字符时问题,请老师解答!欢迎高手共同解决这个问题
- 为什么我做的帮助文件都是红查查?
- vHJ=msg.hj; //msg.hj是int, vHJ是ado数据,_variant_t 怎样给vHJ赋值,急!!!
- 如何去除Google搜索自动填充下拉列表?
- C++Builder5.0与ACCESS数据库连接,怎么避开输入用户名和密码?
- 托拽数据的charset问题
- 嵌入式操作系统RTOS,有兴趣的请进!
- 如何更改CComboBox的字体?
- 网络消息
- windows media player 滚动条
WM_CREATE只在createwindow的时候才调用,所以CreatePen只被调用了一次,而你这里用的是局部变量,需要每次都CreatePen才行,
你最好把HBRUSH hB1,hB2,hB3,hB4,hB5;
HPEN hP;
都设成全局变量吧,要不然你得把DeleteObject(hB1);
DeleteObject(hB2);
DeleteObject(hB3);
DeleteObject(hB4);
DeleteObject(hB5);
DeleteObject(hP);
放到EndPaint(hwnd,&ps); 的后面
因为你在收到case WM_DESTROY: 的时候并不执行前面的hB1=(HBRUSH)GetStockObject(WHITE_BRUSH);
SelectObject(hdc,hB1); 会出错,
你还是去找本windows程序设计的书来看吧
Compiling...
498.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/498.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.498.exe - 1 error(s), 0 warning(s)
帮忙以后怎么可以解决这个问题不胜感激!
[Project] --> [Settings] --> 选择"Link"属性页, 在Project Options中将/subsystem:console改成/subsystem:windows