Windoows窗口程序三

Posted 庖丁解牛

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Windoows窗口程序三相关的知识,希望对你有一定的参考价值。

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

HINSTANCE g_hInstance=0;

//主窗口处理函数
LRESULT WndProc(HWND hWnd,UINT nMsg,WPARAM wParam,LPARAM lParam)
{
    switch(nMsg)
    {
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            break;
    }
    return DefWindowProc(hWnd,nMsg,wParam,lParam);
}

//注册窗口类
BOOL Register(LPSTR lpClassName,WNDPROC wndproc)
{
    WNDCLASSEX wce={0};
    wce.cbSize=sizeof(wce);
    wce.cbClsExtra=0;
    wce.cbWndExtra=0;
    wce.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
    wce.hCursor=NULL;
    wce.hIcon=NULL;
    wce.hIconSm=NULL;
    wce.hInstance=g_hInstance;
    wce.lpfnWndProc=wndproc;
    wce.lpszClassName=lpClassName;
    wce.lpszMenuName=NULL;
    wce.style=CS_HREDRAW|CS_VREDRAW;
    ATOM nAtom=RegisterClassEx(&wce);
    if(nAtom==0)
    {
        return FALSE;
    }
    return TRUE;
}

//创建主窗口
HWND CreateMain(LPSTR lpClassName,LPSTR lpWndName)
{
    HWND hWnd=CreateWindowEx(0,lpClassName,lpWndName,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,g_hInstance,NULL);
return hWnd; } //显示窗口 void Display(HWND hWnd) { ShowWindow(hWnd,SW_SHOW); UpdateWindow(hWnd); } //消息循环 void Message() { MSG nMsg={0}; while(GetMessage(&nMsg,NULL,0,0)) { TranslateMessage(&nMsg); DispatchMessage(&nMsg); } } int WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { g_hInstance=hInstance; if(!Register("Main",(WNDPROC)WndProc)) { MessageBox(NULL,"注册失败","error",MB_OK); return -1; } HWND hWnd=CreateMain("Main","window"); Display(hWnd); Message(); return 0; }

 

以上是关于Windoows窗口程序三的主要内容,如果未能解决你的问题,请参考以下文章

Windoows窗口程序五

Windoows窗口程序三

Windoows窗口程序七

验证码逆向专栏极验三代四代点选类验证码逆向分析

C++项目三代码参考(改进版)

windoows ftp的自动上传bat