新手求解!!!!
#include<windows.h>#include <stdio.h>
#define LINEHEIGHT 15
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);//先要声明一个WndProc回调函数
//LONG WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);也可以用这个来声明回调函数
//相当于C语言中的int main()
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)//HINSTANCE实例句柄
{
HWND hwnd;//窗口句柄
MSG msg;//消息
WNDCLASS wndclass;//窗口类
//1.设计一个窗口类
wndclass.style = CS_HREDRAW | CS_VREDRAW;//这个可以让屏幕自动显示在中间,即使缩小或放大屏幕。 //wndclass.style = 0;//为默认窗口
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL,IDI_WINLOGO);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = TEXT("MyWndClass");//*窗口类的名字
//2.注册一个窗口类
RegisterClass(&wndclass);
//3.创建窗口
hwnd = CreateWindow(TEXT("MyWndClass"),TEXT("Hello SDK Application"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
//4.显示和更新窗口
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
//5.消息循环
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);//转发到窗口过程
}
return msg.wParam;
}
//窗口过程回调函数
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)//还有另一种写法:LONG WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
{
PAINTSTRUCT ps;
HDC hdc;
//RECT rect;
int i;
TCHAR szBuffer;
//对各种消息进行处理
switch(message)
{
case WM_SIZE:
//重制 paint
return 0;
case WM_LBUTTONDOWN:
//PostQuitMessage(0);
return 0;
case WM_PAINT://绘制消息
hdc = BeginPaint(hwnd,&ps);
for(i=0; i<10; ++i)
{
_sntprintf(szBuffer,1024,TEXT("Hello %d"),i);
TextOut(hdc,0,i*LINEHEIGHT,szBuffer,lstrlen(szBuffer));
}
EndPaint(hwnd,&ps);
break;//可以写break,也可以写return 0;
case WM_DESTROY://销毁窗口,即关闭窗口(消息)
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
报错:warning C4013: '_sntprintf' undefined; assuming extern returning int
#include <windows.h>
#include "strsafe.h"
#define LINEHEIGHT 15
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//先要声明一个WndProc回调函数
//LONG WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);也可以用这个来声明回调函数
//相当于C语言中的int main()
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)//HINSTANCE实例句柄
{
HWND hwnd;//窗口句柄
MSG msg;//消息
WNDCLASS wndclass;//窗口类
//1.设计一个窗口类
wndclass.style = CS_HREDRAW | CS_VREDRAW;//这个可以让屏幕自动显示在中间,即使缩小或放大屏幕。 //wndclass.style = 0;//为默认窗口
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = TEXT("MyWndClass");//*窗口类的名字
//2.注册一个窗口类
RegisterClass(&wndclass);
//3.创建窗口
hwnd = CreateWindow(TEXT("MyWndClass"), TEXT("Hello SDK Application"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
//4.显示和更新窗口
ShowWindow(hwnd, nShowCmd);
UpdateWindow(hwnd);
//5.消息循环
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);//转发到窗口过程
}
return msg.wParam;
}
//窗口过程回调函数
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)//还有另一种写法:LONG WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
{
PAINTSTRUCT ps;
HDC hdc;
//RECT rect;
int i;
TCHAR szBuffer;
//对各种消息进行处理
switch (message)
{
case WM_SIZE:
//重制 paint
return 0;
case WM_LBUTTONDOWN:
//PostQuitMessage(0);
return 0;
case WM_PAINT://绘制消息
hdc = BeginPaint(hwnd, &ps);
for (i = 0; i<10; ++i)
{
StringCchPrintf(szBuffer, 1024, TEXT("Hello %d"), i);
TextOut(hdc, 0, i*LINEHEIGHT, szBuffer, lstrlen(szBuffer));
}
EndPaint(hwnd, &ps);
break;//可以写break,也可以写return 0;
case WM_DESTROY://销毁窗口,即关闭窗口(消息)
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
原因是_sntprintf未定义 哇 C语言调用Windows的API来写程序 看起来 好强大呢。。。 {:7_146:}
页:
[1]