• 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;
    }
  • 相关阅读:
    mac上eclipse上运行word count
    利用hadoop自带程序运行wordcount
    mac上eclipse上配置hadoop
    在mac上安装hadoop伪分布式
    0到N数其中三个数的全排列
    【设计模式】【应用】使用模板方法设计模式、策略模式 处理DAO中的增删改查
    【设计模式】【行为型模式】策略模式
    【设计模式】【行为型模式】模板模式
    properties文件操作
    File相关操作
  • 原文地址:https://www.cnblogs.com/tuzhiye/p/1701281.html
Copyright © 2020-2023  润新知