bitmaps in C++ from 98 to xp
bitmaps in C++ from 98 to xp
when i was using windows 98, i was able to easily display bitmaps in my dialog boxes (using the resource editor provided with vc++6.0). then when i switched to xp, and every time i try to, it fails. i can make the spot on my dialog box for the bitmap, and in the resource editor it will show it as well. but when i run i execute it will not display it. where the bitmap should be there is just an empty area. I tried changing the exe to run in windows98[me=fstream]compatability but this did not fix it. funny thing it, my friends that still use 98 send me some progs that they made the same way and on their machine it will shwo up, but on mine it wont. and if i make a program that should display the bitmap on my machine it wont display but on theirs it will. anyone know why and how to fix?[/me]
Re:bitmaps in C++ from 98 to xp
here is what i have for a basic dialog box, (the dialog box was created in the resource editor): (a very simple prog excluding anything with true win32 api (i get the same problem using that too))
#include <windows.h> //this is for the Win32 API
#include "resource.h" //this is for our resources
//Precondition: Dialog is made somewhere
//Postcondition: handles all the messages sent from windows to my program
BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance, //the instance of our program
HINSTANCE hPrevInstance, //previous instances
LPSTR lpCmdLine, //any commandlines
int nCmdShow) //the # of command line params
{
//this turns our dialog into a window... so much better then
//all the CreateWindowEx() crap!
DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC) DlgProc, 0);
//return 0
return(0);
}
/Precondition: Dialog is made somewhere
//Postcondition: handles all the messages sent from windows to my program
BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch( uMsg )
{
//when the dialog gets initialized
case WM_INITDIALOG:
{
//initialize stuff
}break;
//if they perform any actions, IE: clicking, resizing, etc
case WM_COMMAND:
{
//if they clicked anything in the dialogs
switch( LOWORD( wParam ) )
{
}
}
}break;
//if they close the program
case WM_CLOSE:
{
//Quit the Program
PostQuitMessage(0);
}break;
}
//return the BOOL false
return FALSE;
}
The dailog box appears and all is fine, cept no bitmaps.
like i said, when i create it on xp, on 98 it shows the bitmaps but on xp it doesnt. i was thinking that maybe it was because i am using the resource editor instead of writing all the code myself. when i test what i have in vc everything looks fine but by running the exe there are not bitmaps.
#include <windows.h> //this is for the Win32 API
#include "resource.h" //this is for our resources
//Precondition: Dialog is made somewhere
//Postcondition: handles all the messages sent from windows to my program
BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance, //the instance of our program
HINSTANCE hPrevInstance, //previous instances
LPSTR lpCmdLine, //any commandlines
int nCmdShow) //the # of command line params
{
//this turns our dialog into a window... so much better then
//all the CreateWindowEx() crap!
DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC) DlgProc, 0);
//return 0
return(0);
}
/Precondition: Dialog is made somewhere
//Postcondition: handles all the messages sent from windows to my program
BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch( uMsg )
{
//when the dialog gets initialized
case WM_INITDIALOG:
{
//initialize stuff
}break;
//if they perform any actions, IE: clicking, resizing, etc
case WM_COMMAND:
{
//if they clicked anything in the dialogs
switch( LOWORD( wParam ) )
{
}
}
}break;
//if they close the program
case WM_CLOSE:
{
//Quit the Program
PostQuitMessage(0);
}break;
}
//return the BOOL false
return FALSE;
}
The dailog box appears and all is fine, cept no bitmaps.
like i said, when i create it on xp, on 98 it shows the bitmaps but on xp it doesnt. i was thinking that maybe it was because i am using the resource editor instead of writing all the code myself. when i test what i have in vc everything looks fine but by running the exe there are not bitmaps.
Re:bitmaps in C++ from 98 to xp
Try using a valid hInstance here:
Code: Select all
DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC) DlgProc, 0);
Re:bitmaps in C++ from 98 to xp
it's not using the resource editor, because I was able to get a bitmap to show up on XP no problems, and I used the Visual resource editor.
This probably won't solve your problem, but you know the general practice from a dialog procedure is to return TRUE if a message is handled and FALSE if it is not, right? In the case of WM_INITDIALOG, you return FALSE only if your program sets the input focus to one of the dialog's controls. If you want Windows to do that for you, you return TRUE.
It's also not necessary to post a quit message when your main window is a modal dialog box. You have no message loop that needs to terminate -- your program will automatically quit when it returns from DialogBoxParam (incidentally, if you're not using the last parameter of DialogBoxParam, you need only call DialogBox) -- DialogBoxParam returns when your dialog is closed.
This probably won't solve your problem, but you know the general practice from a dialog procedure is to return TRUE if a message is handled and FALSE if it is not, right? In the case of WM_INITDIALOG, you return FALSE only if your program sets the input focus to one of the dialog's controls. If you want Windows to do that for you, you return TRUE.
It's also not necessary to post a quit message when your main window is a modal dialog box. You have no message loop that needs to terminate -- your program will automatically quit when it returns from DialogBoxParam (incidentally, if you're not using the last parameter of DialogBoxParam, you need only call DialogBox) -- DialogBoxParam returns when your dialog is closed.
Re:bitmaps in C++ from 98 to xp
u were right Tom, that fixed the whole thing. makes sense too, since it needs to know where to place it. thanks a billion
Re:bitmaps in C++ from 98 to xp
one question remians tho, why would it still run fine on a 98 machine but not on xp? before i did this in 98 it would show the icons, but on xp it wont, but just by adding hInstance it works on xp?
Re:bitmaps in C++ from 98 to xp
NT, 2000 and XP do a lot more checking than 95/98/Millennium. As a result they're a lot more stable, but it does mean that a few programs which worked on 98 won't work on XP.