windows程序设计 学习记录1
2013-09-14 11:59
375 查看
刚开始的入门程序,在窗口中输出Hello windows 98!,窗口名是hellomsg。
//
调用几个API函数,输出屏幕的像素。
//
用createwindow创建一个多功能的窗口,用消息队列处理从交互中获得的信息。
//
各种函数的名称,返回类型,初始化的变量还不懂,太多太乱。
#include <windows.h> int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { MessageBox(NULL,TEXT("Hello Windows 98!"), TEXT("HelloMsg") , 0 ); return 0; }
//
调用几个API函数,输出屏幕的像素。
#include <windows.h> #include <tchar.h> #include <stdio.h> int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...) { TCHAR szBuffer [1024]; va_list pArgList; va_start (pArgList, szFormat); _vsntprintf (szBuffer, sizeof(szBuffer)/sizeof(TCHAR), szFormat, pArgList ); va_end (pArgList); return MessageBox(NULL, szBuffer, szCaption, 0); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { int cxScreen, cyScreen; cxScreen = GetSystemMetrics(SM_CXSCREEN); cyScreen = GetSystemMetrics(SM_CYSCREEN); MessageBoxPrintf(TEXT("ScrnSize"), TEXT("The screen is %i pixels wide by %i pixels high."), cxScreen, cyScreen); return 0; }
//
用createwindow创建一个多功能的窗口,用消息队列处理从交互中获得的信息。
#include <windows.h> /* Declare Windows procedure */ LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); /* Make the class name into a global variable */ static TCHAR szAppName[]= TEXT ("HelloWin"); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hwnd; /* This is the handle for our window */ MSG msg; /* Here messages to the application are saved */ WNDCLASS wndclass; /* Data structure for the windowclass */ /* The Window structure */ wndclass.hInstance = hInstance; wndclass.lpszClassName = szAppName; wndclass.lpfnWndProc = WndProc; /* This function is called by windows */ wndclass.style = CS_HREDRAW | CS_VREDRAW; /* Catch double-clicks */ //wndclass.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); //wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.lpszMenuName = NULL; /* No menu */ wndclass.cbClsExtra = 0; /* No extra bytes after the window class */ wndclass.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default colour as the background of the window */ wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); /* Register the window class, and if it fails quit the program */ if (!RegisterClass (&wndclass)){ MessageBox (NULL,TEXT("This program requires Windows NT!"), szAppName,MB_ICONERROR); return 0; } /* The class is registered, let's create the program*/ hwnd = CreateWindow ( /* Extended possibilites for variation */ szAppName, /* Classname */ TEXT("The Hello Program"), /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ CW_USEDEFAULT, /* The programs width */ CW_USEDEFAULT, /* and height in pixels */ NULL, /* The window is a child-window to desktop */ NULL, /* No menu */ hInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); /* Make the window visible on the screen */ ShowWindow (hwnd, iCmdShow); UpdateWindow(hwnd); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&msg, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&msg); /* Send message to WindowProcedure */ DispatchMessage(&msg); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return msg.wParam; } /* This function is called by the Windows function DispatchMessage() */ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; switch (message) /* handle the messages */ { case WM_CREATE: PlaySound(TEXT("hellowin.wav"),NULL,SND_FILENAME | SND_ASYNC); return 0; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rect); DrawText(hdc, TEXT("Hello, Windows 98!"),-1,&rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER ); EndPaint(hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage (0); /* send a WM_QUIT to the message queue */ return 0; //default: /* for messages that we don't deal with */ // return DefWindowProc (hwnd, message, wParam, lParam); } return DefWindowProc(hwnd, message, wParam, lParam); }
//
各种函数的名称,返回类型,初始化的变量还不懂,太多太乱。
相关文章推荐
- 记录学习点滴-《Windows 程序设计》-1-1
- 记录学习点滴-《Windows 程序设计》-3-1
- Windows程序设计_Chap02_Unicode_学习笔记
- 今天开始学习Windows下程序设计
- Windows学习记录之网络编程sockaddr_in结构体
- tensorflow学习记录(一):在windows下的安装
- windows程序设计学习笔记-Unicode,绘图基础
- Windows程序设计学习笔记
- 学习咏南BLOG的datasanp 用流下载文件,同时记录WINDOWS系统日志
- windows学习记录之去除掉小数点后面无效的零
- 学习Windows SDK编程(Windows 程序设计)
- 《windows 程序设计》中的翻译错误----学习笔记
- Java学习笔记-Java程序设计环境(Windows)
- 孙鑫VC++学习记录1_windows运行机制
- Windows程序设计学习——动态链接库
- 学习记录:浏览器JAVASCRIPT里的WINDOWS,DOCUMNET
- 今天遇到多线程,windowsService的问题---学习记录
- windows程序设计学习笔记-多文档界面
- Windows程序设计 学习(1)
- windows程序设计学习笔记-设备无关位图