anup007star
September 29th, 2008, 07:06 AM
Hi I am stuck with the following code need guidance.
Well I want to make a normal property sheet using Win API in C . This is my code and the error associated with it:
// myprog.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <windows.h>
#include "resource.h"
#include "prsht.h"
#pragma comment (lib, "comctl32")
#define ID_APPLY_NOW 0x3021 //the ID for the Apply button (i use Spy++)
#define MAX_LOADSTRING 100
//BOOL m_bSheet = FALSE
// Globals
PROPSHEETHEADER m_PropSheet;
PROPSHEETPAGE m_psp[2];
LOGFONT m_lfont;
LRESULT CALLBACK SheetProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Page1DlgProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Page2DlgProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInst;
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szWindowClass[MAX_LOADSTRING];
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// Property Sheet
memset(m_psp, 0, sizeof(m_psp));
memset(&m_PropSheet, 0, sizeof(m_PropSheet));
m_psp[0].dwSize = sizeof(PROPSHEETPAGE);
m_psp[0].dwFlags = PSP_DEFAULT|PSP_USETITLE;
m_psp[0].hInstance = hInstance;
m_psp[0].pszTemplate = (LPCSTR)IDD_PROPPAGE_MEDIUM;
m_psp[0].pszTitle = TEXT("Page 1");
m_psp[0].pfnDlgProc = (DLGPROC)Page1DlgProc;
//m_psp[0].pfnCallback = (LPFNPSPCALLBACK) Page1Proc;
m_psp[1].dwSize = sizeof(PROPSHEETPAGE);
m_psp[1].dwFlags = PSP_USETITLE;
//m_psp[1].dwFlags = PSP_USETITLE | PSP_USECALLBACK;
//m_psp[1].dwFlags = PSP_USECALLBACK;
m_psp[1].hInstance = hInstance;
m_psp[1].pszTemplate = (LPCSTR)IDD_PROPPAGE_MEDIUM1;
m_psp[1].pszTitle = TEXT("Page 2");
m_psp[1].pfnDlgProc = (DLGPROC)Page2DlgProc;
//m_psp[1].pfnCallback = (LPFNPSPCALLBACK) Page2Proc;
m_PropSheet.dwSize = sizeof(PROPSHEETHEADER);
m_PropSheet.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK;
//m_PropSheet.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_MODELESS;
m_PropSheet.hInstance = hInstance;
m_PropSheet.pszCaption =(LPSTR)"Property Sheet";
m_PropSheet.nPages = 2;
m_PropSheet.nStartPage = 0;
m_PropSheet.ppsp = (LPCPROPSHEETPAGE)m_psp;
m_PropSheet.pfnCallback = (PFNPROPSHEETCALLBACK) SheetProc;
MSG msg;
HACCEL hAccelTable;
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_MIKE, szWindowClass, MAX_LOADSTRING);
//MyRegisterClass(hInstance);
//if (!InitInstance (hInstance, nCmdShow)) return FALSE;
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MYPROG));
while (GetMessage(&msg, NULL, 0, 0)) {
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
MessageBox(0,TEXT("Code Guru is the best"),TEXT("~00~"),MB_ICONEXCLAMATION);
return (int)msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYPROG));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_MYPROG);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
//TCHAR szHello[MAX_LOADSTRING];
//LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDM_OPTION_PROPS:
m_PropSheet.hwndParent = hWnd;
/*if(!m_bSheet)
m_bSheet = PropertySheet(&m_PropSheet);*/
PropertySheet(&m_PropSheet);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
/*case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;*/
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// callback function for property sheet
LRESULT CALLBACK SheetProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
//ShowWindow(GetDlgItem(hDlg, IDOK), SW_HIDE);
//ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_HIDE);
//if you want to hide the Apply but i did not hide it to do more things
//ShowWindow(GetDlgItem(hDlg, ID_APPLY_NOW), SW_HIDE);
//PropSheet_GetTabControl(hDlg) \
// (HWND)SNDMSG(hDlg, PSM_GETTABCONTROL, 0, 0)
// set a bold font to the tabs
m_lfont.lfHeight = 8;
m_lfont.lfWeight = FW_NORMAL;
m_lfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
//strcpy(m_lfont.lfFaceName, TEXT("Arial"));
HWND hTabCtrl = PropSheet_GetTabControl(hDlg);
SendMessage(hTabCtrl, WM_SETFONT, (WPARAM)&m_lfont, 0);
switch( message )
{
case WM_INITDIALOG:
return TRUE;
}
return FALSE;
}
// Dialog proc for page 1
LRESULT CALLBACK Page1DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
/*SetWindowText(GetDlgItem(hDlg, IDC_EDITX), "A * cos(u) * cos(v)");
SetWindowText(GetDlgItem(hDlg, IDC_EDITY), "A * sin(u) * cos(v)");
SetWindowText(GetDlgItem(hDlg, IDC_EDITZ), "A * sin(v)");*/
return TRUE;
}
case WM_COMMAND:
//if the textboxes are changed
if (HIWORD(wParam) == EN_CHANGE) {
SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0);
}
break;
case WM_NOTIFY:
switch (((NMHDR FAR *) lParam)->code) {
case PSN_APPLY:
//user clicked APPLY
MessageBox(hDlg, TEXT("Apply"), TEXT("Page1"), 0);
break;
case PSN_KILLACTIVE:
//user clicked OK or selected another page
MessageBox(hDlg, TEXT("OK"), TEXT("Page1"), 0);
break;
}
}
return FALSE;
}
LRESULT CALLBACK Page2DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_NOTIFY:
switch (((NMHDR FAR *) lParam)->code) {
case PSN_APPLY:
//user clicked APPLY
MessageBox(hDlg, TEXT("Apply"), TEXT("Page2"), 0);
break;
case PSN_KILLACTIVE:
//user clicked OK or selected another page
MessageBox(hDlg, TEXT("OK"), TEXT("Page2"), 0);
break;
}
}
return FALSE;
}// Page2DlgProc(HWND, UINT WPARAM, LPARAM)
=====================================================
The above code when i compiled gave the folloewing error:
1>------ Build started: Project: myprog, Configuration: Debug Win32 ------
1>Compiling...
1>myprog.cpp
1>c:\documents and settings\anuhoho\my documents\visual studio 2008\projects\myprog\myprog\myprog.cpp(40) : error C2440: '=' : cannot convert from 'LPCSTR' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\anuhoho\my documents\visual studio 2008\projects\myprog\myprog\myprog.cpp(50) : error C2440: '=' : cannot convert from 'LPCSTR' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\anuhoho\my documents\visual studio 2008\projects\myprog\myprog\myprog.cpp(59) : error C2440: '=' : cannot convert from 'LPSTR' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://c:\Documents and Settings\anuhoho\My Documents\Visual Studio 2008\Projects\myprog\myprog\Debug\BuildLog.htm"
1>myprog - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =====================================================
I am stuck out here.Please i need some guidance .If anyone can help me out ,it will be so kind of you.
Well I want to make a normal property sheet using Win API in C . This is my code and the error associated with it:
// myprog.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <windows.h>
#include "resource.h"
#include "prsht.h"
#pragma comment (lib, "comctl32")
#define ID_APPLY_NOW 0x3021 //the ID for the Apply button (i use Spy++)
#define MAX_LOADSTRING 100
//BOOL m_bSheet = FALSE
// Globals
PROPSHEETHEADER m_PropSheet;
PROPSHEETPAGE m_psp[2];
LOGFONT m_lfont;
LRESULT CALLBACK SheetProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Page1DlgProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Page2DlgProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInst;
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szWindowClass[MAX_LOADSTRING];
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// Property Sheet
memset(m_psp, 0, sizeof(m_psp));
memset(&m_PropSheet, 0, sizeof(m_PropSheet));
m_psp[0].dwSize = sizeof(PROPSHEETPAGE);
m_psp[0].dwFlags = PSP_DEFAULT|PSP_USETITLE;
m_psp[0].hInstance = hInstance;
m_psp[0].pszTemplate = (LPCSTR)IDD_PROPPAGE_MEDIUM;
m_psp[0].pszTitle = TEXT("Page 1");
m_psp[0].pfnDlgProc = (DLGPROC)Page1DlgProc;
//m_psp[0].pfnCallback = (LPFNPSPCALLBACK) Page1Proc;
m_psp[1].dwSize = sizeof(PROPSHEETPAGE);
m_psp[1].dwFlags = PSP_USETITLE;
//m_psp[1].dwFlags = PSP_USETITLE | PSP_USECALLBACK;
//m_psp[1].dwFlags = PSP_USECALLBACK;
m_psp[1].hInstance = hInstance;
m_psp[1].pszTemplate = (LPCSTR)IDD_PROPPAGE_MEDIUM1;
m_psp[1].pszTitle = TEXT("Page 2");
m_psp[1].pfnDlgProc = (DLGPROC)Page2DlgProc;
//m_psp[1].pfnCallback = (LPFNPSPCALLBACK) Page2Proc;
m_PropSheet.dwSize = sizeof(PROPSHEETHEADER);
m_PropSheet.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK;
//m_PropSheet.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_MODELESS;
m_PropSheet.hInstance = hInstance;
m_PropSheet.pszCaption =(LPSTR)"Property Sheet";
m_PropSheet.nPages = 2;
m_PropSheet.nStartPage = 0;
m_PropSheet.ppsp = (LPCPROPSHEETPAGE)m_psp;
m_PropSheet.pfnCallback = (PFNPROPSHEETCALLBACK) SheetProc;
MSG msg;
HACCEL hAccelTable;
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_MIKE, szWindowClass, MAX_LOADSTRING);
//MyRegisterClass(hInstance);
//if (!InitInstance (hInstance, nCmdShow)) return FALSE;
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MYPROG));
while (GetMessage(&msg, NULL, 0, 0)) {
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
MessageBox(0,TEXT("Code Guru is the best"),TEXT("~00~"),MB_ICONEXCLAMATION);
return (int)msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYPROG));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_MYPROG);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
//TCHAR szHello[MAX_LOADSTRING];
//LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDM_OPTION_PROPS:
m_PropSheet.hwndParent = hWnd;
/*if(!m_bSheet)
m_bSheet = PropertySheet(&m_PropSheet);*/
PropertySheet(&m_PropSheet);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
/*case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;*/
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// callback function for property sheet
LRESULT CALLBACK SheetProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
//ShowWindow(GetDlgItem(hDlg, IDOK), SW_HIDE);
//ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_HIDE);
//if you want to hide the Apply but i did not hide it to do more things
//ShowWindow(GetDlgItem(hDlg, ID_APPLY_NOW), SW_HIDE);
//PropSheet_GetTabControl(hDlg) \
// (HWND)SNDMSG(hDlg, PSM_GETTABCONTROL, 0, 0)
// set a bold font to the tabs
m_lfont.lfHeight = 8;
m_lfont.lfWeight = FW_NORMAL;
m_lfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
//strcpy(m_lfont.lfFaceName, TEXT("Arial"));
HWND hTabCtrl = PropSheet_GetTabControl(hDlg);
SendMessage(hTabCtrl, WM_SETFONT, (WPARAM)&m_lfont, 0);
switch( message )
{
case WM_INITDIALOG:
return TRUE;
}
return FALSE;
}
// Dialog proc for page 1
LRESULT CALLBACK Page1DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
/*SetWindowText(GetDlgItem(hDlg, IDC_EDITX), "A * cos(u) * cos(v)");
SetWindowText(GetDlgItem(hDlg, IDC_EDITY), "A * sin(u) * cos(v)");
SetWindowText(GetDlgItem(hDlg, IDC_EDITZ), "A * sin(v)");*/
return TRUE;
}
case WM_COMMAND:
//if the textboxes are changed
if (HIWORD(wParam) == EN_CHANGE) {
SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0);
}
break;
case WM_NOTIFY:
switch (((NMHDR FAR *) lParam)->code) {
case PSN_APPLY:
//user clicked APPLY
MessageBox(hDlg, TEXT("Apply"), TEXT("Page1"), 0);
break;
case PSN_KILLACTIVE:
//user clicked OK or selected another page
MessageBox(hDlg, TEXT("OK"), TEXT("Page1"), 0);
break;
}
}
return FALSE;
}
LRESULT CALLBACK Page2DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_NOTIFY:
switch (((NMHDR FAR *) lParam)->code) {
case PSN_APPLY:
//user clicked APPLY
MessageBox(hDlg, TEXT("Apply"), TEXT("Page2"), 0);
break;
case PSN_KILLACTIVE:
//user clicked OK or selected another page
MessageBox(hDlg, TEXT("OK"), TEXT("Page2"), 0);
break;
}
}
return FALSE;
}// Page2DlgProc(HWND, UINT WPARAM, LPARAM)
=====================================================
The above code when i compiled gave the folloewing error:
1>------ Build started: Project: myprog, Configuration: Debug Win32 ------
1>Compiling...
1>myprog.cpp
1>c:\documents and settings\anuhoho\my documents\visual studio 2008\projects\myprog\myprog\myprog.cpp(40) : error C2440: '=' : cannot convert from 'LPCSTR' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\anuhoho\my documents\visual studio 2008\projects\myprog\myprog\myprog.cpp(50) : error C2440: '=' : cannot convert from 'LPCSTR' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\anuhoho\my documents\visual studio 2008\projects\myprog\myprog\myprog.cpp(59) : error C2440: '=' : cannot convert from 'LPSTR' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://c:\Documents and Settings\anuhoho\My Documents\Visual Studio 2008\Projects\myprog\myprog\Debug\BuildLog.htm"
1>myprog - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =====================================================
I am stuck out here.Please i need some guidance .If anyone can help me out ,it will be so kind of you.