1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
// Main.cpp
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <string>
#include <tchar.h>
#include "Main.h"
long fnWndProc_OnCreate(WndEventArgs& Wea)
{
TCHAR* pBuffer=NULL;
HWND hCtl;
Wea.hIns=((LPCREATESTRUCT)Wea.lParam)->hInstance;
hCtl=CreateWindowEx(0,_T("button"),_T("Button #1"),WS_CHILD | WS_VISIBLE,75,60,150,30,Wea.hWnd,(HMENU)IDC_BUTTON1,Wea.hIns,0);
hCtl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD | WS_VISIBLE,75,110,150,30,Wea.hWnd,(HMENU)IDC_EDITBOX1,Wea.hIns,0);
pBuffer=(TCHAR*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,256);
if(pBuffer)
SetWindowLongPtr(Wea.hWnd,0,(LONG)pBuffer);
return 0;
}
long fnWndProc_OnCommand(WndEventArgs& Wea)
{
TCHAR* pBuffer=NULL;
HWND hEdit;
switch(LOWORD(Wea.wParam))
{
case IDC_BUTTON1:
hEdit=GetDlgItem(Wea.hWnd,IDC_EDITBOX1);
pBuffer=(TCHAR*)GetWindowLongPtr(Wea.hWnd,0);
if(pBuffer)
{
GetWindowText(hEdit,pBuffer,255);
InvalidateRect(Wea.hWnd,NULL,FALSE);
}
break;
}
return 0;
}
long fnWndProc_OnPaint(WndEventArgs& Wea)
{
HDC hDC=NULL;
PAINTSTRUCT ps;
TCHAR* pBuffer=NULL;
int iPrev=0;
hDC=BeginPaint(Wea.hWnd,&ps);
iPrev=SetBkMode(hDC,TRANSPARENT);
pBuffer=(TCHAR*)GetWindowLong(Wea.hWnd,0);
std::wstring strText=pBuffer;
TextOut(hDC,75,160,strText.c_str(),strText.length());
SetBkMode(hDC,iPrev);
EndPaint(Wea.hWnd,&ps);
return 0;
}
long fnWndProc_OnDestroy(WndEventArgs& Wea)
{
TCHAR* pBuffer=NULL;
pBuffer=(TCHAR*)GetWindowLongPtr(Wea.hWnd,0);
if(pBuffer)
HeapFree(GetProcessHeap(),0,pBuffer);
PostQuitMessage(0);
return 0;
}
LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
WndEventArgs Wea;
for(unsigned int i=0; i<dim(EventHandler); i++)
{
if(EventHandler[i].iMsg==msg)
{
Wea.hWnd=hwnd, Wea.lParam=lParam, Wea.wParam=wParam;
return (*EventHandler[i].fnPtr)(Wea);
}
}
return (DefWindowProc(hwnd, msg, wParam, lParam));
}
int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
TCHAR szClassName[]=_T("TextOut");
WNDCLASSEX wc;
MSG messages;
HWND hWnd;
wc.lpszClassName=szClassName; wc.lpfnWndProc=fnWndProc;
wc.cbSize=sizeof (WNDCLASSEX); wc.style=0;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION); wc.hInstance=hIns;
wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION); wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW; wc.cbWndExtra=sizeof(void*);
wc.lpszMenuName=NULL; wc.cbClsExtra=0;
RegisterClassEx(&wc);
hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,75,75,320,305,HWND_DESKTOP,0,hIns,0);
ShowWindow(hWnd,iShow);
while(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
|