View Full Version : C++ Prob
doncraig
April 18, 2007, 11:03 PM
how to attach a dialog to a button in microsoft visual c++
icymint3
April 19, 2007, 03:07 PM
you dont say if u using MFC, WIN32 API, or VC with CLR Extensions...
for WIN32 API it should look something like ... this
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdParam, int iCmdShow)
{
static char szAppName[] = "Kodeci";
HWND hWnd;
MSG msg;
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wndclass.lpfnWndProc = WindowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = NULL;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wndclass);
hWnd = CreateWindow(szAppName, // window class name
"Just test This", // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL); // creation parameters
ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);
while ( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
HDC hDC;
UINT cxClient, cyClient;
LRESULT CALLBACK WindowProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
switch (iMsg)
{
case WM_CREATE:
hDC = GetDC(hWnd);
// ....
return 0;
case WM_PAINT:
BeginPaint(hWnd, &ps);
// some gui stuff
EndPaint(hWnd, &ps);
return 0;
case WM_COMMAND:
switch( LOWORD(wParam) )
{
case ID_OF_MY_BUTTON:
//handle it here
return 0;
}
break;
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
return 0;
case WM_DESTROY:
ReleaseDC(hWnd, hDC);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, iMsg, wParam, lParam);
}
doncraig
April 23, 2007, 09:30 PM
kool, my bad, im using the mfc (exe), made three dialogs want to attach two dialogs a main dialog screen with three buttons
crosswire
April 24, 2007, 12:54 AM
"microsoft visual c++" ... which version you using?
If it is 6, then double click the button (in Dialog mode) and you would be directed to code. Write
MyDialog dia;
dia.DoModal();
You can check the return of DoModal like dialog result OK, Cancel, etc
DoModal contains the message loop eg.
while ( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Maybe the same as the above "2nd post"
In VC7, depending on the version eg Proffessional, Standard, the dialog editor may be absent
I think you may know this but for post info: the dialog class in a subset of the window class/structure
doncraig
April 24, 2007, 01:27 PM
if a do that then it going to tell me undeclared identifier and no claass found
doncraig
April 25, 2007, 01:11 PM
have another prob, i want to import the dialogs into word, how do i go about doing that?
crosswire
April 25, 2007, 04:41 PM
if a do that then it going to tell me undeclared identifier and no claass found
How about posting your code
have another prob, i want to import the dialogs into word, how do i go about doing that?
If you want to run or edit the C++ dialog in Word, then you would need a converter program. I am not aware of any that can convert MFC C++ code to VB code, nor any that can convert .rc (mfc dialog file) to .doc or whatever data vb uses in Word to store dialog info. You can search for these converters still.
One option is to port the code to VB if that is not to much trouble. I have Word XP 2002 and it allows dialog coding and uses VB.
Example, click View->Toolbars-->Control Tool Bar. Add a button from the toolbar to the word document. Double click the button and type the code
Private Sub CommandButton1_Click()
MsgBox "Hello"
End Sub
Another option is to create an active X control in MFC with your dialog class and then insert into word. The control can be programed.
icymint3
April 25, 2007, 05:26 PM
if using this thing in word was what u wanted to do in the first place... then Visual Basic for Applications (VBA) u shoulda use from scratch.
dont b scared by the name is just a watered down version of vb6, most of ur code from vb6 will work anyway. and it way easier than programming a GUI in vc++ for starters.
sking
April 25, 2007, 06:34 PM
have another prob, i want to import the dialogs into word, how do i go about doing that?
Import the dialogs into word? Why, what are you trying to do?
doncraig
April 30, 2007, 11:42 PM
ohh sorry, that was a typo, i wanted to print screen it, thought you could just get them in word without doing that, i already got them print screened into word
T-Zero
May 4, 2007, 11:04 AM
Need help, i am basically new to C++, know a bit about it but my system has problems running microsoft visual 6 so i have to use the new microsoft visual 8 (2005), the feature are totaly different from that of (mv6) and i am now confused, i need to start from scratch, i have been using various c++ book (2005 versions) and all they do is confused me more am lost, i need help from some one who has experience with Microsoft visual 2005
sking
May 4, 2007, 12:46 PM
Need help, i am basically new to C++, know a bit about it but my system has problems running microsoft visual 6 so i have to use the new microsoft visual 8 (2005), the feature are totaly different from that of (mv6) and i am now confused, i need to start from scratch, i have been using various c++ book (2005 versions) and all they do is confused me more am lost, i need help from some one who has experience with Microsoft visual 2005
First, I think you should start a new thread for this.
Second, please be more specific about what help you want.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.