|
I dont know if there would be a better way than this one. Please try this function:
#include <stdlib.h>
#include <iostream.h>
int Convert(char a, char b);
void main(){
cout << "" << Convert('A', 'A') << endl;
}
int Convert(char a, char b){
int intTemp, intVal = 0;
char strBuffer[3];
strBuffer[0] = a;
strBuffer[1] = '\0';
intTemp = atoi(strBuffer);
if (intTemp != 0){
intVal = intTemp << 4;
}
else{
switch (toupper(a)){
case 'A':
intVal = intVal | 0xA0;
break;
case 'B':
intVal = intVal | 0xB0;
break;
case 'C':
intVal = intVal | 0xC0;
break;
case 'D':
intVal = intVal | 0xD0;
break;
case 'E':
intVal = intVal | 0xE0;
break;
case 'F':
intVal = intVal | 0xF0;
break;
default:
return 0;
break;
}
}
strBuffer[0] = b;
strBuffer[1] = '\0';
intTemp = atoi(strBuffer);
if (intTemp != 0){
intVal = intVal | intTemp;
}
else{
switch (toupper(b)){
case 'A':
intVal = intVal | 0x0A;
break;
case 'B':
intVal = intVal | 0x0B;
break;
case 'C':
intVal = intVal | 0x0C;
break;
case 'D':
intVal = intVal | 0x0D;
break;
case 'E':
intVal = intVal | 0x0E;
break;
case 'F':
intVal = intVal | 0x0F;
break;
default:
return 0;
break;
}
}
return intVal;
}
SDE
|
|
|
|
|
Hi
I have 5 seperate Device contexts in which i load 5 bmp's and position them on the screen such that it looks as if it is 1 bmp.
How to combine these 5 dc's into 1.
Thanks and regards,
Salil
|
|
|
|
|
I assume they are memory dc....
Cant you make one more memory dc and bitblt each dc onto this memory dc? this way you convert all 5 memdc's to one dc.
MSN Messenger.
prakashnadar@msn.com
"If history isn't good, just burn it." - Sidhuism.
|
|
|
|
|
Hi,
This is how my OnDraw() looks like and i am having trouble scrolling it
Thanks and regards,
Salil.
CString szFilename("d:\\vc\\mfc\\2001.bmp");
HBITMAP hBmp = (HBITMAP)::LoadImage(NULL,szFilename,
IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp;
bmp.Attach(hBmp);
CClientDC dc(this);
CDC bmDC;
bmDC.CreateCompatibleDC(&dc);
CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
BITMAP bi;
bmp.GetBitmap(&bi);
dc.StretchBlt (0,0,len_in_pix,ht_in_pix,&bmDC,0,0,bi.bmWidth
,bi.bmHeight,SRCCOPY);
bmDC.SelectObject(pOldbmp);
CString szFilename1("d:\\vc\\mfc\\2002.bmp");
HBITMAP hBmp1 = (HBITMAP)::LoadImage(NULL,szFilename1,
IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp1;
bmp1.Attach(hBmp1);
CClientDC dc1(this);
CDC bmDC1;
bmDC1.CreateCompatibleDC(&dc1);
CBitmap *pOldbmp1 = bmDC1.SelectObject(&bmp1);
BITMAP bi1;
bmp1.GetBitmap(&bi1);
dc1.StretchBlt (0,br_in_pix,len_in_pix,ht_in_pix,&bmDC1,0,0,bi.bmWidth
,bi.bmHeight,SRCCOPY);
bmDC1.SelectObject(pOldbmp1);
CString szFilename2("d:\\vc\\mfc\\2003.bmp");
HBITMAP hBmp2 = (HBITMAP)::LoadImage(NULL,szFilename2,
IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp2;
bmp2.Attach(hBmp2);
CClientDC dc2(this);
CDC bmDC2;
bmDC2.CreateCompatibleDC(&dc2);
CBitmap *pOldbmp2 = bmDC2.SelectObject(&bmp2);
BITMAP bi2;
bmp2.GetBitmap(&bi2);
dc2.StretchBlt (0,br_in_pix+ht_in_pix,len_in_pix,br_in_pix,&bmDC2,0,0,bi.bmWidth
,bi.bmHeight,SRCCOPY);
bmDC2.SelectObject(pOldbmp2);
CString szFilename3("d:\\vc\\mfc\\2004.bmp");
HBITMAP hBmp3 = (HBITMAP)::LoadImage(NULL,szFilename3,
IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp3;
bmp3.Attach(hBmp3);
CClientDC dc3(this);
CDC bmDC3;
bmDC3.CreateCompatibleDC(&dc3);
CBitmap *pOldbmp3 = bmDC3.SelectObject(&bmp3);
BITMAP bi3;
bmp3.GetBitmap(&bi3);
dc3.StretchBlt (0,2*br_in_pix+ht_in_pix,len_in_pix,ht_in_pix,&bmDC3
,0,0,bi.bmWidth,bi.bmHeight,SRCCOPY);
bmDC3.SelectObject(pOldbmp3);
CString szFilename4("d:\\vc\\mfc\\2005.bmp");
HBITMAP hBmp4 = (HBITMAP)::LoadImage(NULL,szFilename4,
IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp4;
bmp4.Attach(hBmp4);
CClientDC dc4(this);
CDC bmDC4;
bmDC4.CreateCompatibleDC(&dc4);
CBitmap *pOldbmp4 = bmDC4.SelectObject(&bmp4);
BITMAP bi4;
bmp4.GetBitmap(&bi4);
dc4.StretchBlt (0,2*br_in_pix+2*ht_in_pix,len_in_pix,20,&bmDC4
,0,0,bi.bmWidth,20,SRCCOPY);
bmDC4.SelectObject(pOldbmp4);
|
|
|
|
|
1) Create 2 compatible device contexts: a DC (dcTemp) to temporarly hold current bitmap and a DC (dcOut) to hold the results of bliting.
2) Create a compatible bitmap large enough to hold all 5 bmp's.
3) Select large bitmap into dcOut. (save pOldOutBitmap here)
4) Select bitmap[0] into dcTemp. (save pOldBitmap here - need when finished)
5) Determine what position to blit bigmap to.
6) Blit bitmap[0] (dcTemp) to position in dcOut.
7) Select bitmap[1] into dcTemp.
8) Determine what position to blit bigmap to.
9) Blit bitmap[1] (dcTemp) to position in dcOut.
....
// Now all the bitmaps are in 1 DC.
N) Select pOldBitmap (dcTemp.SelectObject(pOldBitmap);).
N+1) Blit result to client area (pDC->BitBlt(...,&dcOut,...);).
N+2) Select pOldOutBitmap (dcTemp.SelectObject(pOldOutBitmap);).
That is all there is to it.
If you want to increase draw speed then you should create the large bitmap as a member variable and then create a function to copy, using above method, the 5 bitmaps to it. That way you do not need to do all the coping in the OnDraw function, just blit the stored bitmap to the client area.
If you want to you could create an array of bitmap IDs and use a loop to preform the repeated select, calc. position, and dcOut blits. That is how I whould do it, because then to add another bitmap all you need do is add its ID to the array.
Well I hope this helps.
Good Luck!
INTP
|
|
|
|
|
Maybe a newbie question, but I'll ask anyway. Using visual c++ 6.0, I click and drag a bitmap onto the dialog box, set it to a picture I've imported and there it is on the screen at runtime. Now say I want to click a button that would make that "static" bitmap move across the screen to another location by simply accessing the x,y cooridnates and doing some type of UpdateWindow? The code I've seen on here for pages and pages of DC rect this and that just seems a great deal to do for something that should be so simple.
thanx
Dimenser
|
|
|
|
|
There is nothing simple about it! It only looks that way to the user. Doing drag and drop is actualy easier, since Windows has built in support for that; otherwise it would be just as hard.
INTP
|
|
|
|
|
Hi
have a messagebox window which has some text and an "OK" button
I have used EnumWindows to track down the handle to the messagebox window
from there i can get a cwnd* to the window.
I would like to know how to tell the messagebox to close by simulating a button click onthe OK button.
SPY++ tells me control id for the OK button is 2
so i figured a postmessage BN_CLICKED to the messagebox window with the ID set to 2 woudl work..but no luck
the messagebox needs to be closes properly not just hidden or minimized
does anyone have any suggestions/what am i missing?
regards
Bryce
---
Publitor, making Pubmed easy.
http://www.sohocode.com/publitor
|
|
|
|
|
bryce wrote:
does anyone have any suggestions/what am i missing?
Just send it a WM_CLOSE message?
How do you move in a world of fog, That's always changing things?
Makes me wish that i could be a dog, When i see the price that you pay.
|
|
|
|
|
funny u should say that
thats excatly what i wound up doing !
great minds and all that
cheers
bryce
---
Publitor, making Pubmed easy.
http://www.sohocode.com/publitor
|
|
|
|
|
Well, glad you got it.
As for the BN_CLICKED message, you may have needed to include the window handle as well as the ID in order for that to work.
How do you move in a world of fog, That's always changing things?
Makes me wish that i could be a dog, When i see the price that you pay.
|
|
|
|
|
Hi,
I am porting a MFC Dialog-based app from VC6 to VC++.NET. I have got the following error. I have user-defined message handler in the CMyTestApp, instead of CMyTestDlg, in the VC6 project. Does thiis error message tell me that I can not have my message handler in the CMyTestApp and the message handler has to be in the CWnd-derived class, such as CMyTestDlg?
Thansk in advance.
Dion
error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CMyTestApp::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
None of the functions with this name in scope match the target type
|
|
|
|
|
EmptyWorkingSet
EnumDeviceDrivers
EnumProcesses
EnumProcessModules
GetDeviceDriverBaseName
GetDeviceDriverFileName
GetMappedFileName
GetModuleBaseName
GetModuleFileNameEx
GetModuleInformation
GetProcessMemoryInfo
GetWsChanges
InitializeProcessForWsWatch
QueryWorkingSet
is it psapi.h ?
But i can't find it ?
GFLPOWER
|
|
|
|
|
The logical way to find this would be to use the windows find facility and look for the definition of one of these functions, that's assuming that the MSDN docs don't tell you. I presume that they do and that's why you know the name. If you can't find it ( perhaps by using that handy windows file find function again ), then there's a good chance it's in an SDK you need to download.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Hi
I need some help with dialogbars.
I have an app that has a lot of dialogbars. I want to change style of some of the buttons in a dialogbar to have an arrow and a to show a drop down menu when clicked (like the IE back and forward button, or like the MS Word buttons.)
I did some digging around and found code and examples related to CToolBar where the toolbar style is set to TBSTYLE_EX_DRAWDDARROWS and the button style is set to TBSTYLE_DROPDOWN. I could not find appropriate methods to set these styles for a CDialogBar class. Can someone help me to get my buttons to have a dropdown menu just like CToolBar?
Thanks in advance. Any help appreciated.
|
|
|
|
|
There is no method for setting these styles for a CDialogBar class, the styles apply to CToolBarCtrl derived classes only. To recreate the look of the buttons on a CDialogBar you will probably need to custom draw the buttons youself (or try looking at the "Button Controls" section of CP).
Your best hope would prabably be the article "Professional User Interface Suite", buried in there some where is probably code for doing what you want.
Good Luck!
INTP
|
|
|
|
|
Hello,
I was looking for a clean 3DES implementation that uses ECB mode. Does anyone have a recommendation?
I want a PRNG. I typically use Crypto++, but Wei uses a variant of ANSI 9.17 that adds increased security against seed compromise attacks (encrypting the timestamps in CBC mode, instead of in ECB mode as is done in the standard X9.17 generator).
TIA,
Jeff
jeffrey.walton @ ssa.gov
|
|
|
|
|
google it
Don't try it, just do it!
|
|
|
|
|
I am trying to access the Microsoft SDK help files. I've have already registerd the SDK and have created programs that use it. Now either I can not remember how to access the help files in "\help" or I never could. All these .hxt, .hxq, and etc... files mean nothing if I can not access them.
What am I missing here?
Searching the www has not helped at all (yet).
Thanks for any help you can give me.
INTP
|
|
|
|
|
Start -->
All Programs -->
Microsoft Platform SDK <release date> -->
Platform SDK Documentation
|
|
|
|
|
Thanks for the quick reply!
Some times I wonder where I left my brain.
INTP
|
|
|
|
|
John R. Shaw wrote:
Some times I wonder where I left my brain
If you find yours, and mine is hanging around, would you send it home?
It's dinner time.
Software Zen: delete this;
|
|
|
|
|
how to add a number to a string?
can i convert from a string to double and reverse?
e.g
CString (or string) text = "37";
i want to add 4e3 to this value??!!!!!!!
|
|
|
|
|
Lookup the "Data Conversion" functions in the MSDN library (atof).
Basicaly you convert the string to a number add the new value to the old and then use CString::Format() function to replace the string with the new value.
double old = atof(&string);
old += new;
string.Format(_T("%f"),old);
or something simular.
INTP
|
|
|
|
|
Hi, I create this function to convert from double to CString.
var is the number to be converted
ndec Number of digits after decimal point
CString do2CStr(double var,int ndec)<br />
{<br />
int decimal, sign;<br />
char *buffer;<br />
buffer = _fcvt( var, ndec ,&decimal, &sign );<br />
int len=strlen(buffer);<br />
CString number(buffer); <br />
CString valor;<br />
if(sign)
valor="-"+number.Left(decimal)+"."+number.Right(len-decimal);<br />
else<br />
valor=number.Left(decimal)+"."+number.Right(len-decimal);<br />
return valor;<br />
<br />
}
Daniel Cespedes
"There are 10 types of people, those who understand binary and those who do not"
"Santa Cruz de la Sierra Paraiso Terrenal!"
daniel.cespedes@ieee.org
|
|
|
|
|