加入windows的第一天————hellwindow

  我学纯C++已经有一年的时间了,从编程到现在都是基于字符界面的 ,以前打算从事linux的开发 现在想尝试windows下的图形界面了 ,今天就上第一课,分享一下

上hellowin的源代码

 1 /*------------------------------------------------------------
2 HELLOWIN.C -- Displays "Hello, Windows 98!" in client area
3 (c) Charles Petzold, 1998
4 ------------------------------------------------------------*/
5
6 #include <windows.h>
7 #include <winnt.h>
8
9 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
10
11 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
12 PSTR szCmdLine, int iCmdShow)
13 {
14 static TCHAR szAppName[] = TEXT ("HelloWin") ;
15 HWND hwnd ;
16 MSG msg ;
17 WNDCLASS wndclass ;
18
19 wndclass.style = CS_HREDRAW | CS_VREDRAW ;
20 wndclass.lpfnWndProc = WndProc ;
21 wndclass.cbClsExtra = 0 ;
22 wndclass.cbWndExtra = 0 ;
23 wndclass.hInstance = hInstance ;
24 wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
25 wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
26 wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
27 wndclass.lpszMenuName = NULL ;
28 wndclass.lpszClassName = szAppName ;
29
30 if (!RegisterClass (&wndclass))
31 {
32 MessageBox (NULL, TEXT ("This program requires Windows NT!"),
33 szAppName, MB_ICONERROR) ;
34 return 0 ;
35 }
36
37 hwnd = CreateWindow (szAppName, // window class name
38 TEXT ("The Hello Program"), // window caption
39 WS_OVERLAPPEDWINDOW, // window style
40 CW_USEDEFAULT, // initial x position
41 CW_USEDEFAULT, // initial y position
42 CW_USEDEFAULT, // initial x size
43 CW_USEDEFAULT, // initial y size
44 NULL, // parent window handle
45 NULL, // window menu handle
46 hInstance, // program instance handle
47 NULL) ; // creation parameters
48
49 ShowWindow (hwnd, iCmdShow) ;
50 UpdateWindow (hwnd) ;
51
52 while (GetMessage (&msg, NULL, 0, 0))
53 {
54 TranslateMessage (&msg) ;
55 DispatchMessage (&msg) ;
56 }
57 return msg.wParam ;
58 }
59
60 LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
61 {
62 HDC hdc ;
63 PAINTSTRUCT ps ;
64 RECT rect ;
65
66 switch (message)
67 {
68 case WM_CREATE:
69 PlaySound (TEXT ("Until You.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
70 return 0 ;
71
72 case WM_PAINT:
73 hdc = BeginPaint (hwnd, &ps) ;
74
75 GetClientRect (hwnd, &rect) ;
76
77 DrawText (hdc, TEXT ("hell, window 7!"), -1, &rect,
78 DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
79
80 EndPaint (hwnd, &ps) ;
81 return 0 ;
82
83 case WM_DESTROY:
84 PostQuitMessage (0) ;
85 return 0 ;
86 }
87 return DefWindowProc (hwnd, message, wParam, lParam) ;
88 }

 我开始编译了很久都通不过,最后上网查资料才找到两个原因:

     1.  没有加入winmm.lib;导致 PlaySound (TEXT ("Until You.wav"), NULL, SND_FILENAME | SND_ASYNC) ;不能正常运行,你如果不想加入winmm.lib 可以直接把这段代码删除;

    2.     在建立项目的时候不能用 Win32 Console Applocation,而应该选择, ( Win32 Console Applocation 的入口函数是man(),是字符界面,而Win32 Application才是图形界面,入口函数才是WinMan());

转载于:https://www.cnblogs.com/brucehou/archive/2011/10/15/2213464.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值