用C编写一个简单的窗口函数代码?各位大侠提供一下

作者&投稿:才旦汪 (若有异议请与网页底部的电邮联系)
用windows api 函数和c语言写一个窗口程序需要掌握哪些函数?~

给你个例子,建议用 DevC++ 编译 :

#include

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}

/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}


/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}

你拷贝到form1里是因为 Form1是继承自Form, Controls是系统类Form的成员,所以没有错,而你自己创建的这个只是个普通类,是没有Controls的,所以会报错

这个函数需要调用WindowsAPI。。。有英文注释的。能看懂就看一下吧。

要是想写Windows窗口程序建议买本《Windows程序设计》..
#include <windows.h>

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx ( //从这里开始就是窗口集体参数了。
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* 窗口名 */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
); //到这里结束

/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}

/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}

/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}


c语言怎么编出windows窗口
必须使用windows的编译器,如VC,MS等等。RegisterClassEx函数:该函数注册在随后调用CreateWindow函数和CreateWindowEx函数中使用的窗口类。 RegisterClass函数己经由函数RegisterClassEx函数来代替,但是,如果不需要设置类的小目标则仍然可以使用RegisterClass函数。CreateWindowEx函数:该函数创建一个具有扩展风格的层...

用c语言怎么创建一个窗口?
通过调用windows API来创建窗口:#include<windows.h>int main(){MessageBox(NULL,"Hello World!","C图形程序",MB_OK);return 0;}这个是最简单的了 至于MFC QT 什么的 代码太多了

用C语言进行程序设计一个仿真窗口的程序
setcolor(13);settextstyle(1,0,2);outtextxy(115,85,"window");getch();closegraph();return 0;}

谁能教我 怎么用C语言编写 一个窗口? 求源代码 加上注释 谢谢
include <stdio.h>#include <stdlib.h>#include <windows.h>int main(){printf("输入一个字符, 就会出现窗口");getch();MessageBox(NULL,"这就是你要的窗口!这就是你要的窗口!\\n这就是你要的窗口!这就是你要的窗口!\\n这就是你要的窗口!这就是你要的窗口!","hahah",MB_ICONERROR |...

想利用C或C++做界面设计,怎么做?
GTK+: 一个Linux上常用的GUI库,也可以在其他平台上使用。WinAPI: 适用于Windows平台的原生API,可用于创建Windows GUI应用。SDL: 主要用于游戏开发,但也可以用于一些简单的界面设计。2. 学习所选库或框架掌握您选择的库或框架的基本概念和用法是关键。查阅文档、教程和示例代码,以了解如何创建窗口、...

