Click here to Skip to main content
       

C / C++ / MFC

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
GeneralRe: SOLVED Casting structures - another basic questionmemberErudite_Eric2 Jan '13 - 7:13 
Yeah, you often get neted structs in Windows, with a base type at the start and other structs after that in memory, so there is lots of casting rom one type to another whcih is just to access the 'extended' data.
==============================
 
Nothing to say.

QuestionHow to count pages in PDF file using VC++membershanmugarajaa23 Dec '12 - 18:00 
Dear Friends,
I have 11thousand PDF file and I need to take a log of number page in each PDF document and I decided to make tool to read the number pages in each PDF document. Anyone can help me. I have VC6 and visual studio 2008.
 
Thanks and Regards,
S.Shanmga Raja
AnswerRe: How to count pages in PDF file using VC++mvpRichard MacCutchan23 Dec '12 - 22:04 
You need to get hold of one of the PDF libraries available on the internet, or use the documentation available on the Adobe website to write your own. You can then read your PDF files and get information about the content.
One of these days I'm going to think of a really clever signature.

AnswerRe: How to count pages in PDF file using VC++memberJijo.Raj26 Dec '12 - 23:29 
Hi Shanmuga,
 
As Richard suggested, you've to use some thirdparty PDF SDK/library to get the pdf page count.
 
One option would be - QuickPDF Library[^] which is a absolutly free.
You can use the api - DPLPageCount()[^] to get the page count.
 
Have a look at their samples(well documented) about how to initialize the library and use it.
Hope this helps.
 
Best Regards,
Jijo.
_____________________________________________________
 
http://weseetips.com[^] Visual C++ tips and tricks.

QuestionHow to implement C++ raw string literals in VIsual C++ 2010?memberFalconapollo22 Dec '12 - 18:03 
As you may already know, new string literals in C++ 11 can be expressed in a very flexible way.
 
R"..."; - in this code the can be pretty much everything and also no escape characters are needed. Any kind of parentheses can be used to delimit the end of string, Raw string literals are especially useful when defining regular expressions:
 
R"(I love those who yearn for the impossible. (Von Goethe, "Faust"))";
 
Blocks of text can be simply defined using equal occurrences of same characters:
 
R";***************************( ; TINY BASIC FOR INTEL 8080
; VERSION 2.0
; BY LI-CHEN WANG
; MODIFIED AND TRANSLATED
; TO INTEL MNEMONICS
; BY ROGER RAUSKOLB
; 10 OCTOBER, 1976
; @COPYLEFT
; ALL WRONGS RESERVED ) ;***************************";

 
More information can be found here http://en.wikipedia.org/wiki/C++0x#New_string_literals[^] (Wikipedia).
 
I want to implement it with C++ processor, here is what I have. Now double quotation marks are not supported, and I need to compete it like C++ 11. Can anyone help me?
 
