|
ForNow wrote: After researching the problem I deduced the that I needed to use the
corresponding string safe api for strcpy ...StringCchCopy
The secure version of strcpy is strcpy_s[^]
ForNow wrote: I have warnings a W0 -- Turn of all warnings
That's very bad practice. Instead of disabling the warnings, why don't you remove them by writing clean code ?
|
|
|
|
|
Thankx I'll give it a shot
|
|
|
|
|
If you've just changed the #include you will get compile errors. StringCchCopy and similar operations take an extra parameter, the length of buffer you are using. Without adding this parameter into the calls you will get errors.
|
|
|
|
|
I got compile errors from the Header strsafe.h
|
|
|
|
|
Can you post some of the errors you're getting?
Steve
|
|
|
|
|
1>hsccmd.c
Maybe its some compiler options I need to set
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(416) : error C2143: syntax error : missing ')' before 'type'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(418) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(422) : error C2065: 'hr' : undeclared identifier
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(422) : error C2065: 'pszDest' : undeclared identifier
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(422) : error C2065: 'cchDest' : undeclared identifier
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(424) : error C2065: 'hr' : undeclared identifier
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(426) : error C2065: 'hr' : undeclared identifier
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(426) : error C2065: 'pszDest' : undeclared identifier
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(427) : error C2065: 'cchDest' : undeclared identifier
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(429) : error C2065: 'pszSrc' : undeclared identifier
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(433) : error C2065: 'hr' : undeclared identifier
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(438) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(438) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(438) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(438) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(440) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(535) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(535) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(535) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(535) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(537) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(558) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(558) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(558) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(558) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(560) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(682) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(682) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(682) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(682) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(687) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(802) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(802) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(802) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(802) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(807) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1023) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1023) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1023) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1023) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1028) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1140) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1140) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1140) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1140) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1145) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1332) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1332) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1332) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1332) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1335) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1364) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1364) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1364) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1364) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1367) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1473) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1473) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1473) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1473) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1476) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1508) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1508) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1508) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1508) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1511) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1653) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1653) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1653) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1653) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1659) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1774) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1774) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1774) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1774) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(1780) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2003) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2003) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2003) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2003) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2009) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2122) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2122) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2122) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2122) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2128) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2307) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2307) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2307) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2307) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2309) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2330) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2330) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2330) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2330) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2332) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2421) : error C2146: syntax error : missing ')' before identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2421) : error C2061: syntax error : identifier 'pszDest'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2421) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2421) : error C2059: syntax error : ','
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2423) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h(2423) : fatal error C1003: error count exceeds 100; stopping compilation
1
|
|
|
|
|
For 20+yrs C/C++ programmers have been writting programs, without buffer overruns, using strcpy, i find it odd that you _need_ StringCchCopy.
strcpy is also available as an intrinsic which, if you are doing a lot of string copying, can result in a significant performance improvement over StringCchCopy.
The 'safe' versions have been added by MS because of the amount of lazy/poor programming that exists, not because they are needed.
The only legit reason, i see, for using the MS String* functions is an effort to remove all direct references to the CRT, thus removing its direct linking (however, as an intrinsic, strcpy alone does not induce a CRT dependency).
Make sure you include windows.h (winnt.h) before strsafe.h.
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
SEH is exactly a good solution for exception handling, but it depends on the stack to call the user-defined exeception handler function, that means, when exception occurs, the OS catch the exception immediately, and it will call the user-defined callback to give the control to the application. If the trouble which caused the exception makes the stack broken, the calling to the user-defined callback may not success, in this situation, the application will not be notified that an exception occurred. Is there anyway to catch the exception in all the cases? whether stack is OK or NG, the mechanism should work.
Thanks.
|
|
|
|
|
Exception handling in general needs to walk the call stack to find handlers. Maybe you can find some way of using C's longjmp to do your exception handling?
|
|
|
|
|
I think the workflow is, firstly I catch an exception, and then jump to where to handle this exception. I wonder how to catch such an exception when the stack was broken.
|
|
|
|
|
I think that if the stack is "broken" you've got more to worry about than SEH not working.
Steve
|
|
|
|
|
Yes I think so. But I don't want to recover from the error in this case, I just want to record some useful information when an exception happened. Such as error thread ID
|
|
|
|
|
I have very good succes with __try / __except for catching unhandled exceptions (Instead of using SetUnhandledExceptionFilter or set_se_translator with /EHa compiler option). Though one still need to set the following exception handlers:
_set_purecall_handler( );
_set_invalid_parameter_handler( );
Where one raises an exception inside the exception handlers to get the proper exception information to create a useful minidump.
But yes sometimes the memory overwrite be so bad that the exception information cannot give a useful call stack.
|
|
|
|
|
|
I am trying to make Full screen (800 x 480) apps for vehicle PC's.
like this one:
http://i615.photobucket.com/albums/tt235/I_want_to_learn/SentaFS.jpg [i615.photobucket.com]
I'm trying to do apps like that with Fully Alpha Blended PNG's.
I managed to load a PNG as the Dialogs Background and one as a Button.
The button has 2 images:
1: The Normal State
2: the Down (Pressed) State
The problem i'm having is that every time i click the button, the "Down State" PNG gets drawn on top of the "Normal State" PNG and you can clearly see the Normal state Icon in the back of the button's Downstate Image and Viceversa
How can i clear or erase the the normal state image if i click my button and viceversa when i release my button.
If i put a solid background to the button i can fix the image overlapping problem but i get a big color full square, i need to redraw the button with the new image but still having the transparent background.
This is the code for my DialogBox:
#include "stdafx.h"
#include "ODBII Maker Database.h"
#include "ODBII Maker DatabaseDlg.h"
#include "SearchButton.h"
#include <fstream>
#include <gdiplus.h>
#include <gdiplusenums.h>
#pragma comment (lib,"gdiplus.lib")
using namespace std;
fstream database;
CString ItemText;
int mark;
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
CODBIIMakerDatabaseDlg::CODBIIMakerDatabaseDlg(CWnd* pParent )
: CDialog(CODBIIMakerDatabaseDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CODBIIMakerDatabaseDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, m_Maker);
DDX_Control(pDX, IDC_FIND, Search);
DDX_Control(pDX, IDC_CODE, m_Meaning);
DDX_Control(pDX, IDC_Meaning, m_Code);
}
BEGIN_MESSAGE_MAP(CODBIIMakerDatabaseDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_FIND, &CODBIIMakerDatabaseDlg::OnBnClickedFind)
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
BOOL CODBIIMakerDatabaseDlg::OnInitDialog()
{
CDialog::OnInitDialog();
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
Gdiplus::GdiplusStartupInput gdiplusstartupinput;
Gdiplus::GdiplusStartup(&gdiplusToken,&gdiplusstartupinput,NULL);
char Maker[MAX_PATH];
m_Maker.InsertColumn(0,"");
m_Maker.SetColumnWidth(0,180);
database.open("Manufacturers//Manufacturer.txt",fstream::in);
while (database.getline(Maker,sizeof(Maker)) != 0)
{
m_Maker.InsertItem(0,Maker);
}
database.clear();
database.close();
return TRUE;
}
void CODBIIMakerDatabaseDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CODBIIMakerDatabaseDlg::OnPaint()
{
CPaintDC dc(this);
if (IsIconic())
{
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<wparam>(dc.GetSafeHdc()), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CODBIIMakerDatabaseDlg::OnQueryDragIcon()
{
return static_cast<hcursor>(m_hIcon);
}
void CODBIIMakerDatabaseDlg::OnBnClickedFind()
{
CString Search;
CString Folder;
char Temp[MAX_PATH];
char Code[MAX_PATH];
char Meaning[MAX_PATH];
m_Meaning.SetWindowTextA("");
Search = "[";
m_Code.GetWindowTextA(Temp,sizeof(Temp));
Search += Temp;
Search += "]";
if(m_Maker.GetSelectedCount() > 0)
{
mark = m_Maker.GetSelectionMark();
ItemText = m_Maker.GetItemText(mark,NULL);
Folder = "Manufacturers\\";
Folder += ItemText;
Folder += ".txt";
database.open(Folder,fstream::in);
while (database.getline(Code,sizeof(Code)) != 0)
{
if(strcmp(Code,Search) == 0)
{
database.getline(Meaning,MAX_PATH);
m_Meaning.SetWindowTextA(Meaning);
}
}
}
database.close();
database.clear();
}
BOOL CODBIIMakerDatabaseDlg::OnEraseBkgnd(CDC* pDC)
{
Gdiplus::Image * BG;
Gdiplus::Graphics grpx(*pDC);
Gdiplus::Rect rect(0,0,473,261);
BG = Gdiplus::Image::FromFile(L"Image\\BackGround.png",FALSE);
grpx.DrawImage(BG,rect);
return true;
}
</hcursor></wparam></gdiplusenums.h></gdiplus.h></fstream>
and this is the code for my Button:
#include "stdafx.h"
#include "ODBII Maker Database.h"
#include "ODBII Maker DatabaseDlg.h"
#include "SearchButton.h"
#include <gdiplus.h>
#pragma comment (lib,"gdiplus.lib")
IMPLEMENT_DYNAMIC(SearchButton, CButton)
SearchButton::SearchButton()
{
Gdiplus::GdiplusStartupInput gdiplusstartupinput;
Gdiplus::GdiplusStartup(&gdiplusToken,&gdiplusstartupinput,NULL);
ButtonUp = Gdiplus::Image::FromFile(L"Image\\Button1.png",FALSE);
ButtonDown = Gdiplus::Image::FromFile(L"Image\\Button2.png",FALSE);
}
SearchButton::~SearchButton()
{
Gdiplus::GdiplusShutdown(gdiplusToken);
}
BEGIN_MESSAGE_MAP(SearchButton, CButton)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()
void SearchButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
CRect rt;
rt = lpDrawItemStruct->rcItem;
Gdiplus::Graphics grpx(dc);
UINT State = lpDrawItemStruct->itemState;
Gdiplus::Rect rect(0,0,90,90);
if((State & ODS_SELECTED))
{
grpx.DrawImage(ButtonUp,rect);
}
else
{
grpx.DrawImage(ButtonDown,rect);
}
dc.Detach();
}
void SearchButton::OnLButtonDown(UINT nFlags, CPoint point)
{
Invalidate(1);
CButton::OnLButtonDown(nFlags, point);
}
void SearchButton::OnLButtonUp(UINT nFlags, CPoint point)
{
Invalidate(1);
CButton::OnLButtonUp(nFlags, point);
}
BOOL SearchButton::OnEraseBkgnd(CDC* pDC)
{
Gdiplus::Graphics grpx(*pDC);
Gdiplus::Color trans(255,255,255,255);
grpx.Clear(trans);
return CButton::OnEraseBkgnd(pDC);
}
HBRUSH SearchButton::CtlColor(CDC* pDC, UINT )
{
return (HBRUSH)::GetStockObject(NULL_BRUSH);
}
</gdiplus.h>
Thanks so much in advance ^_^.
God Bless.
|
|
|
|
|
AntiBNI wrote: BOOL SearchButton::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
Gdiplus::Graphics grpx(*pDC);
Gdiplus::Color trans(255,255,255,255);
grpx.Clear(trans);
return CButton::OnEraseBkgnd(pDC);
}
Strikes me that clearing with 'transparent' won't erase the existing image(s)? You need to paint with something opaque to actually do any erasing?
|
|
|
|
|
Yep,If i erase with a transparent brush, the images will stay overlapped but if i clear with a color brush, it will work.
|
|
|
|
|
In the Ribbon Control What CMFCRibbon(Combo Box here) do i Put? ComboBox does not work or combobox. I know A button is CMFCRibbonButton and a CheckBox is CMFCRibbonCheckBox. Please Help
|
|
|
|
|
What's wrong with CMFCRibbonComboBox[^]? seems to me that its stated intent (The CMFCRibbonComboBox class implements a combo box control that you can add to a ribbon bar, a ribbon panel, or a ribbon popup menu) is just what you want?
|
|
|
|
|
Hello,
I have managed to pull a program from one of the articles
that displays an image(jpg)
I have added the following code to get each pixel on the screen
COLORREF color = pDC->GetPixel(x,y);
colorNo = (int)GetRValue(color); //Then write values to file for rgb
I then create another program to gather what has been writen
to file and then display it.
Unfortunatly what is displayed is a 'carpet like image'
I understand that the return value for GetRValue is a byte
so I have casted this.
Can any body know why I am having problems.
Is there any good programs for this?
I am doing this for game purposes, eventualy I would like to get into 3d graphics
what programs do the pro's do to save theirs
Please can anybody enlighten me.
cheers Simon
modified on Saturday, February 7, 2009 11:57 AM
|
|
|
|
|
I want to capture Text Under Mouse pointer. I have used
IAccessible::get_accName and
IAccessible::get_accValue to find out Text Under Mouse using
AccessibleObjectFromPoint .
But I want just a word that is under mouse pointer. I am looking for any help.
Thank you
Regards,
Swapnil Shah
|
|
|
|
|
|
I have already used IAccessible. This technique gives you a whole sentence. I am looking for word capture. I want to grab a word under mouse from any application. plz give me some suggestions.
Regards,
Swapnil Shah
|
|
|
|
|
Hi Swapnil,
I am not able to instantly think of a technique to get this done. Probably you can use an OCR and get the word under the mouse cursor, and then search for it in the sentence that IAccessible returned. If it's present in the sentence, you could be double sure.
Ya, I know it's dumb. But why not check if it goes through well?
I'll think on this line and write you another reply if I get a better idea.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hi
Thanks for reply.
I think i should try OCR. I have never used it but i have read that its highly unreliable. plz reply me if u get any better idea.
Regards,
Swapnil Shah
|
|
|
|
|