C语言如何编写一个窗体,上面显示hello,world。具体解释一下代码,不能...
SetTimer(hwnd,1,100,NULL);return 0;case WM_TIMER:\/\/\/实现进程的动画 hdc=GetDC(hwnd);GetClientRect(hwnd,&rect);if(i<rect.right-1)bs=CreateSolidBrush(RGB(0,0,255));else bs=CreateSolidBrush(RGB(255,0,0));SelectObject(hdc,bs);i=i+1;Rectangle(hdc,0,40,i,20);if(i==...

如何用C语言编写一个窗体应用程序?
要用C语言编写一个窗体应用程序需要调用系统或第三方提供的API函数,一般的步骤是:定义窗口类 注册窗口类 创建窗口 显示、更新窗口 进行消息循环,不断处理窗口消息

怎么用c语言在windows下弹出一个置顶的窗口?
一、具体做法:1、C++Builder中,先学会最基本的编写一个可运行的win程序后,将这个程序的窗体的FormStyle属性设定为置顶窗( fsStayOnTop),VC中的窗体也有类似的选项。设定好后编译成可运行的程序,运行编译生成的程序就会弹出置顶窗体。2、也可调用windows的API函数(调用系统功能),所有能调用API的编...

怎样使用visual studio 2010以C语言编一个简单的窗口程序
MessageBox(NULL, L"Hello World!", L"我的第一个窗口程序", MB_OK);一般来说,用 VC 开发程序都不这样写,而是应该是使用微软定义的数据类型和宏,这样便能同时编译 ANSI 版本,不用修改源文件。须包含头文件 tchar.h,对于字符串应使用 _T 或 TEXT 宏将其包含,如 _T("Hello")。当定义 ...

怎样用c语言写一个图形界面
{ static TCHAR szAppName[] = TEXT("MyWindow") ;HWND hwnd ;MSG msg ;WNDCLASS wndclass ; \/\/声明一个窗口类对象 \/\/以下为窗口类对象wndclass的属性 wndclass.style = CS_HREDRAW | CS_VREDRAW ; \/\/窗口样式 wndclass.lpszClassName = szAppName ; \/\/窗口类名 wndclass.lpszMenuNa...

临武县18828852250: 用C编写一个简单的窗口函数代码?各位大侠提供一下 -
前雨复方: 这个函数需要调用WindowsAPI...有英文注释的.能看懂就看一下吧.要是想写Windows窗口程序建议买本《Windows程序设计》..#include <windows.h>/* Declare Windows procedure */LRESULT CALLBACK WindowProcedure (HWND, ...

临武县18828852250: 怎么用c语言写窗体程序 -
前雨复方: 步骤: 1、注册窗口类; 2、创建窗体; 3、消息循环; 4、编写窗口消息处理函数. 代码:#include <windows.h> #include<tchar.h> LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); int ...

临武县18828852250: 怎么用C写个窗口程序 -
前雨复方: 最简单的窗口程序由1个回调函数和程序入口函数WinMain(类似于命令行程序的入口函数为main)构成. 范例很多,比如Dev-C++中默认建立的C语言窗口工程(Windows Application)代码,篇幅原因无法粘贴,见参考资料.

临武县18828852250: 如何 C语言简单的窗口源码?
前雨复方: 用Windows api MessageBox()函数

临武县18828852250: 求个C语言写的弹出窗口的简单程序 -
前雨复方: #include HWND NewWindow(HINSTANCE hInst,HWND hWnd,char *className,char *appName,RECT rect,WNDPROC wndProc) { WNDCLASSEX wclsx; wclsx.cbClsExtra = NULL; wclsx.cbSize = sizeof(wclsx); wclsx.cbWndExtra = NULL; wclsx....

临武县18828852250: 【】用c语言编一个windows窗体应用程序【】 -
前雨复方: 用GetDlgItemText函数把textbox1的内容送到字符串里 利用atof函数转换成double型,然后自加,再把这个double型数字转换成字符串,用SetDlgItemText就能放到textbox2中了

临武县18828852250: vc++6.0怎么写Windows简单窗口代码 -
前雨复方: 只用两个函数,够简单了吧! #include <Windows.h>LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {int wmId, wmEvent;PAINTSTRUCT ps;HDC hdc; switch( msg ){case WM_COMMAND:...

临武县18828852250: C语言编写个窗口求解一元二次方程 -
前雨复方: 我有代码, 如下: #include <stdio.h>#include <windows.h>#include <math.h> int GetRoot(float a,float b,float c,double *root) { double delta,deltasqrt; delta=b*b-4.0*a*c; deltasqrt=sqrt(delta); if(a!=0.0) { root[0]=(-b+deltasqrt)/(2.0*a); root[1]=(-b-...

临武县18828852250: 求VC++显示一个窗体的最简代码. -
前雨复方: #include "stdafx.h"// 窗口函数的函数原形 LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char ...

临武县18828852250: 如何用c语言编辑简单数学公式计算窗口 -
前雨复方: 你是想做做成界面式的操作那种吗?代码本身会很简单,但是界面用C语言较难,也不建议这么做,建议使用VB进行编写(或者Adobe Flash,做界面很方便),甚为方便!

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网