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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

Windows框架

發布時間:2024/7/19 windows 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Windows框架 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#include<Windows.h>
#include<tchar.h>
#include"resource.h"


//全局變量
LPSTR g_MainFrame = "主框架";
LPSTR ?g_ClientFrame = "客戶區框架";
LPSTR g_ChildFrame[] = { "子框架1","子框架2" };


LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

//函數執行的入口函數
int WINAPI WinMain(
?? ?_In_ ? ? ? ? HINSTANCE hInstance,
?? ?_In_opt_ ?HINSTANCE hPrevInstance,
?? ?_In_ ? ? ? ? LPSTR lpCmdLine,
?? ?_In_ ? ? ? ? int nShowCmd)

{

?? ?//1.初始化需要注冊的窗口信息
?? ?WNDCLASS MainFrame = { 0 };
?? ?MainFrame.hbrBackground = (HBRUSH)::GetStockObject(GRAY_BRUSH);//背景
?? ?MainFrame.hCursor = ::LoadCursor(NULL, IDC_ARROW);
?? ?MainFrame.hInstance = hInstance;
?? ?MainFrame.lpfnWndProc = WndProc;
?? ?MainFrame.lpszClassName = g_MainFrame;
?? ?MainFrame.lpszMenuName = MAKEINTRESOURCE(IDR_MainFrame);//定位資源,通過MAKEINTRESOURCE轉換的id, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//也可以是資源名稱的字符串。
?? ?MainFrame.style = CS_VREDRAW | CS_HREDRAW;

?? ?//2.注冊MainFrame窗口
?? ?if (!RegisterClass(&MainFrame))
?? ?{
?? ??? ?MessageBox(NULL, _T("主框架注冊失敗!"), _T("Error"), MB_OK | MB_ICONERROR);//_T() 需用用到tchar.h頭文件
?? ?}

?? ?//3.創建窗口?? ?
?? ??? ?HWND mainframe_hwnd;
?? ??? ?mainframe_hwnd= CreateWindow(
?? ??? ??? ?g_MainFrame,
?? ??? ??? ?g_ClientFrame,
?? ??? ??? ?WS_OVERLAPPEDWINDOW,
?? ??? ??? ?CW_USEDEFAULT,?
?? ??? ??? ?CW_USEDEFAULT,?
?? ??? ??? ?CW_USEDEFAULT,?
?? ??? ??? ?CW_USEDEFAULT,
?? ??? ??? ?NULL,?
?? ??? ??? ?NULL,?
?? ??? ??? ?hInstance,
?? ??? ??? ?NULL);
?? ??? ?if(!mainframe_hwnd)
?? ??? ??? ?MessageBox(NULL, _T("主框架創建失敗!"), _T("Error"), MB_OK | MB_ICONERROR);
?? ?//4.顯示窗口
?? ??? ?ShowWindow(mainframe_hwnd, nShowCmd);

?? ?//5.刷新窗口
?? ??? ?UpdateWindow(mainframe_hwnd);

?? ?//6.信息捕獲
?? ??? ?MSG mainframe_msg;
?? ??? ?while (::GetMessage(&mainframe_msg, NULL, 0, 0))
?? ??? ?{
?? ??? ??? ?::TranslateMessage(&mainframe_msg);//TranslateMessage是用來把虛擬鍵消息轉換為字符消息。
?? ??? ??? ?::DispatchMessage(&mainframe_msg);//消息調度
?? ??? ?}
?? ??? ?return mainframe_msg.wParam;
}


LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
?? ?//處理消息
?? ?switch (message)
?? ?{
?? ??? ?/*1.關不窗口時,會收到該消息,PostQuitMessage()像系統表明終止當前線程,沒有這個函數的話,窗口不會關閉*/
?? ??? ?case WM_DESTROY:
?? ??? ??? ?PostQuitMessage(0);//用于相應關閉消息,否則線程不會關閉,導致系統阻塞
?? ??? ?return 0;
?? ?}
?? ?//將不需要處理的消息傳遞給系統作默認處理
?? ?return DefWindowProc(hwnd, message, wParam, lParam);
}
?

總結

以上是生活随笔為你收集整理的Windows框架的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。