|
How about the use of multidimensional arrays.
<br />
int multi_array[11][10] = {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},<br />
{10, 11, 12, 13, 14, 15, 16, 17, 18, 19},<br />
{20, 21, 22, 23, 24, 25, 26, 27, 28, 29},<br />
{30, 31, 32, 33, 34, 35, 36, 37, 38, 39},<br />
{40, 41, 42, 43, 44, 45, 46, 47, 48, 49},<br />
{50, 51, 52, 53, 54, 55, 56, 57, 58, 59},<br />
{60, 61, 62, 63, 64, 65, 66, 67, 68, 69},<br />
{70, 71, 72, 73, 74, 75, 76, 77, 78, 79},<br />
{80, 81, 82, 83, 84, 85, 86, 87, 88, 89},<br />
{90, 91, 92, 93, 94, 95, 96, 97, 98, 99},<br />
{100}};<br />
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Hi all,
I've a stringstream and I want to remove first two bytes from it and make a new one with the rest of content. From 3rd byte to end. How can I do that.
I've try to remove first two characters but not work.
Please help me.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
I am not sure I can really catch your idea. please refer the below code:
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char** argv)
{
string whole_str;
string res_str;
whole_str = "Hello, this World";
res_str = whole_str.substr(2, string::npos);
return 0;
}
Chris Liu
|
|
|
|
|
Ok so i have tried, and failed epically, to use objects. Even simple ones.
Now its seems that I need more than ever to understand how to use them.
my coding project is random, dont ask what it is for because i dont actually know my self.
What it does it generates a random number from 0-25 that is then used to assign a letter from my array alpha to a variable. 3 letter variables, and 2 number variables in the so called 'Mas' statement (A1B2C) and then the there are 5 number vars in the so called 'Address' statement.
I plan to have a total of 4 'Mas' statements, and thus 4 'Address' statements for the whole application
You can see why i need to learn how to use objects.
Here is the code:
<br />
#include <cstdlib><br />
#include <iostream><br />
#include <cmath><br />
<br />
using namespace std;<br />
<br />
char masc1;
char masc2;<br />
char masc3;<br />
<br />
int masn1;
int masn2;<br />
<br />
int idx1;
int idx2;<br />
<br />
int idrt1;
int idrt2;<br />
int idrt3;<br />
<br />
char alpha[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
int pre;
const int alphn = 26;
const int num = 10;
bool err = false;
<br />
void masgen()<br />
{<br />
srand( rand()*(unsigned)time( NULL ) );<br />
pre = (rand() % alphn + 2) % -alphn ;
masc1 = alpha[pre];<br />
idrt1 = pre;<br />
pre = (rand() % alphn + 2) % -alphn;
masc2 = alpha[pre];<br />
idrt2 = pre;<br />
pre = (rand() % alphn + 2) % -alphn;
masc3 = alpha[pre];<br />
idrt3 = pre;<br />
pre = (rand() % num + 2) % -num;
masn1 = pre;<br />
idx1 = pre;<br />
pre = (rand() % num + 2) % -num;
masn2 = pre;<br />
idx2 = pre;<br />
}<br />
<br />
void cker()<br />
{<br />
if( pre > alphn )
{<br />
cout << "Error. Pre > Alphn \n"; <br />
err = true;
system("PAUSE");<br />
} <br />
}<br />
<br />
int main(int argc, char *argv[])<br />
{<br />
while( err != true )
{<br />
masgen();
cker();
cout << "Mas: " << masc1 << masn1 << masc2 << masn2 << masc3 << '\n';
cout << "Address: " << "E" << idx1 << idx2 << "X" << idrt1 << idrt2 << idrt3 << '\n';
system("PAUSE");<br />
}<br />
system("PAUSE");<br />
return EXIT_SUCCESS;<br />
}<br />
|
|
|
|
|
But what is your question ?
|
|
|
|
|
How would i go about making the vars into an object?
|
|
|
|
|
|
Is it at all possible to link a resource as defined by a Resource Template (e.g. a Dialog, Menu, etc)item on it's own into a project, either as an independent resource script fragment, or, at linker level, as a PE linkable object file.
Regards,
Bram van Kampen
|
|
|
|
|
You can add any number of .rc files into a project. Put the code that you want to reuse into a .rc file and add it to the project.
|
|
|
|
|
Thanks, that's helpfull,
I have to declare the resource identifiers somewhere though, in such a manner that the classwizard does not clobber them.
It does not solve the above problem, but currently I tried to add the CPP Code in as an obj file, and let the linker sort the rest.That works quite well for the CPP Files. But what does the resource compiler do with the .rc file, so that the linker can pick it up. (and, in case someone remarks the obvious, I DO include header files for the obj files).
Bram van Kampen
|
|
|
|
|
You can create resource only dll's:
http://msdn.microsoft.com/en-us/library/24b2tcy0(VS.80).aspx[^]
...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
|
|
|
|
|
as the subject.
Why do the HBITMAP be changed to black?I dont think my code have problems.
my code is as below:
app start,laod the HBITMAP from resource and store to a global HBITMAP.
then paint it on sever windows in the same process.
I found sometimes the HBITMAP was changed to black.
Could anybody meet the same issue?
|
|
|
|
|
Did you use of WM_ERASEBKGND and can you show your code?
|
|
|
|
|
BEGIN_MSG_MAP(CMyButton)
MESSAGE_HANDLER(WM_CREATE,OnCreate)
MESSAGE_HANDLER(WM_PAINT,OnPaint)
MESSAGE_HANDLER(WM_LBUTTONDOWN,OnLButtonDown)
MESSAGE_HANDLER(WM_LBUTTONUP,OnLButtonUp)
MESSAGE_HANDLER(WM_MOUSEMOVE ,OnMouseMove)
MESSAGE_HANDLER(WM_MOUSELEAVE ,OnMouseLeave)
MESSAGE_HANDLER(WM_KILLFOCUS, OnRefresh)
MESSAGE_HANDLER(WM_SETFOCUS, OnRefresh)
MESSAGE_HANDLER(BM_SETCHECK, OnStateChange)
MESSAGE_HANDLER(BM_SETSTATE, OnStateChange)
MESSAGE_HANDLER(WM_ENABLE, OnRefresh)
MESSAGE_HANDLER(WM_UPDATEUISTATE,OnRefresh)
END_MSG_MAP()
I did not use the WM_ERASEBKGND,and the system will do the default?
Need I to disable this msg?such as :
in handle WM_ERASEBKGND msg,return TRUE.
Great & Free windows software for you
http://www.aisnote.com
|
|
|
|
|
Bitmaps don't just change to black by themselves.
You haven't provided anything for us to be able to help you.
How and where are you drawing the bitmap?
What is the format of the bitmap?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks your reply.Let me explain how I used the bitmap in my code.
I used WTL.
I just on WM_PAINT to draw the groupbox background use the bitmap.And I need to make the bitmap transparent.
In common ,the isssue do not duplicated.But sometimes it can be duplicated.
I posted the issue in detail here:
http://aisnote.spaces.live.com/blog/cns!5F43300FF5FC67C!161.entry[^]
Great & Free windows software for you
http://www.aisnote.com
|
|
|
|
|
Still no code showing how you render the bitmap...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
HBITMAP WINAPI ExtractSubBitmap(HBITMAP hSrcBitmap,CPoint ptStart,CPoint ptEnd)
{
HBITMAP hBitmap = NULL;
CDC srcMemDC,desMemDC;
HDC hDC = ::GetDC(0);
srcMemDC.CreateCompatibleDC(hDC);
desMemDC.CreateCompatibleDC(hDC);
srcMemDC.SelectBitmap(hSrcBitmap);
hBitmap = CreateCompatibleBitmap(hDC,ptEnd.x-ptStart.x,ptEnd.y-ptStart.y);
desMemDC.SelectBitmap(hBitmap);
desMemDC.BitBlt(0,0,ptEnd.x-ptStart.x,ptEnd.y-ptStart.y,srcMemDC,ptStart.x,ptStart.y,SRCCOPY);
ReleaseDC(0,hDC);
return hBitmap;
}
And I used the reurn hBitmap to draw.But sometimes I found the passed "HBITMAP hSrcBitmap" have been changed to black.why?
Great & Free windows software for you
http://www.aisnote.com
|
|
|
|
|
I've never used WTL, but generally you need to select bitmaps back out of a DC
(by restoring its previous bitmap) before using the bitmap.
Is hSrcBitmap a device dependent bitmap or a DIBSection?
Is hSrcBitmap always the same format (bits-per-pixel), and is the format compatible
with the screen?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hSrcBitmap is just use LoadBitmap from resource and stored in
a global member so that it can be shared by some windows.
Great & Free windows software for you
http://www.aisnote.com
|
|
|
|
|
e_ilite wrote: hSrcBitmap is just use LoadBitmap from resource
If hSrcBitmap is not a DIBSection:
hSrcBitmap has to be the same format as the screen or the SelectBitmap will fail.
What format is hSrcBitmap? 8bpp? 24bpp?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The origin bitmap of hSrcBitmap is 24bpp.
Great & Free windows software for you
http://www.aisnote.com
|
|
|
|
|
Can you reproduce the problem consistently and debug it, like error checking
all the GDI cal return values?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Hi all,
I am getting an error C2022: '65279' : too big for character at the line in bold below, What should I change here? This code works if I use wsprintfW and wszBuffer is WCHAR however I need this for multibyte and must use "_T" not "L"
Any advise?
Thanks,
Jayjay
if( pRegInfo->uTaskRegID == 0 )
{
GUID AppGUID, TaskGUID;
::CoCreateGuid(&AppGUID);
::CoCreateGuid(&TaskGUID);
WCHAR wszGUID[50], wszTaskGUID[50];
::StringFromGUID2(AppGUID, wszGUID, 50);
::StringFromGUID2(TaskGUID, wszTaskGUID, 50);
TCHAR wszBuffer[1025] = { 0 };
::wsprintf(wszBuffer,
_T("\xfeff<?xml version=\"1.0\" encoding=\"UTF-16\" ?>\n")
_T("<applications xmlns=\"http://schemas.microsoft.com/windows/cpltasks/v1\" xmlns:sh=\"http://schemas.microsoft.com/windows/tasks/v1\">")
_T("<application id=\"%s\">")
_T("<sh:task id=\"%s\" needsElevation=\"%s\">")
#ifdef _UNICODE
L"<sh:name>@%s,-%ld</sh:name>"
L"<sh:keywords>@%s,-%ld</sh:keywords>"
L"<sh:command>%%systemroot%%\\system32\\control.exe /name %s</sh:command>"
#else
_T("<sh:name>@%hs,-%ld</sh:name>")
_T("<sh:keywords>@%hs,-%ld</sh:keywords>")
_T("<sh:command>%%systemroot%%\\system32\\control.exe /name %hs</sh:command>")
#endif // _UNICODE
_T("</sh:task>")
_T("<category id=\"%ld\">")
_T("<sh:task idref=\"%s\"/>")
_T("</category>")
_T("</application>")
_T("</applications>"),
wszGUID,
wszTaskGUID,
pRegInfo->dwRunLevel == 0 ? _T("false") : _T("true"),
szDllName, Info.uTaskRes,
szDllName, Info.uKeywordsRes,
Info.pstrCanonicalName,
pRegInfo->dwCategory,
wszTaskGUID);
::wsprintf(szGUID, _T("%ws"), wszGUID);
::lstrcpy(szTaskFileUrl, szDllFile);
::wsprintf(_FindLastOf(szTaskFileUrl, '.'), _T("_cpl%d.xml"), pRegInfo->iIndex + 1);
if( bRegister ) {
HANDLE hFile = ::CreateFile(szTaskFileUrl, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if( hFile == INVALID_HANDLE_VALUE ) return HRESULT_FROM_WIN32(::GetLastError());
DWORD dwWritten = 0;
::WriteFile(hFile, wszBuffer, ::lstrlen(wszBuffer) * sizeof(WCHAR), &dwWritten, NULL);
::CloseHandle(hFile);
}
else {
::DeleteFile(szTaskFileUrl);
|
|
|
|
|