C++ 学习 二
2013-09-15 10:21
411 查看
1. 利用windows api 创建窗口
曾经出错,问题解决帖子原文。
http://topic.csdn.net/u/20100726/22/b6e33032-471c-44f5-81a0-0ae82c70e0e8.html?seed=219286239&r=67257704#r_67257704
2. 递归的一个例子:
正确代码示例: |
# include<windows.h> # include<stdio.h> LRESULT CALLBACK WindowLiProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { WNDCLASS wndcls; wndcls.cbClsExtra=0; wndcls.cbWndExtra=0; wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH); wndcls.hCursor=LoadCursor(NULL,IDC_CROSS); wndcls.hIcon=LoadIcon(NULL,IDI_WINLOGO); wndcls.hInstance=hInstance; wndcls.lpfnWndProc=WindowLiProc; wndcls.lpszClassName="CheersLi01"; wndcls.lpszMenuName=NULL; wndcls.style=CS_HREDRAW | CS_VREDRAW; RegisterClass(&wndcls); HWND hwnd; hwnd=CreateWindow("CheersLi01","Cheers Li Api 学习",WS_OVERLAPPEDWINDOW,0,0,800,600,NULL,NULL,hInstance,NULL); ShowWindow(hwnd,SW_SHOWNORMAL); UpdateWindow(hwnd); MSG msg; while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK WindowLiProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_CHAR : char szChar[20]; sprintf(szChar,"Char is %d",wParam); MessageBox(hwnd,szChar,"CheersLi01",0); break; case WM_LBUTTONDOWN : MessageBox(hwnd,"mouse click","CheersLi01",0); HDC hdc; hdc=GetDC(hwnd); TextOut(hdc,0,50,"我的C++学习",ARRAYSIZE("我的C++学习")); ReleaseDC(hwnd,hdc); case WM_PAINT : HDC hDc; PAINTSTRUCT ps; hDc=BeginPaint(hwnd,&ps); TextOut(hDc,0,50,"C++ Programming",ARRAYSIZE("C++ Programming")); EndPaint(hwnd,&ps); break; case WM_CLOSE : if(IDYES==MessageBox(hwnd,"是否真的结束?","Hints for you",MB_YESNO)) { DestroyWindow(hwnd); } break; case WM_DESTROY : PostQuitMessage(0); break; default: return DefWindowProc(hwnd,uMsg,wParam,lParam); } return 0; } |
http://topic.csdn.net/u/20100726/22/b6e33032-471c-44f5-81a0-0ae82c70e0e8.html?seed=219286239&r=67257704#r_67257704
2. 递归的一个例子:
#include <iostream.h> void countdown(int n); int main() { countdown(4); return 0; } void countdown(int n) { cout<<"Counting down : "<<n<<endl; if(n>0) countdown(n-1); cout<<"cout down ... "<<n<<endl; } |
相关文章推荐
- C++学习5 - const成员函数
- C++学习6 - 按值传递,按…
- C++学习7 - 按别名传递对象
- C++学习框架 总结(简单步骤)
- 【学习日记3】c++开始&nbsp;我要做…
- 【学习日记2】c++开始&nbsp;我要做…
- C++&nbsp;学习积累-不断更新
- 【学习日记1】c++开始&nbsp;我要做…
- C++&nbsp;指针学习累积(持续)
- C++学习1 - 第一个C++程序
- C++学习2 - 枚举型常量
- C++&nbsp;学习&nbsp;&lt;三&gt;&nbsp;:错误与解决方法
- C++学习3 - 定义一个对象
- C++学习4 - 内联函数
- Flash AS3 学习3 - 右键菜单
- C++ Greedy Snake的OOP实现 贪食蛇 <list> STL初次学习
- C++<Algorithm>学习
- 【C++ Primer】静态链接库(l…
- C++学习笔记(第12章->类和动态内存分配)
- SDL学习(四) Color Keying(抠色…