| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1236 人关注过本帖, 1 人收藏
标题:[分享]窗口应用程序模板代码
只看楼主 加入收藏
好学
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
帖 子:622
专家分:318
注 册:2004-5-4
结帖率:50%
收藏(1)
 问题点数:0 回复次数:2 
[分享]窗口应用程序模板代码

#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窗体,哪个高手再扩展其他的功能吧,我是从C-FREE上复制的", /* 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; }

[此贴子已经被作者于2004-06-15 15:58:22编辑过]

搜索更多相关主题的帖子: 应用程序 模板 窗口 代码 分享 
2004-06-15 15:52
好学
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
帖 子:622
专家分:318
注 册:2004-5-4
收藏
得分:0 
哪个高手把注释给翻译过来啊,让我们菜鸟也明白明白
2004-06-15 16:03
zff_ff
Rank: 1
等 级:新手上路
帖 子:147
专家分:0
注 册:2004-5-12
收藏
得分:0 

先声明,我的英文水平很菜的,这些只是我对这段代码的了解

#include <windows.h>

/* 窗口函数 */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* 本程序的名称 */ char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)/*WIDOWS程序的入口相当与main()函数*/

{ HWND hwnd; /* 定义句柄*/ MSG messages; /* 定义消息*/ WNDCLASSEX wincl; /* 定义一个窗口对象*/

/* 设置窗口*/ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /*CS_DBLCLKS是指双击鼠标这个消息*/ wincl.cbSize = sizeof (WNDCLASSEX);

/* 图标和鼠标的注册*/ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* 菜单为空*/ wincl.cbClsExtra = 0; /* 单窗口 */ wincl.cbWndExtra = 0; /* structure or the window instance */ /*设置窗口颜色为默认颜色*/ wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* 如果记录失败则推出*/ if (!RegisterClassEx (&wincl)) return 0;

/* 窗口注册*/ hwnd = CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* 标题 */ "呵呵,一个空白windows窗体,哪个高手再扩展其他的功能吧,我是从C-FREE上复制的", /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 544, /* 宽*/ 375, /* 高和像素*/ HWND_DESKTOP, /*窗口最小化*/ NULL, /* 菜单设置*/ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ );

/* 显示窗口*/ ShowWindow (hwnd, nFunsterStil);

/* 进入窗口循环 */ while (GetMessage (&messages, NULL, 0, 0)) { /* 抓取键盘消息*/ TranslateMessage(&messages); /* 分派消息*/ DispatchMessage(&messages); }

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

/* 句柄消息处理*/

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) /* handle the messages */ { case WM_DESTROY: PostQuitMessage (0); /* 将消息列队发送到WM_QUIT */ break; default: /* 不需要处理的消息*/ return DefWindowProc (hwnd, message, wParam, lParam); }

return 0; }

希望高手能多多指教

还有一点这个程序在TC里是不能运行的(好象是)

在vc里(如果是ctrl+c和ctrl+v的话)

要先把project options里的/subsystem:console改为/subsystem:windows

否则会出现链接错误


偶是一只想要飞却忘了咋飞的菜鸟
2004-06-15 17:26
快速回复:[分享]窗口应用程序模板代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018290 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved