3,881
社区成员
发帖
与我相关
我的任务
分享
LRESULT CHelloDemoWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
styleValue &= ~WS_CAPTION;
::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
m_pmUI.Init(m_hWnd);
CDialogBuilder builder;
CControlUI* pRoot = builder.Create(_T("HelloDemo.xml"), (UINT)0, NULL, &m_pmUI);
ASSERT(pRoot && "Failed to parse XML");
m_pmUI.AttachDialog(pRoot);
m_pmUI.AddNotifier(this);
Init();
return 0;
}
LRESULT CHelloDemoWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
BOOL bHandle = TRUE;
LRESULT lRes = 0;
switch (uMsg)
{
case WM_CREATE:
{
lRes = OnCreate(uMsg, wParam, lParam, bHandle);
}
break;
case WM_DESTROY:
{
lRes = OnDestroy(uMsg, wParam, lParam, bHandle);
}
break;
default:
bHandle = FALSE;
break;
}
if (bHandle)
{
return lRes;
}
if (m_pmUI.MessageHandler(uMsg, wParam, lParam, lRes))
{
return lRes;
}
return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int nCmdShow)
{
CPaintManagerUI::SetInstance(hInstance);
CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath() + _T("skin\\HelloDemo"));
HRESULT Hr = ::CoInitialize(NULL);
if(FAILED(Hr))
{
return 0;
}
CHelloDemoWnd* pWnd = new CHelloDemoWnd();
if (pWnd == NULL)
{
return 0;
}
pWnd->Create(NULL, _T("HelloWnd"), UI_WNDSTYLE_FRAME, 0L, 0, 0, 0, 0);
pWnd->CenterWindow();
pWnd->ShowWindow();
CPaintManagerUI::MessageLoop();
::CoUninitialize();
return 0;
}
class CHelloDemoWnd : public CWindowWnd, public INotifyUI
{
public:
CHelloDemoWnd();
~CHelloDemoWnd();
LPCTSTR GetWindowClassName() const;
UINT GetClassStyle() const { return CS_DBLCLKS; };
void OnFinalMessage(HWND /*hWnd*/) { delete this; };
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
void Notify(TNotifyUI& msg);
private:
void Init();
private:
CButtonUI* m_pBtnClose;
CPaintManagerUI m_pmUI;
};
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<Window size="500,400">
<VerticalLayout enabled="true" width="500" height="400" bkimage="Desert.jpg">
<HorizontalLayout enabled="true" width="500" height="20">
<Button name="btnClose" float="true" pos="445,0,0,0" enabled="true" width="50" height="20" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="frame_btn_close_normal.bmp" hotimage="frame_btn_close_hot.bmp" pushedimage="frame_btn_close_down.bmp" disabledimage="frame_btn_close_disable.bmp" />
<Button name="btnMin" float="true" pos="408,0,0,0" enabled="true" width="26" height="18" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='frame_btn_min.bmp' source='0,0,26,18'" hotimage="file='frame_btn_min.bmp' source='26,0,52,18'" pushedimage="file='frame_btn_min.bmp' source='52,0,78,18'" disabledimage="file='frame_btn_min.bmp' source='78,0,104,18'" />
</HorizontalLayout>
<HorizontalLayout enabled="true" width="500" height="380" bkimage="Hydrangeas.jpg" />
</VerticalLayout>
</Window>
#include <time.h>
#include <stdlib.h>
#include <windows.h>
int main() {
int a,b[11];//本来是b[10],为判断哪句越界,故意声明为b[11]
srand((unsigned int)time(NULL));//按两次F11,等黄色右箭头指向本行时,调试、新建断点、新建数据断点,地址:&b[10],字节计数:4,确定。
while (1) {//按F5,会停在下面某句,此时a的值为10,b[10]已经被修改为对应0..4之一。
b[(a=rand()%11)]=0;
Sleep(100);
b[(a=rand()%11)]=1;
Sleep(100);
b[(a=rand()%11)]=2;
Sleep(100);
b[(a=rand()%11)]=3;
Sleep(100);
b[(a=rand()%11)]=4;
Sleep(100);
}
return 0;
}