|
thank you gentlemen
i was missing out on the part "extern SCard SCManager" replaced with "extern SCard *SCManager"
such a fool i have been
yes sir thank you for your advice,
i really must go back to my c++ basics.
It appears that i have missed out on very basic and important lessons which i sould have taken before starting to develop a full fledged application
i will surely do that from now on.
but yes thanks to you, now my code runs with no error.
i will not forget to get back with any other problems i face in the future.
|
|
|
|
|
Hi there!!
I want to embed WMP plugin into a dialogue based MFC application..but i m not etting from where to start anyone can help me in guiding so?
|
|
|
|
|
You need to embed it as an ActiveX control - this[^] seems a good introduction.
|
|
|
|
|
but how to embedd it as an active x ctrl? and infact which file of WMP i need to add to my application?
|
|
|
|
|
alizey khan wrote: how to embedd it as an active x ctrl
Did you read the page I pointed you at? It really isn't difficult - try reading the doucmentation.
alizey khan wrote: infact which file of WMP i need to add to my application
What do you mean? The WMP active X control will be a DLL or OCX file that will have to be installed on the system for your application to work. Either you include it in your installer, or you make an assumption that it's already installed.
|
|
|
|
|
let me rephrase my question:
How can i create an activeX control for WMP 11 using WMP SDK?
can u refer me some link for the steps and WMP11 SDk ASAP...
It will be of great help!
|
|
|
|
|
|
Hi,
I am running a C app and ran into a Buffer Overrun problem
After debugging the program I Found the offending API to be a
strcpy statement
After researching the problem I deduced the that I needed to use the
corresponding string safe api for strcpy ...StringCchCopy
However when I included strsafe.h I got loads of compile errors
I have warnings a W0 -- Turn of all warnings could this be the
problem ????
Thankx
|
|
|
|
|
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.
|
|
|
|
|