The addition of the button button of the basic message mechanism of win32

#include <windows.h>


HINSTANCE g_hInstance = 0;
HWND hwndButtonCintinue;
HWND hwndButtonExit;
HWND hwndLabel;
//Message entry function
LRESULT CALLBACK WndProc(HWND hWnd, UINT msgID, WPARAM wparam, LPARAM lParam)
{
   switch (msgID)
   {
              case WM_CREATE :
               hwndButtonCintinue = CreateWindow(TEXT("button"),//must be: button    
                  TEXT("remote connection"),//the character displayed on the button    
                  WS_CHILD | WS_VISIBLE,
                  100, 240, 100, 50, //The button is on the interface The position that appears on
                  hWnd, (HMENU)1, //set the button IDIDC_BUTTON_CONTINUE = 131 to define your own ID
                  ((LPCREATESTRUCT)lParam)->hInstance, NULL);
                     ShowWindow(hwndButtonCintinue, true);


                hwndButtonExit = CreateWindow(TEXT("button"),//must be: button    
                   TEXT("exit"),//the character displayed on the button    
                   WS_CHILD | WS_VISIBLE,
                   400, 240, 100, 50, //The position where the button appears on the interface
                 hWnd, (HMENU)2, //Set the button ID IDC_BUTTON_EXIT =132 to define your own ID
                   ((LPCREATESTRUCT)lParam)->hInstance, NULL);
   ShowWindow(hwndButtonExit, TRUE);


   //Error /* hwndLabel
   = CreateWindow(TEXT("label"), TEXT("1111111111111"), WS_CHILD | WS_VISIBLE, 300, 240, 100, 50, hWnd, (HMENU)3, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
   ShowWindow(hwndLabel, TRUE);*/




   break;
   case  WM_DESTROY:
   PostQuitMessage(0);
    break;
   }
   //给各种消息默认处理
   return DefWindowProc(hWnd,msgID,wparam,lParam);
}
//注册窗口
void Register(LPSTR lpClassName, /*WNDPROC WndProc*/WNDPROC wndProc)
{
WNDCLASSEX wce = { 0 };
wce.cbSize = sizeof(wce);
wce.cbClsExtra = 0;
wce.cbWndExtra = 0;
wce.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wce.hCursor = NULL;
wce.hIcon = NULL;
wce.hIconSm = NULL;
wce.lpfnWndProc = wndProc;
wce.hInstance = g_hInstance;
wce.lpszClassName = lpClassName;
wce.lpszMenuName = NULL;
wce.style = CS_HREDRAW | CS_VREDRAW;
RegisterClassEx(&wce);
}
//创建窗口
HWND   createMain(LPSTR lpClassName,LPSTR lpWndName)
{
HWND hWnd = CreateWindowEx(0, lpClassName, lpWndName, WS_OVERLAPPEDWINDOW, 100, 100, 700, 500, NULL, NULL, g_hInstance, NULL); 
return hWnd;
}
//显示窗口
void  Display(HWND hWnd)
{
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
}


//消息循环
void Messasge()
{
MSG nMsg = { 0 };
while (GetMessage(&nMsg,NULL,0,0))
{
TranslateMessage(&nMsg);
DispatchMessage(&nMsg);
}
}
//WinMain函数
int  CALLBACK WinMain(HINSTANCE hIns,HINSTANCE hPreIns,LPSTR lpCmdLine,int nCmdShow)
{
g_hInstance = hIns;
//注册窗口类
Register("Main", WndProc);
//创建窗口
HWND hWnd = createMain("Main","Window");
Display(hWnd);
Messasge();
return 0;
}



















Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324523370&siteId=291194637