#define STR(a) #a
#define R(var, re)  static char var##_[] = STR(re);\
const char * var = ( var##_[ sizeof(var##_) - 2] = '\0',  (var##_ + 1) );
 
You can use it like this:
 
R(re, "\w\d");//It's OK, no warnings.
 
The code is not friendly to use. So I want the feature like C++ 11 raw string literals.
 
PS: I'm using Visual C++ 2010, the new feature is not supported, I must implement it by myself.
Questionproblems returning/printing poinermemberdoughyi8u20 Dec '12 - 14:16 
I understand that the reason the ret variable will not print (it's at the end of the string when destination is passed) but can't figure out how to return destination out of the my_strcpy() function. I can make this work using array notation but not pointer arithmetic. Here's the code in question:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
char *my_strcpy(char *, const char *);
 
int
main()
{
	char *strA = "This is a string";
	char *strB;
	char *ret;
 
	strB = malloc(strlen(strA)+1);
	ret = my_strcpy(strB, strA);
	puts(ret);
	puts(strB);
	free(strB);
	return 0;
}
 
char *my_strcpy(char *destination, const char *source)
{
	while (*source != '\0')
	{
		*(destination++) = *(source++);
	}
	*destination = '\0';
	return destination;
}

AnswerRe: problems returning/printing poinermemberJochen Arndt20 Dec '12 - 21:15 
Just use a local variable for copying or save the value of destination in a local variable to be returned upon exit:
char *my_strcpy(char *destination, const char *source)
{
    char *ret = destination;
    while (*source != '\0')
    {
        *destination++ = *source++;
    }
    *destination = '\0';
    return ret;
}

AnswerRe: problems returning/printing poinermvpRichard MacCutchan20 Dec '12 - 22:47 
In addition to Jochen's comments, you also need to allocate some memory to strB before calling your copy function. The code above will be copying into some random place and probably crash.
One of these days I'm going to think of a really clever signature.

GeneralRe: problems returning/printing poinermemberJochen Arndt20 Dec '12 - 23:07 
He allocates memory using malloc(). You may have overlooked the line just above the copy call.
GeneralRe: problems returning/printing poinermvpRichard MacCutchan21 Dec '12 - 0:19 
Oops! D'Oh! | :doh:
One of these days I'm going to think of a really clever signature.

QuestionC++ ownerdrawfixed combobox "header"memberNoviceEx19 Dec '12 - 2:49 
Hi,
 
It seems that I have problem drawing ownerdrawfixed combo box, which is actually drawn in ownerdraw listbox control.
 
I am able to draw all items inside shown dropdown of combo box. But I can not draw anything to combo box "header".
 
1. What is actual message of drawing combobox "header" ? I got to conclusion that when itemID is -1 (after I call CB_SELECTSTRING) then it is "header" (Note: Seems that right rect is found in DRAWITEMSTRUCT) and I draw text than but nothing appears.
2. Currently I am trying to draw it after CB_SHOWDROPDOWN is set to true. Should it be done before that?
AnswerRe: C++ ownerdrawfixed combobox "header"memberjeron119 Dec '12 - 4:19 
I'm guessing, handle the WM_DRAWITEM message in the parent window, then check the CtlID
member of DRAWITEMSTRUCT to see it's the correct combobox control, if so check the itemState member to see if it is ODS_COMBOBOXEDIT, and if so, draw the edit box (I think the edit box is what you mean when you say "header")control of the combobox.
 
Hope it helps.
QuestionHow to make a project resolution independent.?membermbatra3118 Dec '12 - 23:56 
Hi,
 
I have one question regarding resolution. How to make a project created as a MFC dialog based application, resolution independent. I am using a number of images in our dialog based project. But the final display using images and controls is not resolution independent. To say if your PC screen resolution is different from the other, it will not properly display the dialog. Some of the part of dialog display will be cut-off.
 
How to make the same resolution independent, so that irrespective of the resolution of the device or screen size, display should be same.
 
Any help will be appreciated.
 
Also, what is the use of ActiveX controls in MFC.?
 

 
Regards,
Mbatra
AnswerRe: How to make a project resolution independent.?memberJochen Arndt19 Dec '12 - 0:29 
I assume that your dialog is created using a resource template.
 
The simple solution is to limit the size of the dialog to the minimum size of supported screen resolutions.
 
If your application must also run on small screens, you may add a second dialog template with smaller controls and smaller total size. Upon program start, choose the small template when necessary.
 
The complex solution would be making your dialog and some or all controls resizable. But this requires proper calculation for sizes and positions of all controls.
 
Regarding ActiveX
There is no need to use ActiveX controls if your application design can be done using the standard Windows and MFC controls. If you have special control requirements, you can build your own controls by using ActiveX or plain C++ code, or use existing controls that fit your requirements. Finally, it's up to you to decide to use ActiveX controls or not.
GeneralRe: How to make a project resolution independent.?membermbatra3119 Dec '12 - 0:39 
Hi,
 
Thanx for your reply.
It is not that my project will run on smaller screeens only. It may run on larger screens also.
Let me explain, I have windows 7 & my PC screen is of bigger size (vertically as well as horizantally) (bigger than a normal LCD display). if I run my project on my PC, I am not able to see the controls on the bottom of the dialog. if I run my project on any PC with windows XP and screen size is small, it will display it perfectly.
 
I want to make it like that all the controls should adjust them accordingly irrespective of the resolution or PC screen size.
 
Any help will be appreciated.
 

 

Regards,
Mbatra
GeneralRe: How to make a project resolution independent.?memberJochen Arndt19 Dec '12 - 0:52 
I'm confused now.
 
The display is OK on small screens but the bottom controls aren't visible on a big screen?
 
At least you should tell us about your dialog. Is it a template based CDialog or a CDHtmlDialog?
GeneralRe: How to make a project resolution independent.?membermbatra3119 Dec '12 - 1:25 
Hi,
 
its a template based CDialog.
 

Regards,
Mbatra
GeneralRe: How to make a project resolution independent.?memberJochen Arndt19 Dec '12 - 1:33 
But then I don't understand why portions are not visible on a big screen. Because with a template based CDialog the size of the dialog and sizes and positions of all controls are defined in the template. As long as nothing is changed by code, the dialog should be shown like in the resource editor. If the screen is larger than the dialog, your app should be opened with centered dialog. If the screen is too small, the right and/or bottom sides are clipped.
GeneralRe: How to make a project resolution independent.?membermbatra3119 Dec '12 - 1:44 
Hi,
 
Sorry for any confusion.
What I understand is, we are using images for all the controls, whether its a button, static control, slider control etc..... So i thought the image size will never change irrespective of the resolution or the size of the screen. Because image size will remain the same.
 
its a dialog based app, I also want to understand what makes it that when I open it on screens with different sizes, some controls at the bottom are not visible.
 

 

Regards,
Mbatra
GeneralRe: How to make a project resolution independent.?memberJochen Arndt19 Dec '12 - 2:06 
Even with images the sizes of the controls are usually not resolution dependant because this would require repositioning inside the dialog to avoid overlapping.
 
It seems that you are using non standard controls but custom ones. So you should have a look into the sources and/or the documentation of these custom controls to know what happens. You may also use the debugger to check if missing controls are created or not and get the sizes and positions of these controls (e.g. by calling GetWindowRect() and printing the values to the debug output window using TRACE).
AnswerRe: How to make a project resolution independent.?memberAlan Balkany19 Dec '12 - 4:25 
Design all your dialogs for the smallest resolution.
 
Then when your application runs, check the resolution and see how much extra space you have in the X and Y directions.
 
Divide this extra space among the controls in your dialog. The extra space shouldn't be divided equally -- Some controls benefit more from extra space than others. For example, a Static or Edit control wouldn't be helped by more Y-direction space, but a List Box would be able to show more items.
 
Likewise, some space between controls will appear better when extended than other space.
 
For each dialog, you can list the percentage of extra space you want to add to each control.
"Microsoft -- Adding unnecessary complexity to your work since 1987!"

QuestionASM with stams library of C ++memberGurunathkudalkar18 Dec '12 - 21:15 
C++ stams library
AnswerRe: ASM with stams library of C ++mvpCPallini18 Dec '12 - 22:19 
Wow, what an interesting post. Sleepy | :zzz:
Veni, vidi, vici.

Questionerror C2228 "must have class/struct/union"memberalaaan7318 Dec '12 - 4:55 
in Flight.h i have this prototype :
bool reserveSeat(Passenger psngr, bool smoker); 
and i have to do the implementation for it , i try to do it but i got an error :
"
error message :
task b\flight.cpp(15): error C2228: left of '.setPassportNumber' must have class/struct/union
1>type is ''unknown-type''
1> b\flight.cpp(16): error C2065: 'passenger' : undeclared identifier
1>b\flight.cpp(16): error C2228: left of '.setContactNumber' must have class/struct/union
1>type is ''unknown-type''
1> b\flight.cpp(17): error C2228: left of '.smokerSeat' must have class/struct/union

and here is my try
bool Flight::reserveSeat(Passenger psngr, bool smoker)
{
   Passenger.setPassengerName(psngr.getPassengerName());
   passenger.setPassportNumber(psngr.getPassportNumber());
   passenger.setContactNumber(psngr.getContactNumber());
   reservations.smokerSeat=smoker;
 
}

note that Flight have an object of Reservation and here's the Reservation constuctor :
Reservation.cpp
Reservation::Reservation(Passenger& psngr, bool smoke)
	
{
   passenger.setPassengerName(psngr.getPassengerName());
   passenger.setPassportNumber(psngr.getPassportNumber());
   passenger.setContactNumber(psngr.getContactNumber());
   smokerSeat=smoke;
}//end consreuctor 

 
and here's the whole Flight Header
 
#include "reservation.h"
#include "okReservation.h"
#include "waitReservation.h"
class Flight{
	
private:
	int waitingListMax;
	int seats;
	int seatsCount;
	Reservation** reservations;
	
public:
	Flight(int capacity, int waitingMax);
	bool reserveSeat(Passenger psngr, bool smoker);
	
	//Searches for the reservation with the given reservation number, and 	//deletes it. Uses the confirmReservation function if the reservation to be 	//deleted was an OK one 
	void cancelReservation(string resNum);
	
	//Deletes the given waiting reservation after creating a new OK reservation 	//for the same passenger. Returns a pointer to the newly created reservation
	okReservation confirmReservation(waitReservation* res); 
	void printWaitingList();
	void printReservationList();
 
	};

AnswerRe: error C2228 "must have class/struct/union"memberChris Losinger18 Dec '12 - 5:19 
alaaan73 wrote:
Passenger.setPassengerName(psngr.getPassengerName());
passenger.setPassportNumber(psngr.getPassportNumber());

 
as far as i can tell, you have not declared any variables named "Passenger" or "passenger".
 
reservations.smokerSeat=smoker;
you have declared reservations as a pointer to a pointer to a Reservation.
 
Reservation** reservations;
so you can't use "reservations.smokerSeat". you would have to declare it as:
Reservation reservations;
 
etc..

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid