C++ windows api 最基本的窗口代码段(抄书)

#include < windows.h >
// #include<string.h>
#include < stdlib.h >
// using namespace windows;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance,
int  nCmdShow);
// 以下初始化窗口类
int  WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR IpszCmdLine, int  nCmdShow) {
    MSG msg;
    
if(!InitWindowsClass(hInstance))
        
return FALSE;
    
if(!InitWindows(hInstance,nCmdShow))
        
return FALSE;
   
    
//创建窗口
  
    
while(GetMessage(&msg,NULL,0,0))
    
{
    TranslateMessage(
&msg);
    DispatchMessage(
&msg);
    }

    
return msg.wParam;
}

// 窗口函数
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lparam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(
0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lparam);
}

return 0;
}

BOOL InitWindows(HINSTANCE hInstance,
int  nCmdShow) {
    HWND hwnd;
    hwnd
=CreateWindow("窗口",
        
"My_Windows",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL);
    
if(!hwnd) return FALSE;
    ShowWindow(hwnd,nCmdShow);
    UpdateWindow(hwnd);
    
return TRUE;

}

BOOL InitWindowsClass(HINSTANCE hInstance)
{
    WNDCLASS wc;
    wc.style 
= 0;
    wc.lpfnWndProc 
= (WNDPROC)WndProc;
    wc.cbClsExtra 
= 0;
    wc.cbWndExtra 
= 0;
    wc.hInstance 
= hInstance;
    wc.hIcon 
= LoadIcon(hInstance,IDI_APPLICATION);
    wc.hCursor 
= LoadCursor(hInstance, IDC_ARROW);
    wc.hbrBackground 
= (HBRUSH)GetStockObject(LTGRAY_BRUSH+3);//(COLOR_WINDOW+1);
    wc.lpszMenuName = NULL;
    wc.lpszClassName 
="窗口";
    
return RegisterClass(&wc);
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值