|
fprintf (gen, "Test:%c",i);
That should work.
fwrite ("Test:", 5, 1, gen);
char c = (char) i;
fwrite (&c, 1, 1, gen);
That will also work.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
|
I was making a game of cards and i wanted to show the player how much time he has before the game ends; just like a negative progress bar, or a burning candle, or an hour glass the hour glass seems kinda cool. so that i started working on it the hour glass should be updated in each ontimer event and the sand in the hourglass should be deposited on the lower glass; i have a picture of an hour glass and i must make the part where the glass is transparent and should draw the sand gradient in behind BUt i don't know how to make a bitmap or part of a bitmap trasparent how can i do that; by the way if u know of making a burning candle llok real i would like to know thanks
|
|
|
|
|
Not too sure if I know what Im talking about but I did something similar in VB once. Apparently in a bitmap every pixel has a red, green, blue and alpha value. The alpha value(0 - 255) is for transparency. You could change the alpha values of each pixel and have different levels of transparency. This transparency value only works under certain scenarios though - maybe google could help out on this one.
|
|
|
|
|
InflatableGarfield wrote:
Not too sure if I know what Im talking about
Sorry, you don't
32 bit images have an extra bit that can be used for alpha, but Windows does not use it at all.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
If you use GDI+, you can make the bits of the image you want transparent a color that you don't use, and specify that color as your transparency mask. Be careful - if you use lossy compression to store your bitmaps, this will fail as colors will change. For example, jpg is right out.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Maybe, this example helps you. The example shows how to create an hour glass progress bar.
class CChildView : public CWnd
{
private:
int m_nPos;
CBitmap m_bmpBk;
CBitmap m_bmpFgMono; the foreground (sand) bitmap
SIZE m_sizeBk;
SIZE m_sizeFg;
CPoint m_ptFgOffset;
CBitmap m_bmpFgMaskMono;
CBitmap m_bmpBkTmp;
CBitmap m_bmpFgTmp;
}
CChildView::CChildView()
{
m_nPos = 0;
m_bmpBk.LoadBitmap(IDB_HGBACKGROUND);
m_bmpFgMono.LoadBitmap(IDB_HGSAND);
BITMAP bm;
m_bmpBk.GetBitmap(&bm);
m_sizeBk.cx = bm.bmWidth;
m_sizeBk.cy = bm.bmHeight;
m_bmpFgMono.GetBitmap(&bm);
m_sizeFg.cx = bm.bmWidth;
m_sizeFg.cy = bm.bmHeight;
HDC hDC = ::GetDC(NULL);
m_bmpBkTmp.CreateCompatibleBitmap(CDC::FromHandle(hDC),m_sizeBk.cx,m_sizeBk.cy);
m_bmpFgTmp.CreateCompatibleBitmap(CDC::FromHandle(hDC),m_sizeFg.cx,m_sizeFg.cy);
::ReleaseDC(NULL,hDC);
m_bmpFgMaskMono.CreateBitmap(m_sizeFg.cx,m_sizeFg.cy,1,1,NULL);
m_ptFgOffset = CPoint(3,3);
}
void CChildView::OnPaint()
{
CPaintDC dc(this);
CDC dcMemBkTmp;
dcMemBkTmp.CreateCompatibleDC(&dc);
CBitmap* pBmpOldBkTmp = dcMemBkTmp.SelectObject(&m_bmpBkTmp);
CDC dcMemBk;
dcMemBk.CreateCompatibleDC(&dc);
CBitmap* pBmpOldBk = dcMemBk.SelectObject(&m_bmpBk);
dcMemBkTmp.BitBlt(0,0,m_sizeBk.cx,m_sizeBk.cy,&dcMemBk,0,0,SRCCOPY);
CDC dcMemFgTmp;
dcMemFgTmp.CreateCompatibleDC(&dc);
CBitmap* pBmpOldFgTmp = dcMemFgTmp.SelectObject(&m_bmpFgTmp);
CDC dcMemFgMono;
dcMemFgMono.CreateCompatibleDC(&dc);
CBitmap* pBmpOldFgMono = dcMemFgMono.SelectObject(&m_bmpFgMono);
CDC dcMemFgMaskMono;
dcMemFgMaskMono.CreateCompatibleDC(&dc);
CBitmap* pBmpOldFgMaskMono = dcMemFgMaskMono.SelectObject(&m_bmpFgMaskMono);
dcMemFgMaskMono.FillSolidRect(CRect(0,0,m_sizeFg.cx,m_sizeFg.cy),RGB(0,0,0));
dcMemFgMaskMono.FillSolidRect(CRect(0,(m_nPos*m_sizeFg.cy)/200,m_sizeFg.cx,m_sizeFg.cy/2),RGB(255,255,255));
dcMemFgMaskMono.FillSolidRect(CRect(0,m_sizeFg.cy-(m_nPos*m_sizeFg.cy)/200,m_sizeFg.cx,m_sizeFg.cy),RGB(255,255,255));
dcMemFgMaskMono.BitBlt(0,0,m_sizeFg.cx,m_sizeFg.cy,&dcMemFgMono,0,0,SRCAND);
COLORREF oldBkColor = dcMemFgTmp.SetBkColor(RGB(255,255,0));
COLORREF oldTxtColor = dcMemFgTmp.SetTextColor(RGB(255,0,255));
dcMemFgTmp.BitBlt(0,0,m_sizeFg.cx,m_sizeFg.cy,&dcMemFgMaskMono,0,0,SRCCOPY);
dcMemFgTmp.SetTextColor(oldTxtColor);
dcMemFgTmp.SetBkColor(oldBkColor);
HINSTANCE hDll = AfxLoadLibrary(_T("msimg32.dll"));
UINT (PASCAL* pfnTransparentBlt)(HDC,int,int,int,int,HDC,int,int,int,int,UINT);
if(hDll)
{
(FARPROC&)pfnTransparentBlt=GetProcAddress(hDll,"TransparentBlt");
if(pfnTransparentBlt)
pfnTransparentBlt(dcMemBkTmp.m_hDC,m_ptFgOffset.x,m_ptFgOffset.y,m_sizeFg.cx,m_sizeFg.cy,dcMemFgTmp.m_hDC,0,0,m_sizeFg.cx,m_sizeFg.cy,RGB(255,0,255));
AfxFreeLibrary(hDll);
}
dc.StretchBlt(0,0,m_sizeBk.cx*10,m_sizeBk.cy*10,&dcMemBkTmp,0,0,m_sizeBk.cx,m_sizeBk.cy,SRCCOPY);
dcMemFgMaskMono.SelectObject(pBmpOldFgMaskMono);
dcMemFgMono.SelectObject(pBmpOldFgMono);
dcMemBk.SelectObject(pBmpOldBk);
dcMemBkTmp.SelectObject(pBmpOldBkTmp);
dcMemFgTmp.SelectObject(pBmpOldFgTmp);
}
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
SetTimer(1,40,NULL);
return 0;
}
void CChildView::OnTimer(UINT nIDEvent)
{
m_nPos++;
m_nPos = m_nPos%100;
Invalidate(FALSE);;
CWnd ::OnTimer(nIDEvent);
}
BOOL CChildView::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
|
|
|
|
|
I have created an ActiveX button control on C++ 6 that uses the UxTheme.dll. All works fine except for when I hover the mouse over the button it doesn't repaint in the hover theme. My code for ::OnOcmDrawItem( ... ) is as below:
LRESULT CCmdButtonCtrl::OnOcmDrawItem(WPARAM wParam, LPARAM lParam)<br />
{<br />
UINT nIDCtl = (UINT) wParam;<br />
LPDRAWITEMSTRUCT lpDrawItemStruct = (LPDRAWITEMSTRUCT) lParam;<br />
HDC dc = lpDrawItemStruct->hDC;<br />
CDC* pDC = CDC::FromHandle(dc);<br />
<br />
BOOL bIsSelected = (lpDrawItemStruct->itemState & ODS_SELECTED);<br />
BOOL bIsFocussed = (lpDrawItemStruct->itemState & ODS_FOCUS);<br />
BOOL bIsDisabled = (lpDrawItemStruct->itemState & ODS_DISABLED);<br />
<br />
CRect rect;<br />
rect.CopyRect(&lpDrawItemStruct->rcItem);<br />
<br />
#ifdef _VISUALSTYLE_XP_H_<br />
if( g_xpStyle.IsAppThemed() )<br />
{<br />
HTHEME hTheme = g_xpStyle.OpenThemeData(GetSafeHwnd(), L"BUTTON");<br />
int state = 1;<br />
<br />
if(bIsSelected)<br />
state = 2;<br />
if(m_bLMouseButtonDown)<br />
state = 3;<br />
<br />
CRect rcContent = rect;<br />
InflateRect(&rcContent, -3, -3);<br />
<br />
HRESULT hr = g_xpStyle.DrawThemeBackground(hTheme, dc, 1, state , &rect, NULL);<br />
hr = g_xpStyle.GetThemeBackgroundContentRect(hTheme, dc, 1, state, &rect, &rcContent);<br />
<br />
if(!m_szCaption.IsEmpty())<br />
{<br />
LPWSTR lpszCaption = new WCHAR[m_szCaption.GetLength()];<br />
LPSTR lpStr = m_szCaption.GetBuffer(m_szCaption.GetLength());<br />
int nLen = MultiByteToWideChar(CP_ACP, 0, lpStr, -1, NULL, NULL);<br />
MultiByteToWideChar(CP_ACP, 0, lpStr, -1, lpszCaption, nLen);<br />
<br />
CFont* pOldFont = SelectStockFont(pDC);<br />
hr = g_xpStyle.DrawThemeText(hTheme, dc, 1, state, lpszCaption, wcslen(lpszCaption), <br />
DT_CENTER | DT_VCENTER | DT_SINGLELINE,<br />
0, &rect);<br />
pDC->SelectObject(pOldFont);<br />
hr = g_xpStyle.CloseThemeData(hTheme);<br />
}<br />
}<br />
else<br />
{<br />
#endif<br />
...
#ifdef _VISUALSTYLE_XP_H_<br />
}<br />
#endif<br />
<br />
return 0;<br />
}
Could someone PLEASE PLEASE tell me what I need to do to get the hover working, do I need to supress the default ::OnDraw( ... ) method if hover is on?
|
|
|
|
|
In XP theme your button (PUSHBUTTON) can be drawn in 5 states: NORMAL(1), HOT(2), PRESSED(3), DISABLED(4) and DEFAULTED(5).
You set HOT state of the button in this line bIsSelected=lpDrawItemStruct->itemState & ODS_SELECTED . The ODS_SELECTED flag doesn't mean HOT.
To get the hover working make the following changes:
1. Change the name of your variable from bIsSelected to m_bIsHot .
2. Declare m_bIsHot in your class.
3. Set m_bIsHot=TRUE and call _TrackMouseEvent with dwFlag=TME_LEAVE when the mouse cursor is over the button (WM_MOUSEMOVE ).
4. Set m_bIsHot=FALSE when the mouse leaves the client area of the button (WM_MOUSELEAVE ).
5. Modify CCmdButtonCtrl::OnOcmDrawItem :
if(m_bIsHot)
state = 2;
Also, your control should support DISABLED and DEFAULTED states.
Here's a link you can find more information on this subject:
http://www.codeproject.com/buttonctrl/CustomBitmapButtonDemo.asp
|
|
|
|
|
Thanks for the help, I will try it out tomorrow when I get back to the office, and will let you know how I get on.
|
|
|
|
|
Thanks for your help, it worked. Well you knew it would anyway. I will read your article on the subject.
|
|
|
|
|
hello,
I just want to know how to generate a random number on 4 bytes, I saw that rand returns an int but it's too short for my purposal, any suggestion? In my project I DON'T use MFC, I searched on codeproject but all I found was MFC sample, thanks
Paolo
|
|
|
|
|
Paolo Ponzano wrote:
generate a random number on 4 bytes
Do you mean that the range of random random numbers should span values that fit in 4 bytes? If so, you could just use rand() after seeding it with a random (or as random as you can get) int .
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
i jus tried my 1st c++ to read from a text file to input into an edit box.
Line by line.
How can i do it?
|
|
|
|
|
Hi,
IF U want To show Entire Content Of Text File To EditBox
Use "RichText Box".
Then use "LoadFile()" Method Display Content.
by
baijumax
|
|
|
|
|
Hi,
here code from MSDN Try this
void LoadMyFile()
{
// Create an OpenFileDialog to request a file to open.
OpenFileDialog* openFile1 = new OpenFileDialog();
// Initialize the OpenFileDialog to look for RTF files.
openFile1->DefaultExt = S"*.rtf";
openFile1->Filter = S"RTF Files|*.rtf";
// Determine whether the user selected a file from the OpenFileDialog.
if(openFile1->ShowDialog() == System::Windows::Forms::DialogResult::OK &&
openFile1->FileName->Length > 0)
{
// Load the contents of the file into the RichTextBox.
richTextBox1->LoadFile(openFile1->FileName, RichTextBoxStreamType::PlainText);
}
}
by
baijumax
|
|
|
|
|
I am trying to create sound effects triggered from switches via parallel port. I want to use MIDI since it doesnt use too much processor resources. But I dunno how to generate sounds (e.g. drum / piano sounds) using MIDI. Does anybody know this?
Programming or Die?
----C++ 4 ever-----
|
|
|
|
|
|
I have problem with that. I use BitBlt at OnDraw(), the print preview was OK, but it prints nothing
<italic>Work hard and a bit of luck is the key to success.
|
|
|
|
|
|
Here is my codes to make a dll:
// =======================================================
// common.h -- header for dll and app.
// =======================================================
#ifndef COMMON_H
#define COMMON_H
#include "iostream"
using namespace std;
#ifdef DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
// export or import a class definition
class DLL_EXPORT test
{
public:
test() : m(5){}
void print() { cout<< "m = " << m <<endl; }
public:
="" int="" m;
};
="" export="" or="" import="" a="" function="" ..
dll_export="" void="" test_interface(test*="" ptest);
#endif
="" =="===================================================
//" main.cpp="" --="" imp="" for="" dll="" ;="" with="" d="" "dll"="" out:"test.dll"
="" "common.h"
void="" ptest)
{
="" ptest-="">print();
}
And the testing app here:
// =====================================================
// app.cpp -- testing "test.dll"
// =====================================================
#include "windows.h"
#include "common.h"
typedef void (* INIT_PROC)(test* pTest);
int main(void)
{
test t;
HMODULE hModule = ::LoadLibrary("test.dll");
if(hModule)
{
INIT_PROC proc = (INIT_PROC)::GetProcAddress(hModule,
"test_interface");
if(proc)
{
(*proc)(&t);
}
::FreeLibrary(hModule);
}
return 0;
}
There is an error when building app.cpp:
app.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public:
__thiscall test::test(void)" (__imp_??0test@@QAE@XZ)
Debug/test_app.exe : fatal error LNK1120: 1 unresolved externals
I cound't fix it. Plz help. Thanks very much.
|
|
|
|
|
First off, you're using dynamic loading (run-time loading), so the DLLEXPORT and DLLIMPORT statements are unnecessary at the class definition. You should remove these, because you are not exporting/importing this class's objects.
Also, instead of using __declspec , create a module definition file (.DEF) and write the exported function in there. This allows you to control the exact name by which the function is exported. See MSDN for details on how to use a definition file. If you use a definition file, remove the __declspec entries. The definition file is only required at the DLL project. The EXE project does not require it, because the GetProcAddress will search the DLL export table for the specified exported function.
Otherwise the code looks intact and working.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I would like to create a gateway software solution (with Visual C++ 6.0):
Some machines are connected over ethernet to a server (control PC).
On the control PC (Windows NT) OPC is imitated in one direction (out),
from the other direction I will get some Information from another OPC (in,
OPC machines).
How can I realize that problem??
Exist there any software for gateway solutions ?
Perhaps can i download any software ?
|
|
|
|
|
hi
i want to implement drag and drop. what i want is when some one drops a file on my exe icon it will process that file.
swarup
|
|
|
|
|
You can make an application which is a container. The process of opening the file is done by serialize
<italic>Work hard and a bit of luck is the key to success.
|
|
|
|
|