Home > Back-end >  Why don't WTL since the draw button to display images...
Why don't WTL since the draw button to display images...

Time:09-16

Is the button above to add a picture, button to set the graphic attribute
.h files
 # pragma once 
# include "stdafx. H"

The class CODButtonImpl: public CWindowImpl ,
Public COwnerDraw
{
Public:
CODButtonImpl ();

BEGIN_MSG_MAP (CODButtonImpl)
CHAIN_MSG_MAP_ALT (COwnerDraw The 1)
DEFAULT_REFLECTION_HANDLER ()
END_MSG_MAP ()

Void DrawItem (LPDRAWITEMSTRUCT lpdis);

Protected:
CBitmap m_bmp;
};

.cpp
 # include "stdafx. H" 
# include "CODButtonImpl. H"
# include "resource. H"


CODButtonImpl: : CODButtonImpl ()
{
M_bmp. LoadBitmap (IDB_ALYSON);
}

Void CODButtonImpl: : DrawItem (LPDRAWITEMSTRUCT lpdis)
{
CDCHandle dc lpdis - & gt; HDC.
The CDC dcMem.

DcMem. CreateCompatibleDC (dc);
Dc. SaveDC ();
DcMem. SaveDC ();

//Draw the button 's background, red if it has the focus, blue if not.
If (lpdis - & gt; ItemState & amp; ODS_FOCUS)
Dc. FillSolidRect (& amp; Lpdis - & gt; RcItem, RGB (0, 255));
The else
Dc. FillSolidRect (& amp; Lpdis - & gt; RcItem, RGB (0,0,255));

//Draw the bitmap in the top left, or offset by 1 pixel if the button
//is clicked.
DcMem. SelectBitmap (m_bmp);

If (lpdis - & gt; ItemState & amp; ODS_SELECTED)
Dc. BitBlt (1, 1, 80, 80, dcMem, 0, 0, SRCCOPY);
The else
Dc. BitBlt (0, 0, 80, 80, dcMem, 0, 0, SRCCOPY);

DcMem. RestoreDC (1);
Dc. RestoreDC (1);
}

Maindlg. H also added the macro
 CODButtonImpl m_wndODBtn; 
BEGIN_MSG_MAP (CMainDlg)
MESSAGE_HANDLER WM_INITDIALOG, OnInitDialog ()
COMMAND_ID_HANDLER (ID_APP_ABOUT OnAppAbout)
COMMAND_ID_HANDLER (IDOK OnOK)
COMMAND_ID_HANDLER (IDCANCEL and OnCancel)
COMMAND_ID_HANDLER_EX (IDC_ALYSON_BTN OnAlysonODBtn)

END_MSG_MAP ()

BEGIN_DDX_MAP (CMainDlg)
DDX_CONTROL (IDC_ALYSON_BTN m_wndODBtn)
END_DDX_MAP ()


Why don't show,,,

CodePudding user response:

Personal think the way the SDK pure API writing Windows programs have been out of date, efficiency is too low, it is ok to understand the principle, main is message mechanism,

A graphical user interface (GUI) programming can learn c + + Builder, advanced architecture (and c # drag controls), introduction to more easily,

C + + Builder is a real visual Development tool, c + + Builder can use the mouse to drag controls followed by a "design" set properties of a graphical user interface of the program, using the visual components/controls like "building blocks", built in the form of "wysiwyg" Application interface, which is the name of c + + Builder in the concept of the Builder, in this way, only needs to be written in c + + language business logic code, similar to the text interface programming under DOS, just concentrate on the business logic function, the code is very concise, data input and performance, in a graphical user interface, intuitive, and easy to use, this is RAD (Rapid Application Development, Rapid Application Development),

Book recommendation:
"C + + Builder 6 program design course (second edition)" (such as loyal lu, wen-liang liu/2011-04-01/science press) (dangdang)
"C + + Builder 6 programming examples of fine solution" (Zhao Mingxian), PDF, is a digital version, a scan version, there is also a complete implementation of tetris game,
"Wonderful" c + + Builder 6 programming Wu Yixian (Taiwan), there are a few simple little game, 10 can read later rewrite, is their mastery of the,
"C + + Builder 5 senior programming examples of fine solution" (written by Liu Bin) are larger practical program,

C + + Builder 6.0 several sample program project source code download:






C + + Builder first program (analog chat room) v1.11
C + + Builder analog to digital double clock sample (unfinished) v0.2.1
C + + Builder card game Demo v0.03
C + + Builder of irregular image transparent texture (transparent display bitmap) three methods and simple animation v1.3
Written by c + + Builder "ZEC, arithmetic exercise program" sea starfish scene v0.9.2
C + + Builder simple example phone book Demo v1.11

CodePudding user response:

A new version of c + + Builder is RAD Studio can also write android, apple app, more than a set of code compilation platform, can be compiled to first Windows convenient debugging and testing,

  • Related