943,940 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3476
  • C++ RSS
Mar 15th, 2005
0

nid help in using dialog box

Expand Post »
i have a sample program,can someone help to find the error of this program or someone to correct this program coz i don't know what is the error of this program

this is the sample program of mine

C++ Syntax (Toggle Plain Text)
  1. #include<windows.h>
  2. #include<string.h>
  3. #include<strstrea.h>
  4. #include"mydialog.h"
  5. void main()
  6. {
  7. LONG FAR PASCAL _export WindowFunc(HWND hwnd, unsigned message,
  8. WORD wParam, LONG lParam);
  9. BOOL FAR PASCAL _export DialogFunc(HWND hdwnd, unsigned message,
  10. WORD wParam, LONG lParam);
  11. char szWinName[] = "MyWin";
  12.  
  13. HANDLE hInst;
  14.  
  15. int PASCAL WinMain(HANDLE hThisInst, HANDLE hPrevInst,
  16. LPSTR lpszArgs, int nWinMode);
  17.  
  18.  
  19. }
  20. {
  21. HWND hwnd;
  22. MSG msg;
  23. WNDCLASS wcl;
  24. HANDLE hAccel;
  25.  
  26. if(!hPrevInst){
  27.  
  28. wcl.hInstance = hThisInst;
  29. wcl.lpszClassName = szWinName;
  30. wcl.lpfnWndProc =WindowFunc;
  31. wcl.style = NULL;
  32.  
  33. wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  34. wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
  35. wcl.lpszMenuName = "MYMENU";
  36.  
  37. wcl.cbClsExtra = 0;
  38. wcl.cbWndExtra = 0;
  39.  
  40. wcl.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  41.  
  42. if(!RegisterClass (&wcl)) return 0;
  43. }
  44. hwnd=CreateWindow (
  45. szWinName,
  46. "Dialog Boxes",
  47. WS_OVERLAPPEDWINDOW,
  48. CW_USEDEFAULT,
  49. CW_USEDEFAULT,
  50. CW_USEDEFAULT,
  51. CW_USEDEFAULT,
  52. NULL,
  53. NULL,
  54. hThisInst,
  55. NULL
  56. );
  57. hAccel = LoadAccelerators(hThisInst, "MYMENU");
  58. hInst = hThisInst;
  59.  
  60. ShowWindow(hwnd, nWinMode);
  61.  
  62. while(GetMessage(&msg, NULL, 0, 0))
  63. {
  64. if(!TranslateAccelerator(hwnd, hAccel, &msg)) {
  65. TranslateMessage(&msg);
  66. DispatchMessage(&msg);
  67. }
  68. {
  69. return msg.wParam;
  70.  
  71.  
  72. long FAR PASCAL WindowFunc(HWND hwnd, WORD message, WORD wParam,
  73. LONG lParam)
  74. {
  75. FARPROC lpDlg;
  76.  
  77. int response;
  78.  
  79. switch(message) {
  80. case WM_COMMAND:
  81. switch(wParam) {
  82. case IDM_DIALOG1:
  83. lpDlg = MakeProcInstance ((FARPROC) DialogFunc, hInst);
  84. DialogBox(hInst,"MYDB", hwnd, lpDlg;
  85. FreeProcInstance(lpDlg);
  86. break;
  87. case IDM_DIALOG2:
  88. MessageBox(hwnd, "Not Implemented", "", MB_OK);
  89. break;
  90. case IDM_HELP:
  91. MessageBox(hwnd, "Not Impelemented", "HELP", MB_OK);
  92. break;
  93. }
  94. break;
  95. case WM_DESTROY:
  96. PostQuitMessage(0);
  97. break;
  98. }
  99.  
  100. return DefWindowProc(hwnd, message, wParam, lParam);
  101. }
  102.  
  103. BOOL FAR PASCAL DialogFunc(HWND hdwnd, unsigned message,
  104. WORD wParam, LONG lParam)
  105. {
  106.  
  107. switch(message){
  108. case WM_COMMAND:
  109. switch(wParam) {
  110. case IDCANCEL:
  111. EndDialog(hdwnd, NULL);
  112. return 1;
  113. case IDD_RED:
  114. MessageBox(hdwnd,"You Picked Red", "RED", MB_OK);
  115. return 1;
  116. case IDD_GREEN:
  117. MessageBox(hdwnd,"You Picked Green", "GREEN", MB_OK);
  118. return 1;
  119. }
  120. }
  121. return 0;
  122. }
Last edited by alc6379; Mar 15th, 2005 at 10:23 am. Reason: added [code] tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
iorisendoh is offline Offline
2 posts
since Sep 2004
Mar 15th, 2005
0

Re: nid help in using dialog box

What is the error? Right off hand I can see you are mixing two entry points. void main () & WinMain. WinMain is empty. There is an example of a sekeltal app in code snippets under cplusplus. Look at that one and it will give you a good idea how to correct yours.
Reputation Points: 47
Solved Threads: 17
Posting Whiz in Training
Tight_Coder_Ex is offline Offline
215 posts
since Feb 2005

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: Sorting
Next Thread in C++ Forum Timeline: C++ Reorder random numbers





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


Follow us on Twitter


© 2011 DaniWeb® LLC