domingo, 15 de agosto de 2021

Win32 - calculadora da lei de ohm II

 

Criamos um projeto em win32, 
mas o VS nos apresentou uma janela branca sem graça,
e com dois menus, e a caixa de ferramenta estava desabilitada.
Decidimos logo escolher uma entre duas opções,
que seria, ou agente programava tudo na mão,
ou descartava a janela ofertada e adicionaria
ao projeto um Dialog.
como hoje tivemos um pouco mais de tempo,
optamos então pela primeira opção.
E assim, criamos este programa, aproveitando
uma boa porcentagem do outro que apresentamos
a poucos dias atrás, e acrescentrando 
alguns outros recursos, na interface e no menu.





//=============================================================================
VOID Cria_Eddit_Pot ( HWND hwnd ) {

    Edit_1 = CreateWindowEx (
        WS_EX_CLIENTEDGE, L"EDIT", L"",
        WS_VISIBLE | WS_CHILD | WS_BORDER | ES_RIGHT,
        250, 94, 60, 20,
        hwnd, ( HMENU ) ID_EDIT_1, NULL, NULL );

    Edit_2 = CreateWindowEx (
        WS_EX_CLIENTEDGE, L"EDIT", L"",
        WS_VISIBLE | WS_CHILD | WS_BORDER | ES_RIGHT,
        250, 117, 60, 20,
        hwnd, ( HMENU ) ID_EDIT_2, NULL, NULL );

    Edit_3 = CreateWindowEx (
        WS_EX_CLIENTEDGE, L"EDIT", L"",
        WS_VISIBLE | WS_CHILD | WS_BORDER | ES_RIGHT | ES_READONLY,
        250, 140, 60, 20,
        hwnd, ( HMENU ) ID_EDIT_3, NULL, NULL );
}
//=============================================================================
VOID Button_1 ( HWND hwnd ) {
    HWND button_1;
    button_1 = CreateWindowW ( L"button", L"Ok",
        WS_VISIBLE | WS_CHILD, 160, 170, 30, 19,
        hwnd, ( HMENU ) IDC_BUTTON3, NULL, NULL );
}
//=============================================================================
VOID Button_2 ( HWND hwnd ) {
    HWND button_2;
    button_2 = CreateWindowW ( L"button", L"Ok",
        WS_VISIBLE | WS_CHILD, 160, 170, 30, 19,
        hwnd, ( HMENU ) IDC_BUTTON4, NULL, NULL );
}
//=============================================================================
VOID Button_3 ( HWND hwnd ) {
    HWND button_3;
    button_3 = CreateWindowW ( L"button", L"Ok",
        WS_VISIBLE | WS_CHILD, 160, 170, 30, 19,
        hwnd, ( HMENU ) IDC_BUTTON5, NULL, NULL );
}
//=============================================================================
VOID Button_4 ( HWND hwnd ) {
    HWND button_4;
    button_4 = CreateWindowW ( L"button", L"Ok",
        WS_VISIBLE | WS_CHILD, 160, 170, 30, 19,
        hwnd, ( HMENU ) IDC_BUTTON6, NULL, NULL );
}
//=============================================================================
VOID Button_5 ( HWND hwnd ) {
    //HWND button_5;
    CreateWindowW ( L"button", L"Novo cálculo",
        WS_VISIBLE | WS_CHILD, 210, 170, 100, 19,
        hwnd, ( HMENU ) IDC_BUTTON7, NULL, NULL );
}
//=============================================================================
VOID Moldura ( HDC hdc ) {
    PAINTSTRUCT ps;

    Graphics graphics ( hdc );

    Graphics* myGraphics;
    GraphicsPath myGraphicsPath;

    Pen penJoin1 ( Color ( 255, 0, 255, 0 ), 10 );
    penJoin1.SetLineJoin ( LineJoinBevel );

    SetBkColor ( hdc, RGB ( 255, 0, 255 ) );
    graphics.DrawRectangle ( &penJoin1, Rect ( 5, 5, 580, 280 ) );
    graphics.DrawPath ( &penJoin1, &myGraphicsPath );

    PointF pointF1 ( 120.0f, 10.0f );
    StringFormat myStringFormat;
    FontFamily fontFamily ( L"Times New Roman" );
    Font font ( &fontFamily, 24, FontStyleItalic, UnitPixel );

    Pen penJoin2 ( Color ( 255, 255, 0, 0 ), 1 );
    myGraphicsPath.AddString ( L"WIN32 - CALCULADORA DA LEI DE OHM", 33, &fontFamily,
        0, 17, pointF1, &myStringFormat );
    graphics.DrawPath ( &penJoin2, &myGraphicsPath );
}
//=============================================================================
VOID Informe ( HDC hdc ) {
    Graphics graphics ( hdc );

    FontFamily fontFamily ( L"Times New Roman" );
    Font font ( &fontFamily, 16, FontStyleItalic, UnitPixel );

    SolidBrush solidBrush_1 ( Color ( 255, 255, 0, 0 ) );//Vermelho
    SolidBrush solidBrush_2 ( Color ( 255, 0, 0, 255 ) );//Azul
    SolidBrush solidBrush_3 ( Color ( 255, 0, 0, 0 ) );//Preto

    graphics.DrawString ( L"Por:", 4, &font, PointF ( 160.0f, 240.0f ), &solidBrush_1 );
    graphics.DrawString ( L"Samuel Lima", 12, &font, PointF ( 195.0f, 240.0f ), &solidBrush_2 );
    graphics.DrawString ( L"sa_sp10@hotmail.com", 20, &font, PointF ( 160.0f, 255.0f ), &solidBrush_3 );
}
//=============================================================================

