日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

C++ 创建一个窗口

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

最近想自學(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)容還不錯(cuò),歡迎將生活随笔推薦給好友。