c语言(注意是c)怎 调用api创建个窗体
1个回答
展开全部
若是你的要在windows上面运行,这属于windows编程编程范畴!c语言只是一种工具而已。
代码如下!(c语言不能像java那样直接new 出窗体)
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch(Message) {
case WM_DESTROY: {
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
static TCHAR szAppName[]="Hello world";
HWND hWnd;
MSG msg;
WNDCLASS wndclass;
memset(&wndclass,0,sizeof(wndclass));
wndclass.style =CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbWndExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon =LoadIcon(null,IDI_WINLOGO);
wndclass.hCursor=LoadCursor(null,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName=null;
wndclass.lpszClassName=szAppName;
if(!RegisterClass(&wndclass))
{
MessageBox(null,TEXT("windows error!"),szAppName,MB_ICONERROR);
return 1;
}
hWnd=CreateWindow(szAppName,
TEXT("THE HELLO PROGRAME"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
null,
null,
hInstance,
null);
ShowWindow(hWnd,iCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg,null,null,null))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
代码如下!(c语言不能像java那样直接new 出窗体)
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch(Message) {
case WM_DESTROY: {
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
static TCHAR szAppName[]="Hello world";
HWND hWnd;
MSG msg;
WNDCLASS wndclass;
memset(&wndclass,0,sizeof(wndclass));
wndclass.style =CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbWndExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon =LoadIcon(null,IDI_WINLOGO);
wndclass.hCursor=LoadCursor(null,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName=null;
wndclass.lpszClassName=szAppName;
if(!RegisterClass(&wndclass))
{
MessageBox(null,TEXT("windows error!"),szAppName,MB_ICONERROR);
return 1;
}
hWnd=CreateWindow(szAppName,
TEXT("THE HELLO PROGRAME"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
null,
null,
hInstance,
null);
ShowWindow(hWnd,iCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg,null,null,null))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
追问
这部分资料什么书上有呢 或者...
我提高了悬赏 感觉你是手打的 不容易 NULL打成了小写 我会采纳的 但是能告诉我 这部分资料哪里有么
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询