quinta-feira, 12 de agosto de 2021

Win32 - calculadora da lei de ohm

Criamos um projeto em win32, 
mas o VS nos apresentou uma janela branca sem graça,
e com dois menus, e a caixa de ferramenta estava desabilitada.
Decidimos logo escolher uma entre duas opções, que seria,
ou agente programava tudo na mão, ou descartava a janela
ofertada e adicionaria ao projeto um Dialog, 
optamos pela segunda opção. Após algumas configurações, 
cortando alguns códigos e inserindo outros já estávamos
rodando um dialog, no win32 e a caixa de ferramenta já estava
totalmente disponível para uso. E assim, criamos este programa, 
para cálculos da lei de ohm, e resolvemos postá-lo assim mesmo, 
mesmo porque já estávamos há muitos dias sem programar.

 


//=============================================================================
INT_PTR String_Com_TextOut ( HWND hwnd ) {

    PAINTSTRUCT ps;
    hdc = BeginPaint ( hwnd, &ps );

    HFONT hFont;

    hFont = CreateFont (
        15,                       // nHeight
        7,                        // nWidth
        0,                        // nEscapement
        0,                        // nOrientation
        FW_NORMAL,                // nWeight
        TRUE,                    // bItalic
        FALSE,                    // bUnderline
        0,                        // cStrikeOut
        ANSI_CHARSET,             // nCharSet
        OUT_DEFAULT_PRECIS,       // nOutPrecision
        CLIP_DEFAULT_PRECIS,      // nClipPrecision
        DEFAULT_QUALITY,          // nQuality
        DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
        _T ( "Times New Roman" ) );            // lpszFacename

    HFONT hfOld = ( HFONT ) SelectObject ( hdc, hFont );

    LOGBRUSH brush;
    COLORREF col = RGB ( 0, 0, 255 );
    DWORD pen_style = PS_SOLID | PS_JOIN_MITER | PS_GEOMETRIC;

    brush.lbStyle = BS_SOLID;
    brush.lbColor = col;
    brush.lbHatch = 0;

    pen_style = PS_SOLID | PS_GEOMETRIC | PS_JOIN_BEVEL;
    HPEN hPen1 = ExtCreatePen ( pen_style, 8, &brush, 0, NULL );

    SelectObject ( hdc, hPen1 );
    RoundRect ( hdc, 5, 5, 562, 266, 10, 10 );

    SetTextColor ( hdc, RGB ( 255, 0, 0 ) );
    TextOut ( hdc, 120, 10, L"WIN32 - CALCULADORA DA LEI DE OHM", 33 );

    std::string text_17 = "Por:";
    std::string text_18 = "Samuel Lima";
    std::string text_19 = "sa_sp10@hotmail.com";

    CString str_29 = text_17.c_str ( );
    CString str_30 = text_18.c_str ( );
    CString str_31 = text_19.c_str ( );

    SetTextColor ( hdc, RGB ( 255, 0, 0 ) );
    TextOut ( hdc, 60, 215, str_29, 5 );
    SetTextColor ( hdc, RGB ( 0, 0, 255 ) );
    TextOut ( hdc, 95, 215, str_30, 12 );
    SetTextColor ( hdc, RGB ( 0, 0, 0 ) );
    TextOut ( hdc, 60, 230, str_31, 20 );

    EndPaint ( hwnd, &ps );

    return ( INT_PTR ) FALSE;
}
//=============================================================================