我的第一个windows应用程序
生活随笔
收集整理的這篇文章主要介紹了
我的第一个windows应用程序
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
創(chuàng)建一個windows應(yīng)用程序,有以下基本步驟
代碼如下:
// Win32_01.cpp : Defines the entry point for the application. //#include "stdafx.h"LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) {// 窗口類名,不要與系統(tǒng)的重復(fù)LPCTSTR lpszClassName = TEXT("My First Window");// 創(chuàng)建窗口類WNDCLASS wndclass;wndclass.style = 0;wndclass.lpfnWndProc = WindowProc;wndclass.cbClsExtra = 0;wndclass.cbWndExtra = 0;wndclass.hInstance = hInstance;wndclass.hIcon = 0;wndclass.hCursor = 0;wndclass.hbrBackground = (HBRUSH)COLOR_MENU;wndclass.lpszMenuName = NULL;wndclass.lpszClassName = lpszClassName;// 注冊窗口類RegisterClass(&wndclass);// 創(chuàng)建窗口HWND hwnd = CreateWindow(lpszClassName,TEXT("我的第N個WIN32應(yīng)用程序"),WS_OVERLAPPEDWINDOW,100,100,400,300,NULL,NULL,hInstance,NULL);if (hwnd == NULL){MessageBox(hwnd, TEXT("創(chuàng)建窗口失敗"), TEXT("錯誤"), MB_OK);return 0;}// 顯示窗口ShowWindow(hwnd, SW_SHOW);// 消息循環(huán)MSG msg;while (GetMessage(&msg, NULL, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}return 0; }LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {switch(uMsg){case WM_DESTROY:PostQuitMessage(0);return 0;}return DefWindowProc(hwnd, uMsg, wParam, lParam); }總結(jié)
以上是生活随笔為你收集整理的我的第一个windows应用程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在Windows C程序中使用Unico
- 下一篇: 使用资源文件绘制Win32对话框