程序代码:
#include <windows.h>
#include <tchar.h>
#include <string.h>
#include <stdio.h>
#include "resource.h"
/*创建窗口的几个过程:
创建窗口类
注册窗口类
创建窗口句柄
显示窗口
更新窗口
循环消息检索
*/
LRESULT CALLBACK WinProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
TCHAR lpClassName[]=_TEXT("ClassName");
WNDCLASS wndclass;
HWND hwnd;
MSG msg;
int Error_code;
TCHAR Error_message[100];
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=WinProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_WARNING);
wndclass.hCursor=LoadIcon(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)COLOR_WINDOWTEXT;
wndclass.lpszMenuName=MAKEINTRESOURCE(IDR_MENU1);
wndclass.lpszClassName=lpClassName;
if(!RegisterClass(&wndclass))
{
Error_code=GetLastError();
_stprintf(Error_message,_TEXT("错误代码为:%d"),Error_code);
MessageBox(NULL,_TEXT("注册失败"),Error_message,MB_OK);
}
hwnd=CreateWindow(lpClassName,_TEXT("我的窗口"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOW);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,NULL,NULL))
{
if(!TranslateAccelerator(hwnd,LoadAccelerators(hInstance,MAKEINTRESOURCE(IDR_ACCELERATOR1)),&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
LRESULT CALLBACK WinProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
static HINSTANCE HIS;
HDC hdc;
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_CREATE:
HIS=((LPCREATESTRUCT)lParam)->hInstance;
return 0;
case WM_COMMAND:
if(HIWORD(wParam)==0)
{
if (LOWORD(wParam)==IDM_ABOUT)
{
// DialogBox(HIS,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,DialogProc);
MessageBox(hwnd,"0","",NULL);
}
}
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
//
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
程序所有源码: