15,980
社区成员
发帖
与我相关
我的任务
分享
#include <windows.h>
#include "YZX_exercise_private.h"
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void ErrorExit(LPTSTR lpszFunction);
/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* 窗口句柄 */
MSG messages; /* 消息结构*/
WNDCLASSEX wincl; /* 窗口类结构 */
HMENU hmenu; /* 菜单句柄 */
/* The Window structure */
wincl.hInstance = hThisInstance; /* 窗口实例句柄 */
wincl.lpszClassName = szClassName; /* 窗口类名称 */
wincl.lpfnWndProc = WindowProcedure; /* 窗口消息的处理程序 */
//wincl.style = CS_DBLCLKS; /* 窗口可获得鼠标双击信息 */
wincl.style =CS_HREDRAW | CS_VREDRAW ;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (hThisInstance,"WINDOWS_ICO"); /*窗口图标样式(显示器下方工具栏上的图标)*/
wincl.hIconSm = LoadIcon (hThisInstance,"WINDOWS_TITLE_ICO"); /*窗口 标题栏 图标样式*/
wincl.hCursor = LoadCursor (NULL,IDC_ARROW) ; /*窗口 鼠标 图标样式*/
wincl.lpszMenuName =NULL; /* 菜单名称(资源名) */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;/* Use Windows's default color as the background of the window */
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* 窗口名称 */
"Windows x App", /* 窗口的标题栏文字*/
WS_OVERLAPPEDWINDOW, /* 窗口风格*/
350, /* 窗口起点位置(水平) */
100, /* 窗口起点位置(垂直) */
650, /* 窗口水平长度 */
350, /* 窗口垂直长度*/
HWND_DESKTOP, /* 此窗口的父窗口句柄*/
NULL, /* 菜单句柄 */
hThisInstance, /*应用程序实例句柄*/
NULL /* No Window Creation data */
);
ShowWindow (hwnd, nFunsterStil);/*显示窗口*/
UpdateWindow (hwnd) ;
while (GetMessage (&messages, NULL, 0, 0))/*消息循环,当有WM_QUIT时,函数GetMessage()返回值是0 */
{
TranslateMessage(&messages); /* Translate virtual-key messages into character messages */
DispatchMessage(&messages); /* Send message to WindowProcedure */
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HMENU hmenu1,hmenu2;
HINSTANCE hInstance;
PAINTSTRUCT ps ;
HDC hdc ;
static k=11,m;
static char xox[]="123456789";
hInstance = (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE) ;
hmenu1= LoadMenu (hInstance,"WINDOWS_MENU_yzx") ;
hmenu2= LoadMenu (hInstance,"WINDOWS_MENU") ;
//SetMenu (hwnd, hmenu2) ;
switch (message) /* handle the messages */
{
case WM_CREATE:
SetMenu (hwnd, hmenu2) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
if(k==11)TextOut (hdc,100,200,"123456789",9) ;
else
switch(m)
{
case 2:TextOut (hdc,100,200,"NEW",3) ;break;
case 3:TextOut (hdc,100,200,"WORD",4) ;break;
case 4:TextOut (hdc,100,200,"SAVE",4) ;break;
default: break;
}
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_MENUSELECT:
switch (LOWORD (wParam))
{
case IDM_FILE_NEW:
k=0;
m=2;
InvalidateRect (hwnd, NULL, 1) ;
break;
case IDM_FILE_OPENW:
k=0;
m=3;
InvalidateRect (hwnd, NULL, 1) ;
break;
case IDM_FILE_SAVE:
k=0;
m=4;
InvalidateRect (hwnd, NULL, 1) ;
break;
case IDM_FILE_SAVE_AS:
break;
case IDM_FILE_EXIT:;
break;
}
InvalidateRect (hwnd, NULL, 0) ;
return 0 ;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case 111:
SetMenu (hwnd, hmenu2) ;
break;
case IDM_FILE_OPENT:
MessageBox(hwnd,"None such function!",szClassName, MB_ICONEXCLAMATION | MB_OK) ;
break;
case IDM_FILE_SAVE:
break;
case IDM_FILE_SAVE_AS:
MessageBeep (0) ;
break;
case IDM_FILE_EXIT:
SendMessage (hwnd, WM_CLOSE, 0, 0) ;
break;
case IDM_TOOLS_CHINESE:
SetMenu (hwnd, hmenu1) ;
break;
default: break;
}
return 0;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}