鱼C论坛

 找回密码
 立即注册
查看: 5008|回复: 17

自己想用c语言写个窗口,怎样写呀

[复制链接]
发表于 2011-10-9 11:44:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
自己想用c语言写个窗口,怎样写呀?
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-9 11:58:24 | 显示全部楼层
C语言高级学了么?
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-9 12:03:59 | 显示全部楼层
  1. #include <windows.h>

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

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

  6. int WINAPI WinMain (HINSTANCE hThisInstance,
  7.                     HINSTANCE hPrevInstance,
  8.                     LPSTR lpszArgument,
  9.                     int nFunsterStil)

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

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

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

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

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

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

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

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


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

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

  71.     return 0;
  72. }
复制代码
1.jpg

以上是Dev—c++中的C win32程序的例子。
建议你找本书看看,比如《windows程序设计》或是罗云彬的《Windows环境下32位汇编语言程序设计》
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-9 12:04:34 | 显示全部楼层

你的意思是学完小甲鱼的入门视频后还要学 C语言高级是吗?哪里有这样的视频下载?请告知,我的入门视频快看完了.
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-9 12:05:43 | 显示全部楼层
本帖最后由 yipwing 于 2011-10-9 12:21 编辑

VS2010看这个帖子
http://bbs.fishc.com/thread-5303-1-1.html
VC6的话这个帖子
http://bbs.fishc.com/thread-5292-1-1.html
这个只是看看,如果要想学会,就好好学C语言和Windows API
这个世上没捷径的。。一步一步的走。。。
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-9 12:11:44 | 显示全部楼层
C语言我这没有视频只有书高级的。他们用得是MFC写得。C语言写出来的窗口是纯文本输入。
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-9 12:16:02 | 显示全部楼层
crazylinux 发表于 2011-10-9 12:11
C语言我这没有视频只有书高级的。他们用得是MFC写得。C语言写出来的窗口是纯文本输入。

C语言也可以写窗口的。。而且不用MFC。。
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-9 12:19:03 | 显示全部楼层
ZPCG 发表于 2011-10-9 12:04
你的意思是学完小甲鱼的入门视频后还要学 C语言高级是吗?哪里有这样的视频下载?请告知,我的入门视频快看完 ...

孙鑫的VC++视频。。
不过他说的是C++和MFC...


3楼说的Windows 程序设计就是C语言和C++的。。

话说SDK编程的中文教程很少。。
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-9 12:26:57 | 显示全部楼层
yipwing 发表于 2011-10-9 12:19
孙鑫的VC++视频。。
不过他说的是C++和MFC...

你看戴建华编写的C开发技术详解那个是纯C写得窗口
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-9 12:31:17 | 显示全部楼层
crazylinux 发表于 2011-10-9 12:26
你看戴建华编写的C开发技术详解那个是纯C写得窗口

书我没看过,但是不知道是不是不用Windows API写Windows窗口。。。

如果是的话,还真想去了解下。。
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-9 12:34:46 | 显示全部楼层
yipwing 发表于 2011-10-9 12:31
书我没看过,但是不知道是不是不用Windows API写Windows窗口。。。

如果是的话,还真想去了解下。。

是得他不用windows   API写得窗口,用API写窗口那就不是C语言了

小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-9 12:36:52 | 显示全部楼层
API不就是C语言写的么?
MFC是微软用C++封装C语言写的API库。。

算了不纠结这个问题。。

顺便恭喜下你,升级成版主了。。
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-10 21:27:28 | 显示全部楼层
估计写不出来,可能要操作系统的支持,如果是那样,就变成mfc了
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-10-11 20:39:04 | 显示全部楼层
crazylinux 发表于 2011-10-9 11:58
C语言高级学了么?

c语言高级学看什么书呀,哪里有教程呀,我根本没有找到
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-10-11 20:41:18 | 显示全部楼层
Seely 发表于 2011-10-9 12:03
以上是Dev—c++中的C win32程序的例子。
建议你找本书看看,比如《windows程序设计》或是罗云彬的《Wi ...

他们里面有自己写窗口嘛,不是调用api
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-12 11:13:39 | 显示全部楼层
这个也是我遇到的问题。我也是快看完入门视频了。下一步,小甲鱼老师可有出C语言的高级视频呢?
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-12 14:56:00 | 显示全部楼层
21克 发表于 2011-10-11 20:41
他们里面有自己写窗口嘛,不是调用api

没有,这两本书都是用的API。好像不用API就得MFC了吧,不太懂,瞎说的。
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-12 18:04:37 | 显示全部楼层
  1. #include <windows.h>

  2. int WINAPI WinMain( HINSTANCE hInstance,
  3.                    HINSTANCE hPrevInstance,
  4.                    PSTR szCmdLine,
  5.                    int iCmdShow
  6.                    )
  7. {
  8.       MessageBox( NULL, TEXT("Hello, welcome to Fishc.com!"),
  9.                   TEXT("Welcome!"), MB_OKCANCEL | MB_OK
  10.                   );
  11.       
  12.       return 0;
  13. }
复制代码

非常简单,窗口编程基于C语言你只管调用相应需要的功能的API函数即可。

学习起来比C语言事实上要容易很多

小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-8 21:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表