Windows GUI - problem with dialog box

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2004
Posts: 55
Reputation: apcxpc is an unknown quantity at this point 
Solved Threads: 0
apcxpc's Avatar
apcxpc apcxpc is offline Offline
Junior Poster in Training

Windows GUI - problem with dialog box

 
0
  #1
Apr 9th, 2006
Hi all

I'm experimenting with win API gui stuff, and I've run into a problem with dialog boxes. Currently, when the "Show DialogBox" option in the menu is pressed, the dialog box pops up.

I then need for this dialog box to be draggable/moveable, and to "hide" when its close button is pressed. (and then pop up again when requested etc.)

The problem is that when the dialog box pops up, I lose control over the initial window, as well as the new dialogbox window. The only thing that remains "active" is the button within the dialog box.

Any help would be much appreciated.


  1. #include "windows.h"
  2. #define IDC_DIALOG1 9090
  3. #define IDC_HELLOBUTTON 9091
  4.  
  5. IDC_DIALOG1 DIALOGEX 0, 0, 100, 100
  6. STYLE WS_POPUP | WS_CAPTION
  7. EXSTYLE WS_EX_TOOLWINDOW
  8. CAPTION "Options Dialog"
  9. FONT 7, "MS Sans Serif"
  10. BEGIN
  11. PUSHBUTTON "&Hello World",IDC_HELLOBUTTON, 10,10,80,30
  12. END
  1. #include <windows.h>
  2. #include <iostream>
  3. #define IDC_DIALOG1 9090
  4. #define IDC_HELLOBUTTON 9091
  5. #define ID_OPTIONS_SHOW 9092
  6.  
  7. using namespace std;
  8.  
  9. /* Declare Windows procedure */
  10.  
  11.  
  12. HWND testDialog = NULL;
  13.  
  14. LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
  15. BOOL CALLBACK ToolDlgProc(HWND, UINT, WPARAM, LPARAM);
  16. /* Make the class name into a global variable */
  17. char szClassName[ ] = "WindowsApp";
  18. int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
  19.  
  20. {
  21. HWND hwnd; /* This is the handle for our window */
  22. MSG messages; /* Here messages to the application are saved */
  23. WNDCLASSEX wincl; /* Data structure for the windowclass */
  24.  
  25. /* The Window structure */
  26. wincl.hInstance = hThisInstance;
  27. wincl.lpszClassName = szClassName;
  28. wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
  29. wincl.style = CS_DBLCLKS; /* Catch double-clicks */
  30. wincl.cbSize = sizeof(WNDCLASSEX);
  31.  
  32. /* Use default icon and mouse-pointer */
  33. wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  34. wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  35. wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
  36. wincl.lpszMenuName = NULL; /* No menu */
  37. wincl.cbClsExtra = 0; /* No extra bytes after the window class */
  38. wincl.cbWndExtra = 0; /* structure or the window instance */
  39. /* Use light-gray as the background of the window */
  40. wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
  41.  
  42. /* Register the window class, if fail quit the program */
  43. if(!RegisterClassEx(&wincl)) return 0;
  44.  
  45. /* The class is registered, let's create the program*/
  46. hwnd = CreateWindowEx(
  47. 0, /* Extended possibilites for variation */
  48. szClassName, /* Classname */
  49. "Windows App", /* Title Text */
  50. WS_OVERLAPPEDWINDOW, /* default window */
  51. CW_USEDEFAULT, /* Windows decides the position */
  52. CW_USEDEFAULT, /* where the window ends up on the screen */
  53. 544, /* The programs width */
  54. 375, /* and height in pixels */
  55. HWND_DESKTOP, /* The window is a child-window to desktop */
  56. NULL, /* No menu */
  57. hThisInstance, /* Program Instance handler */
  58. NULL /* No Window Creation data */
  59. );
  60.  
  61. /* Make the window visible on the screen */
  62. ShowWindow(hwnd, nFunsterStil);
  63. /* Run the message loop. It will run until GetMessage( ) returns 0 */
  64. while(GetMessage(&messages, NULL, 0, 0))
  65. {
  66. /* Translate virtual-key messages into character messages */
  67. TranslateMessage(&messages);
  68. /* Send message to WindowProcedure */
  69. DispatchMessage(&messages);
  70. }
  71.  
  72. /* The program return-value is 0 - The value that PostQuitMessage( ) gave */
  73. return messages.wParam;
  74. }
  75.  
  76. /* This function is called by the Windows function DispatchMessage( ) */
  77. LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  78. {
  79. switch (message) /* handle the messages */
  80. {
  81. case WM_DESTROY:
  82. PostQuitMessage(0); /* send a WM_QUIT to the message queue */
  83. break;
  84.  
  85. case WM_COMMAND:
  86. {
  87. switch(LOWORD(wParam)) //contains the ID of the control that sent message
  88. {
  89. case ID_OPTIONS_SHOW:
  90. cout << "clicked options-show";
  91. ShowWindow(testDialog, SW_SHOW);
  92. }
  93. }
  94.  
  95.  
  96. case WM_CREATE:
  97. {
  98. HMENU hMenu, hSubMenu;
  99. hMenu = CreateMenu();
  100. hSubMenu = CreatePopupMenu();
  101. AppendMenu(hSubMenu, MF_STRING, ID_OPTIONS_SHOW, "&Show DialogBox");
  102. AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Options");
  103. SetMenu(hwnd, hMenu);
  104. testDialog = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDC_DIALOG1),hwnd, ToolDlgProc);
  105. if(testDialog != NULL)
  106. ShowWindow(testDialog, SW_HIDE);
  107.  
  108. else
  109. cout << endl << "testDialog is null!" << endl;
  110.  
  111. }
  112. default: /* for messages that we don't deal with */
  113. return DefWindowProc(hwnd, message, wParam, lParam);
  114. }
  115. return 0;
  116. }
  117.  
  118.  
  119. BOOL CALLBACK ToolDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  120. {
  121. switch (message) /* handle the messages */
  122. {
  123.  
  124. case WM_DESTROY:
  125. ShowWindow(testDialog, SW_HIDE); /* send a WM_QUIT to the message queue */
  126. break;
  127. case WM_COMMAND:
  128. switch(LOWORD(wParam))
  129. {
  130. case IDC_HELLOBUTTON:
  131. cout << endl << "You clicked the button!" << endl;
  132. }
  133. break;
  134.  
  135. default: /* for messages that we don't deal with */
  136. return DefWindowProc(hwnd, message, wParam, lParam);
  137. }
  138. return 0;
  139. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 55
Reputation: apcxpc is an unknown quantity at this point 
Solved Threads: 0
apcxpc's Avatar
apcxpc apcxpc is offline Offline
Junior Poster in Training

Re: Windows GUI - problem with dialog box

 
0
  #2
Apr 9th, 2006
... nevermind, got it working. :cheesy:
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Windows GUI - problem with dialog box

 
0
  #3
Apr 9th, 2006
Well what was the problem?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 55
Reputation: apcxpc is an unknown quantity at this point 
Solved Threads: 0
apcxpc's Avatar
apcxpc apcxpc is offline Offline
Junior Poster in Training

Re: Windows GUI - problem with dialog box

 
0
  #4
Apr 9th, 2006
well ... mainly that I was calling DefWindowProc() from within the dialogbox's callback function, which messed things up. :-|
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 23
Reputation: wamuti is an unknown quantity at this point 
Solved Threads: 1
wamuti wamuti is offline Offline
Newbie Poster

Re: Windows GUI - problem with dialog box

 
0
  #5
Jan 10th, 2008
I read somewhere, the real programmers are the C language programmers. I belive that given the structure of C but you also are a real programmer if you are actually using win API. Why not try MFC? Its alot easier.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC