Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 1st, 2008, 1:41 PM   #1
Viper187
Newbie
 
Join Date: Jun 2008
Posts: 2
Rep Power: 0 Viper187 is on a distinguished road
Need help getting an API app started/working

I've been programming in C, VB6, PHP, etc for a long time, but I was always too lazy to learn how to write C apps with GUIs. Now I decided to try my hand at it, and I'm kind of stumped. I use Dev-C++ and this code is compiling fine, but it refuses to run. I get the error: "Could not create main dialog"

If I can get something going to start with, figuring out how to access each control shouldn't be very hard. I should hopefully be able to just Google for anything I get hung up on.

ELFedit.c:
c Syntax (Toggle Plain Text)
  1.  
  2. #include "ELFedit.h"
  3.  
  4. BOOL CALLBACK MainCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  5. LOGFONT lf;
  6.  
  7. switch(uMsg) {
  8. case WM_INITDIALOG:
  9.  
  10. //setup font
  11. hFont = (HFONT)SendMessage(hwndDlg, WM_GETFONT, 0, 0);
  12. GetObject(hFont, sizeof(LOGFONT), &lf);
  13. strcpy(lf.lfFaceName,"Courier");
  14. hNewFont = CreateFontIndirect(&lf);
  15.  
  16. SendDlgItemMessage(hwndDlg,101,WM_SETFONT,(WPARAM)hNewFont,FALSE);
  17. SendDlgItemMessage(hwndDlg,102,WM_SETFONT,(WPARAM)hNewFont,FALSE);
  18. SendDlgItemMessage(hwndDlg,103,WM_SETFONT,(WPARAM)hNewFont,FALSE);
  19.  
  20. //set text limits
  21. SendDlgItemMessage(hwndDlg,101,EM_SETLIMITTEXT,(TEXTSIZE-1),0);
  22. SendDlgItemMessage(hwndDlg,103,EM_SETLIMITTEXT,3,0);
  23.  
  24. //tick checkbox
  25. CheckDlgButton(hwndDlg,401,BST_CHECKED);
  26.  
  27.  
  28. break;
  29. case WM_CLOSE:
  30. case WM_QUIT:
  31. // gcncryptKill();
  32. break;
  33. case WM_COMMAND:
  34. switch(HIWORD(wParam)) {
  35. case BN_CLICKED:
  36. switch(LOWORD(wParam)) {
  37. case 201: //Decrypt
  38. // DecryptParseList();
  39. break;
  40. case 202: //Encrypt
  41. // EncryptParseList();
  42. break;
  43. case 301: //Close
  44. // gcncryptKill();
  45. break;
  46. case 302: //Clear (input)
  47. SetDlgItemText(hwndDlg,101,"");
  48. break;
  49. case 303: //Clear (output)
  50. SetDlgItemText(hwndDlg,102,"");
  51. break;
  52. case 401: //Game ID:
  53. // SendDlgItemMessage(hwndDlg,103,EM_SETREADONLY,dogameid^1,0);
  54. // EnableWindow(GetDlgItem(hwndDlg,501),dogameid);
  55. break;
  56. }
  57. break;
  58. }
  59. break;
  60. }
  61. return FALSE;
  62. }
  63.  
  64. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) {
  65. MSG msg;
  66. RECT wndRect,dskRect;
  67. int w,h;
  68.  
  69. ghInstance = hInstance;
  70. hWindow = CreateDialog(ghInstance,"MAIN",NULL,MainCallB);
  71. if (!hWindow) {
  72. MessageBox(NULL, "Could not create main dialog", "ERROR", MB_ICONERROR | MB_OK);
  73. return 0;
  74. }
  75.  
  76. //load and set dialog icons
  77. iWindow = LoadIcon(ghInstance,"ICON");
  78. SendMessage(hWindow,WM_SETICON,ICON_BIG,(LPARAM)iWindow);
  79. SendMessage(hWindow,WM_SETICON,ICON_SMALL,(LPARAM)iWindow);
  80.  
  81. //change title bar to include version number
  82. SetWindowText(hWindow, TITLEBAR);
  83.  
  84. //center dialog on screen
  85. GetWindowRect(hWindow,&wndRect);
  86. GetWindowRect(GetDesktopWindow(),&dskRect);
  87. w = (wndRect.right-wndRect.left);
  88. h = (wndRect.bottom-wndRect.top);
  89. MoveWindow(hWindow,((dskRect.right/2)-(w/2)),((dskRect.bottom/2)-(h/2)),w,h,TRUE);
  90.  
  91. //display dialog
  92. ShowWindow(hWindow,ncmdshow);
  93. UpdateWindow(hWindow);
  94.  
  95. while (hWindow) {
  96. if (GetMessage(&msg,NULL,0,0)) {
  97. TranslateMessage(&msg);
  98. DispatchMessage(&msg);
  99. }
  100. }
  101.  
  102. return msg.wParam;
  103. }

ELFedit.h:
c Syntax (Toggle Plain Text)
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. //win32 stuff
  7. #define TITLEBAR "ELF Edit v0.0"
  8. #define TEXTSIZE 32767
  9.  
  10. HWND hWindow;
  11. HINSTANCE ghInstance;
  12. HICON iWindow;
  13. HFONT hFont,hNewFont;

Main.rc:
c Syntax (Toggle Plain Text)
  1. #include <windows.h>
  2. #define MAIN 1000
  3. #define ELFDIS 1001
  4.  
  5. MAIN DIALOGEX 6,6,409,243
  6. CAPTION "ELF Edit"
  7. FONT 8,"MS Sans Serif",0,0,0
  8. STYLE WS_VISIBLE|WS_OVERLAPPEDWINDOW
  9. BEGIN
  10. CONTROL "",ELFDIS,"ListBox",WS_CHILD|WS_VISIBLE|WS_TABSTOP|LBS_NOINTEGRALHEIGHT|LBS_HASSTRINGS|LBS_NOTIFY,16,22,378,201,WS_EX_CLIENTEDGE
  11. END
Viper187 is offline   Reply With Quote
Old Jun 2nd, 2008, 5:28 PM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
Re: Need help getting an API app started/working

You should return TRUE in your callback function when you handle a message, this might be causing the problem, as Windows thinks you haven't handled the INITDIALOG message.
You can use GetLastError and FormatMessage after the CreateDialog call fails to get a more detailed error description, it might point you in the right direction.
The Dark is online now   Reply With Quote
Old Jun 3rd, 2008, 12:47 PM   #3
Viper187
Newbie
 
Join Date: Jun 2008
Posts: 2
Rep Power: 0 Viper187 is on a distinguished road
Re: Need help getting an API app started/working

I finally found a good tutorial to work from. http://www.winprog.org/tutorial/

Now I'd love it if someone could tell me how inline assemblers work. Is it possible to enable editing a single row in a listbox? Or is it some special grid/excel spreadsheet-like control?
Viper187 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
My DataBase App BstrucT Show Off Your Open Source Projects 13 Jul 29th, 2008 9:46 AM
voice chat app Brent Show Off Your Open Source Projects 9 Feb 25th, 2008 6:20 PM
Help compiling app titaniumdecoy C++ 2 Jan 17th, 2008 11:06 PM
Vb6 App from Access97 to Access2002 rednek Visual Basic 0 Nov 10th, 2007 4:50 PM
console app with wxWidgets rwm C++ 7 Sep 4th, 2007 9:44 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:50 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC