#include "stdafx.h"
#include "ExamSubclassWnd.h"
#include "twapi_w01.h"
#include "twapi_w01_gdi.h"
#include "twapi_w01_util.h"
#include "twapi_w01_socket.h"
#pragma comment(lib, "D2D1.lib")
#pragma comment(lib, "D3D11.lib")
#pragma comment(lib, "DXGI.lib")
#pragma comment(lib, "dxguid.lib")
#pragma comment(lib, "DWRITE.lib")
#pragma comment(lib, "Msimg32.lib")
#pragma comment(lib, "WS2_32.lib")
#ifdef _DEBUG
#pragma comment(lib, "DSH_TWAPI_W01.lib")
#else
#pragma comment(lib, "RST_TWAPI_W01.lib")
#endif
WNDPROC g_org_edit_proc;
LRESULT APIENTRY MyEditProc(HWND ah_wnd, UINT message_id,
WPARAM wParam, LPARAM lParam)
{
if (message_id == WM_KEYUP && wParam == VK_RETURN) {
return ::PostMessage(::GetParent(ah_wnd), WM_COMMAND,
MAKEWPARAM(25002, 1000), (LPARAM)ah_wnd);
}
return ::CallWindowProc(g_org_edit_proc,ah_wnd,message_id,wParam,lParam);
}
class MyWnd : public TW_Wnd
{
private:
TW_ListBoxWnd m_chat_list;
HFONT mh_font;
HWND mh_chat_edit;
public:
MyWnd() { }
virtual void OnCommand(INT32 a_ctrl_id, INT32 a_notify_code, HWND ah_ctrl)
{
if (a_ctrl_id == 25002) {
if (a_notify_code == 1000) {
wchar_t str[128];
::GetDlgItemText(mh_wnd, 25002, str, 128);
m_chat_list.InsertString(-1, str);
::SetDlgItemText(mh_wnd, 25002, L"");
}
}
}
virtual int OnCreate(CREATESTRUCT *ap_create_info)
{
TW_Wnd::OnCreate(ap_create_info);
mh_font = TWAPI_CreateFont();
m_chat_list.CreateEx(mh_wnd, 3, 3, 421, 190, 25001);
m_chat_list.SetFont(TWAPI_CreateFont(), 0);
mh_chat_edit = ::CreateWindow(L"EDIT", NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,
3, 193, 418, 22, mh_wnd, (HMENU)25002, NULL, NULL);
::SendMessage(mh_chat_edit, WM_SETFONT, (WPARAM)mh_font, 1);
g_org_edit_proc = (WNDPROC)SetWindowLong(mh_chat_edit,
GWL_WNDPROC, (LONG)MyEditProc);
return 0;
}
virtual void OnPaint()
{
m_chat_list.Invalidate();
::InvalidateRect(mh_chat_edit, NULL, TRUE);
mp_target->BeginDraw();
mp_target->Clear(ColorF(0.1875f, 0.2343f, 0.3203f));
mp_target->EndDraw();
}
virtual void OnDestroy()
{
TW_Wnd::OnDestroy();
SetWindowLong(mh_chat_edit, GWL_WNDPROC, (LONG)g_org_edit_proc);
::DestroyWindow(mh_chat_edit);
::DeleteObject(mh_font);
}
};
class MyApp : public TW_WinApp
{
public:
MyApp(HINSTANCE ah_instance, const wchar_t *ap_class_name)
: TW_WinApp(ah_instance, ap_class_name) { }
virtual void InitInstance()
{
mp_wnd = new MyWnd;
mp_wnd->Create(L"Exam SubclassWnd - Tipssoft.com", 50, 50, 440, 257);
mp_wnd->ShowWindow();
mp_wnd->UpdateWindow();
}
};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MyApp tips_app(hInstance, L"ExamSubclassWnd");
return tips_app.NormalProcess();
}