?? inputdlg.cpp
字號:
#include "stdafx.h"
#include ".\inputdlg.h"
#include "resource.h"
const char * const CInputDlg::lpClassName="CInputDlg";
HINSTANCE CInputDlg::hInstance;
CInputDlg::CInputDlg(void)
{
hWnd=hEdit=hStatic=hOk=hCancel=NULL;
Value=0;
}
int CInputDlg::Register(HINSTANCE hInst)
{
hInstance=hInst;
WNDCLASSEX wc;
wc.cbClsExtra=0;
wc.cbSize=sizeof(wc);
wc.cbWndExtra=0;
wc.hbrBackground=HBRUSH(COLOR_BTNFACE+1);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance=hInstance;
wc.lpfnWndProc=(WNDPROC)WinProc;
wc.lpszClassName=lpClassName;
wc.lpszMenuName=NULL;
wc.style=CS_VREDRAW|CS_HREDRAW;
return RegisterClassEx(&wc);
}
void CInputDlg::Create()
{
int cx=GetSystemMetrics(SM_CXBORDER)*3+288 ;
int cy=GetSystemMetrics(SM_CYBORDER)*3+105+GetSystemMetrics(SM_CYCAPTION);
POINT p;
GetCursorPos(&p);
hWnd=CreateWindow(lpClassName,"實驗七",0,p.x ,p.y,cx,cy,hParent,NULL,hInstance,this);
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
}
LRESULT CInputDlg::WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
CInputDlg *that=(CInputDlg *)GetWindowLong(hWnd,GWL_USERDATA);
if (msg==WM_CREATE)
{
SetWindowLong(hWnd,GWL_USERDATA,(LONG)((CREATESTRUCT *)lParam)->lpCreateParams);
that=(CInputDlg *)((CREATESTRUCT *)lParam)->lpCreateParams;
that->OnCreate(hWnd);
}
if (msg==WM_COMMAND)that->OnCommand(LOWORD(wParam));
if (msg==WM_DESTROY) PostQuitMessage(that->RetId);
if (msg==WM_SETFOCUS)SetFocus(that->hEdit);
return DefWindowProc(hWnd,msg,wParam,lParam);
}
void CInputDlg::OnCommand(UINT wmId)
{
if (wmId==IDOK)
{
RetId=1;
char buf[16];
GetWindowText(hEdit,buf,16);
Value=Val(buf);
wmId=IDCANCEL;
}
if (wmId==IDCANCEL)
{
EnableWindow(hParent,true);
SetActiveWindow(hParent);
DestroyWindow(hWnd);
}
}
void CInputDlg::OnCreate(HWND hWnd)
{
hFont=CreateFont(12,0,0,0,0,0,0,0,0,0,0,0,0,"宋體");
hStatic=CreateWindow("Static",lpPrompt,WS_CHILD |WS_VISIBLE,21,21,150,21,hWnd,NULL,hInstance,0);
SendMessage(hStatic,WM_SETFONT,(WPARAM)hFont,1);
hEdit=CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",Str(Value),WS_CHILD |WS_VISIBLE|ES_NUMBER,21,63,150,21,hWnd,NULL,hInstance,0);
SendMessage(hEdit,WM_SETFONT,(WPARAM)hFont,1);
SendMessage(hEdit,EM_SETLIMITTEXT,9,0);
hOk=CreateWindow("Button","確定",WS_CHILD |WS_VISIBLE|BS_DEFPUSHBUTTON,192,21,75,21,hWnd,(HMENU)IDOK ,hInstance,0);
SendMessage(hOk,WM_SETFONT,(WPARAM)hFont,1);
hCancel=CreateWindow("Button","取消",WS_CHILD |WS_VISIBLE,192,63,75,21,hWnd,(HMENU)IDCANCEL,hInstance,0);
SendMessage(hCancel,WM_SETFONT,(WPARAM)hFont,1);
EnableWindow(hParent,false);
RetId=0;
}
int CInputDlg::DoModal(HWND hWndParent,char * Prompt,int nVal)
{
Value=nVal;
lpPrompt=Prompt;
hParent=hWndParent;
Create();
return Run();
}
int CInputDlg::Run()
{
HACCEL hAccel=LoadAccelerators(hInstance,(LPCSTR)IDR_InputDlg);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
if (!TranslateAccelerator(hWnd,hAccel,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -