|
can you do something like this.. Disable Next Button and Display a progress bar showing that some work going on. once your work is complete show your next window!. sleeping with halt your main thread!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/xml>
|
|
|
|
|
Possibly you have to use threads.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Sleeping in GUI thread is not a good idea. Its recommended to avoid polling mechanism. But if situation demands it, then try using LockWindowUpdate() and UnlockWindowUpdate() . It might be helpful. Check the code snippet.
void CRabbitDlg::OnButton1()
{
LockWindowUpdate();
Sleep( 3000 );
UnlockWindowUpdate();
}
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
I want when I click next button ,next window should'nt appear until all the processing against next button is completed.I used Sleep(1000).It is doing but Interface color get black as I press next button.What should I do?
|
|
|
|
|
I'm working with byte arrays on Windows Mobile using native code. For some custom debugging purposes,(to make sure I'm setting everything up right) I want to read all my struct data, and spit their values back out in a text file using a combination of file writing functions and swprintf. Mostly, I seem to be using C functions.
Easy enough, but some of the data comes in the unfriendly form of byte arrays. Maybe it's a severe lack of Google-fu on my part, but most of the examples I find for converting raw bytes to Hex cite .NET and I want to avoid managed code for efficiency's sake. I also want to convert to Unicode since that's the default in WM anyway. I suppose I could convert ansi to Unicode after the fact, but I was wondering I overlooked something more direct.
Here's some code I found for ansi, but if I want to do wchar strings, what then?
Code:
.
.
.
DWORD j =0;
for(i=0; i < dwSizeOfStrBuf ; i++){
char ch = lpb[i];
char ch0 = (ch>>4) & 0x0F;
char ch1 = ch & 0x0F;
if((0<= ch0) && (ch0 <= 9))
pszCharArr[j] = '0' + ch0;
else
pszCharArr[j] = 'A' + (ch0 - 10);
j++;
if((0<= ch1) && (ch1 <= 9))
pszCharArr[j] = '0' + ch1;
else
pszCharArr[j] = 'A' + (ch1 - 10);
j++;
}
pszCharArr[j] = '\0';
Is there a more direct method of converting a byte array of length 'cb' to a Unicode hex string?
(I guess here is where I mention that up until now, I have actually NEVER done work with bit manipulation. No idea how, I've just never needed to, so to say I'm 'rusty' would be an understatement.)
"For I looked into the Future, far as human eye could see;
Saw the Vision of the world and all the wonder that would be." -- Alfred Tennyson
Beware Geeks bearing .gifs.
|
|
|
|
|
There is (the generic text mapping version of) sprintf for that, for instance
BYTE pb[]={0x46, 0x4F, 0x4F};
const int SIZE = sizeof(pb)/sizeof(pb[0]);
TCHAR *psz = new TCHAR[2*SIZE+1];
int i;
for (i=0; i<size;> {
_stprintf(psz+2*i, _T("%02x"), pb[i]);
}
psz[2*i]=_T('\0');
BTW the generic text version of your function is
DWORD j =0;
for (i = 0; i < dwSizeOfStrBuf ; i++)
{
BYTE b = lpb[i];
BYTE b0 = (b>>4) & 0x0F;
BYTE b1 = b & 0x0F;
if((0<= b0) && (b0 <= 9))
pszCharArr[j] = _T('0') + b0;
else
pszCharArr[j] = _T('A') + (b0 - 10);
j++;
if((0<= b1) && (b1 <= 9))
pszCharArr[j] = _T('0') + b1;
else
pszCharArr[j] = _T('A') + (b1 - 10);
j++;
}
pszCharArr[j] = _T('\0');
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Worked perfectly! Thanks for your expertise.
"For I looked into the Future, far as human eye could see;
Saw the Vision of the world and all the wonder that would be." -- Alfred Tennyson
Beware Geeks bearing .gifs.
|
|
|
|
|
I am facing problems trying to write text onto a bitmap in the hopes of getting pixelated text on it.
I have looked at the code shown here: <ahref>http://www.codeproject.com/KB/GDI/gdionbitmaps.aspx[^]
but I can't seem to get it to work right.
Here's my code, I am using the code shown on the above site and triggering it to run on a button click form a dialog:
void CCaptureAndDisplayDlg::OnTest()
{
HBITMAP hbitmap = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1));
BITMAP bitm;
GetObject( hbitmap, sizeof(BITMAP), &bitm );
long width=bitm.bmWidth;
long height=bitm.bmHeight;
BITMAPINFO bmInfo;
memset(&bmInfo.bmiHeader,0,sizeof(BITMAPINFOHEADER));
bmInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bmInfo.bmiHeader.biWidth=width;
bmInfo.bmiHeader.biHeight=height;
bmInfo.bmiHeader.biPlanes=1;
bmInfo.bmiHeader.biBitCount=24;
HDC pDC = ::GetDC(0);
HDC TmpDC=CreateCompatibleDC(pDC);
BYTE *pbase;
HBITMAP TmpBmp=CreateDIBSection(pDC, &bmInfo,DIB_RGB_COLORS,(void**)&pbase,0,0);
HGDIOBJ TmpObj=SelectObject(TmpDC,TmpBmp);
HDC dcBmp=CreateCompatibleDC(TmpDC);
HGDIOBJ TmpObj2 = SelectObject(dcBmp,hbitmap);
BitBlt(TmpDC,0,0,width,height,dcBmp,0,0,SRCCOPY);
SelectObject(TmpDC,TmpObj2);
DeleteDC(dcBmp);
CFont m_Font;
LOGFONT* m_pLF;
m_pLF=(LOGFONT*)calloc(1,sizeof(LOGFONT));
strncpy(m_pLF->lfFaceName,"Times New Roman",31);
m_pLF->lfHeight=64;
m_pLF->lfWeight=400;
m_pLF->lfItalic=0;
m_pLF->lfUnderline=0;
m_Font.CreateFontIndirect(m_pLF);
CDC dc;
dc.Attach(TmpDC);
CFont* pOldFont=NULL;
if (m_Font.m_hObject)
pOldFont = dc.SelectObject(&m_Font);
else
dc.SelectObject(GetStockObject(DEFAULT_GUI_FONT));
dc.SetTextColor(RGB(0,0,0));
RECT pos = {40,40,0,0};
dc.SetBkMode(TRANSPARENT);
dc.DrawText(strTxt,TxtLen,&pos,DT_CALCRECT);
dc.DrawText(strTxt,TxtLen,&pos,0);
m_Placemat.SetBitmap(TmpBmp);
if (pOldFont) dc.SelectObject(pOldFont);
m_Font.DeleteObject();
dc.Detach();
free(m_pLF);
DeleteObject(hbitmap);
hbitmap=TmpBmp;
SelectObject(TmpDC,TmpObj);
DeleteDC(TmpDC);
}
m_Placemat is a Bitmap object embedded on the dialog window. It is how I am displaying the bitmap on screen.
I can get the bitmap out, but there does not seem to be any change from the original, no text, no visible difference. I seem to be getting the code wrong somehow. Can anyone enlighten me?
I have already posted on the comments section of the page witht he code, but I was hoping for some opinions from someone fast.
I'm running this using VC 6.0, no GDI+ library. If this truely cannot be done on pre-.Net, please tell me
My final objective is to get a text string into pixels or a bit array. If you have a better solution to achieve this, please let me know too.
Thanks.
|
|
|
|
|
It's no biggie, really.
I think you'll find the problem to lie in the fatc that you deselect your loaded bitmap from the DC before you draw the text on it.
Here's some plain win32 code that hacks togeter a result.
void DrawOnBitmap(HBITMAP hBmp)
{
HFONT oldFnt, font1;
HDC memDC;
HBITMAP oldBM;
char *myText = "CrackerJack";
memDC = CreateCompatibleDC(NULL);
oldBM = (HBITMAP)SelectObject(memDC, hBmp);
font1 = CreateFont(-13, 0, 0, 0, 400, FALSE, FALSE, FALSE, 1, 400, 0, 0, 0, "Tahoma Bold");
oldFnt = (HFONT)SelectObject(memDC, font1);
TextOut(memDC, 30, 30, myText, strlen(myText));
SelectObject(memDC, oldBM);
SelectObject(memDC, oldFnt);
DeleteObject(font1);
DeleteDC(memDC);
}
simon
modified on Thursday, November 27, 2008 12:52 AM
|
|
|
|
|
Thanks for the quick reply. I appreciate it.
I have put your function as such:
void DrawOnBitmap(HBITMAP hBmp)
{
HFONT oldFnt, font1;
HDC memDC;
HBITMAP oldBM;
char *myText = "Testing";
memDC = CreateCompatibleDC(NULL);
oldBM = (HBITMAP)SelectObject(memDC, hBmp);
font1 = CreateFont(-13, 0, 0, 0, 400, FALSE, FALSE, FALSE, 1, 400, 0, 0, 0, "Tahoma Bold");
oldFnt = (HFONT)SelectObject(memDC, font1);
TextOut(memDC, 30, 30, myText, strlen(myText));
m_Placemat.SetBitmap(oldBM);
SelectObject(memDC, oldBM);
SelectObject(memDC, oldFnt);
DeleteObject(oldBM);
DeleteObject(oldFnt);
DeleteDC(memDC);
}
void OnTest()
{
HBITMAP hbitmap = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP3));
DrawOnBitmap(hbitmap);
}
What I get back is a black BMP.
The point when
oldBM = (HBITMAP)SelectObject(memDC, hBmp);
was executed, the BMP turned entirely black (when i tried to output at that point). I think when the CreateCompatibleDC is executed with a null, there creates a problem. I tried passing in the DC I used previously but it doesn't make a difference.
When I run
m_Placemat.SetBitmap(hBmp);
instead, I get a black box with a smaller grey box in the centre.
I have tried integrating your Font section into mine:
void CCaptureAndDisplayDlg::OnTest()
{
HBITMAP hbitmap = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP3));
BITMAP bitm;
GetObject( hbitmap, sizeof(BITMAP), &bitm );
long width=bitm.bmWidth;
long height=bitm.bmHeight;
BITMAPINFO bmInfo;
CBitmap FinalBMP;
int rtn=0;
memset(&bmInfo.bmiHeader,0,sizeof(BITMAPINFOHEADER));
bmInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bmInfo.bmiHeader.biWidth=width;
bmInfo.bmiHeader.biHeight=height;
bmInfo.bmiHeader.biPlanes=1;
bmInfo.bmiHeader.biBitCount=24;
HDC pDC = ::GetDC(0);
HDC TmpDC=CreateCompatibleDC(pDC);
BYTE *pbase;
HBITMAP TmpBmp=CreateDIBSection(pDC, &bmInfo,DIB_RGB_COLORS,(void**)&pbase,0,0);
HGDIOBJ TmpObj=SelectObject(TmpDC,TmpBmp);
HDC dcBmp=CreateCompatibleDC(TmpDC);
HGDIOBJ TmpObj2 = SelectObject(dcBmp,hbitmap);
BitBlt(TmpDC,0,0,width,height,dcBmp,0,0,SRCCOPY);
SelectObject(TmpDC,TmpObj2);
DeleteDC(dcBmp);
char *myText = "Testing";
HFONT oldFnt, font1;
font1 = CreateFont(-13, 0, 0, 0, 400, FALSE, FALSE, FALSE, 1, 400, 0, 0, 0, "Tahoma Bold");
oldFnt = (HFONT)SelectObject(TmpDC, font1);
TextOut(TmpDC, 330, 230, myText, strlen(myText));
m_Placemat.SetBitmap(TmpBmp);
SelectObject(TmpDC, oldFnt);
DeleteObject(oldFnt);
DeleteDC(TmpDC);
}
This way I get my BMP displayed, but still no text.
This has to be my understanding of the whole workings of this BMP thing going wonky because i don't know why it doesn't work on my system.
Am I doing this all wrong?
|
|
|
|
|
Hi there.
Just looking at your implementation of void DrawOnBitmap(HBITMAP hBmp) , I notice that you set the bitmap image of the m_Placemat to be the image that _was_ originally selected into the temporary DC - This image has had nothing done to it, so it should be black. Following selecting this empty bitmap, you still do the call to DeleteObject(oldBM)...
I suggest you try changing
m_Placemat.SetBitmap(oldBM); to
m_Placemat.SetBitmap(hBmp);
Since you want to display the loaded bitmap with the added text in your program, and not the (since deleted) empty bitmap that belonged to the temporary DC we created.
Please, let me know if I've been unclear/it doesn't work for you.
|
|
|
|
|
I've tried that.
Running
m_Placemat.SetBitmap(hBmp);
results in a black image with an grey centre (the grey of a standard Dialog window, so i think it's hollow)
I can output text on a blank window like this:
void CGDITest::OnDraw(CDC* pDC)
{
CGDITestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDC->TextOut(50, 42, "Testing", 13);
}
so I don't think it's my VC 6's SDK, I must be doing something wrong...
Can I use the plain pDC->TextOut to get an array of bits that make up the string? Without trying to write it on a standard white bitmap?
I'm really lost now.
And Thank you again for replying.
|
|
|
|
|
JJeffrey wrote: I've tried that.
Oops! Sorry i missed that the first time round.
Hmmmm, I've no idea about pDC->TextOut as I'm away from my other pc.
Something else to consider, are the loaded and created bitmaps of comparable bits/pixel - sorry, it's all i can think of right now.
|
|
|
|
|
Thanks for your time. I appreciate it. Maybe I should try from a different angle or something.
I don't see how, personally, the bits/pixel ratio could affect the writing of the text. If I use a smaller resolution picture (less colour palette size), I don't see why text would suddenly be able to be written.
Anyway, thanks. Hope my boss doesn't kill me for not getting this.... :p
|
|
|
|
|
|
Thank you, Thank you... THANK. YOU!
Your program is fantastic. I see where it went wrong now, the SelectObject s were causing the HDC s to overwrite with old images as they weren't done properly (I think...). I delayed it till later in the code.
For the record, this code works:
void CCaptureAndDisplayDlg::OnTest()
{
HBITMAP hbitmap = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1));
BITMAP bitm;
GetObject( hbitmap, sizeof(BITMAP), &bitm );
long width=bitm.bmWidth;
long height=bitm.bmHeight;
BITMAPINFO bmInfo;
int rtn=0;
memset(&bmInfo.bmiHeader,0,sizeof(BITMAPINFOHEADER));
bmInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bmInfo.bmiHeader.biWidth=width;
bmInfo.bmiHeader.biHeight=height;
bmInfo.bmiHeader.biPlanes=1;
bmInfo.bmiHeader.biBitCount=24;
HDC pDC = ::GetDC(0);
HDC TmpDC=CreateCompatibleDC(pDC);
BYTE *pbase;
HBITMAP TmpBmp=CreateDIBSection(pDC, &bmInfo,DIB_RGB_COLORS,(void**)&pbase,0,0);
HGDIOBJ TmpObj=SelectObject(TmpDC,TmpBmp);
HDC dcBmp=CreateCompatibleDC(TmpDC);
HGDIOBJ TmpObj2 = SelectObject(dcBmp,hbitmap);
BitBlt(TmpDC,0,0,width,height,dcBmp,0,0,SRCCOPY);
char *myText = "Testing";
HFONT oldFnt, font1;
font1 = CreateFont(-13, 0, 0, 0, 400, FALSE, FALSE, FALSE, 1, 400, 0, 0, 0, "Tahoma Bold");
oldFnt = (HFONT)SelectObject(TmpDC, font1);
TextOut(TmpDC, 30, 30, myText, strlen(myText));
SelectObject(TmpDC,TmpObj2);
m_Placemat.SetBitmap(TmpBmp);
SelectObject(TmpDC, oldFnt);
DeleteObject(oldFnt);
DeleteDC(TmpDC);
DeleteDC(dcBmp);
}
Great Program you have there....
Jeffrey
modified on Friday, November 28, 2008 1:40 AM
|
|
|
|
|
I've written a custom GUI library for creating GUI's for my VST plugins. I would love to use MFC, but I've never gotten them to play together nicely (long story).
Anyway, the GUI library has come together well, but there are a few anomalies to work out. The one I'm dealing with right now is a problem with the cursor.
In VST, the host asks the plugin to create a child window representing the plugin's UI. It's the host's job to display the window. All of this works well, but what I've noticed is that if I move the cursor from outside my GUI window to inside the window, sometimes the cursor shape doesn't change. For example, it may get stuck with the resizing handle image.
I've noticed that this problem doesn't occur in a standalone app I made with my library. I've made sure when registering the GUI window class that I used the obligatory: ::LoadCursor(instance, IDC_ARROW).
There's way too much code for me to post anything here. So I'm just looking for some general clues.
EDIT: Strange. I changed the code to ::LoadCursor(NULL, IDC_ARROW), and it fixed the problem.
modified on Wednesday, November 26, 2008 3:09 PM
|
|
|
|
|
Leslie Sanford wrote: EDIT: Strange. I changed the code to ::LoadCursor(NULL, IDC_ARROW), and it fixed the problem.
Not so strange if you have a look at documentation [^]:
To use one of the predefined cursors, the application must set the hInstance parameter to NULL
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Not so strange if you have a look at documentation
Yup. I should have checked out the documenation. Having worked with the Windows API this long, I should have realized that simply taking a function at face value and passing it what it appears to want is not always the correct thing to do.
Sorry if that sounds like whining. It's just that these special cases, these gotchas, add up over time to a point of making an API hard to use.
|
|
|
|
|
Reading the documentation is the best way to avoid headaches, when dealing with Windows API .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
seems like i just got aome people angry at me by not posting code the right way in the message
Just read up on the tag/pretag so......
My question is do I have to put a start tag / end tag on every line of code that
I post ?????? in addtion when I tag my code do I have to check the ignore HTML box or
not
thankx and sorry
|
|
|
|
|
put your code between pre tags.
|
|
|
|
|
Maximilien wrote: /// some coed
Got something else on your mind?
|
|
|
|
|
You should use the code block button or, manually, the <pre> tags, this way:
<code><pre></code>
<code></pre></code>
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
ForNow wrote: seems like i just got aome people angry
Angry? We may have had some fun with you but I didn't see anyone getting angry. Did I miss something?
led mike
|
|
|
|
|