zoukankan      html  css  js  c++  java
  • win32 application

    #include <windows.h>
    #include 
    <stdio.h>

    LRESULT CALLBACK WinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
    {
        
    //设计一个窗口类
        WNDCLASS wndclass;
        wndclass.cbClsExtra 
    = 0;
        wndclass.cbWndExtra 
    = 0;
        wndclass.hbrBackground 
    = (HBRUSH)GetStockObject(BLACK_BRUSH);
        wndclass.hCursor 
    = LoadCursor(NULL, IDC_CROSS);
        wndclass.hIcon 
    = LoadIcon(NULL, IDI_ERROR);
        wndclass.hInstance 
    = hInstance; //应用程序句柄由WinMain函数传进来
        wndclass.lpfnWndProc = WinProc;
        wndclass.lpszClassName 
    = "WinTest";
        wndclass.lpszMenuName 
    = NULL;
        wndclass.style 
    = CS_HREDRAW | CS_VREDRAW;
        RegisterClass(
    &wndclass);

        HWND hwnd 
    = CreateWindow(wndclass.lpszClassName, "TEst",
            WS_OVERLAPPEDWINDOW, 
    00600400, NULL, NULL, hInstance, NULL);

        ShowWindow(hwnd, SW_SHOWNORMAL);
        UpdateWindow(hwnd);

        MSG msg;
        BOOL bRet;
        
    while( (bRet = GetMessage(&msg, NULL, 00)) != 0)
        {
            
    if(bRet == -1)
            {
                
    //handle the error and possibly exit
                return -1;
            }
            
    else
            {
                TranslateMessage(
    &msg);
                DispatchMessage(
    &msg);
            }
        }

        
    return msg.wParam;
    }

    LRESULT CALLBACK WinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        
    switch(uMsg)
        {
        
    case WM_CHAR:
            {
                
    char szChar[20];
                sprintf(szChar, 
    "char code is %d", wParam);
                MessageBox(hwnd, szChar, 
    "char"0);
            }
            
    break;
        
    case WM_LBUTTONDOWN:
            {
                MessageBox(hwnd, 
    "Mouse clicked""message"0);
                HDC hdc 
    = GetDC(hwnd);//不能在WM_PAINT消息中调用
                TextOut(hdc, 050"程序员", strlen("程序员"));
                ReleaseDC(hwnd, hdc);
            }
            
    break;
        
    case WM_PAINT:
            {
                PAINTSTRUCT ps;
                HDC hdc 
    = BeginPaint(hwnd, &ps);//只能在响应WM_PAINT中调用
                TextOut(hdc, 00"http://www", strlen("http://www"));
                EndPaint(hwnd, 
    &ps);
            }
            
    break;
        
    case WM_CLOSE:
            {
                
    if(IDYES == MessageBox(hwnd, "是否结束?""message", MB_YESNO))
                {
                    DestroyWindow(hwnd);
                }
            }
            
    break;
        
    case WM_DESTROY:
            {
                PostQuitMessage(
    0);
            }
            
    break;
        
    default:
            {
                
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
            }

        }
    //end of switch

        
    return false;
    }
  • 相关阅读:
    研修班第四次课笔记
    形象革命——穿搭
    对管理者的几点要求
    全链路压测
    项目管理最忌的5件事,千万不要忽视!
    2018年计划小目标(9月)PMP
    NLP是什么
    (深度好文)重构CMDB,避免运维之耻
    《转》我们不得不面对的中年职场危机
    项目管理,让自己更从容
  • 原文地址:https://www.cnblogs.com/tuzhiye/p/1701281.html
Copyright © 2011-2022 走看看