|
The only idea is to use GetDC() on a window.
I have some question. What are you trying to achieve? Is the window from your app or are you attempting to draw on some other app? To let people help you better, you have to respond to these questions.
|
|
|
|
|
Thanks For Ur Valuable Reply.I appreciate ur time for My Questions.
Let me tell you Again:
There Is an application which is used to draw some images or like that.
But Now,I want to draw Some Transparent Images By Using Draw method Of Graphics(From GDI PLUS).NOw to Draw On that Device Context,I need that DC.And the file in Which I am working doesnt contain any OnDraw or either am not able to get Handle of r that Display Window.
ANd Yes, Window is from my own application.
Regards
Yogesh
|
|
|
|
|
In win32 you can retrieve the active MDI child of a window with this:
HWND active_mdi_child = (HWND)SendMessage(hMainWnd, WM_MDIGETACTIVE, 0, 0);
In MFC you can also retrieve the active MDI child using this code:
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd*)pFrame->GetActiveFrame();
CMyView *pView = (CMyView*)pChild->GetActiveView();
I just copy-pasted this from here[^].
In MFC depending on your window structure you have to draw on either pChild or pView . You can get the HWND by writing either pChild->m_hWnd or pView->m_hWnd . From now on you can use the GetDC() or GetWindowDC() to obtain a HDC to the drawable surface and you have to release it using ReleaseDC() when you are done, but this is the general win32 approach. In MFC you can use the corresponding methods of the pChild or pView objects so you don't have to mess with win32 functions and the m_hWnd member (pChild->GetDC() , pChild->ReleaseDC(...) and so on).
BUT, if you want to draw your image somewhere, then you need a control (maybe a custom control) that draws the image on its own surface every time its WndProc() is called with WM_PAINT event, otherwise your image stays there only till the next time windows asks the window to redraw a part of its surface. It would be better to put a ON_WM_PAINT() to the message map of your view and then implement the OnPaint() method in your view, this guarantees that your image is always drawn there when it is needed. In pure win32 you have to make a control that is subclassed somehow (there are many solutions to this) if order to handle its WM_PAINT event, this is a bit more difficult then just adding an entry in a message map in MFC. If you have to do this then search for "window subclassing" with google.
|
|
|
|
|
Hi All,
I am getting Flicker for Toolbar which is Owner Drawn. I am creating a SplitterWnd which has a Form View in Right Side Pane and TreeView in Leftside Pane. There is no flicer in FormView but when i am trying to Disable the Icons in CToolbar for some Condition it is some times Continuosly Flickers i could not understand why this happens.
Code
----
void CMainFrame::OnUpdateFileDeleteplans(CCmdUI* pCmdUI)
{
bool bExecuteSQLWin = false;
if(bExecuteSQLWin)
pCmdUI->Enable(FALSE);
else
pCmdUI->Enable();
pCmdUI->Enable(CheckOpenPlans()); --> Here i added with a Function CheckOpenPlans().......>==========//
}
bool CMainFrame::CheckOpenPlans()
{
CMDIChildWnd* MyWnd = NULL;
MyWnd = MDIGetActive();
CView* pView = NULL;
if(MyWnd != NULL)
{
pView = (CView*) MyWnd->GetActiveView();
if((pView->IsKindOf(RUNTIME_CLASS(CSelectQueryView)) || pView->IsKindOf(RUNTIME_CLASS(OpenPlansTreeView))))
return false;
else
return true;
}
return true;
}
|
|
|
|
|
The OnUpdateToolbarButton() functions will be called automatically by the MFC rotuing during the OnIdle action of your application.
The flicker is probbaly caused by you changing the state of the button(s) multiple times in the same update call.
Try and make sure you only have a single call to Enable(). Assign the desired state to a local variable, compute any required changes in the variable and then call pCmdUI->Enable(variable). By the looks of it you may well be getting a call to Enable with false and true sequentially.
If you vote me down, my score will only get lower
|
|
|
|
|
Hi Roger,
Thank You Very Much for giving me a solution.
Thanks & Regards,
Uday.
|
|
|
|
|
Hello Everybody,
I am new to C programming not yet even C++ experienced. I am following instructions Beginning C (from novice to Professional) Forth Edition from Ivor Horton. I am working on Program and 7.14.
I am compiling with Visual Studio 2010 Express and NetBeans 6.9.1
The program compiles without errors or warnings with NetBeans.
I really like the VS 2010 Express package because of the ease of looking at locals and would like to know more about VS 2010 Ex. This is why I come to you.
This programs has:
#include <stdbool.h> for a header and
bool sorted = false; for a declaration.
I get errors building the program in VS 2010 Ex. the stdbool.h header is not in any sub folder of the main VS 2010 Ex. directory.
I tried to build it as a cpp and c file and same results.
I found a stdbool.h from the Bloodshed DevC++ or Bloodshed and that did not work.
I downloaded the pdf of C99 standard for c dated 2005 could not understand how to make the 6 lines of code to work correctly. seemed way to advance for a begginer.
I tried using #include <windows.h> that was recommended from a user here at codeproject.com.
I have created a small program just to test bool true and false pulled from Program 7.14 of the C programming book I am learning from.
I made this:
#include <stdio.h>
int main(void)
{
int false = 0;
int true = 1;
int i = 0;
int bool = false;
char sorted = ' ';
sorted = false;
return 0;
}
but as you experience will see that false will not be zero but rather a decimal of 32
Nothing worked.
HELP!! Please..
rarael
|
|
|
|
|
Hi,
Visual Studio is capable of building C programs as well as C++ programs.
The distinction between C and C++ by default is made based on the file extension (.c versus .cpp).
In C, I have never seen or needed a stdbool.h header file (I've used dozens of C compilers for all kinds of microprocessors).
Most C programs I ever wrote had
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
for starters. That was sufficient to get the symbols TRUE and FALSE predefined (note the upper-case in C, not in C++).
Basically, one of those header files contains:
#define FALSE 0
#define TRUE 1
BTW: I must advice against confusing names for variables; in your snippet that would be true, false, bool as those sound like something special but really aren't. C has no actual bool type (other languages do), so whenever you need a boolean value, you normally use a numeric type, mostly an int .
Finally, I see only one way your code will ever hold or show a value of 32: the space character has a value of 0x20, that is 32 in decimal. So "sorted" will be 32, but nothing else will.
Hope this helps.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Sunday, December 19, 2010 11:18 PM
|
|
|
|
|
Thank you very much!
I took your insight and experience and applied them. Thank you very much again.
It worked out great. Just had to put the sorted = false; to the bottom of all
the declarations and had no errors or warnings in the build. All the things I tried through searches, a
build would recommend to change the string function (strcpy) to another string function.
I really appreciate the help and insight. I was getting frustrated with
google searching and the dead ends that resulted in many forums.
I changed this from the book:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define BUFFER_LEN 100 /* Length of input buffer */
#define NUM_P 100 /* maximum number of strings */
int main(void)
{
char buffer[BUFFER_LEN];
char *pS[NUM_P] = { NULL };
char *pTemp = NULL;
int i = 0;
bool sorted = false;
int last_string = 0;
To this from your experience:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFFER_LEN 100 /* Length of input buffer */
#define NUM_P 100 /* maximum number of strings */
#define false 0
#define true 1
int main(void)
{
char buffer[BUFFER_LEN];
char *pS[NUM_P] = { NULL };
char *pTemp = NULL;
int i = 0;
int sorted = 0;
int last_string = 0;
sorted = false;
|
|
|
|
|
You're welcome. I'm glad you're making progress.
I have two comments:
1.
if it is C code you want, you should use TRUE and FALSE (upper-case), and those really should already have be defined (as in #define...) somewhere in one of those header files for you, no need to do it yourself inside your code. You can define your own constants, and use those, but that would deviate from the conventions, and might become confusing later on. BTW: Under no condition you should change the values representing TRUE/true and FALSE/false!
2.
I don't know the book you are referring to; if it is causing too much hassle, I'd suggest you look for another one. On the other hand, if you made it to chapter 7, it may be just fine. Or maybe you skipped a lot?
|
|
|
|
|
improper use a #define in one of the files
|
|
|
|
|
Just to add to Luc's answer - stdbool.h is only defined for C99, Microsoft's C compiler only understands C89 and shows no sign of ever becoming C99 compliant.
Cheers,
Ash
|
|
|
|
|
I'm trying to get a VC 2008 project running on a Windows 7 machine. It builds fine but won't run. The worst thing is that it doesn't even give any useful message about what's wrong, just "The application was unable to start properly". The same project works fine on a Windows XP machine. The development environments are exactly the same on both machines. Anyone have any ideas?
|
|
|
|
|
Download dependency walker; it may be that you need to distribute files such as msvcp100.dll and msvcr100.dll (if you used VC 2010)
|
|
|
|
|
Thanks for the answer.
It's funny, dependancy walker is telling me there are missing dlls on the system that's working. Just suspicious how accurate it is.
|
|
|
|
|
Yes, it does that on my machine too. You have to compare the list on the one that is working to the one that's not.
|
|
|
|
|
I have designed a owner draw button. But I need to calculate the width of button at run time according to text length.
So I used
<br />
m_Font.CreateFont(15,0,0,0,FW_BOLD ,0,0,0,0,0,0,0,0,_T("Arial"));<br />
SetFont(&m_Font);<br />
dc->GetTextMetrics(&tm);<br />
int nWidth = tm.tmAveCharWidth + tm.tmInternalLeading;<br />
nWidth = nWidth * m_szCaption.GetLength(); <br />
<br />
But I am not gwtting the correct width. Whats wrong, pleas guide......
|
|
|
|
|
use CDC::DrawText with the DT_CALCRECT flag to compute the effective RECT the text will take.
go have a look at the documentation.
Watched code never compiles.
|
|
|
|
|
in the following code:
double a;
sscanf_s("0.02", "%.2f", &a);
i get Invalid Input Format exception! what's the problem? i also tried %1.2f and %4.2f, but no change.
|
|
|
|
|
double a;
sscanf_s("0.02", "%lf", &a);
|
|
|
|
|
yes, it works. but since the format is the same as what is used for showing the property (CMFCPropertyGridProperty::m_strFormatDouble), i've to specify the number of digits i want to be shown after the decimal point, so i can't use %lf.
|
|
|
|
|
Your format string is wrong, see here[^] for the width specification in sscanf .
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
thank u, i read it, but i couldn't figure out what to choose as format for a floating point variable with read part of variable digits number and floating point of always two digits.
|
|
|
|
|
As it says in the link I showed: The width field is a positive decimal integer controlling the maximum number of characters to be read for that field. No more than width characters are converted and stored at the corresponding argument. Fewer than width characters may be read if a whitespace character (space, tab, or newline) or a character that cannot be converted according to the given format occurs before width is reached.
So in your case you would code it as
double a;
sscanf_s("0.02", "%4f", &a);
since you have 4 characters in your string value. The number of digits after the decimal point is largely irrelevant for floats and doubles when reading in, it is only important when formatting for output. In general you are better off not specifying a width value as it can lead to loss of precision in input strings - unless your users all know exactly what format to use for their input data.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
thank u for the description. the problem is that format strings for sprintf_s and sscanf_s differ. for sscanf_s including a . in format causes Invalid Input Format exception in anyway. as u mentioned, the input string is read by the number of bytes specified in the format b4 f and the chunk string is processed to be converted into a float. while in sprintf_s . has meaning. %4.2f for example means that the output string must contain at least 4 characters and exactly 2 digits after decimal point. if it be needed this may increase, eg. %2.2f or even %1.2f lead to the same output 0.02 or even 123456789.00.
this is while we has only one format for a grid ctrl, not two separate formats, one for sprintf_s and one for sscanf_s. as i said b4 it's stored in CMFCPropertyGridProperty::m_strFormatFloat or CMFCPropertyGridProperty::m_strFormatDouble. this uniqueness in the source of the problem.
now what's ur suggestion?
i've also another problem. spin ctrls are designated for integral fields. i need to attach a spin ctrl to a field of type float. for example when i've 12.34 in the field it may get 11.34 or 13.34 with up and down arrows. if i specify it to limit to 20, after 19.34 it gets 20.00 with arrow up. when i specify low limit of zero it gets 0.00 after 0.34 with arrow down. the spin ctrl doesn't expect the input field to be a float while it doesn't contrast with its behavior.
so the summary of the two problems are:
1. how can i overcome the uniqueness of floating point fields format in a grid ctrl which is both used for showing and inputting?
2. how can i have a spin ctrl for a floating point input field?
thx
|
|
|
|