📄 frame.cpp
字号:
#include ".\frame.h"
HWND CFrame::m_Hwnd = NULL;
string CFrame::m_String;
string CFrame::m_Result;
HRESULT CALLBACK WindowProc( HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam )
{
return ( CFrame::WndProc( hwnd,msg,wparam,lparam ) );
}
CFrame::CFrame(void)
{
m_Hwnd = NULL;
m_ButtonWidth = 30;
m_ButtonHeight = 20;
w = m_ButtonWidth + m_ButtonWidth / 2 + 10;
h = m_ButtonHeight + m_ButtonHeight / 2;
x = 35;
y = 80;
m_WindowWidth = 5 * w;
m_WindowHeight = 8 * h;
}
CFrame::~CFrame(void)
{
}
void CFrame::Init( HINSTANCE hinstance )
{
m_Hinstance = hinstance;
WNDCLASS winclass;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hbrBackground = CreateSolidBrush(RGB(0xa6, 0xca, 0xf0));//( HBRUSH )GetStockObject( BLACK_BRUSH );
winclass.hCursor = LoadCursor( NULL,IDC_ARROW );
winclass.hIcon = LoadIcon( NULL,IDI_APPLICATION );
winclass.hInstance = hinstance;
winclass.lpfnWndProc = WindowProc;
winclass.lpszClassName = "CLASS";
winclass.lpszMenuName = NULL;
winclass.style = 0;
if( !RegisterClass( &winclass) )
{
MessageBox( 0,"Window class initlize failed!",0,0 );
exit( 0 );
}
m_Hwnd = CreateWindow( "CLASS","Compute",WS_EX_TOPMOST | WS_SYSMENU,0,0,m_WindowWidth,m_WindowHeight,0,0,NULL,0 );
if( m_Hwnd == NULL )
{
MessageBox( 0,"create window failed!",0,0 );
exit( 0 );
}
ShowWindow( m_Hwnd,SW_SHOW );
//create button
//::CreateWindowEx(0, "button", "0", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
// 50, 30,m_ButtonWidth,m_ButtonHeight, m_Hwnd, (HMENU)IDC_BUTTON0, hinstance, NULL);
CreateButton( "0",( HMENU )IDC_BUTTON0,x,y+3*h );
CreateButton( "(",( HMENU )IDC_BUTTON_LEF,x+w,y+3*h );
CreateButton( ")",( HMENU )IDC_BUTTON_RIG,x+2*w,y+3*h );
CreateButton( "1",( HMENU )IDC_BUTTON1,x,y+2*h );
CreateButton( "2",( HMENU )IDC_BUTTON2,x+w,y+2*h );
CreateButton( "3",( HMENU )IDC_BUTTON3,x+2*w,y+2*h );
CreateButton( "4",( HMENU )IDC_BUTTON4,x ,y + h);
CreateButton( "5",( HMENU )IDC_BUTTON5,x+w,y + h );
CreateButton( "6",( HMENU )IDC_BUTTON6,x+2*w,y+h );
CreateButton( "7",( HMENU )IDC_BUTTON7,x,y );
CreateButton( "8",( HMENU )IDC_BUTTON8,x+w,y );
CreateButton( "9",( HMENU )IDC_BUTTON9,x+2*w,y );
CreateButton( "+",( HMENU )IDC_BUTTON_ADD,x+3*w,y );
CreateButton( "-",( HMENU )IDC_BUTTON_MIN,x+3*w,y+h );
CreateButton( "*",( HMENU )IDC_BUTTON_MUL,x+3*w,y+2*h );
CreateButton( "/",( HMENU )IDC_BUTTON_DEV,x+3*w,y+3*h );
CreateButton( "=",( HMENU )IDC_BUTTON_EQU,x+w,y-h );
CreateButton( "bac",( HMENU )IDC_BUTTON_BAC,x,y - h );
CreateWindowEx(0, "static", "", WS_CHILD|WS_VISIBLE|SS_SUNKEN,
x-20,10,8 * m_ButtonWidth,m_ButtonHeight, m_Hwnd, (HMENU)IDC_EDIT, m_Hinstance, NULL);
CreateWindowEx(0, "static", "", WS_CHILD|WS_VISIBLE|SS_SUNKEN,
x+2*w,y-h,3 * m_ButtonWidth - 5,m_ButtonHeight, m_Hwnd, (HMENU)IDC_EDIT1, m_Hinstance, NULL);
}
void CFrame::CreateButton( char* title,HMENU menu,int x,int y )
{
CreateWindowEx(0, "button", title, WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
x, y,m_ButtonWidth,m_ButtonHeight, m_Hwnd, (HMENU)menu, m_Hinstance, NULL);
}
HRESULT CFrame::WndProc( HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam )
{
switch( msg )
{
case WM_DESTROY:
{
PostQuitMessage( 0 );
}break;
case WM_KEYDOWN:
{
if( VK_ESCAPE == wparam )
{
DestroyWindow( hwnd );
}
}break;
case WM_COMMAND:
{
OnCommand( wparam,lparam );
}break;
}
return ( DefWindowProc( hwnd,msg,wparam,lparam ) );
}
void CFrame::Run()
{
MSG msg;
ZeroMemory( &msg,sizeof( msg ) );
while( GetMessage( &msg,0,0,0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
void CFrame::OnCommand( WPARAM wparam,LPARAM lparam )
{
char sz[10];
switch( LOWORD( wparam ) )
{
case IDC_BUTTON0:
{
m_String += '0';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON1:
{
m_String += '1';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON2:
{
m_String += '2';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON3:
{
m_String += '3';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON4:
{
m_String += '4';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON5:
{
m_String += '5';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON6:
{
m_String += '6';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON7:
{
m_String += '7';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON8:
{
m_String += '8';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON9:
{
m_String += '9';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON_ADD:
{
m_String += '+';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON_MIN:
{
m_String += '-';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON_MUL:
{
m_String += '*';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON_DEV:
{
m_String += '/';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON_LEF:
{
m_String += '(';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON_RIG:
{
m_String += ')';
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}break;
case IDC_BUTTON_EQU:
{
string temp;
temp = m_String;
temp += '#';
string result;
main( temp,result );
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT1),result.c_str() );
m_String.clear();
}break;
case IDC_BUTTON_BAC:
{
int a = m_String.size();
if( a >= 1 )
{
a -= 1;
m_String.erase( a );
SetWindowText( GetDlgItem(m_Hwnd, IDC_EDIT),m_String.c_str() );
}
}break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -