日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

C++ 创建一个窗口

發(fā)布時(shí)間:2025/7/14 c/c++ 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++ 创建一个窗口 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

最近想自學(xué)C++,那就從最基本的開始吧。學(xué)著別人很上進(jìn)的樣子,用博客來記錄點(diǎn)點(diǎn)成長,希望有天能成為大牛。加油吧!!!

?

#include <windows.h>
#include <stdio.h>

LRESULT CALLBACK WinSunProc(
? HWND hwnd,????? // handle to window
? UINT uMsg,????? // message identifier
? WPARAM wParam,? // first message parameter
? LPARAM lParam?? // second message parameter
);


int WINAPI WinMain(
? HINSTANCE hInstance,? // handle to current instance
? HINSTANCE hPrevInstance, // handle to previous instance
? LPSTR lpCmdLine,????? // pointer to command line
? int nCmdShow????????? // show state of window
);


int WINAPI WinMain(
? HINSTANCE hInstance,? // handle to current instance
? HINSTANCE hPrevInstance,? // handle to previous instance
? LPSTR lpCmdLine,????? // pointer to command line
? int nCmdShow????????? // show state of window
)
{
?? ?WNDCLASS wndcls;//設(shè)置窗口屬性
?? ?wndcls.cbClsExtra=0;
?? ?wndcls.cbWndExtra=0;
?? ?wndcls.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
?? ?wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
?? ?wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
?? ?wndcls.hInstance=hInstance;
?? ?wndcls.lpfnWndProc=WinSunProc;
?? ?wndcls.lpszClassName="WinMain_Test";
?? ?wndcls.lpszMenuName=NULL;
?? ?wndcls.style=CS_HREDRAW|CS_VREDRAW;
?? ?RegisterClass(&wndcls);//注冊窗口類

?? ?HWND hwnd;
?? ?hwnd=CreateWindow("WinMain_Test","TxxxxTTT",WS_OVERLAPPEDWINDOW,0,0,600,400,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 WinSunProc(
? HWND hwnd,????? // handle to window
? UINT uMsg,????? // message identifier
? WPARAM wParam,? // first message parameter
? LPARAM lParam?? // second message parameter
)
{
?? ?switch(uMsg)
?? ?{
?? ?case WM_CHAR:
?? ??? ?char szChar[20];
?? ???? sprintf(szChar,"Char is %d",wParam);
?? ??? ?MessageBox(hwnd,szChar,"TTTT",0);
?? ??? ?break;
?? ?//case ...可以加入其它感興趣的消息
?? ?case WM_DESTROY:
?? ??? ?PostQuitMessage(0);
?? ??? ?break;
?? ?default:
?? ??? ?return DefWindowProc(hwnd,uMsg,wParam,lParam);
?? ?}
?? ?return 0;
}

轉(zhuǎn)載于:https://www.cnblogs.com/bear412/archive/2013/03/22/2974654.html

總結(jié)

以上是生活随笔為你收集整理的C++ 创建一个窗口的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。