#define MWINCLUDECOLORS
#include <windows.h>
LRESULT CALLBACK wproc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static char szAppName[]="Microwindows Windows!";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
int width, height;
RECT r;
HWND hlist,hedit;
GetWindowRect(GetDesktopWindow(), &r);
width = height = r.right / 2;
MwRegisterButtonControl(NULL);
MwRegisterEditControl(NULL);
MwRegisterListboxControl(NULL);
MwRegisterProgressBarControl(NULL);
MwRegisterStaticControl(NULL);
MwRegisterComboboxControl(NULL);
MwRegisterScrollbarControl(NULL); //注册不同的窗口控件
wndclass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = (WNDPROC)wproc;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra =0;
wndclass.hInstance =0;
wndclass.hIcon =0;
wndclass.hCursor =0;
wndclass.hbrBackground =(HBRUSH)GetStockObject(LTGRAY_BRUSH);
wndclass.lpszMenuName =NULL;
wndclass.lpszClassName = szAppName;
RegisterClass(&wndclass);
hwnd=CreateWindowEx(0L,
szAppName,
"Microwindows Application Demo",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
width, /* 80, */
height, /* 80, */
NULL, NULL, NULL, NULL);
hedit=CreateWindowEx(0L, "EDIT","OK",WS_BORDER|WS_CHILD | WS_VISIBLE,
width * 5 / 8, 10, 100, 18,
hwnd, (HMENU)5, NULL, NULL);
CreateWindowEx(0L, "PROGBAR",
"OK",WS_BORDER|WS_CHILD | WS_VISIBLE,
width * 5 / 8, 32, 100, 18,hwnd, (HMENU)6, NULL, NULL);
hlist = CreateWindowEx(0L, "LISTBOX",
"OK",WS_VSCROLL|WS_BORDER|WS_CHILD | WS_VISIBLE,
width * 5 / 8, 54, 100, 54,hwnd, (HMENU)7, NULL, NULL); //创建不同的控件窗口
SendMessage(hlist, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Cherry");
SendMessage(hlist, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Apple");
SendMessage(hlist, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Orange");
SendMessage(hlist, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Banana");
SendMessage(hlist, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Smooth");
CreateWindowEx(0L, "BUTTON",
"Cancel", WS_CHILD | WS_VISIBLE, width * 5 / 8 + 50, 106+16+6, 50, 14,
hwnd, (HMENU)8, NULL, NULL); //创建不同的控件窗口
CreateWindowEx(0L, "STATIC", "Static", WS_CHILD | WS_VISIBLE,
width * 5 / 8, 106+34+6, 100, 18, hwnd, (HMENU)9, NULL, NULL);
//创建不同的控件窗口
CreateWindowEx(0L, "SCROLLBAR","OK",SBS_VERT |
WS_CHILD | WS_VISIBLE ,width * 5 / 8 -(18*2), 106+68, 18, 128,
hwnd, (HMENU)11, NULL, NULL); //创建不同的控件窗口
CreateWindowEx(0L, "SCROLLBAR","OK",SBS_HORZ |
WS_CHILD | WS_VISIBLE ,width * 5 / 8 -18 , 106+68, 128, 18,
hwnd, (HMENU)12, NULL, NULL); //创建不同的控件窗口
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg,NULL,0,0)) { //进入消息循环
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK wproc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
HGDIOBJ oldfont;
switch (iMsg) {
case WM_CREATE:
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
oldfont=SelectObject(hdc,CreateFont(12,
0,0,0,0,0,0,0,0,0,0,0,
FF_DONTCARE|DEFAULT_PITCH,
"HZXFONT"));
DrawText(hdc, "Microwindows Control", -1, &rect,
DT_SINGLELINE|DT_CENTER|DT_VCENTER);
DeleteObject(SelectObject(hdc,oldfont));
EndPaint(hwnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,iMsg,wParam,lParam);
}
return 0;
}