C++ 创建一个窗口
最近想自學(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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: interceptor拦截器典型应用实例
- 下一篇: 大话设计模式--建造者模式 Builde