943,487 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 7563
  • C RSS
Mar 14th, 2003
0

GDI

Expand Post »
Hello fellow programmers,

I have a problem that I have been trying to figure out for a while now. I am trying to use the GDIPLUS library but am having troubles. To test this code as it is meant to be used, open a new solution in MSVC6.0 or 7.0. Open a Win32 project an make sure it is a hello world program. Then replace the .cpp program it creates for you with the following .cpp. Include the linker path for gdiplus.lib and gdiplus.h and you should be ready to compile. Now for the errors:

: error C2871: 'Gdiplus' : a namespace with this name does not exist
: error C2653: 'Gdiplus' : is not a class or namespace name

I am using the .NET version but have the same problem on MSVC6.0. This does not make sense because Gdiplus is a namespace. Here is the code

  1. // Sample.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include <gdiplus.h>
  5. #include <windows.h>
  6. #include "stdafx.h"
  7. #include "Sample.h"
  8. #define MAX_LOADSTRING 100
  9.  
  10. //using namespace Gdiplus; //added just to see what would happen.
  11.  
  12. ULONG_PTR gdiplusToken;
  13. Gdiplus::GdiplusStartupInput gdiplusStartupInput;
  14.  
  15. // Global Variables:
  16. HINSTANCE hInst; // current instance
  17. TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
  18. TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
  19.  
  20. // Forward declarations of functions included in this code module:
  21. ATOM MyRegisterClass(HINSTANCE hInstance);
  22. BOOL InitInstance(HINSTANCE, int);
  23. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  24. LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  25.  
  26. int APIENTRY _tWinMain(HINSTANCE hInstance,
  27. HINSTANCE hPrevInstance,
  28. LPTSTR lpCmdLine,
  29. int nCmdShow)
  30. {
  31. // TODO: Place code here.
  32. MSG msg;
  33. HACCEL hAccelTable;
  34.  
  35. // Initialize global strings
  36. LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  37. LoadString(hInstance, IDC_SAMPLE, szWindowClass, MAX_LOADSTRING);
  38. MyRegisterClass(hInstance);
  39.  
  40. // Perform application initialization:
  41. if (!InitInstance (hInstance, nCmdShow))
  42. {
  43. return FALSE;
  44. }
  45.  
  46. hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SAMPLE);
  47.  
  48. Gdiplus::GdiplusStartup(&gdiplusToken,&gdiplusStartupInput,NULL);
  49. // Main message loop:
  50. while (GetMessage(&msg, NULL, 0, 0))
  51. {
  52. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  53. {
  54. TranslateMessage(&msg);
  55. DispatchMessage(&msg);
  56. }
  57. Gdiplus::GdiplusShutdown(gdiplusToken);
  58.  
  59. }
  60.  
  61. return (int) msg.wParam;
  62. }
  63.  
  64.  
  65.  
  66. //
  67. // FUNCTION: MyRegisterClass()
  68. //
  69. // PURPOSE: Registers the window class.
  70. //
  71. // COMMENTS:
  72. //
  73. // This function and its usage are only necessary if you want this code
  74. // to be compatible with Win32 systems prior to the 'RegisterClassEx'
  75. // function that was added to Windows 95. It is important to call this function
  76. // so that the application will get 'well formed' small icons associated
  77. // with it.
  78. //
  79. ATOM MyRegisterClass(HINSTANCE hInstance)
  80. {
  81. WNDCLASSEX wcex;
  82.  
  83. wcex.cbSize = sizeof(WNDCLASSEX);
  84.  
  85. wcex.style = CS_HREDRAW | CS_VREDRAW;
  86. wcex.lpfnWndProc = (WNDPROC)WndProc;
  87. wcex.cbClsExtra = 0;
  88. wcex.cbWndExtra = 0;
  89. wcex.hInstance = hInstance;
  90. wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SAMPLE);
  91. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  92. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  93. wcex.lpszMenuName = (LPCTSTR)IDC_SAMPLE;
  94. wcex.lpszClassName = szWindowClass;
  95. wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
  96.  
  97. return RegisterClassEx(&wcex);
  98. }
  99.  
  100. //
  101. // FUNCTION: InitInstance(HANDLE, int)
  102. //
  103. // PURPOSE: Saves instance handle and creates main window
  104. //
  105. // COMMENTS:
  106. //
  107. // In this function, we save the instance handle in a global variable and
  108. // create and display the main program window.
  109. //
  110. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  111. {
  112. HWND hWnd;
  113.  
  114. hInst = hInstance; // Store instance handle in our global variable
  115.  
  116. hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  117. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  118.  
  119. if (!hWnd)
  120. {
  121. return FALSE;
  122. }
  123.  
  124. ShowWindow(hWnd, nCmdShow);
  125. UpdateWindow(hWnd);
  126.  
  127. return TRUE;
  128. }
  129.  
  130. //
  131. // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
  132. //
  133. // PURPOSE: Processes messages for the main window.
  134. //
  135. // WM_COMMAND - process the application menu
  136. // WM_PAINT - Paint the main window
  137. // WM_DESTROY - post a quit message and return
  138. //
  139. //
  140. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  141. {
  142. int wmId, wmEvent;
  143. PAINTSTRUCT ps;
  144. HDC hdc;
  145.  
  146. switch (message)
  147. {
  148. case WM_COMMAND:
  149. wmId = LOWORD(wParam);
  150. wmEvent = HIWORD(wParam);
  151. // Parse the menu selections:
  152. switch (wmId)
  153. {
  154. case IDM_ABOUT:
  155. DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
  156. break;
  157. case IDM_EXIT:
  158. DestroyWindow(hWnd);
  159. break;
  160. default:
  161. return DefWindowProc(hWnd, message, wParam, lParam);
  162. }
  163. break;
  164. case WM_PAINT:
  165. hdc = BeginPaint(hWnd, &ps);
  166. ////////////////////THE ONLY CODE THAT I HAVE ADDED OTHER THAN HEADER INCLUDES
  167. Gdiplus::Graphics gs(hdc);
  168. Gdiplus::Image image(L"misc0001.tif");
  169. gs.DrawImage(&image,0,0);
  170. EndPaint(hWnd, &ps);
  171. ////////////////////////////////////////////////////////////////////////////// EndPaint(hWnd, &ps);
  172. break;
  173. case WM_DESTROY:
  174. PostQuitMessage(0);
  175. break;
  176. default:
  177. return DefWindowProc(hWnd, message, wParam, lParam);
  178. }
  179. return 0;
  180. }
  181.  
  182. // Message handler for about box.
  183. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  184. {
  185. switch (message)
  186. {
  187. case WM_INITDIALOG:
  188. return TRUE;
  189.  
  190. case WM_COMMAND:
  191. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  192. {
  193. EndDialog(hDlg, LOWORD(wParam));
  194. return TRUE;
  195. }
  196. break;
  197. }
  198. return FALSE;
  199. }

If anyone could help me figure out why I am getting this error I would greatly appreciate it. There might be a bunch of other problems with the code, but it is just practice with GDI+.

Seriously thankful,
Kendal
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gvector is offline Offline
1 posts
since Mar 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: need programmers
Next Thread in C Forum Timeline: Spider websearch





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC